|
@@ -17,6 +17,7 @@ package discovery
|
|
|
|
|
|
import (
|
|
import (
|
|
"context"
|
|
"context"
|
|
|
|
+ "os"
|
|
"time"
|
|
"time"
|
|
|
|
|
|
"github.com/ipfs/go-log"
|
|
"github.com/ipfs/go-log"
|
|
@@ -24,7 +25,8 @@ import (
|
|
|
|
|
|
"github.com/libp2p/go-libp2p-core/host"
|
|
"github.com/libp2p/go-libp2p-core/host"
|
|
"github.com/libp2p/go-libp2p-core/peer"
|
|
"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"
|
|
|
|
+ mdnsLegacy "github.com/libp2p/go-libp2p/p2p/discovery/mdns_legacy"
|
|
)
|
|
)
|
|
|
|
|
|
type MDNS struct {
|
|
type MDNS struct {
|
|
@@ -54,19 +56,21 @@ func (d *MDNS) Option(ctx context.Context) func(c *libp2p.Config) error {
|
|
|
|
|
|
func (d *MDNS) Run(l log.StandardLogger, ctx context.Context, host host.Host) error {
|
|
func (d *MDNS) Run(l log.StandardLogger, ctx context.Context, host host.Host) error {
|
|
// setup mDNS discovery to find local peers
|
|
// setup mDNS discovery to find local peers
|
|
- // XXX: Valid for new mdns
|
|
|
|
- // disc := mdns.NewMdnsService(host, d.DiscoveryServiceTag, &discoveryNotifee{h: host, c: l})
|
|
|
|
- // return disc.Start()
|
|
|
|
- // We stick to legacy atm as mdns 0.15 is kinda of broken
|
|
|
|
- // see: https://github.com/libp2p/go-libp2p/pull/1192
|
|
|
|
- disc, err := mdns.NewMdnsService(ctx, host, time.Hour, d.DiscoveryServiceTag)
|
|
|
|
- if err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
|
|
+ if os.Getenv("MDNS_LEGACY") == "true" {
|
|
|
|
+ // We stick to legacy atm as mdns 0.15 is kinda of broken
|
|
|
|
+ // see: https://github.com/libp2p/go-libp2p/pull/1192
|
|
|
|
+ disc, err := mdnsLegacy.NewMdnsService(ctx, host, time.Hour, d.DiscoveryServiceTag)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
|
|
- n := &discoveryNotifee{h: host, c: l}
|
|
|
|
|
|
+ n := &discoveryNotifee{h: host, c: l}
|
|
|
|
|
|
- disc.RegisterNotifee(n)
|
|
|
|
|
|
+ disc.RegisterNotifee(n)
|
|
|
|
+ } else {
|
|
|
|
+ disc := mdns.NewMdnsService(host, d.DiscoveryServiceTag, &discoveryNotifee{h: host, c: l})
|
|
|
|
+ return disc.Start()
|
|
|
|
+ }
|
|
|
|
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|