diff --git a/dht.go b/dht.go index 8b5ff9ce9..a7052f44a 100644 --- a/dht.go +++ b/dht.go @@ -145,6 +145,9 @@ type IpfsDHT struct { refreshFinishedCh chan struct{} rtFreezeTimeout time.Duration + + // configuration variables for tests + testAddressUpdateProcessing bool } // Assert that IPFS assumptions about interfaces aren't broken. These aren't a @@ -187,6 +190,8 @@ func New(ctx context.Context, h host.Host, options ...Option) (*IpfsDHT, error) dht.Validator = cfg.validator + dht.testAddressUpdateProcessing = cfg.testAddressUpdateProcessing + dht.auto = cfg.mode switch cfg.mode { case ModeAuto, ModeClient: diff --git a/dht_bootstrap_test.go b/dht_bootstrap_test.go index 42bd48cc7..8ea9c3609 100644 --- a/dht_bootstrap_test.go +++ b/dht_bootstrap_test.go @@ -15,7 +15,7 @@ import ( func TestSelfWalkOnAddressChange(t *testing.T) { ctx := context.Background() // create three DHT instances with auto refresh disabled - d1 := setupDHT(ctx, t, false, DisableAutoRefresh()) + d1 := setupDHT(ctx, t, false, DisableAutoRefresh(), forceAddressUpdateProcessing(t)) d2 := setupDHT(ctx, t, false, DisableAutoRefresh()) d3 := setupDHT(ctx, t, false, DisableAutoRefresh()) diff --git a/dht_options.go b/dht_options.go index 0c072d9ac..6edce9dd6 100644 --- a/dht_options.go +++ b/dht_options.go @@ -64,9 +64,12 @@ type config struct { } // set to true if we're operating in v1 dht compatible mode - v1CompatibleMode bool - bootstrapPeers []peer.AddrInfo - disableFixLowPeers bool + v1CompatibleMode bool + bootstrapPeers []peer.AddrInfo + + // test specific config options + disableFixLowPeers bool + testAddressUpdateProcessing bool } func emptyQueryFilter(_ *IpfsDHT, ai peer.AddrInfo) bool { return true } @@ -428,3 +431,13 @@ func disableFixLowPeersRoutine(t *testing.T) Option { return nil } } + +// forceAddressUpdateProcessing forces the DHT to handle changes to the hosts addresses. +// This occurs even when AutoRefresh has been disabled. +// This is ONLY for tests. +func forceAddressUpdateProcessing(t *testing.T) Option { + return func(c *config) error { + c.testAddressUpdateProcessing = true + return nil + } +} diff --git a/subscriber_notifee.go b/subscriber_notifee.go index fc5ed2296..75e9cbe83 100644 --- a/subscriber_notifee.go +++ b/subscriber_notifee.go @@ -85,7 +85,9 @@ func (nn *subscriberNotifee) subscribe(proc goprocess.Process) { // with our new address to all peers we are connected to. However, we might not necessarily be connected // to our closet peers & so in the true spirit of Zen, searching for ourself in the network really is the best way // to to forge connections with those matter. - dht.rtRefreshManager.RefreshNoWait() + if dht.autoRefresh || dht.testAddressUpdateProcessing { + dht.rtRefreshManager.RefreshNoWait() + } case event.EvtPeerProtocolsUpdated: handlePeerChangeEvent(dht, evt.Peer) case event.EvtPeerIdentificationCompleted: