Skip to content
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

mdns: don't discover ourselves #1661

Merged
merged 5 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions p2p/discovery/mdns/mdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ func (s *mdnsService) startResolver(ctx context.Context) {
continue
}
for _, info := range infos {
if info.ID == s.host.ID() {
continue
}
go s.notifee.HandlePeerFound(info)
}
}
Expand Down
30 changes: 6 additions & 24 deletions p2p/discovery/mdns/mdns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,6 @@ func (n *notif) GetPeers() []peer.AddrInfo {
return infos
}

func TestSelfDiscovery(t *testing.T) {
notif := &notif{}
hostID := setupMDNS(t, notif)
assert.Eventuallyf(
t,
func() bool {
var found bool
for _, info := range notif.GetPeers() {
if info.ID == hostID {
found = true
break
}
}
return found
},
5*time.Second,
5*time.Millisecond,
"expected peer to find itself",
)
}

func TestOtherDiscovery(t *testing.T) {
const n = 4

Expand All @@ -78,9 +57,12 @@ func TestOtherDiscovery(t *testing.T) {
hostIDs[i] = setupMDNS(t, notif)
}

containsAllHostIDs := func(ids []peer.ID) bool {
containsAllHostIDs := func(ids []peer.ID, currentHostID peer.ID) bool {
for _, id := range hostIDs {
var found bool
if currentHostID == id {
continue
}
for _, i := range ids {
if id == i {
found = true
Expand All @@ -97,13 +79,13 @@ func TestOtherDiscovery(t *testing.T) {
assert.Eventuallyf(
t,
func() bool {
for _, notif := range notifs {
for i, notif := range notifs {
infos := notif.GetPeers()
ids := make([]peer.ID, 0, len(infos))
for _, info := range infos {
ids = append(ids, info.ID)
}
if !containsAllHostIDs(ids) {
if !containsAllHostIDs(ids, hostIDs[i]) {
return false
}
}
Expand Down