Skip to content

Commit

Permalink
fix: do not refresh during address changes if autorefresh is disabled
Browse files Browse the repository at this point in the history
testing: add test-specific option to force processing of Host address changes even when AutoRefresh is disabled
  • Loading branch information
aschmahmann committed Aug 17, 2020
1 parent 57a49f1 commit 5729f0a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
5 changes: 5 additions & 0 deletions dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion dht_bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
19 changes: 16 additions & 3 deletions dht_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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
}
}
4 changes: 3 additions & 1 deletion subscriber_notifee.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 5729f0a

Please sign in to comment.