Skip to content

Commit

Permalink
basichost: allow overriding Addrs()
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars Gierth committed May 29, 2017
1 parent a718165 commit 4067302
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion p2p/host/basic/basic_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ var log = logging.Logger("basichost")

var NegotiateTimeout = time.Second * 60

type AddrsFactory func([]ma.Multiaddr) []ma.Multiaddr

// Option is a type used to pass in options to the host.
type Option int

Expand All @@ -45,6 +47,7 @@ type BasicHost struct {
mux *msmux.MultistreamMuxer
ids *identify.IDService
natmgr *natManager
addrs AddrsFactory

NegotiateTimeout time.Duration

Expand Down Expand Up @@ -72,6 +75,9 @@ func New(net inet.Network, opts ...interface{}) *BasicHost {
// setup host services
h.ids = identify.NewIDService(h)

// default addresses factory, can be override via opts argument
h.addrs = func(addrs []ma.Multiaddr) []ma.Multiaddr { return addrs }

for _, o := range opts {
switch o := o.(type) {
case Option:
Expand All @@ -81,6 +87,8 @@ func New(net inet.Network, opts ...interface{}) *BasicHost {
}
case metrics.Reporter:
h.bwc = o
case AddrsFactory:
h.addrs = AddrsFactory(o)
}
}

Expand Down Expand Up @@ -355,7 +363,7 @@ func (h *BasicHost) Addrs() []ma.Multiaddr {
}
}

return addrs
return h.addrs(addrs)
}

// Close shuts down the Host's services (network, etc).
Expand Down

0 comments on commit 4067302

Please sign in to comment.