Skip to content

Commit 117fa6d

Browse files
committed
chore(dot/network): use mdns instead of mdns_legacy
1 parent 8af315b commit 117fa6d

File tree

1 file changed

+9
-24
lines changed

1 file changed

+9
-24
lines changed

dot/network/mdns.go

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,14 @@ package network
55

66
import (
77
"context"
8-
"time"
98

109
"github.com/ChainSafe/gossamer/internal/log"
1110
"github.com/libp2p/go-libp2p-core/peer"
1211
"github.com/libp2p/go-libp2p-core/peerstore"
13-
libp2pdiscovery "github.com/libp2p/go-libp2p/p2p/discovery/mdns_legacy"
12+
libp2pdiscovery "github.com/libp2p/go-libp2p/p2p/discovery/mdns"
1413
)
1514

16-
// MDNSPeriod is 1 minute
17-
const MDNSPeriod = time.Minute
18-
19-
// Notifee See https://godoc.org/github.com/libp2p/go-libp2p/p2p/discovery#Notifee
15+
// Notifee see https://pkg.go.dev/github.com/libp2p/[email protected]/p2p/discovery/mdns#Notifee
2016
type Notifee struct {
2117
logger log.LeveledLogger
2218
ctx context.Context
@@ -41,29 +37,18 @@ func newMDNS(host *host) *mdns {
4137
// startMDNS starts a new mDNS discovery service
4238
func (m *mdns) start() {
4339
m.logger.Debugf(
44-
"Starting mDNS discovery service with host %s, period %s and protocol %s...",
45-
m.host.id(), MDNSPeriod, m.host.protocolID)
40+
"Starting mDNS discovery service with host %s and protocol %s...",
41+
m.host.id(), m.host.protocolID)
4642

4743
// create and start service
48-
mdns, err := libp2pdiscovery.NewMdnsService(
49-
m.host.ctx,
50-
m.host.p2pHost,
51-
MDNSPeriod,
52-
string(m.host.protocolID),
53-
)
54-
if err != nil {
55-
m.logger.Errorf("Failed to start mDNS discovery service: %s", err)
56-
return
57-
}
58-
59-
// register Notifee on service
60-
mdns.RegisterNotifee(Notifee{
44+
serviceName := string(m.host.protocolID)
45+
notifee := &Notifee{
6146
logger: m.logger,
6247
ctx: m.host.ctx,
6348
host: m.host,
64-
})
65-
66-
m.mdns = mdns
49+
}
50+
m.mdns = libp2pdiscovery.NewMdnsService(
51+
m.host.p2pHost, serviceName, notifee)
6752
}
6853

6954
// close shuts down the mDNS discovery service

0 commit comments

Comments
 (0)