Files
go-libp2p/examples/chat-with-mdns/mdns.go
Marten Seemann d2398ee4f2 quic: update quic-go to v0.37.5 (#2497)
* Small changes for new quic-go API

* Update quic-go dependency

* Manually bump Go version in go-test

* Don't run examples in Go 1.21 yet

Revert this commit when we release a new go-libp2p version compatible
with Go 1.21

* update quic-go to v0.37.5

---------

Co-authored-by: Marco Munizaga <git@marcopolo.io>
2023-08-17 00:26:56 -07:00

34 lines
836 B
Go

//go:build !go1.21
package main
import (
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/p2p/discovery/mdns"
)
type discoveryNotifee struct {
PeerChan chan peer.AddrInfo
}
// interface to be called when new peer is found
func (n *discoveryNotifee) HandlePeerFound(pi peer.AddrInfo) {
n.PeerChan <- pi
}
// Initialize the MDNS service
func initMDNS(peerhost host.Host, rendezvous string) chan peer.AddrInfo {
// register with service so that we get notified about peer discovery
n := &discoveryNotifee{}
n.PeerChan = make(chan peer.AddrInfo)
// An hour might be a long long period in practical applications. But this is fine for us
ser := mdns.NewMdnsService(peerhost, rendezvous, n)
if err := ser.Start(); err != nil {
panic(err)
}
return n.PeerChan
}