From c0f8296b83c2059c7dbadaf3f817ccfdc26edf29 Mon Sep 17 00:00:00 2001 From: joshemb <josh@elixxir.io> Date: Mon, 25 Jul 2022 10:10:18 -0700 Subject: [PATCH] Refactor xxdk.E2e references to user --- bindings/authenticatedConnection.go | 4 +- bindings/connect.go | 4 +- bindings/e2eAuth.go | 4 +- bindings/fileTransfer.go | 14 ++-- cmd/backup.go | 8 +- cmd/broadcast.go | 18 ++--- cmd/callbacks.go | 10 +-- cmd/connect.go | 56 ++++++------- cmd/dumpRounds.go | 10 +-- cmd/fileTransfer.go | 32 ++++---- cmd/group.go | 18 ++--- cmd/init.go | 22 ++--- cmd/precan.go | 10 +-- cmd/proto.go | 6 +- cmd/root.go | 120 ++++++++++++++-------------- cmd/single.go | 24 +++--- cmd/ud.go | 56 ++++++------- cmd/utils.go | 4 +- connect/authCallbacks.go | 12 +-- connect/authenticated.go | 8 +- connect/connect.go | 14 ++-- groupChat/manager.go | 22 ++--- groupChat/manager_test.go | 6 +- groupChat/messenger_test.go | 22 ++--- groupChat/utils_test.go | 8 +- ud/addFact.go | 4 +- ud/lookup_test.go | 4 +- ud/manager.go | 30 +++---- ud/register.go | 4 +- ud/register_test.go | 6 +- ud/remove.go | 4 +- ud/search_test.go | 2 +- ud/utils_test.go | 2 +- xxdk/cmix.go | 8 +- xxdk/e2e.go | 6 +- xxmutils/restoreContacts.go | 22 ++--- 36 files changed, 302 insertions(+), 302 deletions(-) diff --git a/bindings/authenticatedConnection.go b/bindings/authenticatedConnection.go index abbc556b7..33aac039b 100644 --- a/bindings/authenticatedConnection.go +++ b/bindings/authenticatedConnection.go @@ -47,7 +47,7 @@ func (c *Cmix) ConnectWithAuthentication(e2eId int, recipientContact, return nil, err } - messenger, err := e2eTrackerSingleton.get(e2eId) + user, err := e2eTrackerSingleton.get(e2eId) if err != nil { return nil, err } @@ -58,7 +58,7 @@ func (c *Cmix) ConnectWithAuthentication(e2eId int, recipientContact, } connection, err := connect.ConnectWithAuthentication(cont, - messenger.api, params) + user.api, params) return authenticatedConnectionTrackerSingleton.make(connection), err } diff --git a/bindings/connect.go b/bindings/connect.go index 1f02e5f6a..57cb090bd 100644 --- a/bindings/connect.go +++ b/bindings/connect.go @@ -60,7 +60,7 @@ func (c *Cmix) Connect(e2eId int, recipientContact, e2eParamsJSON []byte) ( return nil, err } - messenger, err := e2eTrackerSingleton.get(e2eId) + user, err := e2eTrackerSingleton.get(e2eId) if err != nil { return nil, err } @@ -70,7 +70,7 @@ func (c *Cmix) Connect(e2eId int, recipientContact, e2eParamsJSON []byte) ( return nil, err } - connection, err := connect.Connect(cont, messenger.api, p) + connection, err := connect.Connect(cont, user.api, p) if err != nil { return nil, err } diff --git a/bindings/e2eAuth.go b/bindings/e2eAuth.go index 073dfd8ab..57ea1fe4f 100644 --- a/bindings/e2eAuth.go +++ b/bindings/e2eAuth.go @@ -214,13 +214,13 @@ func (e *E2e) VerifyOwnership( return false, err } - messenger, err := e2eTrackerSingleton.get(e2eId) + user, err := e2eTrackerSingleton.get(e2eId) if err != nil { return false, err } return e.api.GetAuth().VerifyOwnership( - received, verified, messenger.api.GetE2E()), nil + received, verified, user.api.GetE2E()), nil } // AddPartnerCallback adds a new callback that overrides the generic auth diff --git a/bindings/fileTransfer.go b/bindings/fileTransfer.go index 4dfd1d47c..3f9e342ce 100644 --- a/bindings/fileTransfer.go +++ b/bindings/fileTransfer.go @@ -129,15 +129,15 @@ type FileTransferReceiveProgressCallback interface { // - paramsJSON - JSON marshalled fileTransfer.Params func InitFileTransfer(e2eID int, paramsJSON []byte) (*FileTransfer, error) { - // Get messenger from singleton - messenger, err := e2eTrackerSingleton.get(e2eID) + // Get user from singleton + user, err := e2eTrackerSingleton.get(e2eID) if err != nil { return nil, err } // Client info - myID := messenger.api.GetReceptionIdentity().ID - rng := messenger.api.GetRng() + myID := user.api.GetReceptionIdentity().ID + rng := user.api.GetRng() params, err := parseFileTransferParams(paramsJSON) if err != nil { @@ -146,16 +146,16 @@ func InitFileTransfer(e2eID int, paramsJSON []byte) (*FileTransfer, error) { // Create file transfer manager m, err := fileTransfer.NewManager(params, myID, - messenger.api.GetCmix(), messenger.api.GetStorage(), rng) + user.api.GetCmix(), user.api.GetStorage(), rng) // Add file transfer processes to client services tracking - err = messenger.api.AddService(m.StartProcesses) + err = user.api.AddService(m.StartProcesses) if err != nil { return nil, err } // Return wrapped manager - return &FileTransfer{ft: m, e2eCl: messenger}, nil + return &FileTransfer{ft: m, e2eCl: user}, nil } // Send is the bindings-level function for sending a file. diff --git a/cmd/backup.go b/cmd/backup.go index ecac98375..e6df9a991 100644 --- a/cmd/backup.go +++ b/cmd/backup.go @@ -27,7 +27,7 @@ func loadOrInitBackup(backupPath string, backupPass string, password []byte, sto cmixParams xxdk.CMIXParams, e2eParams xxdk.E2EParams, cbs xxdk.AuthCallbacks) *xxdk.E2e { jww.INFO.Printf("Using Backup sender") - // create a new client if none exist + // create a new user if none exist if _, err := os.Stat(storeDir); errors.Is(err, fs.ErrNotExist) { // Initialize from scratch ndfJson, err := ioutil.ReadFile(viper.GetString(ndfFlag)) @@ -49,7 +49,7 @@ func loadOrInitBackup(backupPath string, backupPass string, password []byte, sto jww.FATAL.Panicf("Failed to write backup to file: %+v", err) } - // Construct client from backup data + // Construct cMix from backup data backupIdList, _, err := backup.NewClientFromBackup(string(ndfJson), storeDir, password, []byte(backupPass), backupFile) if err != nil { @@ -92,11 +92,11 @@ func loadOrInitBackup(backupPath string, backupPass string, password []byte, sto } } - messenger, err := xxdk.Login(net, cbs, identity, e2eParams) + user, err := xxdk.Login(net, cbs, identity, e2eParams) if err != nil { jww.FATAL.Panicf("%+v", err) } - return messenger + return user } func loadBackup(backupPath, backupPass string) (backupCrypto.Backup, []byte) { diff --git a/cmd/broadcast.go b/cmd/broadcast.go index bdd460137..2a8d8e315 100644 --- a/cmd/broadcast.go +++ b/cmd/broadcast.go @@ -28,21 +28,21 @@ var broadcastCmd = &cobra.Command{ cmixParams, e2eParams := initParams() authCbs := makeAuthCallbacks( viper.GetBool(unsafeChannelCreationFlag), e2eParams) - client := initE2e(cmixParams, e2eParams, authCbs) + user := initE2e(cmixParams, e2eParams, authCbs) // Write user contact to file - user := client.GetReceptionIdentity() - jww.INFO.Printf("User: %s", user.ID) - writeContact(user.GetContact()) + identity := user.GetReceptionIdentity() + jww.INFO.Printf("User: %s", identity.ID) + writeContact(identity.GetContact()) - err := client.StartNetworkFollower(5 * time.Second) + err := user.StartNetworkFollower(5 * time.Second) if err != nil { jww.FATAL.Panicf("Failed to start network follower: %+v", err) } // Wait until connected or crash on timeout connected := make(chan bool, 10) - client.GetCmix().AddHealthCallback( + user.GetCmix().AddHealthCallback( func(isConnected bool) { connected <- isConnected }) @@ -75,7 +75,7 @@ var broadcastCmd = &cobra.Command{ var cryptChannel *crypto.Channel if viper.GetBool(broadcastNewFlag) { // Create a new broadcast channel - cryptChannel, pk, err = crypto.NewChannel(name, desc, client.GetRng().GetStream()) + cryptChannel, pk, err = crypto.NewChannel(name, desc, user.GetRng().GetStream()) if err != nil { jww.FATAL.Panicf("Failed to create new channel: %+v", err) } @@ -152,7 +152,7 @@ var broadcastCmd = &cobra.Command{ asymmetric := viper.GetString(broadcastAsymmetricFlag) // Connect to broadcast channel - bcl, err := broadcast.NewBroadcastChannel(*channel, client.GetCmix(), client.GetRng()) + bcl, err := broadcast.NewBroadcastChannel(*channel, user.GetCmix(), user.GetRng()) // Create & register symmetric receiver callback receiveChan := make(chan []byte, 100) @@ -284,7 +284,7 @@ var broadcastCmd = &cobra.Command{ jww.INFO.Printf("Received %d/%d Messages!", receivedCount, expectedCnt) bcl.Stop() - err = client.StopNetworkFollower() + err = user.StopNetworkFollower() if err != nil { jww.WARN.Printf("Failed to cleanly close threads: %+v\n", err) } diff --git a/cmd/callbacks.go b/cmd/callbacks.go index d700147c0..df834ca48 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, messenger *xxdk.E2e) { + round rounds.Round, user *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(verifySendFlag) { // Verify message sends were successful - acceptChannelVerified(messenger, requestor.ID, a.params) + acceptChannelVerified(user, requestor.ID, a.params) } else { - acceptChannel(messenger, requestor.ID) + acceptChannel(user, requestor.ID) } a.confCh <- requestor.ID @@ -75,9 +75,9 @@ func (a *authCallbacks) Reset(requestor contact.Contact, fmt.Printf(msg) } -func registerMessageListener(client *xxdk.E2e) chan receive.Message { +func registerMessageListener(user *xxdk.E2e) chan receive.Message { recvCh := make(chan receive.Message, 10000) - listenerID := client.GetE2E().RegisterChannel("DefaultCLIReceiver", + listenerID := user.GetE2E().RegisterChannel("DefaultCLIReceiver", receive.AnyUser(), catalog.NoType, recvCh) jww.INFO.Printf("Message ListenerID: %v", listenerID) return recvCh diff --git a/cmd/connect.go b/cmd/connect.go index 9b11ffa9a..efbd9ddfd 100644 --- a/cmd/connect.go +++ b/cmd/connect.go @@ -70,7 +70,7 @@ func secureConnServer(forceLegacy bool, statePass []byte, statePath, regCode str cmixParams xxdk.CMIXParams, e2eParams xxdk.E2EParams) { connChan := make(chan connect.Connection, 1) - // Load client state and identity------------------------------------------ + // Load cMix state and identity------------------------------------------ net := loadOrInitCmix(statePass, statePath, regCode, cmixParams) identity := loadOrInitReceptionIdentity(forceLegacy, net) @@ -106,7 +106,7 @@ func secureConnServer(forceLegacy bool, statePass []byte, statePath, regCode str // Start network threads--------------------------------------------------- networkFollowerTimeout := 5 * time.Second - err = connectServer.Messenger.StartNetworkFollower(networkFollowerTimeout) + err = connectServer.User.StartNetworkFollower(networkFollowerTimeout) if err != nil { jww.FATAL.Panicf("Failed to start network follower: %+v", err) } @@ -132,7 +132,7 @@ func secureConnServer(forceLegacy bool, statePass []byte, statePath, regCode str connected := make(chan bool, 10) // Provide a callback that will be signalled when network health // status changes - connectServer.Messenger.GetCmix().AddHealthCallback( + connectServer.User.GetCmix().AddHealthCallback( func(isConnected bool) { connected <- isConnected }) @@ -146,7 +146,7 @@ func secureConnServer(forceLegacy bool, statePass []byte, statePath, regCode str select { case conn := <-connChan: // Perform functionality shared by client & server - miscConnectionFunctions(connectServer.Messenger, conn) + miscConnectionFunctions(connectServer.User, conn) case <-connectionTimeout.C: connectionTimeout.Stop() @@ -173,7 +173,7 @@ func secureConnServer(forceLegacy bool, statePass []byte, statePath, regCode str signal.Notify(c, os.Interrupt, syscall.SIGTERM) <-c - err = connectServer.Messenger.StopNetworkFollower() + err = connectServer.User.StopNetworkFollower() if err != nil { jww.ERROR.Printf("Failed to stop network follower: %+v", err) } else { @@ -190,7 +190,7 @@ func insecureConnServer(forceLegacy bool, statePass []byte, statePath, regCode s connChan := make(chan connect.Connection, 1) - // Load client state and identity------------------------------------------ + // Load cMix state and identity------------------------------------------ net := loadOrInitCmix(statePass, statePath, regCode, cmixParams) identity := loadOrInitReceptionIdentity(forceLegacy, net) @@ -224,7 +224,7 @@ func insecureConnServer(forceLegacy bool, statePass []byte, statePath, regCode s // Start network threads--------------------------------------------------- networkFollowerTimeout := 5 * time.Second - err = connectServer.Messenger.StartNetworkFollower(networkFollowerTimeout) + err = connectServer.User.StartNetworkFollower(networkFollowerTimeout) if err != nil { jww.FATAL.Panicf("Failed to start network follower: %+v", err) } @@ -250,7 +250,7 @@ func insecureConnServer(forceLegacy bool, statePass []byte, statePath, regCode s connected := make(chan bool, 10) // Provide a callback that will be signalled when network health // status changes - connectServer.Messenger.GetCmix().AddHealthCallback( + connectServer.User.GetCmix().AddHealthCallback( func(isConnected bool) { connected <- isConnected }) @@ -264,7 +264,7 @@ func insecureConnServer(forceLegacy bool, statePass []byte, statePath, regCode s select { case conn := <-connChan: // Perform functionality shared by client & server - miscConnectionFunctions(connectServer.Messenger, conn) + miscConnectionFunctions(connectServer.User, conn) case <-connectionTimeout.C: connectionTimeout.Stop() @@ -289,7 +289,7 @@ func insecureConnServer(forceLegacy bool, statePass []byte, statePath, regCode s signal.Notify(c, os.Interrupt, syscall.SIGTERM) <-c - err = connectServer.Messenger.StopNetworkFollower() + err = connectServer.User.StopNetworkFollower() if err != nil { jww.ERROR.Printf("Failed to stop network follower: %+v", err) } else { @@ -307,15 +307,15 @@ func insecureConnServer(forceLegacy bool, statePass []byte, statePath, regCode s // Secure (authenticated) connection client path func secureConnClient(forceLegacy bool, statePass []byte, statePath, regCode string, cmixParams xxdk.CMIXParams, e2eParams xxdk.E2EParams) { - // Load client ------------------------------------------------------------------ - var messenger *xxdk.E2e + // Load user ------------------------------------------------------------------ + var user *xxdk.E2e if viper.GetBool(connectionEphemeralFlag) { fmt.Println("Loading ephemerally") - messenger = loadOrInitEphemeral(forceLegacy, statePass, statePath, regCode, + user = loadOrInitEphemeral(forceLegacy, statePass, statePath, regCode, cmixParams, e2eParams, xxdk.DefaultAuthCallbacks{}) } else { fmt.Println("Loading non-ephemerally") - messenger = loadOrInitMessenger(forceLegacy, statePass, statePath, regCode, + user = loadOrInitUser(forceLegacy, statePass, statePath, regCode, cmixParams, e2eParams, xxdk.DefaultAuthCallbacks{}) } @@ -323,7 +323,7 @@ func secureConnClient(forceLegacy bool, statePass []byte, statePath, regCode str // Set networkFollowerTimeout to a value of your choice (seconds) networkFollowerTimeout := 5 * time.Second - err := messenger.StartNetworkFollower(networkFollowerTimeout) + err := user.StartNetworkFollower(networkFollowerTimeout) if err != nil { jww.FATAL.Panicf("Failed to start network follower: %+v", err) } @@ -349,7 +349,7 @@ func secureConnClient(forceLegacy bool, statePass []byte, statePath, regCode str connected := make(chan bool, 10) // Provide a callback that will be signalled when network // health status changes - messenger.GetCmix().AddHealthCallback( + user.GetCmix().AddHealthCallback( func(isConnected bool) { connected <- isConnected }) @@ -362,7 +362,7 @@ func secureConnClient(forceLegacy bool, statePass []byte, statePath, regCode str fmt.Println("Sending connection request") // Establish connection with partner - conn, err := connect.ConnectWithAuthentication(serverContact, messenger, + conn, err := connect.ConnectWithAuthentication(serverContact, user, e2eParams) if err != nil { jww.FATAL.Panicf("[CONN] Failed to build connection with %s: %v", @@ -373,7 +373,7 @@ func secureConnClient(forceLegacy bool, statePass []byte, statePath, regCode str conn.GetPartner().PartnerId()) fmt.Println("Established authenticated connection with server.") - miscConnectionFunctions(messenger, conn) + miscConnectionFunctions(user, conn) } @@ -381,15 +381,15 @@ func secureConnClient(forceLegacy bool, statePass []byte, statePath, regCode str func insecureConnClient(forceLegacy bool, statePass []byte, statePath, regCode string, cmixParams xxdk.CMIXParams, e2eParams xxdk.E2EParams) { - // Load client ------------------------------------------------------------------ - var messenger *xxdk.E2e + // Load user ------------------------------------------------------------------ + var user *xxdk.E2e if viper.GetBool(connectionEphemeralFlag) { fmt.Println("Loading ephemerally") - messenger = loadOrInitEphemeral(forceLegacy, statePass, statePath, regCode, + user = loadOrInitEphemeral(forceLegacy, statePass, statePath, regCode, cmixParams, e2eParams, xxdk.DefaultAuthCallbacks{}) } else { fmt.Println("Loading non-ephemerally") - messenger = loadOrInitMessenger(forceLegacy, statePass, statePath, regCode, + user = loadOrInitUser(forceLegacy, statePass, statePath, regCode, cmixParams, e2eParams, xxdk.DefaultAuthCallbacks{}) } @@ -397,7 +397,7 @@ func insecureConnClient(forceLegacy bool, statePass []byte, statePath, regCode s // Set networkFollowerTimeout to a value of your choice (seconds) networkFollowerTimeout := 5 * time.Second - err := messenger.StartNetworkFollower(networkFollowerTimeout) + err := user.StartNetworkFollower(networkFollowerTimeout) if err != nil { jww.FATAL.Panicf("Failed to start network follower: %+v", err) } @@ -423,7 +423,7 @@ func insecureConnClient(forceLegacy bool, statePass []byte, statePath, regCode s connected := make(chan bool, 10) // Provide a callback that will be signalled when network // health status changes - messenger.GetCmix().AddHealthCallback( + user.GetCmix().AddHealthCallback( func(isConnected bool) { connected <- isConnected }) @@ -438,7 +438,7 @@ func insecureConnClient(forceLegacy bool, statePass []byte, statePath, regCode s serverContact.ID) // Establish connection with partner - handler, err := connect.Connect(serverContact, messenger, + handler, err := connect.Connect(serverContact, user, e2eParams) if err != nil { jww.FATAL.Panicf("[CONN] Failed to build connection with %s: %v", @@ -449,7 +449,7 @@ func insecureConnClient(forceLegacy bool, statePass []byte, statePath, regCode s fmt.Println("Established connection with server") jww.INFO.Printf("[CONN] Established connection with %s", handler.GetPartner().PartnerId()) - miscConnectionFunctions(messenger, handler) + miscConnectionFunctions(user, handler) } //////////////////////////////////////////////////////////////////////////////////////////// @@ -458,7 +458,7 @@ func insecureConnClient(forceLegacy bool, statePass []byte, statePath, regCode s // miscConnectionFunctions contains miscellaneous functionality for the subcommand connect. // This functionality should be shared between client & server. -func miscConnectionFunctions(client *xxdk.E2e, conn connect.Connection) { +func miscConnectionFunctions(user *xxdk.E2e, conn connect.Connection) { // Send a message to connection partner-------------------------------------------- msgBody := viper.GetString(messageFlag) paramsE2E := e2e.GetDefaultParams() @@ -476,7 +476,7 @@ func miscConnectionFunctions(client *xxdk.E2e, conn connect.Connection) { // Verify message sends were successful when verifySendFlag is present if viper.GetBool(verifySendFlag) { - if !verifySendSuccess(client, paramsE2E, roundIDs, + if !verifySendSuccess(user, paramsE2E, roundIDs, conn.GetPartner().PartnerId(), payload) { continue } diff --git a/cmd/dumpRounds.go b/cmd/dumpRounds.go index 79fe5a60a..f690f5ba1 100644 --- a/cmd/dumpRounds.go +++ b/cmd/dumpRounds.go @@ -35,14 +35,14 @@ var dumpRoundsCmd = &cobra.Command{ cmixParams, e2eParams := initParams() authCbs := makeAuthCallbacks( viper.GetBool(unsafeChannelCreationFlag), e2eParams) - client := initE2e(cmixParams, e2eParams, authCbs) - err := client.StartNetworkFollower(5 * time.Second) + user := initE2e(cmixParams, e2eParams, authCbs) + err := user.StartNetworkFollower(5 * time.Second) if err != nil { jww.FATAL.Panicf("%+v", err) } connected := make(chan bool, 10) - client.GetCmix().AddHealthCallback( + user.GetCmix().AddHealthCallback( func(isconnected bool) { connected <- isconnected }) @@ -51,7 +51,7 @@ var dumpRoundsCmd = &cobra.Command{ numRequests := len(roundIDs) requestCh := make(chan bool, numRequests) - registration := client.GetStorage().GetNDF().Registration + registration := user.GetStorage().GetNDF().Registration ecp := registration.EllipticPubKey pubkey, err := ec.LoadPublicKey(ecp) if err != nil { @@ -124,7 +124,7 @@ var dumpRoundsCmd = &cobra.Command{ for i := range roundIDs { rid := roundIDs[i] - err := client.GetCmix().LookupHistoricalRound(rid, rcb) + err := user.GetCmix().LookupHistoricalRound(rid, rcb) if err != nil { fmt.Printf("error on %v: %v", rid, err) } diff --git a/cmd/fileTransfer.go b/cmd/fileTransfer.go index 30420ff02..0a6cfbf97 100644 --- a/cmd/fileTransfer.go +++ b/cmd/fileTransfer.go @@ -38,26 +38,26 @@ var ftCmd = &cobra.Command{ cmixParams, e2eParams := initParams() authCbs := makeAuthCallbacks( viper.GetBool(unsafeChannelCreationFlag), e2eParams) - client := initE2e(cmixParams, e2eParams, authCbs) + user := initE2e(cmixParams, e2eParams, authCbs) // Print user's reception ID and save contact file - user := client.GetReceptionIdentity() - jww.INFO.Printf("User: %s", user.ID) - writeContact(user.GetContact()) + identity := user.GetReceptionIdentity() + jww.INFO.Printf("User: %s", identity.ID) + writeContact(identity.GetContact()) // Start the network follower - err := client.StartNetworkFollower(5 * time.Second) + err := user.StartNetworkFollower(5 * time.Second) if err != nil { jww.FATAL.Panicf("Failed to start the network follower: %+v", err) } // Initialize the file transfer manager maxThroughput := viper.GetInt(fileMaxThroughputFlag) - m, receiveChan := initFileTransferManager(client, maxThroughput) + m, receiveChan := initFileTransferManager(user, maxThroughput) // Wait until connected or crash on timeout connected := make(chan bool, 10) - client.GetCmix().AddHealthCallback( + user.GetCmix().AddHealthCallback( func(isConnected bool) { connected <- isConnected }) @@ -67,7 +67,7 @@ var ftCmd = &cobra.Command{ for numReg, total := 1, 100; numReg < (total*3)/4; { time.Sleep(1 * time.Second) - numReg, total, err = client.GetNodeRegistrationStatus() + numReg, total, err = user.GetNodeRegistrationStatus() if err != nil { jww.FATAL.Panicf( "Failed to get node registration status: %+v", err) @@ -110,7 +110,7 @@ var ftCmd = &cobra.Command{ receiveQuit <- struct{}{} // Stop network follower - err = client.StopNetworkFollower() + err = user.StopNetworkFollower() if err != nil { jww.WARN.Printf("[FT] Failed to stop network follower: %+v", err) } @@ -134,7 +134,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(messenger *xxdk.E2e, maxThroughput int) ( +func initFileTransferManager(user *xxdk.E2e, maxThroughput int) ( *ftE2e.Wrapper, chan receivedFtResults) { // Create interfaces.ReceiveCallback that returns the results on a channel @@ -154,24 +154,24 @@ func initFileTransferManager(messenger *xxdk.E2e, maxThroughput int) ( // Create new manager manager, err := ft.NewManager(p, - messenger.GetReceptionIdentity().ID, - messenger.GetCmix(), - messenger.GetStorage(), - messenger.GetRng()) + user.GetReceptionIdentity().ID, + user.GetCmix(), + user.GetStorage(), + user.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 = messenger.AddService(manager.StartProcesses) + err = user.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, - messenger.GetReceptionIdentity().ID, messenger.GetE2E(), messenger.GetCmix()) + user.GetReceptionIdentity().ID, user.GetE2E(), user.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 9c5e1d09d..1c1b1f721 100644 --- a/cmd/group.go +++ b/cmd/group.go @@ -37,23 +37,23 @@ var groupCmd = &cobra.Command{ cmixParams, e2eParams := initParams() authCbs := makeAuthCallbacks( viper.GetBool(unsafeChannelCreationFlag), e2eParams) - client := initE2e(cmixParams, e2eParams, authCbs) + user := initE2e(cmixParams, e2eParams, authCbs) // Print user's reception ID - user := client.GetReceptionIdentity() - jww.INFO.Printf("User: %s", user.ID) + identity := user.GetReceptionIdentity() + jww.INFO.Printf("User: %s", identity.ID) - err := client.StartNetworkFollower(5 * time.Second) + err := user.StartNetworkFollower(5 * time.Second) if err != nil { jww.FATAL.Panicf("%+v", err) } // Initialize the group chat manager - groupManager, recChan, reqChan := initGroupManager(client) + groupManager, recChan, reqChan := initGroupManager(user) // Wait until connected or crash on timeout connected := make(chan bool, 10) - client.GetCmix().AddHealthCallback( + user.GetCmix().AddHealthCallback( func(isConnected bool) { connected <- isConnected }) @@ -63,7 +63,7 @@ var groupCmd = &cobra.Command{ // the nodes for numReg, total := 1, 100; numReg < (total*3)/4; { time.Sleep(1 * time.Second) - numReg, total, err = client.GetNodeRegistrationStatus() + numReg, total, err = user.GetNodeRegistrationStatus() if err != nil { jww.FATAL.Panicf("%+v", err) } @@ -118,7 +118,7 @@ var groupCmd = &cobra.Command{ // initGroupManager creates a new group chat manager and starts the process // service. -func initGroupManager(messenger *xxdk.E2e) (groupChat.GroupChat, +func initGroupManager(user *xxdk.E2e) (groupChat.GroupChat, chan groupChat.MessageReceive, chan groupStore.Group) { recChan := make(chan groupChat.MessageReceive, 10) @@ -128,7 +128,7 @@ func initGroupManager(messenger *xxdk.E2e) (groupChat.GroupChat, } jww.INFO.Print("[GC] Creating new group manager.") - manager, err := groupChat.NewManager(messenger, requestCb, + manager, err := groupChat.NewManager(user, 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 0c4b874ee..e78ef22bb 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -75,7 +75,7 @@ func init() { // or from a new storage that it will create if none already exists func loadOrInitCmix(password []byte, storeDir, regCode string, cmixParams xxdk.CMIXParams) *xxdk.Cmix { - // create a new client if none exist + // create a new cMix if none exist if _, err := os.Stat(storeDir); errors.Is(err, fs.ErrNotExist) { // Initialize from scratch ndfJson, err := ioutil.ReadFile(viper.GetString(ndfFlag)) @@ -122,20 +122,20 @@ func loadOrInitReceptionIdentity(forceLegacy bool, net *xxdk.Cmix) xxdk.Receptio return identity } -// loadOrInitMessenger will build a new xxdk.E2e from existing storage +// loadOrInitUser will build a new xxdk.E2e from existing storage // or from a new storage that it will create if none already exists -func loadOrInitMessenger(forceLegacy bool, password []byte, storeDir, regCode string, +func loadOrInitUser(forceLegacy bool, password []byte, storeDir, regCode string, cmixParams xxdk.CMIXParams, e2eParams xxdk.E2EParams, cbs xxdk.AuthCallbacks) *xxdk.E2e { jww.INFO.Printf("Using normal sender") net := loadOrInitCmix(password, storeDir, regCode, cmixParams) identity := loadOrInitReceptionIdentity(forceLegacy, net) - messenger, err := xxdk.Login(net, cbs, identity, e2eParams) + user, err := xxdk.Login(net, cbs, identity, e2eParams) if err != nil { jww.FATAL.Panicf("%+v", err) } - return messenger + return user } // loadOrInitEphemeral will build a new ephemeral xxdk.E2e. @@ -146,11 +146,11 @@ func loadOrInitEphemeral(forceLegacy bool, password []byte, storeDir, regCode st net := loadOrInitCmix(password, storeDir, regCode, cmixParams) identity := loadOrInitReceptionIdentity(forceLegacy, net) - messenger, err := xxdk.LoginEphemeral(net, cbs, identity, e2eParams) + user, err := xxdk.LoginEphemeral(net, cbs, identity, e2eParams) if err != nil { jww.FATAL.Panicf("%+v", err) } - return messenger + return user } // loadOrInitVanity will build a new xxdk.E2e from existing storage @@ -159,7 +159,7 @@ func loadOrInitVanity(password []byte, storeDir, regCode, userIdPrefix string, cmixParams xxdk.CMIXParams, e2eParams xxdk.E2EParams, cbs xxdk.AuthCallbacks) *xxdk.E2e { jww.INFO.Printf("Using Vanity sender") - // create a new client if none exist + // create a new cMix if none exist if _, err := os.Stat(storeDir); errors.Is(err, fs.ErrNotExist) { // Initialize from scratch ndfJson, err := ioutil.ReadFile(viper.GetString(ndfFlag)) @@ -167,7 +167,7 @@ func loadOrInitVanity(password []byte, storeDir, regCode, userIdPrefix string, jww.FATAL.Panicf("%+v", err) } - err = xxdk.NewVanityClient(string(ndfJson), storeDir, + err = xxdk.NewVanityCmix(string(ndfJson), storeDir, password, regCode, userIdPrefix) if err != nil { jww.FATAL.Panicf("%+v", err) @@ -193,9 +193,9 @@ func loadOrInitVanity(password []byte, storeDir, regCode, userIdPrefix string, } } - messenger, err := xxdk.Login(net, cbs, identity, e2eParams) + user, err := xxdk.Login(net, cbs, identity, e2eParams) if err != nil { jww.FATAL.Panicf("%+v", err) } - return messenger + return user } diff --git a/cmd/precan.go b/cmd/precan.go index e6993d993..c7155d19e 100644 --- a/cmd/precan.go +++ b/cmd/precan.go @@ -27,7 +27,7 @@ func loadOrInitPrecan(precanId uint, password []byte, storeDir string, cmixParams xxdk.CMIXParams, e2eParams xxdk.E2EParams, cbs xxdk.AuthCallbacks) *xxdk.E2e { jww.INFO.Printf("Using Precanned sender") - // create a new client if none exist + // create a new cMix if none exist if _, err := os.Stat(storeDir); errors.Is(err, fs.ErrNotExist) { // Initialize from scratch ndfJson, err := ioutil.ReadFile(viper.GetString(ndfFlag)) @@ -60,11 +60,11 @@ func loadOrInitPrecan(precanId uint, password []byte, storeDir string, } } - messenger, err := xxdk.Login(net, cbs, identity, e2eParams) + user, err := xxdk.Login(net, cbs, identity, e2eParams) if err != nil { jww.FATAL.Panicf("%+v", err) } - return messenger + return user } func isPrecanID(id *id.ID) bool { @@ -85,10 +85,10 @@ func getPrecanID(recipientID *id.ID) uint { return uint(recipientID.Bytes()[7]) } -func addPrecanAuthenticatedChannel(messenger *xxdk.E2e, recipientID *id.ID, +func addPrecanAuthenticatedChannel(user *xxdk.E2e, recipientID *id.ID, recipient contact.Contact) { jww.WARN.Printf("Precanned user id detected: %s", recipientID) - preUsr, err := messenger.MakePrecannedAuthenticatedChannel( + preUsr, err := user.MakePrecannedAuthenticatedChannel( getPrecanID(recipientID)) if err != nil { jww.FATAL.Panicf("%+v", err) diff --git a/cmd/proto.go b/cmd/proto.go index e5677a55e..e42abd37a 100644 --- a/cmd/proto.go +++ b/cmd/proto.go @@ -25,7 +25,7 @@ func loadOrInitProto(protoUserPath string, password []byte, storeDir string, cmixParams xxdk.CMIXParams, e2eParams xxdk.E2EParams, cbs xxdk.AuthCallbacks) *xxdk.E2e { jww.INFO.Printf("Using Proto sender") - // create a new client if none exist + // create a new cMix if none exist if _, err := os.Stat(storeDir); errors.Is(err, fs.ErrNotExist) { // Initialize from scratch ndfJson, err := ioutil.ReadFile(viper.GetString(ndfFlag)) @@ -70,9 +70,9 @@ func loadOrInitProto(protoUserPath string, password []byte, storeDir string, } } - messenger, err := xxdk.Login(net, cbs, identity, e2eParams) + user, err := xxdk.Login(net, cbs, identity, e2eParams) if err != nil { jww.FATAL.Panicf("%+v", err) } - return messenger + return user } diff --git a/cmd/root.go b/cmd/root.go index 074d710d5..1e10cd3c7 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -71,11 +71,11 @@ var rootCmd = &cobra.Command{ authCbs := makeAuthCallbacks( viper.GetBool(unsafeChannelCreationFlag), e2eParams) - client := initE2e(cmixParams, e2eParams, authCbs) + user := initE2e(cmixParams, e2eParams, authCbs) jww.INFO.Printf("Client Initialized...") - receptionIdentity := client.GetReceptionIdentity() + receptionIdentity := user.GetReceptionIdentity() jww.INFO.Printf("User: %s", receptionIdentity.ID) writeContact(receptionIdentity.GetContact()) @@ -102,12 +102,12 @@ var rootCmd = &cobra.Command{ jww.INFO.Printf("Client: %s, Partner: %s", receptionIdentity.ID, recipientID) - client.GetE2E().EnableUnsafeReception() - recvCh := registerMessageListener(client) + user.GetE2E().EnableUnsafeReception() + recvCh := registerMessageListener(user) jww.INFO.Printf("Starting Network followers...") - err := client.StartNetworkFollower(5 * time.Second) + err := user.StartNetworkFollower(5 * time.Second) if err != nil { jww.FATAL.Panicf("%+v", err) } @@ -116,13 +116,13 @@ var rootCmd = &cobra.Command{ // Wait until connected or crash on timeout connected := make(chan bool, 10) - client.GetCmix().AddHealthCallback( + user.GetCmix().AddHealthCallback( func(isConnected bool) { connected <- isConnected }) waitUntilConnected(connected) - // err = client.RegisterForNotifications("dJwuGGX3KUyKldWK5PgQH8:APA91bFjuvimRc4LqOyMDiy124aLedifA8DhldtaB_b76ggphnFYQWJc_fq0hzQ-Jk4iYp2wPpkwlpE1fsOjs7XWBexWcNZoU-zgMiM0Mso9vTN53RhbXUferCbAiEylucEOacy9pniN") + // err = user.RegisterForNotifications("dJwuGGX3KUyKldWK5PgQH8:APA91bFjuvimRc4LqOyMDiy124aLedifA8DhldtaB_b76ggphnFYQWJc_fq0hzQ-Jk4iYp2wPpkwlpE1fsOjs7XWBexWcNZoU-zgMiM0Mso9vTN53RhbXUferCbAiEylucEOacy9pniN") // if err != nil { // jww.FATAL.Panicf("Failed to register for notifications: %+v", err) // } @@ -135,7 +135,7 @@ var rootCmd = &cobra.Command{ for numReg < (total*3)/4 { time.Sleep(1 * time.Second) - numReg, total, err = client.GetNodeRegistrationStatus() + numReg, total, err = user.GetNodeRegistrationStatus() if err != nil { jww.FATAL.Panicf("%+v", err) } @@ -143,7 +143,7 @@ var rootCmd = &cobra.Command{ numReg, total) } - client.GetBackupContainer().TriggerBackup("Integration test.") + user.GetBackupContainer().TriggerBackup("Integration test.") jww.INFO.Printf("Client backup triggered...") @@ -157,11 +157,11 @@ var rootCmd = &cobra.Command{ // Verify that the confirmation message makes it to the // original sender if viper.GetBool(verifySendFlag) { - acceptChannelVerified(client, recipientID, + acceptChannelVerified(user, recipientID, e2eParams) } else { // Accept channel, agnostic of round result - acceptChannel(client, recipientID) + acceptChannel(user, recipientID) } // Do not wait for channel confirmations if we @@ -169,8 +169,8 @@ var rootCmd = &cobra.Command{ authConfirmed = true } - jww.INFO.Printf("Preexisting E2e partners: %+v", client.GetE2E().GetAllPartnerIDs()) - if client.GetE2E().HasAuthenticatedChannel(recipientID) { + jww.INFO.Printf("Preexisting E2e partners: %+v", user.GetE2E().GetAllPartnerIDs()) + if user.GetE2E().HasAuthenticatedChannel(recipientID) { jww.INFO.Printf("Authenticated channel already in "+ "place for %s", recipientID) authConfirmed = true @@ -184,16 +184,16 @@ var rootCmd = &cobra.Command{ sendAuthReq := viper.GetBool(sendAuthRequestFlag) if !unsafe && !authConfirmed && !isPrecanPartner && sendAuthReq { - addAuthenticatedChannel(client, recipientID, + addAuthenticatedChannel(user, recipientID, recipientContact, e2eParams) } else if !unsafe && !authConfirmed && isPrecanPartner { - addPrecanAuthenticatedChannel(client, + addPrecanAuthenticatedChannel(user, recipientID, recipientContact) authConfirmed = true } else if !unsafe && authConfirmed && !isPrecanPartner && sendAuthReq { jww.WARN.Printf("Resetting negotiated auth channel") - resetAuthenticatedChannel(client, recipientID, + resetAuthenticatedChannel(user, recipientID, recipientContact, e2eParams) authConfirmed = false } @@ -228,16 +228,16 @@ var rootCmd = &cobra.Command{ jww.INFO.Printf("Authentication channel confirmation"+ " took %d seconds", scnt) jww.INFO.Printf("Authenticated partners saved: %v\n PartnersList: %+v", - !client.GetStorage().GetKV().IsMemStore(), client.GetE2E().GetAllPartnerIDs()) + !user.GetStorage().GetKV().IsMemStore(), user.GetE2E().GetAllPartnerIDs()) } // DeleteFingerprint this recipient if viper.GetBool(deleteChannelFlag) { - deleteChannel(client, recipientID) + deleteChannel(user, recipientID) } if viper.GetBool(deleteReceiveRequestsFlag) { - err = client.GetAuth().DeleteReceiveRequests() + err = user.GetAuth().DeleteReceiveRequests() if err != nil { jww.FATAL.Panicf("Failed to delete received requests:"+ " %+v", err) @@ -245,7 +245,7 @@ var rootCmd = &cobra.Command{ } if viper.GetBool(deleteSentRequestsFlag) { - err = client.GetAuth().DeleteSentRequests() + err = user.GetAuth().DeleteSentRequests() if err != nil { jww.FATAL.Panicf("Failed to delete sent requests:"+ " %+v", err) @@ -253,7 +253,7 @@ var rootCmd = &cobra.Command{ } if viper.GetBool(deleteAllRequestsFlag) { - err = client.GetAuth().DeleteAllRequests() + err = user.GetAuth().DeleteAllRequests() if err != nil { jww.FATAL.Panicf("Failed to delete all requests:"+ " %+v", err) @@ -261,7 +261,7 @@ var rootCmd = &cobra.Command{ } if viper.GetBool(deleteRequestFlag) { - err = client.GetAuth().DeleteRequest(recipientID) + err = user.GetAuth().DeleteRequest(recipientID) if err != nil { jww.FATAL.Panicf("Failed to delete request for %s:"+ " %+v", recipientID, err) @@ -288,12 +288,12 @@ var rootCmd = &cobra.Command{ var roundIDs []id.Round if unsafe { e2eParams.Base.DebugTag = "cmd.Unsafe" - roundIDs, _, err = client.GetE2E().SendUnsafe( + roundIDs, _, err = user.GetE2E().SendUnsafe( mt, recipient, payload, e2eParams.Base) } else { e2eParams.Base.DebugTag = "cmd.E2E" - roundIDs, _, _, err = client.GetE2E().SendE2E(mt, + roundIDs, _, _, err = user.GetE2E().SendE2E(mt, recipient, payload, e2eParams.Base) } if err != nil { @@ -302,7 +302,7 @@ var rootCmd = &cobra.Command{ // Verify message sends were successful if viper.GetBool(verifySendFlag) { - if !verifySendSuccess(client, e2eParams.Base, + if !verifySendSuccess(user, e2eParams.Base, roundIDs, recipientID, payload) { continue } @@ -378,10 +378,10 @@ var rootCmd = &cobra.Command{ jww.INFO.Printf("Received %d/%d Messages!", receiveCnt, expectedCnt) fmt.Printf("Received %d\n", receiveCnt) if roundsNotepad != nil { - roundsNotepad.INFO.Printf("\n%s", client.GetCmix().GetVerboseRounds()) + roundsNotepad.INFO.Printf("\n%s", user.GetCmix().GetVerboseRounds()) } wg.Wait() - err = client.StopNetworkFollower() + err = user.StopNetworkFollower() if err != nil { jww.WARN.Printf( "Failed to cleanly close threads: %+v\n", @@ -427,7 +427,7 @@ func initE2e(cmixParams xxdk.CMIXParams, e2eParams xxdk.E2EParams, initLog(viper.GetUint(logLevelFlag), viper.GetString(logFlag)) jww.INFO.Printf(Version()) - // Intake parameters for client initialization + // Intake parameters for user initialization precanId := viper.GetUint(sendIdFlag) protoUserPath := viper.GetString(protoUserPathFlag) userIdPrefix := viper.GetString(userIdPrefixFlag) @@ -439,23 +439,23 @@ func initE2e(cmixParams xxdk.CMIXParams, e2eParams xxdk.E2EParams, forceLegacy := viper.GetBool(forceLegacyFlag) jww.DEBUG.Printf("sessionDir: %v", storeDir) - // Initialize the client of the proper type - var messenger *xxdk.E2e + // Initialize the user of the proper type + var user *xxdk.E2e if precanId != 0 { - messenger = loadOrInitPrecan(precanId, storePassword, storeDir, cmixParams, e2eParams, callbacks) + user = loadOrInitPrecan(precanId, storePassword, storeDir, cmixParams, e2eParams, callbacks) } else if protoUserPath != "" { - messenger = loadOrInitProto(protoUserPath, storePassword, storeDir, cmixParams, e2eParams, callbacks) + user = loadOrInitProto(protoUserPath, storePassword, storeDir, cmixParams, e2eParams, callbacks) } else if userIdPrefix != "" { - messenger = loadOrInitVanity(storePassword, storeDir, regCode, userIdPrefix, cmixParams, e2eParams, callbacks) + user = loadOrInitVanity(storePassword, storeDir, regCode, userIdPrefix, cmixParams, e2eParams, callbacks) } else if backupPath != "" { - messenger = loadOrInitBackup(backupPath, backupPass, storePassword, storeDir, cmixParams, e2eParams, callbacks) + user = loadOrInitBackup(backupPath, backupPass, storePassword, storeDir, cmixParams, e2eParams, callbacks) } else { - messenger = loadOrInitMessenger(forceLegacy, storePassword, storeDir, regCode, cmixParams, e2eParams, callbacks) + user = loadOrInitUser(forceLegacy, storePassword, storeDir, regCode, cmixParams, e2eParams, callbacks) } // Handle protoUser output if protoUser := viper.GetString(protoUserOutFlag); protoUser != "" { - jsonBytes, err := messenger.ConstructProtoUserFile() + jsonBytes, err := user.ConstructProtoUserFile() if err != nil { jww.FATAL.Panicf("cannot construct proto user file: %v", err) @@ -504,24 +504,24 @@ func initE2e(cmixParams xxdk.CMIXParams, e2eParams xxdk.E2EParams, } } _, err := backup.InitializeBackup(backupPass, updateBackupCb, - messenger.GetBackupContainer(), messenger.GetE2E(), messenger.GetStorage(), - nil, messenger.GetStorage().GetKV(), messenger.GetRng()) + user.GetBackupContainer(), user.GetE2E(), user.GetStorage(), + nil, user.GetStorage().GetKV(), user.GetRng()) if err != nil { jww.FATAL.Panicf("Failed to initialize backup with key %q: %+v", backupPass, err) } } - return messenger + return user } -func acceptChannel(messenger *xxdk.E2e, recipientID *id.ID) id.Round { - recipientContact, err := messenger.GetAuth().GetReceivedRequest( +func acceptChannel(user *xxdk.E2e, recipientID *id.ID) id.Round { + recipientContact, err := user.GetAuth().GetReceivedRequest( recipientID) if err != nil { jww.FATAL.Panicf("%+v", err) } - rid, err := messenger.GetAuth().Confirm( + rid, err := user.GetAuth().Confirm( recipientContact) if err != nil { jww.FATAL.Panicf("%+v", err) @@ -530,14 +530,14 @@ func acceptChannel(messenger *xxdk.E2e, recipientID *id.ID) id.Round { return rid } -func deleteChannel(messenger *xxdk.E2e, partnerId *id.ID) { - err := messenger.DeleteContact(partnerId) +func deleteChannel(user *xxdk.E2e, partnerId *id.ID) { + err := user.DeleteContact(partnerId) if err != nil { jww.FATAL.Panicf("%+v", err) } } -func addAuthenticatedChannel(messenger *xxdk.E2e, recipientID *id.ID, +func addAuthenticatedChannel(user *xxdk.E2e, recipientID *id.ID, recipient contact.Contact, e2eParams xxdk.E2EParams) { var allowed bool if viper.GetBool(unsafeChannelCreationFlag) { @@ -560,17 +560,17 @@ func addAuthenticatedChannel(messenger *xxdk.E2e, recipientID *id.ID, recipientContact := recipient if recipientContact.ID != nil && recipientContact.DhPubKey != nil { - me := messenger.GetReceptionIdentity().GetContact() + me := user.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(verifySendFlag) { - requestChannelVerified(messenger, recipientContact, me, e2eParams) + requestChannelVerified(user, recipientContact, me, e2eParams) } else { // Just call Request, agnostic of round result - _, err := messenger.GetAuth().Request(recipientContact, + _, err := user.GetAuth().Request(recipientContact, me.Facts) if err != nil { jww.FATAL.Panicf("%+v", err) @@ -583,7 +583,7 @@ func addAuthenticatedChannel(messenger *xxdk.E2e, recipientID *id.ID, } } -func resetAuthenticatedChannel(messenger *xxdk.E2e, recipientID *id.ID, +func resetAuthenticatedChannel(user *xxdk.E2e, recipientID *id.ID, recipient contact.Contact, e2eParams xxdk.E2EParams) { var allowed bool if viper.GetBool(unsafeChannelCreationFlag) { @@ -611,10 +611,10 @@ func resetAuthenticatedChannel(messenger *xxdk.E2e, recipientID *id.ID, // Verify that the auth request makes it to the recipient // by monitoring the round result if viper.GetBool(verifySendFlag) { - resetChannelVerified(messenger, recipientContact, + resetChannelVerified(user, recipientContact, e2eParams) } else { - _, err := messenger.GetAuth().Reset(recipientContact) + _, err := user.GetAuth().Reset(recipientContact) if err != nil { jww.FATAL.Panicf("%+v", err) } @@ -625,17 +625,17 @@ func resetAuthenticatedChannel(messenger *xxdk.E2e, recipientID *id.ID, } } -func acceptChannelVerified(messenger *xxdk.E2e, recipientID *id.ID, +func acceptChannelVerified(user *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(messenger, recipientID) + rid := acceptChannel(user, recipientID) // Monitor rounds for results - err := messenger.GetCmix().GetRoundResults(roundTimeout, + err := user.GetCmix().GetRoundResults(roundTimeout, makeVerifySendsCallback(retryChan, done), rid) if err != nil { jww.DEBUG.Printf("Could not verify "+ @@ -661,7 +661,7 @@ func acceptChannelVerified(messenger *xxdk.E2e, recipientID *id.ID, } } -func requestChannelVerified(messenger *xxdk.E2e, +func requestChannelVerified(user *xxdk.E2e, recipientContact, me contact.Contact, params xxdk.E2EParams) { roundTimeout := params.Base.CMIXParams.SendTimeout @@ -669,14 +669,14 @@ func requestChannelVerified(messenger *xxdk.E2e, retryChan := make(chan struct{}, 1) done := make(chan struct{}, 1) for { - rid, err := messenger.GetAuth().Request(recipientContact, + rid, err := user.GetAuth().Request(recipientContact, me.Facts) if err != nil { continue } // Monitor rounds for results - err = messenger.GetCmix().GetRoundResults(roundTimeout, + err = user.GetCmix().GetRoundResults(roundTimeout, makeVerifySendsCallback(retryChan, done), rid) if err != nil { @@ -701,7 +701,7 @@ func requestChannelVerified(messenger *xxdk.E2e, } } -func resetChannelVerified(messenger *xxdk.E2e, recipientContact contact.Contact, +func resetChannelVerified(user *xxdk.E2e, recipientContact contact.Contact, params xxdk.E2EParams) { roundTimeout := params.Base.CMIXParams.SendTimeout @@ -709,13 +709,13 @@ func resetChannelVerified(messenger *xxdk.E2e, recipientContact contact.Contact, done := make(chan struct{}, 1) for { - rid, err := messenger.GetAuth().Reset(recipientContact) + rid, err := user.GetAuth().Reset(recipientContact) if err != nil { jww.FATAL.Panicf("%+v", err) } // Monitor rounds for results - err = messenger.GetCmix().GetRoundResults(roundTimeout, + err = user.GetCmix().GetRoundResults(roundTimeout, makeVerifySendsCallback(retryChan, done), rid) if err != nil { diff --git a/cmd/single.go b/cmd/single.go index 60c148fa3..949384075 100644 --- a/cmd/single.go +++ b/cmd/single.go @@ -36,21 +36,21 @@ var singleCmd = &cobra.Command{ cmixParams, e2eParams := initParams() authCbs := makeAuthCallbacks( viper.GetBool(unsafeChannelCreationFlag), e2eParams) - client := initE2e(cmixParams, e2eParams, authCbs) + user := initE2e(cmixParams, e2eParams, authCbs) // Write user contact to file - user := client.GetReceptionIdentity() - jww.INFO.Printf("User: %s", user.ID) - writeContact(user.GetContact()) + identity := user.GetReceptionIdentity() + jww.INFO.Printf("User: %s", identity.ID) + writeContact(identity.GetContact()) - err := client.StartNetworkFollower(5 * time.Second) + err := user.StartNetworkFollower(5 * time.Second) if err != nil { jww.FATAL.Panicf("%+v", err) } // Wait until connected or crash on timeout connected := make(chan bool, 10) - client.GetCmix().AddHealthCallback( + user.GetCmix().AddHealthCallback( func(isconnected bool) { connected <- isconnected }) @@ -68,21 +68,21 @@ var singleCmd = &cobra.Command{ }), } - dhKeyPriv, err := user.GetDHKeyPrivate() + dhKeyPriv, err := identity.GetDHKeyPrivate() if err != nil { jww.FATAL.Panicf("%+v", err) } - myID := user.ID + myID := identity.ID listener := single.Listen(tag, myID, dhKeyPriv, - client.GetCmix(), - client.GetStorage().GetE2EGroup(), + user.GetCmix(), + user.GetStorage().GetE2EGroup(), receiver) for numReg, total := 1, 100; numReg < (total*3)/4; { time.Sleep(1 * time.Second) - numReg, total, err = client.GetNodeRegistrationStatus() + numReg, total, err = user.GetNodeRegistrationStatus() if err != nil { jww.FATAL.Panicf("%+v", err) } @@ -99,7 +99,7 @@ var singleCmd = &cobra.Command{ partner := readSingleUseContact(singleContactFlag) maxMessages := uint8(viper.GetUint(singleMaxMessagesFlag)) - sendSingleUse(client.Cmix, partner, payload, + sendSingleUse(user.Cmix, partner, payload, maxMessages, timeout, tag) } diff --git a/cmd/ud.go b/cmd/ud.go index dfc9f5e20..d15d164c7 100644 --- a/cmd/ud.go +++ b/cmd/ud.go @@ -27,7 +27,7 @@ import ( // udCmd is the user discovery subcommand, which allows for user lookup, // registration, and search. This basically runs a client for these functions -// with the UD module enabled. Normally, clients do not need it so it is not +// with the UD module enabled. Normally, clients do not need it, so it is not // loaded for the rest of the commands. var udCmd = &cobra.Command{ Use: "ud", @@ -37,14 +37,14 @@ var udCmd = &cobra.Command{ cmixParams, e2eParams := initParams() authCbs := makeAuthCallbacks( viper.GetBool(unsafeChannelCreationFlag), e2eParams) - client := initE2e(cmixParams, e2eParams, authCbs) + user := initE2e(cmixParams, e2eParams, authCbs) - // get user and save contact to file - user := client.GetReceptionIdentity() - jww.INFO.Printf("[UD]User: %s", user.ID) - writeContact(user.GetContact()) + // get identity and save contact to file + identity := user.GetReceptionIdentity() + jww.INFO.Printf("[UD]User: %s", identity.ID) + writeContact(identity.GetContact()) - err := client.StartNetworkFollower(50 * time.Millisecond) + err := user.StartNetworkFollower(50 * time.Millisecond) if err != nil { jww.FATAL.Panicf("%+v", err) } @@ -53,7 +53,7 @@ var udCmd = &cobra.Command{ // Wait until connected or crash on timeout connected := make(chan bool, 10) - client.GetCmix().AddHealthCallback( + user.GetCmix().AddHealthCallback( func(isconnected bool) { connected <- isconnected }) @@ -62,14 +62,14 @@ var udCmd = &cobra.Command{ jww.TRACE.Printf("[UD] Connected!") // Make user discovery manager - rng := client.GetRng() + rng := user.GetRng() userToRegister := viper.GetString(udRegisterFlag) - jww.TRACE.Printf("[UD] Registering user %v...", userToRegister) - userDiscoveryMgr, err := ud.NewManager(client, client.GetComms(), - client.NetworkFollowerStatus, userToRegister, nil) + jww.TRACE.Printf("[UD] Registering identity %v...", userToRegister) + userDiscoveryMgr, err := ud.NewManager(user, user.GetComms(), + user.NetworkFollowerStatus, userToRegister, nil) if err != nil { if strings.Contains(err.Error(), ud.IsRegisteredErr) { - userDiscoveryMgr, err = ud.LoadManager(client, client.GetComms()) + userDiscoveryMgr, err = ud.LoadManager(user, user.GetComms()) if err != nil { jww.FATAL.Panicf("Failed to load UD manager: %+v", err) } @@ -78,7 +78,7 @@ var udCmd = &cobra.Command{ } } - jww.INFO.Printf("[UD] Registered user %v", userToRegister) + jww.INFO.Printf("[UD] Registered identity %v", userToRegister) var newFacts fact.FactList phone := viper.GetString(udAddPhoneFlag) @@ -127,8 +127,8 @@ var udCmd = &cobra.Command{ udContact, err := userDiscoveryMgr.GetContact() if err != nil { - fmt.Printf("Failed to get user discovery contact object: %+v", err) - jww.FATAL.Printf("Failed to get user discovery contact object: %+v", err) + fmt.Printf("Failed to get identity discovery contact object: %+v", err) + jww.FATAL.Printf("Failed to get identity discovery contact object: %+v", err) } // Handle lookup (verification) process @@ -146,8 +146,8 @@ var udCmd = &cobra.Command{ } stream := rng.GetStream() - _, _, err = ud.Lookup(client.GetCmix(), - stream, client.GetE2E().GetGroup(), + _, _, err = ud.Lookup(user.GetCmix(), + stream, user.GetE2E().GetGroup(), udContact, cb, lookupID, single.GetDefaultRequestParams()) if err != nil { jww.WARN.Printf("Failed UD lookup: %+v", err) @@ -166,13 +166,13 @@ var udCmd = &cobra.Command{ } jww.INFO.Printf("[UD] BATCHADD: Running") restored, _, _, err := xxmutils.RestoreContactsFromBackup( - idListFile, client, userDiscoveryMgr, nil) + idListFile, user, userDiscoveryMgr, nil) if err != nil { jww.FATAL.Panicf("%+v", err) } for i := 0; i < len(restored); i++ { uid := restored[i] - for !client.GetE2E().HasAuthenticatedChannel(uid) { + for !user.GetE2E().HasAuthenticatedChannel(uid) { time.Sleep(time.Second) } jww.INFO.Printf("[UD] Authenticated channel established for %s", uid) @@ -214,18 +214,18 @@ var udCmd = &cobra.Command{ } err = userDiscoveryMgr.PermanentDeleteAccount(f) if err != nil { - fmt.Printf("Couldn't remove user %s\n", + fmt.Printf("Couldn't remove identity %s\n", userToRemove) jww.FATAL.Panicf( - "Failed to remove user %s: %+v", + "Failed to remove identity %s: %+v", userToRemove, err) } - fmt.Printf("Removed user from discovery: %s\n", + fmt.Printf("Removed identity from discovery: %s\n", userToRemove) } if len(facts) == 0 { - err = client.StopNetworkFollower() + err = user.StopNetworkFollower() if err != nil { jww.WARN.Print(err) } @@ -244,16 +244,16 @@ var udCmd = &cobra.Command{ stream := rng.GetStream() defer stream.Close() jww.INFO.Printf("[UD] Search: %v", facts) - _, _, err = ud.Search(client.GetCmix(), - client.GetEventReporter(), - stream, client.GetE2E().GetGroup(), + _, _, err = ud.Search(user.GetCmix(), + user.GetEventReporter(), + stream, user.GetE2E().GetGroup(), udContact, cb, facts, single.GetDefaultRequestParams()) if err != nil { jww.FATAL.Panicf("%+v", err) } time.Sleep(91 * time.Second) - err = client.StopNetworkFollower() + err = user.StopNetworkFollower() if err != nil { jww.WARN.Print(err) } diff --git a/cmd/utils.go b/cmd/utils.go index 723d1d47d..74ee3a8f5 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -26,7 +26,7 @@ func bindFlagHelper(key string, command *cobra.Command) { } } -func verifySendSuccess(client *xxdk.E2e, paramsE2E e2e.Params, +func verifySendSuccess(user *xxdk.E2e, paramsE2E e2e.Params, roundIDs []id.Round, partnerId *id.ID, payload []byte) bool { retryChan := make(chan struct{}) done := make(chan struct{}, 1) @@ -45,7 +45,7 @@ func verifySendSuccess(client *xxdk.E2e, paramsE2E e2e.Params, } // Monitor rounds for results - err := client.GetCmix().GetRoundResults( + err := user.GetCmix().GetRoundResults( paramsE2E.CMIXParams.Timeout, f, roundIDs...) if err != nil { jww.DEBUG.Printf("Could not verify messages were sent " + diff --git a/connect/authCallbacks.go b/connect/authCallbacks.go index 5415267ca..cf1740905 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, messenger *xxdk.E2e) { + _ receptionID.EphemeralIdentity, _ rounds.Round, user *xxdk.E2e) { if a.requestCallback == nil { jww.ERROR.Printf("Received a request when requests are" + "not enable, will not accept") } - _, err := messenger.GetAuth().Confirm(requestor) + _, err := user.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 := messenger.GetE2E().GetPartner(requestor.ID) + newPartner, err := user.GetE2E().GetPartner(requestor.ID) if err != nil { jww.ERROR.Printf("Unable to build connection with "+ "partner %s: %+v", requestor.ID, err) @@ -142,13 +142,13 @@ func (a serverAuthCallback) Request(requestor contact.Contact, // Return the new Connection object c := BuildConnection( - newPartner, messenger.GetE2E(), messenger.GetAuth(), a.connectionParams) + newPartner, user.GetE2E(), user.GetAuth(), a.connectionParams) a.cl.Add(c) a.requestCallback(c) } // Reset will be called when an auth Reset operation occurs. func (a serverAuthCallback) Reset(requestor contact.Contact, - receptionId receptionID.EphemeralIdentity, round rounds.Round, messenger *xxdk.E2e) { - a.Request(requestor, receptionId, round, messenger) + receptionId receptionID.EphemeralIdentity, round rounds.Round, user *xxdk.E2e) { + a.Request(requestor, receptionId, round, user) } diff --git a/connect/authenticated.go b/connect/authenticated.go index 7e16fd0f8..6a311978d 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, messenger *xxdk.E2e, +func ConnectWithAuthentication(recipient contact.Contact, user *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, messenger, p) + conn, err := Connect(recipient, user, 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 := messenger.GetReceptionIdentity() + identity := user.GetReceptionIdentity() privKey, err := identity.GetRSAPrivatePem() if err != nil { return nil, err } return connectWithAuthentication(conn, timeStart, recipient, - identity.Salt, privKey, messenger.GetRng(), messenger.GetCmix(), p) + identity.Salt, privKey, user.GetRng(), user.GetCmix(), p) } // connectWithAuthentication builds and sends an IdentityAuthentication to diff --git a/connect/connect.go b/connect/connect.go index 526d0780c..b221e5853 100644 --- a/connect/connect.go +++ b/connect/connect.go @@ -81,19 +81,19 @@ type Callback func(connection Connection) // and returns a Connection object for the newly-created partner.Manager // This function is to be used sender-side and will block until the // partner.Manager is confirmed. -func Connect(recipient contact.Contact, messenger *xxdk.E2e, +func Connect(recipient contact.Contact, user *xxdk.E2e, p xxdk.E2EParams) (Connection, error) { // Build callback for E2E negotiation signalChannel := make(chan Connection, 1) cb := func(connection Connection) { signalChannel <- connection } - callback := getClientAuthCallback(cb, nil, messenger.GetE2E(), - messenger.GetAuth(), p) - messenger.GetAuth().AddPartnerCallback(recipient.ID, callback) + callback := getClientAuthCallback(cb, nil, user.GetE2E(), + user.GetAuth(), p) + user.GetAuth().AddPartnerCallback(recipient.ID, callback) // Perform the auth request - _, err := messenger.GetAuth().Reset(recipient) + _, err := user.GetAuth().Reset(recipient) if err != nil { return nil, err } @@ -151,8 +151,8 @@ func StartServer(identity xxdk.ReceptionIdentity, connectionCallback Callback, // ConnectionServer contains type ConnectionServer struct { - Messenger *xxdk.E2e - Cl *ConnectionList + User *xxdk.E2e + Cl *ConnectionList } // handler provides an implementation for the Connection interface. diff --git a/groupChat/manager.go b/groupChat/manager.go index 37ef25a0a..0e8fb0364 100644 --- a/groupChat/manager.go +++ b/groupChat/manager.go @@ -47,22 +47,22 @@ type manager struct { // Callback that is called when a new group request is received requestFunc RequestCallback - messenger groupE2e + user groupE2e } // NewManager creates a new group chat manager -func NewManager(messenger groupE2e, +func NewManager(user groupE2e, requestFunc RequestCallback, receiveFunc Processor) (GroupChat, error) { // Initialize a member object - handler := messenger.GetE2E() + handler := user.GetE2E() member := group.Member{ - ID: messenger.GetReceptionIdentity().ID, + ID: user.GetReceptionIdentity().ID, DhKey: handler.GetHistoricalDHPubkey(), } // Load the group chat storage or create one if one does not exist - kv := messenger.GetStorage().GetKV() + kv := user.GetStorage().GetKV() gStore, err := gs.NewOrLoadStore(kv, member) if err != nil { return nil, errors.Errorf(newGroupStoreErr, err) @@ -73,7 +73,7 @@ func NewManager(messenger groupE2e, gs: gStore, services: make(map[string]Processor), requestFunc: requestFunc, - messenger: messenger, + user: user, } // Register listener for incoming e2e group chat requests @@ -144,21 +144,21 @@ func (m *manager) NumGroups() int { ///////////////////////////////////////////////////////////////////////////////////////// func (m *manager) getCMix() groupCmix { - return m.messenger.GetCmix() + return m.user.GetCmix() } func (m *manager) getE2eHandler() groupE2eHandler { - return m.messenger.GetE2E() + return m.user.GetE2E() } func (m *manager) getReceptionIdentity() xxdk.ReceptionIdentity { - return m.messenger.GetReceptionIdentity() + return m.user.GetReceptionIdentity() } func (m *manager) getRng() *fastRNG.StreamGenerator { - return m.messenger.GetRng() + return m.user.GetRng() } func (m *manager) getE2eGroup() *cyclic.Group { - return m.messenger.GetStorage().GetE2EGroup() + return m.user.GetStorage().GetE2EGroup() } diff --git a/groupChat/manager_test.go b/groupChat/manager_test.go index 07009a543..c5edaeedf 100644 --- a/groupChat/manager_test.go +++ b/groupChat/manager_test.go @@ -48,7 +48,7 @@ func TestNewManager(t *testing.T) { requestChan := make(chan gs.Group) requestFunc := func(g gs.Group) { requestChan <- g } receiveChan := make(chan MessageReceive) - mockMess := newMockMessenger(t, nil) + mockMess := newMockE2e(t, nil) gcInt, err := NewManager(mockMess, requestFunc, mockProcessor{receiveChan}) if err != nil { @@ -106,7 +106,7 @@ func TestNewManager_LoadStorage(t *testing.T) { expectedGroups = append(expectedGroups, grp) } - mockMess := newMockMessenger(t, kv) + mockMess := newMockE2e(t, kv) gcInt, err := NewManager(mockMess, nil, nil) if err != nil { t.Errorf("NewManager returned an error: %+v", err) @@ -144,7 +144,7 @@ func TestNewManager_LoadError(t *testing.T) { expectedErr := strings.SplitN(newGroupStoreErr, "%", 2)[0] - mockMess := newMockMessenger(t, kv) + mockMess := newMockE2e(t, kv) _, err = NewManager(mockMess, nil, nil) if err == nil || !strings.Contains(err.Error(), expectedErr) { t.Errorf("NewManager did not return the expected error."+ diff --git a/groupChat/messenger_test.go b/groupChat/messenger_test.go index 918947452..56436ad65 100644 --- a/groupChat/messenger_test.go +++ b/groupChat/messenger_test.go @@ -15,8 +15,8 @@ import ( "testing" ) -// mockMessenger implementation for groupE2e interface -type mockMessenger struct { +// mockE2e implementation for groupE2e interface +type mockE2e struct { receptionId *id.ID net cmix.Client e2e clientE2E.Handler @@ -25,7 +25,7 @@ type mockMessenger struct { storage storage.Session } -func newMockMessenger(t testing.TB, kv *versioned.KV) groupE2e { +func newMockE2e(t testing.TB, kv *versioned.KV) groupE2e { receptionId := id.NewIdFromString("test", id.User, t) mockCmix := newTestNetworkManager(0) prng := rand.New(rand.NewSource(42)) @@ -34,7 +34,7 @@ func newMockMessenger(t testing.TB, kv *versioned.KV) groupE2e { rng := fastRNG.NewStreamGenerator(1000, 10, csprng.NewSystemRNG) mockSession := newMockSesion(kv) - return mockMessenger{ + return mockE2e{ receptionId: receptionId, net: mockCmix, e2e: e2eHandler, @@ -44,7 +44,7 @@ func newMockMessenger(t testing.TB, kv *versioned.KV) groupE2e { } } -func newMockMessengerWithStore(t testing.TB, sendErr int) groupE2e { +func newMockE2eWithStore(t testing.TB, sendErr int) groupE2e { receptionId := id.NewIdFromString("test", id.User, t) mockCmix := newTestNetworkManager(sendErr) prng := rand.New(rand.NewSource(42)) @@ -52,7 +52,7 @@ func newMockMessengerWithStore(t testing.TB, sendErr int) groupE2e { rng := fastRNG.NewStreamGenerator(1000, 10, csprng.NewSystemRNG) mockSession := newMockSesion(nil) - return mockMessenger{ + return mockE2e{ receptionId: receptionId, net: mockCmix, e2e: &testE2eManager{ @@ -68,15 +68,15 @@ func newMockMessengerWithStore(t testing.TB, sendErr int) groupE2e { } } -func (m mockMessenger) GetCmix() cmix.Client { +func (m mockE2e) GetCmix() cmix.Client { return m.net } -func (m mockMessenger) GetE2E() clientE2E.Handler { +func (m mockE2e) GetE2E() clientE2E.Handler { return m.e2e } -func (m mockMessenger) GetReceptionIdentity() xxdk.ReceptionIdentity { +func (m mockE2e) GetReceptionIdentity() xxdk.ReceptionIdentity { keyData, _ := m.e2e.GetHistoricalDHPrivkey().MarshalJSON() groupData, _ := getGroup().MarshalJSON() return xxdk.ReceptionIdentity{ @@ -86,10 +86,10 @@ func (m mockMessenger) GetReceptionIdentity() xxdk.ReceptionIdentity { } } -func (m mockMessenger) GetRng() *fastRNG.StreamGenerator { +func (m mockE2e) GetRng() *fastRNG.StreamGenerator { return m.rng } -func (m mockMessenger) GetStorage() storage.Session { +func (m mockE2e) GetStorage() storage.Session { return m.storage } diff --git a/groupChat/utils_test.go b/groupChat/utils_test.go index f672c61cc..024d4c024 100644 --- a/groupChat/utils_test.go +++ b/groupChat/utils_test.go @@ -32,10 +32,10 @@ import ( // newTestManager creates a new manager for testing. func newTestManager(t testing.TB) (*manager, gs.Group) { prng := rand.New(rand.NewSource(42)) - mockMess := newMockMessenger(t, nil) + mockMess := newMockE2e(t, nil) m := &manager{ - messenger: mockMess, + user: mockMess, } user := group.Member{ ID: m.getReceptionIdentity().ID, @@ -57,12 +57,12 @@ func newTestManager(t testing.TB) (*manager, gs.Group) { // of the groups in the list is also returned. func newTestManagerWithStore(rng *rand.Rand, numGroups int, sendErr int, requestFunc RequestCallback, t *testing.T) (*manager, gs.Group) { - mockMess := newMockMessengerWithStore(t, sendErr) + mockMess := newMockE2eWithStore(t, sendErr) m := &manager{ services: make(map[string]Processor), requestFunc: requestFunc, - messenger: mockMess, + user: mockMess, } user := group.Member{ ID: m.getReceptionIdentity().ID, diff --git a/ud/addFact.go b/ud/addFact.go index 116975372..20d33bc5f 100644 --- a/ud/addFact.go +++ b/ud/addFact.go @@ -22,7 +22,7 @@ func (m *Manager) SendRegisterFact(f fact.Fact) (string, error) { jww.INFO.Printf("ud.SendRegisterFact(%s)", f.Stringify()) m.factMux.Lock() defer m.factMux.Unlock() - return m.addFact(f, m.messenger.GetReceptionIdentity().ID, m.comms) + return m.addFact(f, m.user.GetReceptionIdentity().ID, m.comms) } // addFact is the helper function for SendRegisterFact. @@ -45,7 +45,7 @@ func (m *Manager) addFact(inFact fact.Fact, myId *id.ID, fHash := factID.Fingerprint(f) // Sign our inFact for putting into the request - privKey, err := m.messenger.GetReceptionIdentity().GetRSAPrivatePem() + privKey, err := m.user.GetReceptionIdentity().GetRSAPrivatePem() if err != nil { return "", err } diff --git a/ud/lookup_test.go b/ud/lookup_test.go index 662ac8552..b85aed132 100644 --- a/ud/lookup_test.go +++ b/ud/lookup_test.go @@ -65,8 +65,8 @@ func TestManager_Lookup(t *testing.T) { defer mockListener.Stop() - r := m.messenger.GetE2E().GetGroup().NewInt(1) - m.messenger.GetE2E().GetGroup().Random(r) + r := m.user.GetE2E().GetGroup().NewInt(1) + m.user.GetE2E().GetGroup().Random(r) s := "" jsonable, err := r.MarshalJSON() if err != nil { diff --git a/ud/manager.go b/ud/manager.go index c9d408f06..eac707be3 100644 --- a/ud/manager.go +++ b/ud/manager.go @@ -27,9 +27,9 @@ const ( // Manager is the control structure for the contacting the user discovery service. type Manager struct { - // messenger is a sub-interface of the e2e.Handler. It allows the Manager + // user is a sub-interface of the e2e.Handler. It allows the Manager // to retrieve the client's E2E information. - messenger udE2e + user udE2e // store is an instantiation of this package's storage object. // It contains the facts that are in some state of being registered @@ -58,7 +58,7 @@ type Manager struct { // It requires that an updated // NDF is available and will error if one is not. // registrationValidationSignature may be set to nil -func NewManager(messenger udE2e, comms Comms, follower udNetworkStatus, +func NewManager(user udE2e, comms Comms, follower udNetworkStatus, username string, registrationValidationSignature []byte) (*Manager, error) { jww.INFO.Println("ud.NewManager()") @@ -69,7 +69,7 @@ func NewManager(messenger udE2e, comms Comms, follower udNetworkStatus, // Initialize manager m := &Manager{ - messenger: messenger, + user: user, comms: comms, registrationValidationSignature: registrationValidationSignature, } @@ -113,7 +113,7 @@ func NewManager(messenger udE2e, comms Comms, follower udNetworkStatus, // NewManagerFromBackup builds a new user discover manager from a backup. // It will construct a manager that is already registered and restore // already registered facts into store. -func NewManagerFromBackup(messenger udE2e, comms Comms, follower udNetworkStatus, +func NewManagerFromBackup(user udE2e, comms Comms, follower udNetworkStatus, email, phone fact.Fact) (*Manager, error) { jww.INFO.Println("ud.NewManagerFromBackup()") if follower() != xxdk.Running { @@ -124,8 +124,8 @@ func NewManagerFromBackup(messenger udE2e, comms Comms, follower udNetworkStatus // Initialize manager m := &Manager{ - messenger: messenger, - comms: comms, + user: user, + comms: comms, } // Initialize our store @@ -188,10 +188,10 @@ func InitStoreFromBackup(kv *versioned.KV, // LoadManager loads the state of the Manager // from disk. This is meant to be called after any the first // instantiation of the manager by NewUserDiscovery. -func LoadManager(messenger udE2e, comms Comms) (*Manager, error) { +func LoadManager(user udE2e, comms Comms) (*Manager, error) { m := &Manager{ - messenger: messenger, - comms: comms, + user: user, + comms: comms, } if !m.isRegistered() { @@ -222,7 +222,7 @@ func (m *Manager) GetStringifiedFacts() []string { // GetContact returns the contact for UD as retrieved from the NDF. func (m *Manager) GetContact() (contact.Contact, error) { - grp, err := m.messenger.GetReceptionIdentity().GetGroup() + grp, err := m.user.GetReceptionIdentity().GetGroup() if err != nil { return contact.Contact{}, err } @@ -319,24 +319,24 @@ func (m *Manager) getOrAddUdHost() (*connect.Host, error) { // getCmix retrieve a sub-interface of cmix.Client. // It allows the Manager to retrieve network state. func (m *Manager) getCmix() udCmix { - return m.messenger.GetCmix() + return m.user.GetCmix() } // getKv returns a versioned.KV used for isRegistered and setRegistered. // This is separated from store operations as store's kv // has a different prefix which breaks backwards compatibility. func (m *Manager) getKv() *versioned.KV { - return m.messenger.GetStorage().GetKV() + return m.user.GetStorage().GetKV() } // getEventReporter returns an event.Reporter. This allows // the Manager to report events to the other levels of the client. func (m *Manager) getEventReporter() event.Reporter { - return m.messenger.GetEventReporter() + return m.user.GetEventReporter() } // getRng returns a fastRNG.StreamGenerator. This RNG is for // generating signatures for adding/removing facts. func (m *Manager) getRng() *fastRNG.StreamGenerator { - return m.messenger.GetRng() + return m.user.GetRng() } diff --git a/ud/register.go b/ud/register.go index bac71c0ce..66aa812b1 100644 --- a/ud/register.go +++ b/ud/register.go @@ -18,7 +18,7 @@ func (m *Manager) register(username string, rng csprng.Source, comm registerUserComms, udHost *connect.Host) error { var err error - identity := m.messenger.GetReceptionIdentity() + identity := m.user.GetReceptionIdentity() privKey, err := identity.GetRSAPrivatePem() if err != nil { return err @@ -43,7 +43,7 @@ func (m *Manager) register(username string, rng csprng.Source, Salt: identity.Salt, }, UID: identity.ID.Marshal(), - Timestamp: m.messenger.GetTransmissionIdentity().RegistrationTimestamp, + Timestamp: m.user.GetTransmissionIdentity().RegistrationTimestamp, } // Sign the identity data and add to user registration message diff --git a/ud/register_test.go b/ud/register_test.go index fc1d4be40..a5bd09bcb 100644 --- a/ud/register_test.go +++ b/ud/register_test.go @@ -43,7 +43,7 @@ func TestManager_register(t *testing.T) { isCorrect("testUser", c.msg, m, t) // Verify the signed identity data - pubKeyPem := m.messenger.GetReceptionIdentity().RSAPrivatePem + pubKeyPem := m.user.GetReceptionIdentity().RSAPrivatePem privKey, err := rsa.LoadPrivateKeyFromPem(pubKeyPem) if err != nil { t.Fatalf("Failed to load public key: %+v", err) @@ -72,7 +72,7 @@ func isCorrect(username string, msg *pb.UDBUserRegistration, m *Manager, t *test m.registrationValidationSignature, msg.PermissioningSignature) } - identity := m.messenger.GetReceptionIdentity() + identity := m.user.GetReceptionIdentity() privKey, err := rsa.LoadPrivateKeyFromPem(identity.RSAPrivatePem) if err != nil { t.Fatalf("Failed to load private key: %v", err) @@ -97,7 +97,7 @@ func isCorrect(username string, msg *pb.UDBUserRegistration, m *Manager, t *test t.Fatalf("%v", err) } - grp := m.messenger.GetE2E().GetGroup() + grp := m.user.GetE2E().GetGroup() dhKeyPub := grp.ExpG(dhKeyPriv, grp.NewInt(1)) if !bytes.Equal(dhKeyPub.Bytes(), msg.IdentityRegistration.DhPubKey) { diff --git a/ud/remove.go b/ud/remove.go index 0e462019a..5502096c7 100644 --- a/ud/remove.go +++ b/ud/remove.go @@ -45,7 +45,7 @@ func (m *Manager) removeFact(f fact.Fact, fHash := factID.Fingerprint(f) // Sign our inFact for putting into the request - identity := m.messenger.GetReceptionIdentity() + identity := m.user.GetReceptionIdentity() privKey, err := identity.GetRSAPrivatePem() if err != nil { return err @@ -89,7 +89,7 @@ func (m *Manager) PermanentDeleteAccount(f fact.Fact) error { return err } - identity := m.messenger.GetReceptionIdentity() + identity := m.user.GetReceptionIdentity() privKey, err := identity.GetRSAPrivatePem() if err != nil { return err diff --git a/ud/search_test.go b/ud/search_test.go index 9276aece3..3d9e68984 100644 --- a/ud/search_test.go +++ b/ud/search_test.go @@ -71,7 +71,7 @@ func TestManager_Search(t *testing.T) { CmixParams: cmix.GetDefaultCMIXParams(), } - _, _, err = Search(m.getCmix(), m.getEventReporter(), prng, m.messenger.GetE2E().GetGroup(), + _, _, err = Search(m.getCmix(), m.getEventReporter(), prng, m.user.GetE2E().GetGroup(), udContact, callback, factList, p) if err != nil { t.Fatalf("Search() returned an error: %+v", err) diff --git a/ud/utils_test.go b/ud/utils_test.go index 084cc16de..c4082605b 100644 --- a/ud/utils_test.go +++ b/ud/utils_test.go @@ -58,7 +58,7 @@ func newTestManager(t *testing.T) (*Manager, *testNetworkManager) { // Create our Manager object tnm := newTestNetworkManager(t) m := &Manager{ - messenger: mockE2e{ + user: mockE2e{ grp: getGroup(), events: event.NewEventManager(), rng: rngGen, diff --git a/xxdk/cmix.go b/xxdk/cmix.go index d490fcb3a..a3a798055 100644 --- a/xxdk/cmix.go +++ b/xxdk/cmix.go @@ -87,14 +87,14 @@ func NewCmix( return err } -// NewVanityClient creates a user with a receptionID that starts with the +// NewVanityCmix creates a user with a receptionID that starts with the // supplied prefix. It creates client storage, generates keys, and connects and // registers with the network. Note that this does not register a username/ // identity, but merely creates a new cryptographic identity for adding such // information at a later date. -func NewVanityClient(ndfJSON, storageDir string, password []byte, +func NewVanityCmix(ndfJSON, storageDir string, password []byte, registrationCode string, userIdPrefix string) error { - jww.INFO.Printf("NewVanityClient()") + jww.INFO.Printf("NewVanityCmix()") rngStreamGen := fastRNG.NewStreamGenerator(12, 1024, csprng.NewSystemRNG) rngStream := rngStreamGen.GetStream() @@ -556,7 +556,7 @@ func DecodeGroups(ndf *ndf.NetworkDefinition) (cmixGrp, e2eGrp *cyclic.Group) { // CheckVersionAndSetupStorage checks the client version and creates a new // storage for user data. This function is common code shared by NewCmix, -//// NewPrecannedClient and NewVanityClient. +//// NewPrecannedClient and NewVanityCmix. func CheckVersionAndSetupStorage(def *ndf.NetworkDefinition, storageDir string, password []byte, userInfo user.Info, cmixGrp, e2eGrp *cyclic.Group, registrationCode string) (storage.Session, error) { diff --git a/xxdk/e2e.go b/xxdk/e2e.go index 86c5f5f66..980d00fe8 100644 --- a/xxdk/e2e.go +++ b/xxdk/e2e.go @@ -39,11 +39,11 @@ type E2e struct { // initializing an E2e object without an E2e-dependant auth.Callbacks. type AuthCallbacks interface { Request(partner contact.Contact, receptionID receptionID.EphemeralIdentity, - round rounds.Round, messenger *E2e) + round rounds.Round, user *E2e) Confirm(partner contact.Contact, receptionID receptionID.EphemeralIdentity, - round rounds.Round, messenger *E2e) + round rounds.Round, user *E2e) Reset(partner contact.Contact, receptionID receptionID.EphemeralIdentity, - round rounds.Round, messenger *E2e) + round rounds.Round, user *E2e) } // Login creates a new E2e backed by the xxdk.Cmix persistent versioned.KV. It diff --git a/xxmutils/restoreContacts.go b/xxmutils/restoreContacts.go index 0ec8e38c0..57c9af7ae 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, messenger *xxdk.E2e, +func RestoreContactsFromBackup(backupPartnerIDs []byte, user *xxdk.E2e, udManager *ud.Manager, updatesCb interfaces.RestoreContactsUpdater) ([]*id.ID, []*id.ID, []error, error) { @@ -63,7 +63,7 @@ func RestoreContactsFromBackup(backupPartnerIDs []byte, messenger *xxdk.E2e, } store := stateStore{ - apiStore: messenger.GetStorage(), + apiStore: user.GetStorage(), } // Unmarshal IDs and then check restore state @@ -99,8 +99,8 @@ func RestoreContactsFromBackup(backupPartnerIDs []byte, messenger *xxdk.E2e, rsWg := &sync.WaitGroup{} rsWg.Add(numRoutines) for i := 0; i < numRoutines; i++ { - go LookupContacts(lookupCh, foundCh, failCh, messenger, udContact, lcWg) - go ResetSessions(resetContactCh, restoredCh, failCh, messenger, + go LookupContacts(lookupCh, foundCh, failCh, user, udContact, lcWg) + go ResetSessions(resetContactCh, restoredCh, failCh, user, rsWg) } @@ -178,13 +178,13 @@ func RestoreContactsFromBackup(backupPartnerIDs []byte, messenger *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, messenger *xxdk.E2e, udContact contact.Contact, + failCh chan failure, user *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, messenger, udContact) + c, err := LookupContact(lookupID, user, 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, - messenger *xxdk.E2e, wg *sync.WaitGroup) { + user *xxdk.E2e, wg *sync.WaitGroup) { defer wg.Done() for c := range in { - _, err := messenger.GetAuth().Reset(*c) + _, err := user.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, messenger *xxdk.E2e, udContact contact.Contact) ( +func LookupContact(userID *id.ID, user *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, messenger *xxdk.E2e, udContact contact.Contact waiter.Lock() // in MS, so 90 seconds - stream := messenger.GetRng().GetStream() + stream := user.GetRng().GetStream() defer stream.Close() - _, _, err = ud.Lookup(messenger.GetCmix(), stream, messenger.GetE2E().GetGroup(), + _, _, err = ud.Lookup(user.GetCmix(), stream, user.GetE2E().GetGroup(), udContact, lookupCB, userID, single.GetDefaultRequestParams()) // Now force a wait for callback to exit -- GitLab