From 1562e1b88105746a309172c5974c74667ab6d220 Mon Sep 17 00:00:00 2001 From: vyzo Date: Tue, 8 May 2018 16:11:33 +0300 Subject: [PATCH] AutoNATState is AmbientAutoNAT --- autonat.go | 12 ++++++------ notify.go | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/autonat.go b/autonat.go index 79b0c89..cad8a8d 100644 --- a/autonat.go +++ b/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/notify.go b/notify.go index 2c68e8e..4e2bc9d 100644 --- a/notify.go +++ b/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) {}