Skip to content
Snippets Groups Projects
Commit 4b466c8e authored by Jonah Husson's avatar Jonah Husson
Browse files

Fix naming around cmix package

parent 13bf8163
Branches
Tags
3 merge requests!510Release,!207WIP: Client Restructure,!203Symmetric broadcast
...@@ -349,7 +349,7 @@ func Login(storageDir string, password []byte, parameters params.Network) (*Clie ...@@ -349,7 +349,7 @@ func Login(storageDir string, password []byte, parameters params.Network) (*Clie
} }
// Initialize network and link it to context // Initialize network and link it to context
c.network, err = cmix.NewManager(c.storage, c.switchboard, c.rng, c.network, err = cmix.NewClient(c.storage, c.switchboard, c.rng,
c.events, c.comms, parameters, def) c.events, c.comms, parameters, def)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -409,7 +409,7 @@ func LoginWithNewBaseNDF_UNSAFE(storageDir string, password []byte, ...@@ -409,7 +409,7 @@ func LoginWithNewBaseNDF_UNSAFE(storageDir string, password []byte,
} }
// Initialize network and link it to context // Initialize network and link it to context
c.network, err = cmix.NewManager(c.storage, c.switchboard, c.rng, c.network, err = cmix.NewClient(c.storage, c.switchboard, c.rng,
c.events, c.comms, parameters, def) c.events, c.comms, parameters, def)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -467,7 +467,7 @@ func LoginWithProtoClient(storageDir string, password []byte, protoClientJSON [] ...@@ -467,7 +467,7 @@ func LoginWithProtoClient(storageDir string, password []byte, protoClientJSON []
} }
// Initialize network and link it to context // Initialize network and link it to context
c.network, err = cmix.NewManager(c.storage, c.switchboard, c.rng, c.network, err = cmix.NewClient(c.storage, c.switchboard, c.rng,
c.events, c.comms, parameters, def) c.events, c.comms, parameters, def)
if err != nil { if err != nil {
return nil, err return nil, err
......
...@@ -87,8 +87,8 @@ type client struct { ...@@ -87,8 +87,8 @@ type client struct {
maxMsgLen int maxMsgLen int
} }
// NewManager builds a new reception client object using inputted key fields. // NewClient builds a new reception client object using inputted key fields.
func NewManager(params Params, comms *commClient.Comms, session storage.Session, func NewClient(params Params, comms *commClient.Comms, session storage.Session,
ndf *ndf.NetworkDefinition, rng *fastRNG.StreamGenerator, ndf *ndf.NetworkDefinition, rng *fastRNG.StreamGenerator,
events event.Manager) (Client, error) { events event.Manager) (Client, error) {
......
package cmix package cmix
//func TestManager_Follow(t *testing.T) { //func TestClient_Follow(t *testing.T) {
// m, err := newTestManager(t) // m, err := newTestClient(t)
// if err != nil { // if err != nil {
// t.Fatalf("Failed to create test client: %+v", err) // t.Fatalf("Failed to create test client: %+v", err)
// } // }
......
...@@ -28,10 +28,10 @@ func TestPollTracker(t *testing.T) { ...@@ -28,10 +28,10 @@ func TestPollTracker(t *testing.T) {
if i, ok := (*pt)[*id]; ok { if i, ok := (*pt)[*id]; ok {
if j, ok2 := i[eid.Int64()]; ok2 { if j, ok2 := i[eid.Int64()]; ok2 {
if j != 1 { if j != 1 {
t.Errorf("EID entry value not 1") t.Errorf("First EID entry value not 1")
} }
} else { } else {
t.Errorf("No entry made for EID") t.Errorf("No entry made for first EID")
} }
} else { } else {
t.Errorf("No entry made for ID") t.Errorf("No entry made for ID")
...@@ -42,13 +42,13 @@ func TestPollTracker(t *testing.T) { ...@@ -42,13 +42,13 @@ func TestPollTracker(t *testing.T) {
if i, ok := (*pt)[*id]; ok { if i, ok := (*pt)[*id]; ok {
if j, ok2 := i[eid2.Int64()]; ok2 { if j, ok2 := i[eid2.Int64()]; ok2 {
if j != 1 { if j != 1 {
t.Errorf("EID entry value not 1") t.Errorf("Second EID entry value not 1")
} }
} else { } else {
t.Errorf("No entry made for EID") t.Errorf("No entry made for second EID")
} }
} else { } else {
t.Errorf("No entry made for ID") t.Errorf("No entry made for ID (2)")
} }
// re-add tracked eid & id // re-add tracked eid & id
...@@ -56,13 +56,13 @@ func TestPollTracker(t *testing.T) { ...@@ -56,13 +56,13 @@ func TestPollTracker(t *testing.T) {
if i, ok := (*pt)[*id]; ok { if i, ok := (*pt)[*id]; ok {
if j, ok2 := i[eid2.Int64()]; ok2 { if j, ok2 := i[eid2.Int64()]; ok2 {
if j != 2 { if j != 2 {
t.Errorf("EID entry value not 1") t.Errorf("EID entry value not 2")
} }
} else { } else {
t.Errorf("No entry made for EID") t.Errorf("No entry made for second EID (2)")
} }
} else { } else {
t.Errorf("No entry made for ID") t.Errorf("No entry made for ID (3)")
} }
// Check report output // Check report output
......
...@@ -44,7 +44,7 @@ func TestClient_GetRoundResults(t *testing.T) { ...@@ -44,7 +44,7 @@ func TestClient_GetRoundResults(t *testing.T) {
} }
} }
m, err := newTestManager(t) m, err := newTestClient(t)
if err != nil { if err != nil {
t.Fatalf("Failed in setup: %v", err) t.Fatalf("Failed in setup: %v", err)
} }
...@@ -114,7 +114,7 @@ func TestClient_GetRoundResults_FailedRounds(t *testing.T) { ...@@ -114,7 +114,7 @@ func TestClient_GetRoundResults_FailedRounds(t *testing.T) {
} }
// Create a new copy of the test client for this test // Create a new copy of the test client for this test
m, err := newTestManager(t) m, err := newTestClient(t)
if err != nil { if err != nil {
t.Fatalf("Failed in setup: %v", err) t.Fatalf("Failed in setup: %v", err)
} }
...@@ -179,7 +179,7 @@ func TestClient_GetRoundResults_HistoricalRounds(t *testing.T) { ...@@ -179,7 +179,7 @@ func TestClient_GetRoundResults_HistoricalRounds(t *testing.T) {
} }
// Create a new copy of the test client for this test // Create a new copy of the test client for this test
m, err := newTestManager(t) m, err := newTestClient(t)
if err != nil { if err != nil {
t.Fatalf("Failed in setup: %v", err) t.Fatalf("Failed in setup: %v", err)
} }
...@@ -223,7 +223,7 @@ func TestClient_GetRoundResults_Timeout(t *testing.T) { ...@@ -223,7 +223,7 @@ func TestClient_GetRoundResults_Timeout(t *testing.T) {
sendResults = nil sendResults = nil
// Create a new copy of the test client for this test // Create a new copy of the test client for this test
m, err := newTestManager(t) m, err := newTestClient(t)
if err != nil { if err != nil {
t.Fatalf("Failed in setup: %v", err) t.Fatalf("Failed in setup: %v", err)
} }
......
...@@ -8,110 +8,8 @@ import ( ...@@ -8,110 +8,8 @@ import (
"testing" "testing"
) )
/* func TestClient_SendCMIX(t *testing.T) {
type dummyEvent struct{} c, err := newTestClient(t)
func (e *dummyEvent) Report(priority int, category, evtType, details string) {}
// Unit test
func Test_attemptSendCmix(t *testing.T) {
sess1 := storage.InitTestingSession(t)
sess2 := storage.InitTestingSession(t)
events := &dummyEvent{}
sw := switchboard.New()
l := message2.TestListener{
ch: make(chan bool),
}
sw.RegisterListener(sess2.GetUser().TransmissionID, message.Raw, l)
comms, err := client.NewClientComms(sess1.GetUser().TransmissionID, nil, nil, nil)
if err != nil {
t.Errorf("Failed to start client comms: %+v", err)
}
inst, err := network.NewInstanceTesting(comms.ProtoComms, message2.getNDF(), nil, nil, nil, t)
if err != nil {
t.Errorf("Failed to start instance: %+v", err)
}
now := netTime.Now()
nid1 := id.NewIdFromString("zezima", id.Node, t)
nid2 := id.NewIdFromString("jakexx360", id.Node, t)
nid3 := id.NewIdFromString("westparkhome", id.Node, t)
grp := cyclic.NewGroup(large.NewInt(7), large.NewInt(13))
sess1.Cmix().Add(nid1, grp.NewInt(1), 0, nil)
sess1.Cmix().Add(nid2, grp.NewInt(2), 0, nil)
sess1.Cmix().Add(nid3, grp.NewInt(3), 0, nil)
timestamps := []uint64{
uint64(now.Add(-30 * time.Second).UnixNano()), //PENDING
uint64(now.Add(-25 * time.Second).UnixNano()), //PRECOMPUTING
uint64(now.Add(-5 * time.Second).UnixNano()), //STANDBY
uint64(now.Add(5 * time.Second).UnixNano()), //QUEUED
0} //REALTIME
ri := &mixmessages.RoundInfo{
ID: 3,
UpdateID: 0,
State: uint32(states.QUEUED),
BatchSize: 0,
Topology: [][]byte{nid1.Marshal(), nid2.Marshal(), nid3.Marshal()},
Timestamps: timestamps,
Errors: nil,
ClientErrors: nil,
ResourceQueueTimeoutMillis: 0,
Signature: nil,
AddressSpaceSize: 4,
}
if err = testutils.SignRoundInfoRsa(ri, t); err != nil {
t.Errorf("Failed to sign mock round info: %v", err)
}
pubKey, err := testutils.LoadPublicKeyTesting(t)
if err != nil {
t.Errorf("Failed to load a key for testing: %v", err)
}
rnd := ds.NewRound(ri, pubKey, nil)
inst.GetWaitingRounds().Insert([]*ds.Round{rnd}, nil)
i := internal.Internal{
Session: sess1,
Switchboard: sw,
Rng: fastRNG.NewStreamGenerator(1, 1, csprng.NewSystemRNG),
Comms: comms,
Health: nil,
TransmissionID: sess1.GetUser().TransmissionID,
Instance: inst,
NodeRegistration: nil,
}
p := gateway.DefaultPoolParams()
p.MaxPoolSize = 1
sender, err := gateway.NewSender(p, i.Rng, message2.getNDF(), &message2.MockSendCMIXComms{t: t}, i.Session, nil)
if err != nil {
t.Errorf("%+v", errors.New(err.Error()))
return
}
m := message2.NewHandler(i, params.Network{Messages: params.Messages{
MessageReceptionBuffLen: 20,
MessageReceptionWorkerPoolSize: 20,
MaxChecksRetryMessage: 20,
RetryMessageWait: time.Hour,
}}, nil, sender)
msgCmix := format.NewMessage(m.Session.Cmix().GetGroup().GetP().ByteLen())
msgCmix.SetContents([]byte("test"))
e2e.SetUnencrypted(msgCmix, m.Session.User().GetCryptographicIdentity().GetTransmissionID())
_, _, err = sendCmixHelper(sender, msgCmix, sess2.GetUser().ReceptionID,
params.GetDefaultCMIX(), make(map[string]interface{}), m.Instance, m.Session, m.nodeRegistration,
m.Rng, events, m.TransmissionID, &message2.MockSendCMIXComms{t: t}, nil)
if err != nil {
t.Errorf("Failed to sendcmix: %+v", err)
panic("t")
return
}
}*/
func TestManager_SendCMIX(t *testing.T) {
m, err := newTestManager(t)
if err != nil { if err != nil {
t.Fatalf("Failed to create test client: %+v", err) t.Fatalf("Failed to create test client: %+v", err)
} }
...@@ -127,7 +25,7 @@ func TestManager_SendCMIX(t *testing.T) { ...@@ -127,7 +25,7 @@ func TestManager_SendCMIX(t *testing.T) {
} }
mac[0] = 0 mac[0] = 0
params := GetDefaultCMIXParams() params := GetDefaultCMIXParams()
rid, eid, err := m.Send(recipientID, fp, service, contents, mac, params) rid, eid, err := c.Send(recipientID, fp, service, contents, mac, params)
if err != nil { if err != nil {
t.Errorf("Failed to sendcmix: %+v", err) t.Errorf("Failed to sendcmix: %+v", err)
t.FailNow() t.FailNow()
......
...@@ -8,148 +8,8 @@ import ( ...@@ -8,148 +8,8 @@ import (
"testing" "testing"
) )
/* func TestClient_SendMany_SendManyCMIX(t *testing.T) {
import ( c, err := newTestClient(t)
"github.com/pkg/errors"
"gitlab.com/elixxir/client/interfaces/message"
"gitlab.com/elixxir/client/interfaces/params"
"gitlab.com/elixxir/client/network/gateway"
"gitlab.com/elixxir/client/network/internal"
message2 "gitlab.com/elixxir/client/network/message"
"gitlab.com/elixxir/client/storage"
"gitlab.com/elixxir/client/switchboard"
"gitlab.com/elixxir/comms/client"
"gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/comms/network"
ds "gitlab.com/elixxir/comms/network/dataStructures"
"gitlab.com/elixxir/comms/testutils"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/e2e"
"gitlab.com/elixxir/crypto/fastRNG"
"gitlab.com/elixxir/primitives/format"
"gitlab.com/elixxir/primitives/states"
"gitlab.com/xx_network/crypto/csprng"
"gitlab.com/xx_network/crypto/large"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/netTime"
"testing"
"time"
)
// Unit test
func Test_attemptSendManyCmix(t *testing.T) {
sess1 := storage.InitTestingSession(t)
events := &dummyEvent{}
numRecipients := 3
recipients := make([]*id.ID, numRecipients)
sw := switchboard.New()
l := message2.TestListener{
ch: make(chan bool),
}
for i := 0; i < numRecipients; i++ {
sess := storage.InitTestingSession(t)
sw.RegisterListener(sess.GetUser().TransmissionID, message.Raw, l)
recipients[i] = sess.GetUser().ReceptionID
}
comms, err := client.NewClientComms(sess1.GetUser().TransmissionID, nil, nil, nil)
if err != nil {
t.Errorf("Failed to start client comms: %+v", err)
}
inst, err := network.NewInstanceTesting(comms.ProtoComms, message2.getNDF(), nil, nil, nil, t)
if err != nil {
t.Errorf("Failed to start instance: %+v", err)
}
now := netTime.Now()
nid1 := id.NewIdFromString("zezima", id.Node, t)
nid2 := id.NewIdFromString("jakexx360", id.Node, t)
nid3 := id.NewIdFromString("westparkhome", id.Node, t)
grp := cyclic.NewGroup(large.NewInt(7), large.NewInt(13))
sess1.Cmix().Add(nid1, grp.NewInt(1), 0, nil)
sess1.Cmix().Add(nid2, grp.NewInt(2), 0, nil)
sess1.Cmix().Add(nid3, grp.NewInt(3), 0, nil)
timestamps := []uint64{
uint64(now.Add(-30 * time.Second).UnixNano()), // PENDING
uint64(now.Add(-25 * time.Second).UnixNano()), // PRECOMPUTING
uint64(now.Add(-5 * time.Second).UnixNano()), // STANDBY
uint64(now.Add(5 * time.Second).UnixNano()), // QUEUED
0} // REALTIME
ri := &mixmessages.RoundInfo{
ID: 3,
UpdateID: 0,
State: uint32(states.QUEUED),
BatchSize: 0,
Topology: [][]byte{nid1.Marshal(), nid2.Marshal(), nid3.Marshal()},
Timestamps: timestamps,
Errors: nil,
ClientErrors: nil,
ResourceQueueTimeoutMillis: 0,
Signature: nil,
AddressSpaceSize: 4,
}
if err = testutils.SignRoundInfoRsa(ri, t); err != nil {
t.Errorf("Failed to sign mock round info: %v", err)
}
pubKey, err := testutils.LoadPublicKeyTesting(t)
if err != nil {
t.Errorf("Failed to load a key for testing: %v", err)
}
rnd := ds.NewRound(ri, pubKey, nil)
inst.GetWaitingRounds().Insert([]*ds.Round{rnd}, nil)
i := internal.Internal{
Session: sess1,
Switchboard: sw,
Rng: fastRNG.NewStreamGenerator(1, 1, csprng.NewSystemRNG),
Comms: comms,
Health: nil,
TransmissionID: sess1.GetUser().TransmissionID,
Instance: inst,
NodeRegistration: nil,
}
p := gateway.DefaultPoolParams()
p.MaxPoolSize = 1
sender, err := gateway.NewSender(p, i.Rng, message2.getNDF(), &message2.MockSendCMIXComms{t: t}, i.Session, nil)
if err != nil {
t.Errorf("%+v", errors.New(err.Error()))
return
}
m := message2.NewHandler(i, params.Network{Messages: params.Messages{
MessageReceptionBuffLen: 20,
MessageReceptionWorkerPoolSize: 20,
MaxChecksRetryMessage: 20,
RetryMessageWait: time.Hour,
}}, nil, sender)
msgCmix := format.NewMessage(m.Session.Cmix().GetGroup().GetP().ByteLen())
msgCmix.SetContents([]byte("test"))
e2e.SetUnencrypted(msgCmix, m.Session.User().GetCryptographicIdentity().GetTransmissionID())
messages := make([]format.Message, numRecipients)
for i := 0; i < numRecipients; i++ {
messages[i] = msgCmix
}
msgList := make([]message.TargetedCmixMessage, numRecipients)
for i := 0; i < numRecipients; i++ {
msgList[i] = message.TargetedCmixMessage{
Recipient: recipients[i],
Message: msgCmix,
}
}
_, _, err = sendManyCmixHelper(sender, msgList, params.GetDefaultCMIX(),
make(map[string]interface{}), m.Instance, m.Session, m.nodeRegistration,
m.Rng, events, m.TransmissionID, &message2.MockSendCMIXComms{t: t}, nil)
if err != nil {
t.Errorf("Failed to sendcmix: %+v", err)
}
}*/
func TestManager_SendManyCMIX(t *testing.T) {
m, err := newTestManager(t)
if err != nil { if err != nil {
t.Fatalf("Failed to create test client: %+v", err) t.Fatalf("Failed to create test client: %+v", err)
} }
...@@ -181,7 +41,7 @@ func TestManager_SendManyCMIX(t *testing.T) { ...@@ -181,7 +41,7 @@ func TestManager_SendManyCMIX(t *testing.T) {
}, },
} }
rid, eid, err := m.SendMany(messages, GetDefaultCMIXParams()) rid, eid, err := c.SendMany(messages, GetDefaultCMIXParams())
if err != nil { if err != nil {
t.Errorf("Failed to run SendMany: %+v", err) t.Errorf("Failed to run SendMany: %+v", err)
} }
......
...@@ -209,7 +209,7 @@ func mockFailCriticalSender(msg format.Message, recipient *id.ID, ...@@ -209,7 +209,7 @@ func mockFailCriticalSender(msg format.Message, recipient *id.ID,
return id.Round(1), ephemeral.Id{}, errors.New("Test error") return id.Round(1), ephemeral.Id{}, errors.New("Test error")
} }
func newTestManager(t *testing.T) (*client, error) { func newTestClient(t *testing.T) (*client, error) {
kv := versioned.NewKV(ekv.Memstore{}) kv := versioned.NewKV(ekv.Memstore{})
myID := id.NewIdFromString("zezima", id.User, t) myID := id.NewIdFromString("zezima", id.User, t)
comms, err := commClient.NewClientComms(myID, nil, nil, nil) comms, err := commClient.NewClientComms(myID, nil, nil, nil)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment