Skip to content

Commit

Permalink
make getAddrs a static argument (not variadic)
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Oct 18, 2018
1 parent 9a4502a commit 00f3153
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions p2p/host/autonat/autonat.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ type AmbientAutoNAT struct {
}

// NewAutoNAT creates a new ambient NAT autodiscovery instance attached to a host
func NewAutoNAT(ctx context.Context, h host.Host, ga ...GetAddrs) AutoNAT {
getAddrs := h.Addrs
if len(ga) > 0 {
getAddrs = ga[0]
// If getAddrs is nil, h.Addrs will be used
func NewAutoNAT(ctx context.Context, h host.Host, getAddrs GetAddrs) AutoNAT {
if getAddrs == nil {
getAddrs = h.Addrs
}

as := &AmbientAutoNAT{
Expand Down
2 changes: 1 addition & 1 deletion p2p/host/autonat/autonat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func newDialResponseError(status pb.Message_ResponseStatus, text string) *pb.Mes

func makeAutoNAT(ctx context.Context, t *testing.T, ash host.Host) (host.Host, AutoNAT) {
h := bhost.NewBlankHost(swarmt.GenSwarm(t, ctx))
a := NewAutoNAT(ctx, h)
a := NewAutoNAT(ctx, h, nil)
a.(*AmbientAutoNAT).peers[ash.ID()] = struct{}{}

return h, a
Expand Down
8 changes: 4 additions & 4 deletions p2p/host/autonat/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ type AutoNATError struct {
type GetAddrs func() []ma.Multiaddr

// NewAutoNATClient creates a fresh instance of an AutoNATClient
func NewAutoNATClient(h host.Host, ga ...GetAddrs) AutoNATClient {
getAddrs := h.Addrs
if len(ga) > 0 {
getAddrs = ga[0]
// If getAddrs is nil, h.Addrs will be used
func NewAutoNATClient(h host.Host, getAddrs GetAddrs) AutoNATClient {
if getAddrs == nil {
getAddrs = h.Addrs
}
return &client{h: h, getAddrs: getAddrs}
}
Expand Down

0 comments on commit 00f3153

Please sign in to comment.