Skip to content

Commit

Permalink
examples: call NewStream from only one side (#2677)
Browse files Browse the repository at this point in the history
* refactor: call NewStream from only one side

* Update examples/chat-with-mdns/main.go

Co-authored-by: Sukun <[email protected]>

* Update examples/chat-with-mdns/main.go

Co-authored-by: Sukun <[email protected]>

---------

Co-authored-by: Sukun <[email protected]>
  • Loading branch information
Halimao and sukunrt authored Dec 29, 2023
1 parent 317c9ff commit 43be145
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/chat-with-mdns/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 43be145

Please sign in to comment.