diff --git a/cmd/callbacks.go b/cmd/callbacks.go index 4be99e0d0b6c7521d34cdd4cfa7e9ac90a763dbe..ec6bf4cd1760e009c9477b0d845d7a228c5f9e6f 100644 --- a/cmd/callbacks.go +++ b/cmd/callbacks.go @@ -40,7 +40,7 @@ func makeAuthCallbacks(autoConfirm bool, params xxdk.E2EParams) *authCallbacks { func (a *authCallbacks) Request(requestor contact.Contact, receptionID receptionID.EphemeralIdentity, - round rounds.Round, client *xxdk.E2e) { + round rounds.Round, messenger *xxdk.E2e) { msg := fmt.Sprintf("Authentication channel request from: %s\n", requestor.ID) jww.INFO.Printf(msg) @@ -49,9 +49,9 @@ func (a *authCallbacks) Request(requestor contact.Contact, jww.INFO.Printf("Channel Request: %s", requestor.ID) if viper.GetBool("verify-sends") { // Verify message sends were successful - acceptChannelVerified(client, requestor.ID, a.params) + acceptChannelVerified(messenger, requestor.ID, a.params) } else { - acceptChannel(client, requestor.ID) + acceptChannel(messenger, requestor.ID) } a.confCh <- requestor.ID @@ -60,15 +60,15 @@ func (a *authCallbacks) Request(requestor contact.Contact, } func (a *authCallbacks) Confirm(requestor contact.Contact, - receptionID receptionID.EphemeralIdentity, - round rounds.Round, client *xxdk.E2e) { + _ receptionID.EphemeralIdentity, + _ rounds.Round, _ *xxdk.E2e) { jww.INFO.Printf("Channel Confirmed: %s", requestor.ID) a.confCh <- requestor.ID } func (a *authCallbacks) Reset(requestor contact.Contact, - receptionID receptionID.EphemeralIdentity, - round rounds.Round, client *xxdk.E2e) { + _ receptionID.EphemeralIdentity, + _ rounds.Round, _ *xxdk.E2e) { msg := fmt.Sprintf("Authentication channel reset from: %s\n", requestor.ID) jww.INFO.Printf(msg) diff --git a/cmd/fileTransfer.go b/cmd/fileTransfer.go index eb9b7f34e441b078db012e114b3abc45f00154a3..20e8968bf9e4e2ef69556ad7cd1459984c07bee9 100644 --- a/cmd/fileTransfer.go +++ b/cmd/fileTransfer.go @@ -132,7 +132,7 @@ type receivedFtResults struct { // initFileTransferManager creates a new file transfer manager with a new // reception callback. Returns the file transfer manager and the channel that // will be triggered when the callback is called. -func initFileTransferManager(client *xxdk.E2e, maxThroughput int) ( +func initFileTransferManager(messenger *xxdk.E2e, maxThroughput int) ( *ftE2e.Wrapper, chan receivedFtResults) { // Create interfaces.ReceiveCallback that returns the results on a channel @@ -152,24 +152,24 @@ func initFileTransferManager(client *xxdk.E2e, maxThroughput int) ( // Create new manager manager, err := ft.NewManager(p, - client.GetReceptionIdentity().ID, - client.GetCmix(), - client.GetStorage(), - client.GetRng()) + messenger.GetReceptionIdentity().ID, + messenger.GetCmix(), + messenger.GetStorage(), + messenger.GetRng()) if err != nil { jww.FATAL.Panicf( "[FT] Failed to create new file transfer manager: %+v", err) } // Start the file transfer sending and receiving threads - err = client.AddService(manager.StartProcesses) + err = messenger.AddService(manager.StartProcesses) if err != nil { jww.FATAL.Panicf("[FT] Failed to start file transfer threads: %+v", err) } e2eParams := ftE2e.DefaultParams() e2eFt, err := ftE2e.NewWrapper(receiveCB, e2eParams, manager, - client.GetReceptionIdentity().ID, client.GetE2E(), client.GetCmix()) + messenger.GetReceptionIdentity().ID, messenger.GetE2E(), messenger.GetCmix()) if err != nil { jww.FATAL.Panicf( "[FT] Failed to create new e2e file transfer wrapper: %+v", err) diff --git a/cmd/group.go b/cmd/group.go index 3045e71b328bc51dc71fd30364398e761c7170b3..8909d2214812729af586dd75e7a6f342e01d18f0 100644 --- a/cmd/group.go +++ b/cmd/group.go @@ -116,7 +116,7 @@ var groupCmd = &cobra.Command{ // initGroupManager creates a new group chat manager and starts the process // service. -func initGroupManager(client *xxdk.E2e) (groupChat.GroupChat, +func initGroupManager(messenger *xxdk.E2e) (groupChat.GroupChat, chan groupChat.MessageReceive, chan groupStore.Group) { recChan := make(chan groupChat.MessageReceive, 10) @@ -126,10 +126,10 @@ func initGroupManager(client *xxdk.E2e) (groupChat.GroupChat, } jww.INFO.Print("[GC] Creating new group manager.") - manager, err := groupChat.NewManager(client.GetCmix(), - client.GetE2E(), client.GetStorage().GetReceptionID(), - client.GetRng(), client.GetStorage().GetE2EGroup(), - client.GetStorage().GetKV(), requestCb, &receiveProcessor{recChan}) + manager, err := groupChat.NewManager(messenger.GetCmix(), + messenger.GetE2E(), messenger.GetStorage().GetReceptionID(), + messenger.GetRng(), messenger.GetStorage().GetE2EGroup(), + messenger.GetStorage().GetKV(), requestCb, &receiveProcessor{recChan}) if err != nil { jww.FATAL.Panicf("[GC] Failed to initialize group chat manager: %+v", err) } diff --git a/cmd/init.go b/cmd/init.go index 9536dcb17871da20596c545323f92c957f99391a..56ad9de058b2698bfa5952ab4e8ea54e6817972d 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -40,17 +40,17 @@ var initCmd = &cobra.Command{ } err = xxdk.NewCmix(string(ndfJson), storeDir, storePassword, regCode) - baseClient, err := xxdk.OpenCmix(storeDir, storePassword) + net, err := xxdk.OpenCmix(storeDir, storePassword) if err != nil { jww.FATAL.Panicf("%+v", err) } - identity, err := xxdk.MakeReceptionIdentity(baseClient) + identity, err := xxdk.MakeReceptionIdentity(net) if err != nil { jww.FATAL.Panicf("%+v", err) } - err = xxdk.StoreReceptionIdentity(identityStorageKey, identity, baseClient) + err = xxdk.StoreReceptionIdentity(identityStorageKey, identity, net) if err != nil { jww.FATAL.Panicf("%+v", err) } @@ -78,7 +78,7 @@ func loadOrInitClient(password []byte, storeDir, regCode string, jww.INFO.Printf("Using normal sender") // create a new client if none exist - var baseClient *xxdk.Cmix + var net *xxdk.Cmix var identity xxdk.ReceptionIdentity if _, err := os.Stat(storeDir); errors.Is(err, fs.ErrNotExist) { // Initialize from scratch @@ -88,33 +88,33 @@ func loadOrInitClient(password []byte, storeDir, regCode string, } err = xxdk.NewCmix(string(ndfJson), storeDir, password, regCode) - baseClient, err = xxdk.LoadCmix(storeDir, password, cmixParams) + net, err = xxdk.LoadCmix(storeDir, password, cmixParams) if err != nil { jww.FATAL.Panicf("%+v", err) } - identity, err = xxdk.MakeReceptionIdentity(baseClient) + identity, err = xxdk.MakeReceptionIdentity(net) if err != nil { jww.FATAL.Panicf("%+v", err) } - err = xxdk.StoreReceptionIdentity(identityStorageKey, identity, baseClient) + err = xxdk.StoreReceptionIdentity(identityStorageKey, identity, net) if err != nil { jww.FATAL.Panicf("%+v", err) } } else { // Initialize from storage - baseClient, err = xxdk.LoadCmix(storeDir, password, cmixParams) + net, err = xxdk.LoadCmix(storeDir, password, cmixParams) if err != nil { jww.FATAL.Panicf("%+v", err) } - identity, err = xxdk.LoadReceptionIdentity(identityStorageKey, baseClient) + identity, err = xxdk.LoadReceptionIdentity(identityStorageKey, net) if err != nil { jww.FATAL.Panicf("%+v", err) } } - client, err := xxdk.Login(baseClient, authCbs, identity, e2eParams) + client, err := xxdk.Login(net, authCbs, identity, e2eParams) if err != nil { jww.FATAL.Panicf("%+v", err) } diff --git a/cmd/precan.go b/cmd/precan.go index 15498fe1176d09e7b39b0ffaa1ae41a1790d7d97..dded07723871e34ba54065ab628a346b055603a0 100644 --- a/cmd/precan.go +++ b/cmd/precan.go @@ -89,10 +89,10 @@ func getPrecanID(recipientID *id.ID) uint { return uint(recipientID.Bytes()[7]) } -func addPrecanAuthenticatedChannel(client *xxdk.E2e, recipientID *id.ID, +func addPrecanAuthenticatedChannel(messenger *xxdk.E2e, recipientID *id.ID, recipient contact.Contact) { jww.WARN.Printf("Precanned user id detected: %s", recipientID) - preUsr, err := client.MakePrecannedAuthenticatedChannel( + preUsr, err := messenger.MakePrecannedAuthenticatedChannel( getPrecanID(recipientID)) if err != nil { jww.FATAL.Panicf("%+v", err) diff --git a/cmd/root.go b/cmd/root.go index 59c83e81871ab52418cd8d5703830df926768d03..9d0709e82bff6f7d282768d9829b7281f57ee524 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -592,22 +592,22 @@ func initE2e(cmixParams xxdk.CMIXParams, e2eParams xxdk.E2EParams) *xxdk.E2e { viper.GetBool("unsafe-channel-creation"), e2eParams) // Initialize the client of the proper type - var client *xxdk.E2e + var messenger *xxdk.E2e if precanId != 0 { - client = loadOrInitPrecan(precanId, storePassword, storeDir, cmixParams, e2eParams) + messenger = loadOrInitPrecan(precanId, storePassword, storeDir, cmixParams, e2eParams) } else if protoUserPath != "" { - client = loadOrInitProto(protoUserPath, storePassword, storeDir, cmixParams, e2eParams) + messenger = loadOrInitProto(protoUserPath, storePassword, storeDir, cmixParams, e2eParams) } else if userIdPrefix != "" { - client = loadOrInitVanity(storePassword, storeDir, regCode, userIdPrefix, cmixParams, e2eParams) + messenger = loadOrInitVanity(storePassword, storeDir, regCode, userIdPrefix, cmixParams, e2eParams) } else if backupPath != "" { - client = loadOrInitBackup(backupPath, backupPass, storePassword, storeDir, cmixParams, e2eParams) + messenger = loadOrInitBackup(backupPath, backupPass, storePassword, storeDir, cmixParams, e2eParams) } else { - client = loadOrInitClient(storePassword, storeDir, regCode, cmixParams, e2eParams) + messenger = loadOrInitClient(storePassword, storeDir, regCode, cmixParams, e2eParams) } // Handle protoUser output if protoUser := viper.GetString("protoUserOut"); protoUser != "" { - jsonBytes, err := client.ConstructProtoUserFile() + jsonBytes, err := messenger.ConstructProtoUserFile() if err != nil { jww.FATAL.Panicf("cannot construct proto user file: %v", err) @@ -653,24 +653,24 @@ func initE2e(cmixParams xxdk.CMIXParams, e2eParams xxdk.E2EParams) *xxdk.E2e { } } _, err := backup.InitializeBackup(backupPass, updateBackupCb, - client.GetBackupContainer(), client.GetE2E(), client.GetStorage(), - nil, client.GetStorage().GetKV(), client.GetRng()) + messenger.GetBackupContainer(), messenger.GetE2E(), messenger.GetStorage(), + nil, messenger.GetStorage().GetKV(), messenger.GetRng()) if err != nil { jww.FATAL.Panicf("Failed to initialize backup with key %q: %+v", backupPass, err) } } - return client + return messenger } -func acceptChannel(client *xxdk.E2e, recipientID *id.ID) id.Round { - recipientContact, err := client.GetAuth().GetReceivedRequest( +func acceptChannel(messenger *xxdk.E2e, recipientID *id.ID) id.Round { + recipientContact, err := messenger.GetAuth().GetReceivedRequest( recipientID) if err != nil { jww.FATAL.Panicf("%+v", err) } - rid, err := client.GetAuth().Confirm( + rid, err := messenger.GetAuth().Confirm( recipientContact) if err != nil { jww.FATAL.Panicf("%+v", err) @@ -679,14 +679,14 @@ func acceptChannel(client *xxdk.E2e, recipientID *id.ID) id.Round { return rid } -func deleteChannel(client *xxdk.E2e, partnerId *id.ID) { - err := client.DeleteContact(partnerId) +func deleteChannel(messenger *xxdk.E2e, partnerId *id.ID) { + err := messenger.DeleteContact(partnerId) if err != nil { jww.FATAL.Panicf("%+v", err) } } -func addAuthenticatedChannel(client *xxdk.E2e, recipientID *id.ID, +func addAuthenticatedChannel(messenger *xxdk.E2e, recipientID *id.ID, recipient contact.Contact, e2eParams xxdk.E2EParams) { var allowed bool if viper.GetBool("unsafe-channel-creation") { @@ -709,17 +709,17 @@ func addAuthenticatedChannel(client *xxdk.E2e, recipientID *id.ID, recipientContact := recipient if recipientContact.ID != nil && recipientContact.DhPubKey != nil { - me := client.GetReceptionIdentity().GetContact() + me := messenger.GetReceptionIdentity().GetContact() jww.INFO.Printf("Requesting auth channel from: %s", recipientID) // Verify that the auth request makes it to the recipient // by monitoring the round result if viper.GetBool("verify-sends") { - requestChannelVerified(client, recipientContact, me, e2eParams) + requestChannelVerified(messenger, recipientContact, me, e2eParams) } else { // Just call Request, agnostic of round result - _, err := client.GetAuth().Request(recipientContact, + _, err := messenger.GetAuth().Request(recipientContact, me.Facts) if err != nil { jww.FATAL.Panicf("%+v", err) @@ -732,7 +732,7 @@ func addAuthenticatedChannel(client *xxdk.E2e, recipientID *id.ID, } } -func resetAuthenticatedChannel(client *xxdk.E2e, recipientID *id.ID, +func resetAuthenticatedChannel(messenger *xxdk.E2e, recipientID *id.ID, recipient contact.Contact, e2eParams xxdk.E2EParams) { var allowed bool if viper.GetBool("unsafe-channel-creation") { @@ -760,10 +760,10 @@ func resetAuthenticatedChannel(client *xxdk.E2e, recipientID *id.ID, // Verify that the auth request makes it to the recipient // by monitoring the round result if viper.GetBool("verify-sends") { - resetChannelVerified(client, recipientContact, + resetChannelVerified(messenger, recipientContact, e2eParams) } else { - _, err := client.GetAuth().Reset(recipientContact) + _, err := messenger.GetAuth().Reset(recipientContact) if err != nil { jww.FATAL.Panicf("%+v", err) } @@ -774,17 +774,17 @@ func resetAuthenticatedChannel(client *xxdk.E2e, recipientID *id.ID, } } -func acceptChannelVerified(client *xxdk.E2e, recipientID *id.ID, +func acceptChannelVerified(messenger *xxdk.E2e, recipientID *id.ID, params xxdk.E2EParams) { roundTimeout := params.Base.CMIXParams.SendTimeout done := make(chan struct{}, 1) retryChan := make(chan struct{}, 1) for { - rid := acceptChannel(client, recipientID) + rid := acceptChannel(messenger, recipientID) // Monitor rounds for results - err := client.GetCmix().GetRoundResults(roundTimeout, + err := messenger.GetCmix().GetRoundResults(roundTimeout, makeVerifySendsCallback(retryChan, done), rid) if err != nil { jww.DEBUG.Printf("Could not verify "+ @@ -810,7 +810,7 @@ func acceptChannelVerified(client *xxdk.E2e, recipientID *id.ID, } } -func requestChannelVerified(client *xxdk.E2e, +func requestChannelVerified(messenger *xxdk.E2e, recipientContact, me contact.Contact, params xxdk.E2EParams) { roundTimeout := params.Base.CMIXParams.SendTimeout @@ -818,14 +818,14 @@ func requestChannelVerified(client *xxdk.E2e, retryChan := make(chan struct{}, 1) done := make(chan struct{}, 1) for { - rid, err := client.GetAuth().Request(recipientContact, + rid, err := messenger.GetAuth().Request(recipientContact, me.Facts) if err != nil { continue } // Monitor rounds for results - err = client.GetCmix().GetRoundResults(roundTimeout, + err = messenger.GetCmix().GetRoundResults(roundTimeout, makeVerifySendsCallback(retryChan, done), rid) if err != nil { @@ -850,7 +850,7 @@ func requestChannelVerified(client *xxdk.E2e, } } -func resetChannelVerified(client *xxdk.E2e, recipientContact contact.Contact, +func resetChannelVerified(messenger *xxdk.E2e, recipientContact contact.Contact, params xxdk.E2EParams) { roundTimeout := params.Base.CMIXParams.SendTimeout @@ -858,13 +858,13 @@ func resetChannelVerified(client *xxdk.E2e, recipientContact contact.Contact, done := make(chan struct{}, 1) for { - rid, err := client.GetAuth().Reset(recipientContact) + rid, err := messenger.GetAuth().Reset(recipientContact) if err != nil { jww.FATAL.Panicf("%+v", err) } // Monitor rounds for results - err = client.GetCmix().GetRoundResults(roundTimeout, + err = messenger.GetCmix().GetRoundResults(roundTimeout, makeVerifySendsCallback(retryChan, done), rid) if err != nil { diff --git a/cmd/single.go b/cmd/single.go index 406374c939efacb4af6e0e5b55f5cf91581da5c0..6a7e99575ff163f03c82bb2cc9799fa884e8775e 100644 --- a/cmd/single.go +++ b/cmd/single.go @@ -157,7 +157,7 @@ func (r *Response) Callback(payload []byte, receptionID receptionID.EphemeralIde } // sendSingleUse sends a single use message. -func sendSingleUse(m *xxdk.Cmix, partner contact.Contact, payload []byte, +func sendSingleUse(net *xxdk.Cmix, partner contact.Contact, payload []byte, maxMessages uint8, timeout time.Duration, tag string) { // Construct callback callback := &Response{ @@ -178,12 +178,12 @@ func sendSingleUse(m *xxdk.Cmix, partner contact.Contact, payload []byte, partner.ID, payload) params := single.GetDefaultRequestParams() params.MaxResponseMessages = maxMessages - rng := m.GetRng().GetStream() + rng := net.GetRng().GetStream() defer rng.Close() - e2eGrp := m.GetStorage().GetE2EGroup() + e2eGrp := net.GetStorage().GetE2EGroup() rnd, ephID, err := single.TransmitRequest(partner, tag, payload, callback, params, - m.GetCmix(), rng, e2eGrp) + net.GetCmix(), rng, e2eGrp) if err != nil { jww.FATAL.Panicf("Failed to transmit single-use message: %+v", err) } diff --git a/connect/authCallbacks.go b/connect/authCallbacks.go index 227c47500e166155655ce96d0bdc0b9bfbfa2a94..01eb5e90ff994f83d79e68a11a0285104307a6f4 100644 --- a/connect/authCallbacks.go +++ b/connect/authCallbacks.go @@ -117,12 +117,12 @@ func (a serverAuthCallback) Confirm(contact.Contact, // Request will be called when an auth Request message is processed. func (a serverAuthCallback) Request(requestor contact.Contact, - _ receptionID.EphemeralIdentity, _ rounds.Round, e2e *xxdk.E2e) { + _ receptionID.EphemeralIdentity, _ rounds.Round, messenger *xxdk.E2e) { if a.requestCallback == nil { jww.ERROR.Printf("Received a request when requests are" + "not enable, will not accept") } - _, err := e2e.GetAuth().Confirm(requestor) + _, err := messenger.GetAuth().Confirm(requestor) if err != nil { jww.ERROR.Printf("Unable to build connection with "+ "partner %s: %+v", requestor.ID, err) @@ -130,7 +130,7 @@ func (a serverAuthCallback) Request(requestor contact.Contact, a.requestCallback(nil) } // After confirmation, get the new partner - newPartner, err := e2e.GetE2E().GetPartner(requestor.ID) + newPartner, err := messenger.GetE2E().GetPartner(requestor.ID) if err != nil { jww.ERROR.Printf("Unable to build connection with "+ "partner %s: %+v", requestor.ID, err) @@ -142,7 +142,7 @@ func (a serverAuthCallback) Request(requestor contact.Contact, // Return the new Connection object c := BuildConnection( - newPartner, e2e.GetE2E(), e2e.GetAuth(), a.connectionParams) + newPartner, messenger.GetE2E(), messenger.GetAuth(), a.connectionParams) a.cl.Add(c) a.requestCallback(c) } diff --git a/connect/authenticated.go b/connect/authenticated.go index 4376a2ceec13c2588e2dd637ce742cff02a4b033..11f0d2de9d92cb2b42e34dab9618b61d48d77328 100644 --- a/connect/authenticated.go +++ b/connect/authenticated.go @@ -52,27 +52,27 @@ type AuthenticatedCallback func(connection AuthenticatedConnection) // ConnectWithAuthentication is called by the client, ie the one establishing // connection with the server. Once a connect.Connection has been established // with the server and then authenticate their identity to the server. -func ConnectWithAuthentication(recipient contact.Contact, e2eClient *xxdk.E2e, +func ConnectWithAuthentication(recipient contact.Contact, messenger *xxdk.E2e, p xxdk.E2EParams) (AuthenticatedConnection, error) { // Track the time since we started to attempt to establish a connection timeStart := netTime.Now() // Establish a connection with the server - conn, err := Connect(recipient, e2eClient, p) + conn, err := Connect(recipient, messenger, p) if err != nil { return nil, errors.Errorf("failed to establish connection "+ "with recipient %s: %+v", recipient.ID, err) } // Build the authenticated connection and return - identity := e2eClient.GetReceptionIdentity() + identity := messenger.GetReceptionIdentity() privKey, err := identity.GetRSAPrivatePem() if err != nil { return nil, err } return connectWithAuthentication(conn, timeStart, recipient, identity.Salt, privKey, - e2eClient.GetRng(), e2eClient.GetCmix(), p) + messenger.GetRng(), messenger.GetCmix(), p) } // connectWithAuthentication builds and sends an IdentityAuthentication to diff --git a/connect/connect.go b/connect/connect.go index c949ee1013bb9948a1b3a0561d316b46d2b88199..ea755c0b181cbace7c64f2bb8878dcfd612b022e 100644 --- a/connect/connect.go +++ b/connect/connect.go @@ -151,8 +151,8 @@ func StartServer(identity xxdk.ReceptionIdentity, cb Callback, net *xxdk.Cmix, // ConnectionServer contains type ConnectionServer struct { - E2e *xxdk.E2e - Cl *ConnectionList + Messenger *xxdk.E2e + Cl *ConnectionList } // handler provides an implementation for the Connection interface. diff --git a/dummy/manager.go b/dummy/manager.go index 28ddd25e69c7e40bd2ee8a31a4b84d16ac9a7f5a..4832f3ef505ea37114c2f4d202c82604ddd7eab0 100644 --- a/dummy/manager.go +++ b/dummy/manager.go @@ -57,25 +57,25 @@ type Manager struct { statusChan chan bool // Cmix interfaces - client *xxdk.Cmix - store *storage.Session - net interfaces.NetworkManager - rng *fastRNG.StreamGenerator + net *xxdk.Cmix + store *storage.Session + networkManager interfaces.NetworkManager + rng *fastRNG.StreamGenerator } // NewManager creates a new dummy Manager with the specified average send delta // and the range used for generating random durations. func NewManager(maxNumMessages int, avgSendDelta, randomRange time.Duration, - client *xxdk.Cmix, manager interfaces.NetworkManager) *Manager { - clientStorage := client.GetStorage() - return newManager(maxNumMessages, avgSendDelta, randomRange, client, - &clientStorage, manager, client.GetRng()) + net *xxdk.Cmix, manager interfaces.NetworkManager) *Manager { + clientStorage := net.GetStorage() + return newManager(maxNumMessages, avgSendDelta, randomRange, net, + &clientStorage, manager, net.GetRng()) } // newManager builds a new dummy Manager from fields explicitly passed in. This // function is a helper function for NewManager to make it easier to test. func newManager(maxNumMessages int, avgSendDelta, randomRange time.Duration, - client *xxdk.Cmix, store *storage.Session, net interfaces.NetworkManager, + net *xxdk.Cmix, store *storage.Session, networkManager interfaces.NetworkManager, rng *fastRNG.StreamGenerator) *Manager { return &Manager{ maxNumMessages: maxNumMessages, @@ -83,9 +83,9 @@ func newManager(maxNumMessages int, avgSendDelta, randomRange time.Duration, randomRange: randomRange, status: notStarted, statusChan: make(chan bool, statusChanLen), - client: client, - store: store, net: net, + store: store, + networkManager: networkManager, rng: rng, } } diff --git a/dummy/manager_test.go b/dummy/manager_test.go index 753b0fcb215855f960a5517305c430b0207e9776..6a49bcc6a597ebf476ee8bbfb8f45a79045a4488 100644 --- a/dummy/manager_test.go +++ b/dummy/manager_test.go @@ -59,7 +59,7 @@ func TestManager_StartDummyTraffic(t *testing.T) { msgChan := make(chan bool) go func() { - for m.net.(*testNetworkManager).GetMsgListLen() == 0 { + for m.networkManager.(*testNetworkManager).GetMsgListLen() == 0 { time.Sleep(5 * time.Millisecond) } msgChan <- true @@ -71,7 +71,7 @@ func TestManager_StartDummyTraffic(t *testing.T) { t.Errorf("Timed out after %s waiting for messages to be sent.", 3*m.avgSendDelta) case <-msgChan: - numReceived += m.net.(*testNetworkManager).GetMsgListLen() + numReceived += m.networkManager.(*testNetworkManager).GetMsgListLen() } err = stop.Close() @@ -86,7 +86,7 @@ func TestManager_StartDummyTraffic(t *testing.T) { msgChan = make(chan bool) go func() { - for m.net.(*testNetworkManager).GetMsgListLen() == numReceived { + for m.networkManager.(*testNetworkManager).GetMsgListLen() == numReceived { time.Sleep(5 * time.Millisecond) } msgChan <- true @@ -118,10 +118,10 @@ func TestManager_SetStatus(t *testing.T) { go func() { var numReceived int for i := 0; i < 2; i++ { - for m.net.(*testNetworkManager).GetMsgListLen() == numReceived { + for m.networkManager.(*testNetworkManager).GetMsgListLen() == numReceived { time.Sleep(5 * time.Millisecond) } - numReceived = m.net.(*testNetworkManager).GetMsgListLen() + numReceived = m.networkManager.(*testNetworkManager).GetMsgListLen() msgChan <- true } }() @@ -161,7 +161,7 @@ func TestManager_SetStatus(t *testing.T) { t.Errorf("Timed out after %s waiting for messages to be sent.", 3*m.avgSendDelta) case <-msgChan: - numReceived += m.net.(*testNetworkManager).GetMsgListLen() + numReceived += m.networkManager.(*testNetworkManager).GetMsgListLen() } // Setting status to true multiple times does not interrupt sending @@ -177,10 +177,10 @@ func TestManager_SetStatus(t *testing.T) { t.Errorf("Timed out after %s waiting for messages to be sent.", 3*m.avgSendDelta) case <-msgChan: - if m.net.(*testNetworkManager).GetMsgListLen() <= numReceived { + if m.networkManager.(*testNetworkManager).GetMsgListLen() <= numReceived { t.Errorf("Failed to receive second send."+ "\nmessages on last receive: %d\nmessages on this receive: %d", - numReceived, m.net.(*testNetworkManager).GetMsgListLen()) + numReceived, m.networkManager.(*testNetworkManager).GetMsgListLen()) } } @@ -254,10 +254,10 @@ func TestManager_GetStatus(t *testing.T) { go func() { var numReceived int for i := 0; i < 2; i++ { - for m.net.(*testNetworkManager).GetMsgListLen() == numReceived { + for m.networkManager.(*testNetworkManager).GetMsgListLen() == numReceived { time.Sleep(5 * time.Millisecond) } - numReceived = m.net.(*testNetworkManager).GetMsgListLen() + numReceived = m.networkManager.(*testNetworkManager).GetMsgListLen() msgChan <- true } }() @@ -292,7 +292,7 @@ func TestManager_GetStatus(t *testing.T) { t.Errorf("Timed out after %s waiting for messages to be sent.", 3*m.avgSendDelta) case <-msgChan: - numReceived += m.net.(*testNetworkManager).GetMsgListLen() + numReceived += m.networkManager.(*testNetworkManager).GetMsgListLen() } // Setting status to true multiple times does not interrupt sending @@ -311,10 +311,10 @@ func TestManager_GetStatus(t *testing.T) { t.Errorf("Timed out after %s waiting for messages to be sent.", 3*m.avgSendDelta) case <-msgChan: - if m.net.(*testNetworkManager).GetMsgListLen() <= numReceived { + if m.networkManager.(*testNetworkManager).GetMsgListLen() <= numReceived { t.Errorf("Failed to receive second send."+ "\nmessages on last receive: %d\nmessages on this receive: %d", - numReceived, m.net.(*testNetworkManager).GetMsgListLen()) + numReceived, m.networkManager.(*testNetworkManager).GetMsgListLen()) } } diff --git a/dummy/send.go b/dummy/send.go index f6f532c81557a3c440a1296a8c60f2f114146f73..84271b67ea4310bf91af057a58ffe2256520460a 100644 --- a/dummy/send.go +++ b/dummy/send.go @@ -106,7 +106,7 @@ func (m *Manager) sendMessages(msgs map[id.ID]format.Message) error { // } // rng.Close() // p.DebugTag = "dummy" - _, _, err := m.net.SendCMIX(msg, &recipient, p) + _, _, err := m.networkManager.SendCMIX(msg, &recipient, p) if err != nil { jww.WARN.Printf("Failed to send dummy message %d/%d via "+ "Send: %+v", i, len(msgs), err) diff --git a/dummy/send_test.go b/dummy/send_test.go index 6a5a91feff0c152b70982e60e769aae53c37813e..9af8ee8796e4d76faa7d45188c60db271d772335 100644 --- a/dummy/send_test.go +++ b/dummy/send_test.go @@ -40,10 +40,10 @@ func TestManager_sendThread(t *testing.T) { go func() { var numReceived int for i := 0; i < 2; i++ { - for m.net.(*testNetworkManager).GetMsgListLen() == numReceived { + for m.networkManager.(*testNetworkManager).GetMsgListLen() == numReceived { time.Sleep(5 * time.Millisecond) } - numReceived = m.net.(*testNetworkManager).GetMsgListLen() + numReceived = m.networkManager.(*testNetworkManager).GetMsgListLen() msgChan <- true } }() @@ -54,7 +54,7 @@ func TestManager_sendThread(t *testing.T) { t.Errorf("Timed out after %s waiting for messages to be sent.", 3*m.avgSendDelta) case <-msgChan: - numReceived += m.net.(*testNetworkManager).GetMsgListLen() + numReceived += m.networkManager.(*testNetworkManager).GetMsgListLen() } select { @@ -62,10 +62,10 @@ func TestManager_sendThread(t *testing.T) { t.Errorf("Timed out after %s waiting for messages to be sent.", 3*m.avgSendDelta) case <-msgChan: - if m.net.(*testNetworkManager).GetMsgListLen() <= numReceived { + if m.networkManager.(*testNetworkManager).GetMsgListLen() <= numReceived { t.Errorf("Failed to receive second send."+ "\nmessages on last receive: %d\nmessages on this receive: %d", - numReceived, m.net.(*testNetworkManager).GetMsgListLen()) + numReceived, m.networkManager.(*testNetworkManager).GetMsgListLen()) } } @@ -115,7 +115,7 @@ func TestManager_sendMessages(t *testing.T) { } // get sent messages - receivedMsgs := m.net.(*testNetworkManager).GetMsgList() + receivedMsgs := m.networkManager.(*testNetworkManager).GetMsgList() // Test that all messages were received if len(receivedMsgs) != len(msgs) { diff --git a/dummy/utils_test.go b/dummy/utils_test.go index cbc441c22d732469ecc77f145c8de9796c6adee7..bc838731f5f42b345c4fbdfd849750b4551c0ef5 100644 --- a/dummy/utils_test.go +++ b/dummy/utils_test.go @@ -59,7 +59,7 @@ func newTestManager(maxNumMessages int, avgSendDelta, randomRange time.Duration, randomRange: randomRange, statusChan: make(chan bool, statusChanLen), store: &store, - net: newTestNetworkManager(sendErr, t), + networkManager: newTestNetworkManager(sendErr, t), rng: fastRNG.NewStreamGenerator(1000, 10, csprng.NewSystemRNG), } diff --git a/xxdk/e2e.go b/xxdk/e2e.go index 1d4b3ba6ae47011af44e12e3ada995a81df47dc1..2fe5fdf87ed43b2b90be8dc7b1286cb19262e067 100644 --- a/xxdk/e2e.go +++ b/xxdk/e2e.go @@ -39,11 +39,11 @@ type E2e struct { // that allows for initializing an E2e object without an E2e-dependant auth.Callbacks type AuthCallbacks interface { Request(partner contact.Contact, receptionID receptionID.EphemeralIdentity, - round rounds.Round, e2e *E2e) + round rounds.Round, messenger *E2e) Confirm(partner contact.Contact, receptionID receptionID.EphemeralIdentity, - round rounds.Round, e2e *E2e) + round rounds.Round, messenger *E2e) Reset(partner contact.Contact, receptionID receptionID.EphemeralIdentity, - round rounds.Round, e2e *E2e) + round rounds.Round, messenger *E2e) } // Login creates a new E2e backed by the xxdk.Cmix persistent versioned.KV diff --git a/xxmutils/restoreContacts.go b/xxmutils/restoreContacts.go index 0f8b6a565b0903fd8ea98b279610a0e307902383..0ec8e38c00b8b2a7693921f88651c633ad643525 100644 --- a/xxmutils/restoreContacts.go +++ b/xxmutils/restoreContacts.go @@ -37,7 +37,7 @@ import ( // xxDK users should not use this function. This function is used by // the mobile phone apps and are not intended to be part of the xxDK. It // should be treated as internal functions specific to the phone apps. -func RestoreContactsFromBackup(backupPartnerIDs []byte, client *xxdk.E2e, +func RestoreContactsFromBackup(backupPartnerIDs []byte, messenger *xxdk.E2e, udManager *ud.Manager, updatesCb interfaces.RestoreContactsUpdater) ([]*id.ID, []*id.ID, []error, error) { @@ -63,7 +63,7 @@ func RestoreContactsFromBackup(backupPartnerIDs []byte, client *xxdk.E2e, } store := stateStore{ - apiStore: client.GetStorage(), + apiStore: messenger.GetStorage(), } // Unmarshal IDs and then check restore state @@ -99,8 +99,8 @@ func RestoreContactsFromBackup(backupPartnerIDs []byte, client *xxdk.E2e, rsWg := &sync.WaitGroup{} rsWg.Add(numRoutines) for i := 0; i < numRoutines; i++ { - go LookupContacts(lookupCh, foundCh, failCh, client, udContact, lcWg) - go ResetSessions(resetContactCh, restoredCh, failCh, client, + go LookupContacts(lookupCh, foundCh, failCh, messenger, udContact, lcWg) + go ResetSessions(resetContactCh, restoredCh, failCh, messenger, rsWg) } @@ -178,13 +178,13 @@ func RestoreContactsFromBackup(backupPartnerIDs []byte, client *xxdk.E2e, // the mobile phone apps and are not intended to be part of the xxDK. It // should be treated as internal functions specific to the phone apps. func LookupContacts(in chan *id.ID, out chan *contact.Contact, - failCh chan failure, client *xxdk.E2e, udContact contact.Contact, + failCh chan failure, messenger *xxdk.E2e, udContact contact.Contact, wg *sync.WaitGroup) { defer wg.Done() // Start looking up contacts with user discovery and feed this // contacts channel. for lookupID := range in { - c, err := LookupContact(lookupID, client, udContact) + c, err := LookupContact(lookupID, messenger, udContact) if err == nil { out <- c continue @@ -205,10 +205,10 @@ func LookupContacts(in chan *id.ID, out chan *contact.Contact, // the mobile phone apps and are not intended to be part of the xxDK. It // should be treated as internal functions specific to the phone apps. func ResetSessions(in, out chan *contact.Contact, failCh chan failure, - client *xxdk.E2e, wg *sync.WaitGroup) { + messenger *xxdk.E2e, wg *sync.WaitGroup) { defer wg.Done() for c := range in { - _, err := client.GetAuth().Reset(*c) + _, err := messenger.GetAuth().Reset(*c) if err == nil { out <- c continue @@ -224,7 +224,7 @@ func ResetSessions(in, out chan *contact.Contact, failCh chan failure, // xxDK users should not use this function. This function is used by // the mobile phone apps and are not intended to be part of the xxDK. It // should be treated as internal functions specific to the phone apps. -func LookupContact(userID *id.ID, client *xxdk.E2e, udContact contact.Contact) ( +func LookupContact(userID *id.ID, messenger *xxdk.E2e, udContact contact.Contact) ( *contact.Contact, error) { // This is a little wonky, but wait until we get called then // set the result to the contact objects details if there is @@ -243,9 +243,9 @@ func LookupContact(userID *id.ID, client *xxdk.E2e, udContact contact.Contact) ( waiter.Lock() // in MS, so 90 seconds - stream := client.GetRng().GetStream() + stream := messenger.GetRng().GetStream() defer stream.Close() - _, _, err = ud.Lookup(client.GetCmix(), stream, client.GetE2E().GetGroup(), + _, _, err = ud.Lookup(messenger.GetCmix(), stream, messenger.GetE2E().GetGroup(), udContact, lookupCB, userID, single.GetDefaultRequestParams()) // Now force a wait for callback to exit