detect listen addr changes in BasicHost
This commit is contained in:
parent
3364dccbbf
commit
bd9e7b59ce
|
@ -232,6 +232,16 @@ func NewHost(ctx context.Context, net network.Network, opts *HostOpts) (*BasicHo
|
|||
|
||||
net.SetStreamHandler(h.newStreamHandler)
|
||||
|
||||
// register to be notified when the network's listen addrs change,
|
||||
// so we can update our address set and push events if needed
|
||||
listenHandler := func(network.Network, ma.Multiaddr) {
|
||||
h.SignalAddressChange()
|
||||
}
|
||||
net.Notify(&network.NotifyBundle{
|
||||
ListenF: listenHandler,
|
||||
ListenCloseF: listenHandler,
|
||||
})
|
||||
|
||||
return h, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -112,9 +112,9 @@ func TestSignedPeerRecordWithNoListenAddrs(t *testing.T) {
|
|||
t.Errorf("expected at least 1 listen addr, got %d", len(h.Addrs()))
|
||||
}
|
||||
|
||||
// sadly, we still don't have a signed peer record, since the addr change ticker hasn't ticked yet
|
||||
// uncommenting this causes the test to pass:
|
||||
// time.Sleep(5100 * time.Millisecond)
|
||||
// we need to sleep for a moment, since the signed record with the new addr is
|
||||
// added async
|
||||
time.Sleep(time.Millisecond)
|
||||
|
||||
cab, ok := peerstore.GetCertifiedAddrBook(h.Peerstore())
|
||||
if !ok {
|
||||
|
|
Loading…
Reference in New Issue