diff --git a/network/gateway/hostPool.go b/network/gateway/hostPool.go index f86b302a4579061819730d961a98e62fda1d35b7..525c597286e7ccdee07317aa0a8aa70d047c2f63 100644 --- a/network/gateway/hostPool.go +++ b/network/gateway/hostPool.go @@ -77,7 +77,7 @@ type PoolParams struct { MaxPoolSize uint32 // Maximum number of Hosts in the HostPool PoolSize uint32 // Allows override of HostPool size. Set to zero for dynamic size calculation ProxyAttempts uint32 // How many proxies will be used in event of send failure - MaxPings uint32 // How many gateways to concurrently test when initializing HostPool + MaxPings uint32 // How many gateways to concurrently test when initializing HostPool. Disabled if zero. HostParams connect.HostParams // Parameters for the creation of new Host objects } @@ -87,7 +87,7 @@ func DefaultPoolParams() PoolParams { MaxPoolSize: 30, ProxyAttempts: 5, PoolSize: 0, - MaxPings: 50, + MaxPings: 0, HostParams: connect.GetDefaultHostParams(), } p.HostParams.MaxRetries = 1 @@ -157,9 +157,20 @@ func newHostPool(poolParams PoolParams, rng *fastRNG.StreamGenerator, } // Build the initial HostPool and return - err = result.initialize(uint32(numHostsAdded)) - if err != nil { - return nil, err + if result.poolParams.MaxPings > 0 { + // If pinging enabled, select random performant Hosts + err = result.initialize(uint32(numHostsAdded)) + if err != nil { + return nil, err + } + } else { + // Else, select random Hosts + for i := numHostsAdded; i < len(result.hostList); i++ { + err := result.replaceHost(result.selectGateway(), uint32(i)) + if err != nil { + return nil, err + } + } } jww.INFO.Printf("Initialized HostPool with size: %d/%d", poolParams.PoolSize, len(netDef.Gateways)) diff --git a/network/gateway/hostpool_test.go b/network/gateway/hostpool_test.go index b748e123d410dc92cad9b543aedaa7d390773059..919d3faedbada3445219de4886fc84ba2362cdeb 100644 --- a/network/gateway/hostpool_test.go +++ b/network/gateway/hostpool_test.go @@ -371,7 +371,7 @@ func TestHostPool_ForceReplace(t *testing.T) { oldHost := testPool.hostList[oldGatewayIndex] // Force replace the gateway at a given index - err = testPool.forceReplace(uint32(oldGatewayIndex)) + err = testPool.replaceHost(testPool.selectGateway(), uint32(oldGatewayIndex)) if err != nil { t.Errorf("Failed to force replace: %v", err) } diff --git a/network/manager.go b/network/manager.go index 831d303d81c29df748a5a3be7680387770e8cef7..35f3c668247586618ea3d52e442b3800bc2efd76 100644 --- a/network/manager.go +++ b/network/manager.go @@ -114,6 +114,8 @@ func NewManager(session *storage.Session, switchboard *switchboard.Switchboard, poolParams := gateway.DefaultPoolParams() // Client will not send KeepAlive packets poolParams.HostParams.KaClientOpts.Time = time.Duration(math.MaxInt64) + // Enable optimized HostPool initialization + poolParams.MaxPings = 50 m.sender, err = gateway.NewSender(poolParams, rng, ndf, comms, session, m.NodeRegistration) if err != nil {