From 2584bc51ffaec27e77a6f00971030dc7800a7660 Mon Sep 17 00:00:00 2001 From: vyzo Date: Tue, 8 May 2018 16:11:33 +0300 Subject: [PATCH] AutoNATState is AmbientAutoNAT --- p2p/host/autonat/autonat.go | 12 ++++++------ p2p/host/autonat/notify.go | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/p2p/host/autonat/autonat.go b/p2p/host/autonat/autonat.go index 79b0c89a..cad8a8d3 100644 --- a/p2p/host/autonat/autonat.go +++ b/p2p/host/autonat/autonat.go @@ -25,7 +25,7 @@ type AutoNAT interface { PublicAddr() (ma.Multiaddr, error) } -type AutoNATState struct { +type AmbientAutoNAT struct { ctx context.Context host host.Host peers map[peer.ID]struct{} @@ -35,7 +35,7 @@ type AutoNATState struct { } func NewAutoNAT(ctx context.Context, h host.Host) AutoNAT { - as := &AutoNATState{ + as := &AmbientAutoNAT{ ctx: ctx, host: h, peers: make(map[peer.ID]struct{}), @@ -48,11 +48,11 @@ func NewAutoNAT(ctx context.Context, h host.Host) AutoNAT { return as } -func (as *AutoNATState) Status() NATStatus { +func (as *AmbientAutoNAT) Status() NATStatus { return as.status } -func (as *AutoNATState) PublicAddr() (ma.Multiaddr, error) { +func (as *AmbientAutoNAT) PublicAddr() (ma.Multiaddr, error) { as.mx.Lock() defer as.mx.Unlock() @@ -63,7 +63,7 @@ func (as *AutoNATState) PublicAddr() (ma.Multiaddr, error) { return as.addr, nil } -func (as *AutoNATState) background() { +func (as *AmbientAutoNAT) background() { // wait a bit for the node to come online and establish some connections // before starting autodetection time.Sleep(15 * time.Second) @@ -77,7 +77,7 @@ func (as *AutoNATState) background() { } } -func (as *AutoNATState) autodetect() { +func (as *AmbientAutoNAT) autodetect() { if len(as.peers) == 0 { log.Debugf("skipping NAT auto detection; no autonat peers") return diff --git a/p2p/host/autonat/notify.go b/p2p/host/autonat/notify.go index 2c68e8ea..4e2bc9d9 100644 --- a/p2p/host/autonat/notify.go +++ b/p2p/host/autonat/notify.go @@ -6,14 +6,14 @@ import ( ma "github.com/multiformats/go-multiaddr" ) -var _ inet.Notifiee = (*AutoNATState)(nil) +var _ inet.Notifiee = (*AmbientAutoNAT)(nil) -func (as *AutoNATState) Listen(net inet.Network, a ma.Multiaddr) {} -func (as *AutoNATState) ListenClose(net inet.Network, a ma.Multiaddr) {} -func (as *AutoNATState) OpenedStream(net inet.Network, s inet.Stream) {} -func (as *AutoNATState) ClosedStream(net inet.Network, s inet.Stream) {} +func (as *AmbientAutoNAT) Listen(net inet.Network, a ma.Multiaddr) {} +func (as *AmbientAutoNAT) ListenClose(net inet.Network, a ma.Multiaddr) {} +func (as *AmbientAutoNAT) OpenedStream(net inet.Network, s inet.Stream) {} +func (as *AmbientAutoNAT) ClosedStream(net inet.Network, s inet.Stream) {} -func (as *AutoNATState) Connected(net inet.Network, c inet.Conn) { +func (as *AmbientAutoNAT) Connected(net inet.Network, c inet.Conn) { go func(p peer.ID) { s, err := as.host.NewStream(as.ctx, p, AutoNATProto) if err != nil { @@ -28,4 +28,4 @@ func (as *AutoNATState) Connected(net inet.Network, c inet.Conn) { }(c.RemotePeer()) } -func (as *AutoNATState) Disconnected(net inet.Network, c inet.Conn) {} +func (as *AmbientAutoNAT) Disconnected(net inet.Network, c inet.Conn) {}