Skip to content

Commit

Permalink
refactor: call NewStream from only one side
Browse files Browse the repository at this point in the history
  • Loading branch information
Halimao committed Dec 27, 2023
1 parent d996df5 commit 543ebae
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion examples/chat-with-mdns/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ func main() {
peerChan := initMDNS(host, cfg.RendezvousString)
for { // allows multiple peers to join
peer := <-peerChan // will block until we discover a peer
fmt.Println("Found peer:", peer, ", connecting")
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 connect us")
continue
}
fmt.Println("Found peer:", peer, ", connecting to it")

if err := host.Connect(ctx, peer); err != nil {
fmt.Println("Connection failed:", err)
Expand Down

0 comments on commit 543ebae

Please sign in to comment.