-
Notifications
You must be signed in to change notification settings - Fork 387
fix(kademlia): neighborhood rebroadcast sends wrong peer lists #5595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gacevicljubisa
wants to merge
2
commits into
master
Choose a base branch
from
fix/kademlia-neighborhood-rebroadcast
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+73
−13
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1779,6 +1779,67 @@ func TestAnnounceNeighborhoodToNeighbor(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| // TestRebroadcastNeighborhood checks that the periodic neighborhood gossip | ||
| // sends every neighbor exactly one message listing all the other neighbors. | ||
| func TestRebroadcastNeighborhood(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| var ( | ||
| conns int32 | ||
| base, kad, ab, disc, signer = newTestKademlia(t, &conns, nil, kademlia.Options{}) | ||
| ) | ||
|
|
||
| // With a storage radius of zero every connected peer is a neighbor. | ||
| kad.SetStorageRadius(0) | ||
|
|
||
| if err := kad.Start(context.Background()); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| testutil.CleanupCloser(t, kad) | ||
|
|
||
| const n = 4 | ||
| neighbors := make([]swarm.Address, n) | ||
| for i := range neighbors { | ||
| neighbors[i] = swarm.RandAddressAt(t, base, i) | ||
| connectOne(t, signer, kad, ab, neighbors[i], nil) | ||
| } | ||
| waitPeers(t, kad, n) | ||
|
|
||
| // Connecting peer j announces it to the j peers connected before it and | ||
| // introduces those j peers to it. Wait for all of that to land before | ||
| // clearing the recorder, so only the rebroadcast is measured. | ||
| wantAnnounces := 0 | ||
| for j := 1; j < n; j++ { | ||
| wantAnnounces += j + 1 | ||
| } | ||
| if err := spinlock.Wait(spinLockWaitTime, func() bool { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this package again... why not synctest and some other channel driven mocks or something? would really like to see this package go away from the codebase |
||
| return disc.Broadcasts() == wantAnnounces | ||
| }); err != nil { | ||
| t.Fatalf("waiting for announce broadcasts: got %d, want %d", disc.Broadcasts(), wantAnnounces) | ||
| } | ||
| disc.Reset() | ||
|
|
||
| kad.RebroadcastNeighborhood(context.Background()) | ||
|
|
||
| for _, addressee := range neighbors { | ||
| got, ok := disc.AddresseeRecords(addressee) | ||
| if !ok { | ||
| t.Fatalf("neighbor %s received no rebroadcast", addressee) | ||
| } | ||
| if len(got) != n-1 { | ||
| t.Fatalf("neighbor %s received %d peers, want %d", addressee, len(got), n-1) | ||
| } | ||
| if swarm.ContainsAddress(got, addressee) { | ||
| t.Fatalf("neighbor %s was told about itself", addressee) | ||
| } | ||
| for _, other := range neighbors { | ||
| if !other.Equal(addressee) && !swarm.ContainsAddress(got, other) { | ||
| t.Fatalf("neighbor %s was not told about %s", addressee, other) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestIteratorOpts(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would test here the method that creates the set of peers to be sent to every peer separately. just unit test that the sets are correct. then calling discovery is either trivial (and can go without a test at all) or very simple to test.