flag to enable the autonat service
This commit is contained in:
parent
7b998143ea
commit
353f81ce6c
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
logging "github.com/ipfs/go-log"
|
logging "github.com/ipfs/go-log"
|
||||||
libp2p "github.com/libp2p/go-libp2p"
|
libp2p "github.com/libp2p/go-libp2p"
|
||||||
|
autonat "github.com/libp2p/go-libp2p-autonat-svc"
|
||||||
host "github.com/libp2p/go-libp2p-host"
|
host "github.com/libp2p/go-libp2p-host"
|
||||||
dht "github.com/libp2p/go-libp2p-kad-dht"
|
dht "github.com/libp2p/go-libp2p-kad-dht"
|
||||||
dhtopts "github.com/libp2p/go-libp2p-kad-dht/opts"
|
dhtopts "github.com/libp2p/go-libp2p-kad-dht/opts"
|
||||||
|
@ -27,6 +28,7 @@ type Daemon struct {
|
||||||
|
|
||||||
dht *dht.IpfsDHT
|
dht *dht.IpfsDHT
|
||||||
pubsub *ps.PubSub
|
pubsub *ps.PubSub
|
||||||
|
autonat *autonat.AutoNATService
|
||||||
|
|
||||||
mx sync.Mutex
|
mx sync.Mutex
|
||||||
// stream handlers: map of protocol.ID to multi-address
|
// stream handlers: map of protocol.ID to multi-address
|
||||||
|
@ -113,6 +115,12 @@ func (d *Daemon) EnablePubsub(router string, sign, strict bool) error {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Daemon) EnableAutoNAT(opts ...libp2p.Option) error {
|
||||||
|
svc, err := autonat.NewAutoNATService(d.ctx, d.host, opts...)
|
||||||
|
d.autonat = svc
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func (d *Daemon) ID() peer.ID {
|
func (d *Daemon) ID() peer.ID {
|
||||||
return d.host.ID()
|
return d.host.ID()
|
||||||
}
|
}
|
||||||
|
|
15
p2pd/main.go
15
p2pd/main.go
|
@ -44,6 +44,7 @@ func main() {
|
||||||
relayHop := flag.Bool("relayHop", false, "Enables hop for relay")
|
relayHop := flag.Bool("relayHop", false, "Enables hop for relay")
|
||||||
relayDiscovery := flag.Bool("relayDiscovery", false, "Enables passive discovery for relay")
|
relayDiscovery := flag.Bool("relayDiscovery", false, "Enables passive discovery for relay")
|
||||||
autoRelay := flag.Bool("autoRelay", false, "Enables autorelay")
|
autoRelay := flag.Bool("autoRelay", false, "Enables autorelay")
|
||||||
|
autonat := flag.Bool("autonat", false, "Enables the AutoNAT service")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
var opts []libp2p.Option
|
var opts []libp2p.Option
|
||||||
|
@ -112,6 +113,20 @@ func main() {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *autonat {
|
||||||
|
var opts []libp2p.Option
|
||||||
|
if *QUIC {
|
||||||
|
opts = append(opts,
|
||||||
|
libp2p.DefaultTransports,
|
||||||
|
libp2p.Transport(quic.NewTransport),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
err := d.EnableAutoNAT(opts...)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if *pubsub {
|
if *pubsub {
|
||||||
if *gossipsubHeartbeatInterval > 0 {
|
if *gossipsubHeartbeatInterval > 0 {
|
||||||
ps.GossipSubHeartbeatInterval = *gossipsubHeartbeatInterval
|
ps.GossipSubHeartbeatInterval = *gossipsubHeartbeatInterval
|
||||||
|
|
|
@ -38,6 +38,12 @@
|
||||||
"hash": "QmZcLBXKaFe8ND5YHPkJRAwmhJGrVsi1JqDZNyJ4nRK5Mj",
|
"hash": "QmZcLBXKaFe8ND5YHPkJRAwmhJGrVsi1JqDZNyJ4nRK5Mj",
|
||||||
"name": "go-multiaddr-net",
|
"name": "go-multiaddr-net",
|
||||||
"version": "1.7.1"
|
"version": "1.7.1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"author": "vyzo",
|
||||||
|
"hash": "QmRmMbeY5QC5iMsuW16wchtFt8wmYTv2suWb8t9MV8dsxm",
|
||||||
|
"name": "go-libp2p-autonat-svc",
|
||||||
|
"version": "1.0.5"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"gxVersion": "0.12.1",
|
"gxVersion": "0.12.1",
|
||||||
|
|
Loading…
Reference in New Issue