From a89e74a1553db4b110cd2bf55759f2529752be59 Mon Sep 17 00:00:00 2001 From: vyzo Date: Wed, 17 Oct 2018 17:04:46 +0300 Subject: [PATCH] basic host: export AddrsFactory, provide method to push identify --- p2p/host/basic/basic_host.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/p2p/host/basic/basic_host.go b/p2p/host/basic/basic_host.go index d1bd0d6..b5d2108 100644 --- a/p2p/host/basic/basic_host.go +++ b/p2p/host/basic/basic_host.go @@ -59,10 +59,11 @@ type BasicHost struct { ids *identify.IDService pings *ping.PingService natmgr NATManager - addrs AddrsFactory maResolver *madns.Resolver cmgr ifconnmgr.ConnManager + AddrsFactory AddrsFactory + negtimeout time.Duration proc goprocess.Process @@ -106,11 +107,11 @@ type HostOpts struct { // NewHost constructs a new *BasicHost and activates it by attaching its stream and connection handlers to the given inet.Network. func NewHost(ctx context.Context, net inet.Network, opts *HostOpts) (*BasicHost, error) { h := &BasicHost{ - network: net, - mux: msmux.NewMultistreamMuxer(), - negtimeout: DefaultNegotiationTimeout, - addrs: DefaultAddrsFactory, - maResolver: madns.DefaultResolver, + network: net, + mux: msmux.NewMultistreamMuxer(), + negtimeout: DefaultNegotiationTimeout, + AddrsFactory: DefaultAddrsFactory, + maResolver: madns.DefaultResolver, } h.proc = goprocessctx.WithContextAndTeardown(ctx, func() error { @@ -136,7 +137,7 @@ func NewHost(ctx context.Context, net inet.Network, opts *HostOpts) (*BasicHost, } if opts.AddrsFactory != nil { - h.addrs = opts.AddrsFactory + h.AddrsFactory = opts.AddrsFactory } if opts.NATManager != nil { @@ -256,6 +257,11 @@ func (h *BasicHost) newStreamHandler(s inet.Stream) { go handle(protoID, s) } +// PushIdentify pushes an identify update through the identify push protocol +func (h *BasicHost) PushIdentify() { + h.ids.Push() +} + // ID returns the (local) peer.ID associated with this Host func (h *BasicHost) ID() peer.ID { return h.Network().LocalPeer() @@ -474,7 +480,7 @@ func (h *BasicHost) ConnManager() ifconnmgr.ConnManager { // Addrs returns listening addresses that are safe to announce to the network. // The output is the same as AllAddrs, but processed by AddrsFactory. func (h *BasicHost) Addrs() []ma.Multiaddr { - return h.addrs(h.AllAddrs()) + return h.AddrsFactory(h.AllAddrs()) } // mergeAddrs merges input address lists, leave only unique addresses -- GitLab