AutoNATState is AmbientAutoNAT

This commit is contained in:
vyzo 2018-05-08 16:11:33 +03:00
parent da3f7b5527
commit 2584bc51ff
2 changed files with 13 additions and 13 deletions

View File

@ -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

View File

@ -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) {}