diff --git a/cmd/broadcast.go b/cmd/broadcast.go index c4c1209e95bb462b808adc79947bf8237988f99c..1b4039dd54afbaca2ed87ae257c5c584fcb52a73 100644 --- a/cmd/broadcast.go +++ b/cmd/broadcast.go @@ -23,7 +23,7 @@ var broadcastCmd = &cobra.Command{ Short: "Send broadcast messages", Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { - client := initClient() + client := initE2e() // Write user contact to file user := client.GetReceptionIdentity() diff --git a/cmd/fileTransfer.go b/cmd/fileTransfer.go index bdafb1edf63440c3f1109516f687a66ba2778b37..468bc50fe270ecc3a9114cc8aedf8627ddcd0f90 100644 --- a/cmd/fileTransfer.go +++ b/cmd/fileTransfer.go @@ -36,11 +36,11 @@ var ftCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { // Initialise a new client - client := initClient() + client := initE2e() // Print user's reception ID and save contact file - user := client.GetUser() - jww.INFO.Printf("User: %s", user.ReceptionID) + user := client.GetReceptionIdentity() + jww.INFO.Printf("User: %s", user.ID) writeContact(user.GetContact()) // Start the network follower @@ -152,7 +152,7 @@ func initFileTransferManager(client *xxdk.E2e, maxThroughput int) ( // Create new manager manager, err := ft.NewManager(p, - client.GetUser().ReceptionID, + client.GetReceptionIdentity().ID, client.GetCmix(), client.GetStorage(), client.GetRng()) @@ -169,7 +169,7 @@ func initFileTransferManager(client *xxdk.E2e, maxThroughput int) ( e2eParams := ftE2e.DefaultParams() e2eFt, err := ftE2e.NewWrapper(receiveCB, e2eParams, manager, - client.GetUser().ReceptionID, client.GetE2E(), client.GetCmix()) + client.GetReceptionIdentity().ID, client.GetE2E(), client.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 8ea7fd73870ec504605674be1f3c2817412abe75..9a718542250f5cc89977c02e45f87677e535c766 100644 --- a/cmd/group.go +++ b/cmd/group.go @@ -34,11 +34,11 @@ var groupCmd = &cobra.Command{ Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { - client := initClient() + client := initE2e() // Print user's reception ID - user := client.GetUser() - jww.INFO.Printf("User: %s", user.ReceptionID) + user := client.GetReceptionIdentity() + jww.INFO.Printf("User: %s", user.ID) err := client.StartNetworkFollower(5 * time.Second) if err != nil { diff --git a/cmd/init.go b/cmd/init.go index f5c7483d088ae7bb42c2ee9ceac7ad471bc841d8..75ea00e6c75bee432de3164d6f721291028ef97b 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -9,35 +9,21 @@ package cmd import ( - jww "github.com/spf13/jwalterweatherman" - "gitlab.com/elixxir/client/xxdk" - "github.com/spf13/cobra" + jww "github.com/spf13/jwalterweatherman" "github.com/spf13/viper" ) -const identityStorageKey = "identityStorageKey" - // initCmd creates a new user object with the given NDF var initCmd = &cobra.Command{ Use: "init", Short: "Initialize a user ID but do not connect to the network", Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { - client := createClient() - - identity, err := xxdk.MakeReceptionIdentity(client) - if err != nil { - return - } - - err = xxdk.StoreReceptionIdentity(identityStorageKey, identity, client) - if err != nil { - return - } + _, receptionIdentity := initCmix() - jww.INFO.Printf("User: %s", identity.ID) - writeContact(identity.GetContact()) + jww.INFO.Printf("User: %s", receptionIdentity.ID) + writeContact(receptionIdentity.GetContact()) }, } diff --git a/cmd/root.go b/cmd/root.go index 0f0a42ad98fddb2791e659930573a752f639e555..813bd9c41932a4c0a59b9f742c12fe071027f6d5 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -167,6 +167,9 @@ EnretBzQkeKeBwoB2u6NTiOmUjk= testNetCert = `` ) +// Key used for storing xxdk.ReceptionIdentity objects +const identityStorageKey = "identityStorageKey" + var authCbs *authCallbacks // Execute adds all child commands to the root command and sets flags @@ -194,14 +197,12 @@ var rootCmd = &cobra.Command{ pprof.StartCPUProfile(f) } - client := initClient() + client := initE2e() jww.INFO.Printf("Client Initialized...") - user := client.GetUser() - jww.INFO.Printf("USERPUBKEY: %s", - user.E2eDhPublicKey.TextVerbose(16, 0)) - jww.INFO.Printf("User: %s", user.ReceptionID) + user := client.GetReceptionIdentity() + jww.INFO.Printf("User: %s", user.ID) writeContact(user.GetContact()) // get Recipient and/or set it to myself @@ -218,11 +219,11 @@ var rootCmd = &cobra.Command{ // Set it to myself if recipientID == nil { jww.INFO.Printf("sending message to self") - recipientID = user.ReceptionID + recipientID = user.ID recipientContact = user.GetContact() } - jww.INFO.Printf("Client: %s, Partner: %s", user.ReceptionID, + jww.INFO.Printf("Client: %s, Partner: %s", user.ID, recipientID) client.GetE2E().EnableUnsafeReception() @@ -533,7 +534,8 @@ var rootCmd = &cobra.Command{ }, } -func createClient() *xxdk.Cmix { +// initCmix returns a newly-initialized xxdk.Cmix object and its stored xxdk.ReceptionIdentity +func initCmix() (*xxdk.Cmix, xxdk.ReceptionIdentity) { logLevel := viper.GetUint("logLevel") initLog(logLevel, viper.GetString("log")) jww.INFO.Printf(Version()) @@ -630,7 +632,21 @@ func createClient() *xxdk.Cmix { if err != nil { jww.FATAL.Panicf("%+v", err) } - return client + + // Attempt to load extant xxdk.ReceptionIdentity + identity, err := xxdk.LoadReceptionIdentity(identityStorageKey, client) + if err != nil { + // If no extant xxdk.ReceptionIdentity, generate and store a new one + identity, err = xxdk.MakeReceptionIdentity(client) + if err != nil { + jww.FATAL.Panicf("%+v", err) + } + err = xxdk.StoreReceptionIdentity(identityStorageKey, identity, client) + if err != nil { + jww.FATAL.Panicf("%+v", err) + } + } + return client, identity } func initParams() xxdk.Params { @@ -654,8 +670,9 @@ func initParams() xxdk.Params { return p } -func initClient() *xxdk.E2e { - createClient() +// initE2e returns a fully-formed xxdk.E2e object +func initE2e() *xxdk.E2e { + _, receptionIdentity := initCmix() pass := parsePassword(viper.GetString("password")) storeDir := viper.GetString("session") @@ -664,7 +681,7 @@ func initClient() *xxdk.E2e { params := initParams() // load the client - baseclient, err := xxdk.LoadCmix(storeDir, pass, params) + baseClient, err := xxdk.LoadCmix(storeDir, pass, params) if err != nil { jww.FATAL.Panicf("%+v", err) @@ -673,7 +690,7 @@ func initClient() *xxdk.E2e { authCbs = makeAuthCallbacks( viper.GetBool("unsafe-channel-creation")) - client, err := xxdk.LoginLegacy(baseclient, authCbs) + client, err := xxdk.Login(baseClient, authCbs, receptionIdentity) if err != nil { jww.FATAL.Panicf("%+v", err) } @@ -783,7 +800,7 @@ func addAuthenticatedChannel(client *xxdk.E2e, recipientID *id.ID, recipientContact := recipient if recipientContact.ID != nil && recipientContact.DhPubKey != nil { - me := client.GetUser().GetContact() + me := client.GetReceptionIdentity().GetContact() jww.INFO.Printf("Requesting auth channel from: %s", recipientID) diff --git a/cmd/single.go b/cmd/single.go index 2ce03e5c35162a909d3c502410ed35bede436c13..ed6939618864287668739abd0e6e258c02ae41f4 100644 --- a/cmd/single.go +++ b/cmd/single.go @@ -33,12 +33,11 @@ var singleCmd = &cobra.Command{ Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { - client := initClient() + client := initE2e() // Write user contact to file - user := client.GetUser() - jww.INFO.Printf("User: %s", user.ReceptionID) - jww.INFO.Printf("User Transmission: %s", user.TransmissionID) + user := client.GetReceptionIdentity() + jww.INFO.Printf("User: %s", user.ID) writeContact(user.GetContact()) err := client.StartNetworkFollower(5 * time.Second) @@ -66,9 +65,14 @@ var singleCmd = &cobra.Command{ }), } - myID := client.GetUser().ReceptionID + dhKeyPriv, err := user.GetDHKeyPrivate() + if err != nil { + jww.FATAL.Panicf("%+v", err) + } + + myID := user.ID listener := single.Listen(tag, myID, - client.GetUser().E2eDhPrivateKey, + dhKeyPriv, client.GetCmix(), client.GetStorage().GetE2EGroup(), receiver) diff --git a/cmd/ud.go b/cmd/ud.go index 4666cba3fec19f620b0903e191c3955b2b42439a..94de6775c2a031dc37410fdc186dc4b090f1186c 100644 --- a/cmd/ud.go +++ b/cmd/ud.go @@ -33,11 +33,11 @@ var udCmd = &cobra.Command{ Short: "Register for and search users using the xx network user discovery service.", Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { - client := initClient() + client := initE2e() // get user and save contact to file - user := client.GetUser() - jww.INFO.Printf("User: %s", user.ReceptionID) + user := client.GetReceptionIdentity() + jww.INFO.Printf("User: %s", user.ID) writeContact(user.GetContact()) // // Set up reception handler