Skip to content

Commit

Permalink
use the new mDNS service in the chat-with-mdns example
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Oct 5, 2021
1 parent 6139a3d commit 64693c6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/chat-with-mdns/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func main() {

fmt.Printf("\n[*] Your Multiaddress Is: /ip4/%s/tcp/%v/p2p/%s\n", cfg.listenHost, cfg.listenPort, host.ID().Pretty())

peerChan := initMDNS(ctx, host, cfg.RendezvousString)
peerChan := initMDNS(host, cfg.RendezvousString)

peer := <-peerChan // will block untill we discover a peer
fmt.Println("Found peer:", peer, ", connecting")
Expand Down
13 changes: 4 additions & 9 deletions examples/chat-with-mdns/mdns.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package main

import (
"context"
"time"

"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/peer"
mdns "github.com/libp2p/go-libp2p/p2p/discovery/mdns_legacy"

"github.com/libp2p/go-libp2p/p2p/discovery/mdns"
)

type discoveryNotifee struct {
Expand All @@ -19,12 +17,9 @@ func (n *discoveryNotifee) HandlePeerFound(pi peer.AddrInfo) {
}

//Initialize the MDNS service
func initMDNS(ctx context.Context, peerhost host.Host, rendezvous string) chan peer.AddrInfo {
func initMDNS(peerhost host.Host, rendezvous string) chan peer.AddrInfo {
// An hour might be a long long period in practical applications. But this is fine for us
ser, err := mdns.NewMdnsService(ctx, peerhost, time.Hour, rendezvous)
if err != nil {
panic(err)
}
ser := mdns.NewMdnsService(peerhost, rendezvous)

//register with service so that we get notified about peer discovery
n := &discoveryNotifee{}
Expand Down
1 change: 0 additions & 1 deletion examples/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,6 @@ github.com/warpfork/go-wish v0.0.0-20200122115046-b9ea61034e4a/go.mod h1:x6AKhvS
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 h1:EKhdznlJHPMoKr0XTrX+IlJs1LH3lyx2nfr1dOlZ79k=
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1/go.mod h1:8UvriyWtv5Q5EOgjHaSseUEdkQfvwFv1I/In/O2M9gc=
github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1:bopw91TMyo8J3tvftk8xmU2kPmlrt4nScJQZU2hE5EM=
github.com/whyrusleeping/mdns v0.0.0-20190826153040-b9b60ed33aa9 h1:Y1/FEOpaCpD21WxrmfeIYCFPuVPRCY2XZTWzTNHGw30=
github.com/whyrusleeping/mdns v0.0.0-20190826153040-b9b60ed33aa9/go.mod h1:j4l84WPFclQPj320J9gp0XwNKBb3U0zt5CBqjPp22G4=
github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 h1:E9S12nwJwEOXe2d6gT6qxdvqMnNq+VnSsKPgm2ZZNds=
github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7/go.mod h1:X2c0RVCI1eSUFI8eLcY3c0423ykwiUdxLJtkDvruhjI=
Expand Down

0 comments on commit 64693c6

Please sign in to comment.