Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
AutoNATState is AmbientAutoNAT
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed May 8, 2018
1 parent aaaa90e commit 1562e1b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions autonat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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{}),
Expand All @@ -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()

Expand All @@ -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)
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {}

0 comments on commit 1562e1b

Please sign in to comment.