Skip to content

Commit

Permalink
fix api
Browse files Browse the repository at this point in the history
  • Loading branch information
sukunrt committed Aug 10, 2023
1 parent 57ee2e8 commit 0fddd94
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,13 @@ func (cfg *Config) NewNode() (host.Host, error) {
rcmgr.MustRegisterWith(cfg.PrometheusRegisterer)
}

var autonatv2Dialer network.Network
var autonatv2Dialer *blankhost.BlankHost
if !cfg.DisableAutoNATv2 {
ah, err := cfg.makeAutoNATHost()
if err != nil {
return nil, err
}
autonatv2Dialer = ah.Network()
autonatv2Dialer = ah
}

h, err := bhost.NewHost(swrm, &bhost.HostOpts{
Expand Down
2 changes: 1 addition & 1 deletion p2p/host/basic/basic_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ type HostOpts struct {
PrometheusRegisterer prometheus.Registerer

EnableAutoNATv2 bool
AutoNATv2Dialer network.Network
AutoNATv2Dialer host.Host
}

// NewHost constructs a new *BasicHost and activates it by attaching its stream and connection handlers to the given inet.Network.
Expand Down
24 changes: 24 additions & 0 deletions p2p/protocol/autonatv2/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,27 @@ func TestServerDataRequest(t *testing.T) {

require.Equal(t, res[0].Rch, network.ReachabilityPublic)
}

func TestServerDial(t *testing.T) {
h := bhost.NewBlankHost(swarmt.GenSwarm(t))
dialer := bhost.NewBlankHost(swarmt.GenSwarm(t))
as := NewServer(h, dialer, nil, true)
defer as.host.Close()
as.Start()

c := newAutoNAT(t)
c.allowAllAddrs = true
defer c.Close()
defer c.host.Close()

c.host.Peerstore().AddAddrs(as.host.ID(), as.host.Addrs(), peerstore.PermanentAddrTTL)
c.host.Peerstore().AddProtocols(as.host.ID(), DialProtocol)
randAddr := ma.StringCast("/ip4/1.2.3.4/tcp/2")
res, err := c.CheckReachability(context.Background(), []ma.Multiaddr{randAddr}, c.host.Addrs())
require.NoError(t, err)
require.Equal(t, res[0].Rch, network.ReachabilityPrivate)

res, err = c.CheckReachability(context.Background(), nil, c.host.Addrs())
require.NoError(t, err)
require.Equal(t, res[0].Rch, network.ReachabilityPublic)
}

0 comments on commit 0fddd94

Please sign in to comment.