diff --git a/examples/chat-with-mdns/main.go b/examples/chat-with-mdns/main.go index b45e4fd44e..55c36adf40 100644 --- a/examples/chat-with-mdns/main.go +++ b/examples/chat-with-mdns/main.go @@ -116,6 +116,11 @@ func main() { peerChan := initMDNS(host, cfg.RendezvousString) for { // allows multiple peers to join peer := <-peerChan // will block until we discover a peer + if peer.ID > host.ID() { + // if other end peer id greater than us, don't connect to it, just wait for it to connect us + fmt.Println("Found peer:", peer, " id is greater than us, wait for it to connect to us") + continue + } fmt.Println("Found peer:", peer, ", connecting") if err := host.Connect(ctx, peer); err != nil {