diff --git a/backup/backup_test.go b/backup/backup_test.go index 4b6d964b1ea1a681b8ed0d75149a11817355a638..1dc785aa311e0916f06f71618975dc9afadb1c25 100644 --- a/backup/backup_test.go +++ b/backup/backup_test.go @@ -24,7 +24,7 @@ import ( // Tests that Backup.initializeBackup returns a new Backup with a copy of the // key and the callback. func Test_initializeBackup(t *testing.T) { - cbChan := make(chan []byte) + cbChan := make(chan []byte, 2) cb := func(encryptedBackup []byte) { cbChan <- encryptedBackup } expectedPassword := "MySuperSecurePassword" b, err := initializeBackup(expectedPassword, cb, nil, @@ -34,6 +34,12 @@ func Test_initializeBackup(t *testing.T) { t.Errorf("initializeBackup returned an error: %+v", err) } + select { + case <-cbChan: + case <-time.After(10 * time.Millisecond): + t.Error("Timed out waiting for callback.") + } + // Check that the correct password is in storage loadedPassword, err := loadPassword(b.store.GetKV()) if err != nil { @@ -89,6 +95,12 @@ func Test_resumeBackup(t *testing.T) { t.Errorf("Failed to initialize new Backup: %+v", err) } + select { + case <-cbChan1: + case <-time.After(10 * time.Millisecond): + t.Error("Timed out waiting for callback.") + } + // Get key and salt to compare to later key1, salt1, _, err := loadBackup(b.store.GetKV()) if err != nil { @@ -135,7 +147,7 @@ func Test_resumeBackup(t *testing.T) { select { case r := <-cbChan1: - t.Errorf("Callback of first Backup called: %q", r) // TODO: i think there is a race condition here + t.Errorf("Callback of first Backup called: %q", r) case r := <-cbChan2: if !bytes.Equal(encryptedBackup, r) { t.Errorf("Callback has unexepected data."+ diff --git a/network/gateway/hostPool.go b/network/gateway/hostPool.go index 4b0210fcf2e49d2e543ac9d251730e62f01d629a..dd4616cc4583d54621cf2fb42dc2611ab96cee95 100644 --- a/network/gateway/hostPool.go +++ b/network/gateway/hostPool.go @@ -74,23 +74,23 @@ type HostPool struct { // PoolParams Allows configuration of HostPool parameters 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. Disabled if zero. - LazyConnection bool // Flag determining whether Host connections are initialized when added to HostPool - HostParams connect.HostParams // Parameters for the creation of new Host objects + 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. Disabled if zero. + ForceConnection bool // Flag determining whether Host connections are initialized when added to HostPool + HostParams connect.HostParams // Parameters for the creation of new Host objects } // DefaultPoolParams Returns a default set of PoolParams func DefaultPoolParams() PoolParams { p := PoolParams{ - MaxPoolSize: 30, - ProxyAttempts: 5, - PoolSize: 0, - MaxPings: 0, - LazyConnection: true, - HostParams: connect.GetDefaultHostParams(), + MaxPoolSize: 30, + ProxyAttempts: 5, + PoolSize: 0, + MaxPings: 0, + ForceConnection: false, + HostParams: connect.GetDefaultHostParams(), } p.HostParams.MaxRetries = 1 p.HostParams.MaxSendRetries = 1 @@ -550,7 +550,7 @@ func (h *HostPool) replaceHostNoStore(newId *id.ID, oldPoolIndex uint32) error { } // Manually connect the new Host - if !h.poolParams.LazyConnection { + if h.poolParams.ForceConnection { go func() { err := newHost.Connect() if err != nil { @@ -664,7 +664,6 @@ func (h *HostPool) addGateway(gwId *id.ID, ndfIndex int) { // Check if the host exists host, ok := h.manager.GetHost(gwId) if !ok { - // Check if gateway ID collides with an existing hard coded ID if id.CollidesWithHardCodedID(gwId) { jww.ERROR.Printf("Gateway ID invalid, collides with a "+ diff --git a/network/gateway/hostpool_test.go b/network/gateway/hostpool_test.go index 5e93ba8df80ded94f70034bdc6ba3540ac6d1644..30f3b6a6151626a68e5d2b2fe4d3c282de0aefeb 100644 --- a/network/gateway/hostpool_test.go +++ b/network/gateway/hostpool_test.go @@ -485,11 +485,12 @@ func TestHostPool_UpdateNdf(t *testing.T) { // Construct a manager (bypass business logic in constructor) hostPool := &HostPool{ - manager: manager, - hostList: make([]*connect.Host, newIndex+1), - hostMap: make(map[id.ID]uint32), - ndf: testNdf, - storage: storage.InitTestingSession(t), + manager: manager, + hostList: make([]*connect.Host, newIndex+1), + hostMap: make(map[id.ID]uint32), + ndf: testNdf, + storage: storage.InitTestingSession(t), + poolParams: DefaultPoolParams(), filter: func(m map[id.ID]int, _ *ndf.NetworkDefinition) map[id.ID]int { return m }, @@ -855,6 +856,7 @@ func TestHostPool_AddGateway(t *testing.T) { hostList: make([]*connect.Host, newIndex+1), hostMap: make(map[id.ID]uint32), ndf: testNdf, + poolParams: params, addGatewayChan: make(chan network.NodeGateway), storage: storage.InitTestingSession(t), } @@ -888,6 +890,7 @@ func TestHostPool_RemoveGateway(t *testing.T) { hostList: make([]*connect.Host, newIndex+1), hostMap: make(map[id.ID]uint32), ndf: testNdf, + poolParams: params, addGatewayChan: make(chan network.NodeGateway), storage: storage.InitTestingSession(t), rng: fastRNG.NewStreamGenerator(1, 1, csprng.NewSystemRNG), diff --git a/network/manager.go b/network/manager.go index bba264c6b63263a196d4bfc135f1db42649948ec..1cec837978ffc0aaa120ea061b4d993df8110e07 100644 --- a/network/manager.go +++ b/network/manager.go @@ -133,6 +133,7 @@ func NewManager(session *storage.Session, switchboard *switchboard.Switchboard, poolParams.HostParams.KaClientOpts.Time = time.Duration(math.MaxInt64) // Enable optimized HostPool initialization poolParams.MaxPings = 50 + poolParams.ForceConnection = true m.sender, err = gateway.NewSender(poolParams, rng, ndf, comms, session, m.NodeRegistration) if err != nil { diff --git a/network/message/utils_test.go b/network/message/utils_test.go index 80b31c9a911a49babe5862078fc864498f3fdb32..e0bf2222d6f36a6934fd3469cfa1222fe257bae1 100644 --- a/network/message/utils_test.go +++ b/network/message/utils_test.go @@ -17,10 +17,10 @@ func (mc *MockSendCMIXComms) GetHost(*id.ID) (*connect.Host, bool) { nid1 := id.NewIdFromString("zezima", id.Node, mc.t) gwID := nid1.DeepCopy() gwID.SetType(id.Gateway) - h, _ := connect.NewHost(gwID, "0.0.0.0", []byte(""), connect.HostParams{ - MaxRetries: 0, - AuthEnabled: false, - }) + p := connect.GetDefaultHostParams() + p.MaxRetries = 0 + p.AuthEnabled = false + h, _ := connect.NewHost(gwID, "0.0.0.0", []byte(""), p) return h, true } diff --git a/network/rounds/remoteFilters_test.go b/network/rounds/remoteFilters_test.go index 51d26973d9f024142ed89b04e57d8f7117992268..e490432857d5e94bf599d3b7eb3c4b1a66ee8017 100644 --- a/network/rounds/remoteFilters_test.go +++ b/network/rounds/remoteFilters_test.go @@ -20,7 +20,7 @@ import ( ) func TestMain(m *testing.M) { - jww.SetStdoutThreshold(jww.LevelTrace) + jww.SetStdoutThreshold(jww.LevelDebug) connect.TestingOnlyDisableTLS = true os.Exit(m.Run()) } @@ -98,4 +98,4 @@ func TestRemoteFilter_FirstLastRound(t *testing.T) { "\n\tExpected: %v\n\tReceived: %v", receivedLastRound, firstRound+uint64(roundRange)) } -} \ No newline at end of file +} diff --git a/network/rounds/utils_test.go b/network/rounds/utils_test.go index 8779a68acdf4f0c929186ddb59b6a0ad26bc3f05..ea24534930b93b345ef2bff86de0f29f6663507b 100644 --- a/network/rounds/utils_test.go +++ b/network/rounds/utils_test.go @@ -62,10 +62,10 @@ func (mmrc *mockMessageRetrievalComms) RemoveHost(hid *id.ID) { } func (mmrc *mockMessageRetrievalComms) GetHost(hostId *id.ID) (*connect.Host, bool) { - h, _ := connect.NewHost(hostId, "0.0.0.0", []byte(""), connect.HostParams{ - MaxRetries: 0, - AuthEnabled: false, - }) + p := connect.GetDefaultHostParams() + p.MaxRetries = 0 + p.AuthEnabled = false + h, _ := connect.NewHost(hostId, "0.0.0.0", []byte(""), p) return h, true }