detect listen addr changes in BasicHost

This commit is contained in:
Yusef Napora 2020-05-19 16:12:56 -04:00
parent 3364dccbbf
commit bd9e7b59ce
2 changed files with 13 additions and 3 deletions

View File

@ -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
}

View File

@ -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 {