diff --git a/api/utilsInterfaces_test.go b/api/utilsInterfaces_test.go index 8d63541750796aefb1d27f793cac0a8f41517ab2..62ab16f5231d0bdc81ab30f8e0a1b890fb0931c7 100644 --- a/api/utilsInterfaces_test.go +++ b/api/utilsInterfaces_test.go @@ -80,6 +80,7 @@ func (ht *historicalRounds) GetHost(hostId *id.ID) (*connect.Host, bool) { // Contains a test implementation of the networkManager interface. type testNetworkManagerGeneric struct { instance *network.Instance + sender *gateway.Sender } /* Below methods built for interface adherence */ @@ -122,5 +123,5 @@ func (t *testNetworkManagerGeneric) InProgressRegistrations() int { } func (t *testNetworkManagerGeneric) GetSender() *gateway.Sender { - return nil + return t.sender } diff --git a/api/utils_test.go b/api/utils_test.go index 31e09e2d4f5b87a16e434ef1c6eef58423a903b3..ed6ce4b66da769e2744c10f499090863194c8314 100644 --- a/api/utils_test.go +++ b/api/utils_test.go @@ -8,6 +8,7 @@ package api import ( + "gitlab.com/elixxir/client/network/gateway" "testing" "github.com/pkg/errors" @@ -64,7 +65,10 @@ func newTestingClient(face interface{}) (*Client, error) { return nil, nil } - c.network = &testNetworkManagerGeneric{instance: thisInstance} + p := gateway.DefaultPoolParams() + p.PoolSize = 1 + sender, _ := gateway.NewSender(p, c.rng.GetStream(), def, commsManager, c.storage, nil) + c.network = &testNetworkManagerGeneric{instance: thisInstance, sender: sender} return c, nil } diff --git a/network/gateway/sender.go b/network/gateway/sender.go index 08de8eeb56ceec4c7f1bb333622fef82a6d93501..afa459304a9577f2d905c56bdcdd14cc0e19537c 100644 --- a/network/gateway/sender.go +++ b/network/gateway/sender.go @@ -74,7 +74,6 @@ func (m *Sender) SendToAny(sendFunc func(host *connect.Host) (interface{}, error // SendToPreferred Call given sendFunc to any Host in the HostPool, attempting with up to numProxies destinations func (m *Sender) SendToPreferred(targets []*id.ID, sendFunc func(host *connect.Host, target *id.ID) (interface{}, error)) (interface{}, error) { - targetHosts := m.getPreferred(targets) for i, host := range targetHosts { result, err := sendFunc(host, targets[i]) diff --git a/network/rounds/retrieve.go b/network/rounds/retrieve.go index 917d2401d4bdb67b53ca006b919d2c4fcf68dc16..3430e71849fc873eece5654385653a50e72da92e 100644 --- a/network/rounds/retrieve.go +++ b/network/rounds/retrieve.go @@ -49,7 +49,7 @@ func (m *Manager) processMessageRetrieval(comms messageRetrievalComms, for i, idBytes := range ri.Topology { gwId, err := id.Unmarshal(idBytes) if err != nil { - // TODO + jww.FATAL.Panicf("processMessageRetrieval: Unable to unmarshal: %+v", err) } gwIds[i] = gwId } diff --git a/network/rounds/retrieve_test.go b/network/rounds/retrieve_test.go index 2efd2c89c6865ba335d2e167cab343bb786370db..7e5e28b57995a08862355b6939c89d00a9f254ea 100644 --- a/network/rounds/retrieve_test.go +++ b/network/rounds/retrieve_test.go @@ -8,11 +8,15 @@ package rounds import ( "bytes" + "gitlab.com/elixxir/client/network/gateway" "gitlab.com/elixxir/client/network/message" "gitlab.com/elixxir/client/storage/reception" pb "gitlab.com/elixxir/comms/mixmessages" + "gitlab.com/elixxir/crypto/fastRNG" + "gitlab.com/xx_network/crypto/csprng" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id/ephemeral" + "gitlab.com/xx_network/primitives/ndf" "reflect" "testing" "time" @@ -25,6 +29,17 @@ func TestManager_ProcessMessageRetrieval(t *testing.T) { roundId := id.Round(5) mockComms := &mockMessageRetrievalComms{testingSignature: t} quitChan := make(chan struct{}) + testNdf := getNDF() + nodeId := id.NewIdFromString(ReturningGateway, id.Node, &testing.T{}) + gwId := nodeId.DeepCopy() + gwId.SetType(id.Gateway) + testNdf.Gateways = []ndf.Gateway{{ID: gwId.Marshal()}} + + p := gateway.DefaultPoolParams() + p.PoolSize = 1 + testManager.sender, _ = gateway.NewSender(p, + fastRNG.NewStreamGenerator(1, 1, csprng.NewSystemRNG).GetStream(), + testNdf, mockComms, testManager.Session, nil) // Create a local channel so reception is possible (testManager.messageBundles is // send only via newManager call above) @@ -103,8 +118,19 @@ func TestManager_ProcessMessageRetrieval(t *testing.T) { func TestManager_ProcessMessageRetrieval_NoRound(t *testing.T) { // General initializations testManager := newManager(t) + p := gateway.DefaultPoolParams() + p.PoolSize = 1 roundId := id.Round(5) mockComms := &mockMessageRetrievalComms{testingSignature: t} + testNdf := getNDF() + nodeId := id.NewIdFromString(FalsePositive, id.Node, &testing.T{}) + gwId := nodeId.DeepCopy() + gwId.SetType(id.Gateway) + testNdf.Gateways = []ndf.Gateway{{ID: gwId.Marshal()}} + + testManager.sender, _ = gateway.NewSender(p, + fastRNG.NewStreamGenerator(1, 1, csprng.NewSystemRNG).GetStream(), + testNdf, mockComms, testManager.Session, nil) quitChan := make(chan struct{}) // Create a local channel so reception is possible (testManager.messageBundles is @@ -130,7 +156,7 @@ func TestManager_ProcessMessageRetrieval_NoRound(t *testing.T) { }, } - idList := [][]byte{dummyGateway.Bytes()} + idList := [][]byte{dummyGateway.Marshal()} roundInfo := &pb.RoundInfo{ ID: uint64(roundId), @@ -172,6 +198,17 @@ func TestManager_ProcessMessageRetrieval_FalsePositive(t *testing.T) { roundId := id.Round(5) mockComms := &mockMessageRetrievalComms{testingSignature: t} quitChan := make(chan struct{}) + testNdf := getNDF() + nodeId := id.NewIdFromString(FalsePositive, id.Node, &testing.T{}) + gwId := nodeId.DeepCopy() + gwId.SetType(id.Gateway) + testNdf.Gateways = []ndf.Gateway{{ID: gwId.Marshal()}} + + p := gateway.DefaultPoolParams() + p.PoolSize = 1 + testManager.sender, _ = gateway.NewSender(p, + fastRNG.NewStreamGenerator(1, 1, csprng.NewSystemRNG).GetStream(), + testNdf, mockComms, testManager.Session, nil) // Create a local channel so reception is possible (testManager.messageBundles is // send only via newManager call above) @@ -306,6 +343,17 @@ func TestManager_ProcessMessageRetrieval_MultipleGateways(t *testing.T) { roundId := id.Round(5) mockComms := &mockMessageRetrievalComms{testingSignature: t} quitChan := make(chan struct{}) + testNdf := getNDF() + nodeId := id.NewIdFromString(ReturningGateway, id.Node, &testing.T{}) + gwId := nodeId.DeepCopy() + gwId.SetType(id.Gateway) + testNdf.Gateways = []ndf.Gateway{{ID: gwId.Marshal()}} + + p := gateway.DefaultPoolParams() + p.PoolSize = 1 + testManager.sender, _ = gateway.NewSender(p, + fastRNG.NewStreamGenerator(1, 1, csprng.NewSystemRNG).GetStream(), + testNdf, mockComms, testManager.Session, nil) // Create a local channel so reception is possible (testManager.messageBundles is // send only via newManager call above) diff --git a/network/rounds/utils_test.go b/network/rounds/utils_test.go index c963199bedc637e13a050ac9c08d769d8c4a7acf..d352078dcd1219b188c8c7fde0b807748d8c3521 100644 --- a/network/rounds/utils_test.go +++ b/network/rounds/utils_test.go @@ -14,6 +14,7 @@ import ( pb "gitlab.com/elixxir/comms/mixmessages" "gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/ndf" "testing" ) @@ -28,7 +29,6 @@ func newManager(face interface{}) *Manager { TransmissionID: sess1.GetUser().TransmissionID, }, } - return testManager } @@ -43,6 +43,15 @@ type mockMessageRetrievalComms struct { testingSignature *testing.T } +func (mmrc *mockMessageRetrievalComms) AddHost(hid *id.ID, address string, cert []byte, params connect.HostParams) (host *connect.Host, err error) { + host, _ = mmrc.GetHost(nil) + return host, nil +} + +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, @@ -92,3 +101,42 @@ func (mmrc *mockMessageRetrievalComms) RequestMessages(host *connect.Host, return nil, nil } + +func getNDF() *ndf.NetworkDefinition { + return &ndf.NetworkDefinition{ + E2E: ndf.Group{ + Prime: "E2EE983D031DC1DB6F1A7A67DF0E9A8E5561DB8E8D49413394C049B" + + "7A8ACCEDC298708F121951D9CF920EC5D146727AA4AE535B0922C688B55B3DD2AE" + + "DF6C01C94764DAB937935AA83BE36E67760713AB44A6337C20E7861575E745D31F" + + "8B9E9AD8412118C62A3E2E29DF46B0864D0C951C394A5CBBDC6ADC718DD2A3E041" + + "023DBB5AB23EBB4742DE9C1687B5B34FA48C3521632C4A530E8FFB1BC51DADDF45" + + "3B0B2717C2BC6669ED76B4BDD5C9FF558E88F26E5785302BEDBCA23EAC5ACE9209" + + "6EE8A60642FB61E8F3D24990B8CB12EE448EEF78E184C7242DD161C7738F32BF29" + + "A841698978825B4111B4BC3E1E198455095958333D776D8B2BEEED3A1A1A221A6E" + + "37E664A64B83981C46FFDDC1A45E3D5211AAF8BFBC072768C4F50D7D7803D2D4F2" + + "78DE8014A47323631D7E064DE81C0C6BFA43EF0E6998860F1390B5D3FEACAF1696" + + "015CB79C3F9C2D93D961120CD0E5F12CBB687EAB045241F96789C38E89D796138E" + + "6319BE62E35D87B1048CA28BE389B575E994DCA755471584A09EC723742DC35873" + + "847AEF49F66E43873", + Generator: "2", + }, + CMIX: ndf.Group{ + Prime: "9DB6FB5951B66BB6FE1E140F1D2CE5502374161FD6538DF1648218642F0B5C48" + + "C8F7A41AADFA187324B87674FA1822B00F1ECF8136943D7C55757264E5A1A44F" + + "FE012E9936E00C1D3E9310B01C7D179805D3058B2A9F4BB6F9716BFE6117C6B5" + + "B3CC4D9BE341104AD4A80AD6C94E005F4B993E14F091EB51743BF33050C38DE2" + + "35567E1B34C3D6A5C0CEAA1A0F368213C3D19843D0B4B09DCB9FC72D39C8DE41" + + "F1BF14D4BB4563CA28371621CAD3324B6A2D392145BEBFAC748805236F5CA2FE" + + "92B871CD8F9C36D3292B5509CA8CAA77A2ADFC7BFD77DDA6F71125A7456FEA15" + + "3E433256A2261C6A06ED3693797E7995FAD5AABBCFBE3EDA2741E375404AE25B", + Generator: "5C7FF6B06F8F143FE8288433493E4769C4D988ACE5BE25A0E24809670716C613" + + "D7B0CEE6932F8FAA7C44D2CB24523DA53FBE4F6EC3595892D1AA58C4328A06C4" + + "6A15662E7EAA703A1DECF8BBB2D05DBE2EB956C142A338661D10461C0D135472" + + "085057F3494309FFA73C611F78B32ADBB5740C361C9F35BE90997DB2014E2EF5" + + "AA61782F52ABEB8BD6432C4DD097BC5423B285DAFB60DC364E8161F4A2A35ACA" + + "3A10B1C4D203CC76A470A33AFDCBDD92959859ABD8B56E1725252D78EAC66E71" + + "BA9AE3F1DD2487199874393CD4D832186800654760E1E34C09E4D155179F9EC0" + + "DC4473F996BDCE6EED1CABED8B6F116F7AD9CF505DF0F998E34AB27514B0FFE7", + }, + } +}