From 71702a272bd47daa396d162bbd29df5ea961cca2 Mon Sep 17 00:00:00 2001 From: joshemb <josh@elixxir.io> Date: Fri, 15 Jul 2022 15:50:01 -0700 Subject: [PATCH] Remove authCbs global in cmd/ --- cmd/broadcast.go | 4 +++- cmd/dumpRounds.go | 5 ++++- cmd/fileTransfer.go | 4 +++- cmd/group.go | 4 +++- cmd/root.go | 23 ++++++++++------------- cmd/single.go | 4 +++- cmd/ud.go | 4 +++- 7 files changed, 29 insertions(+), 19 deletions(-) diff --git a/cmd/broadcast.go b/cmd/broadcast.go index 5d98893bd..feef96ad5 100644 --- a/cmd/broadcast.go +++ b/cmd/broadcast.go @@ -25,7 +25,9 @@ var broadcastCmd = &cobra.Command{ Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { cmixParams, e2eParams := initParams() - client := initE2e(cmixParams, e2eParams) + authCbs := makeAuthCallbacks( + viper.GetBool("unsafe-channel-creation"), e2eParams) + client := initE2e(cmixParams, e2eParams, authCbs) // Write user contact to file user := client.GetReceptionIdentity() diff --git a/cmd/dumpRounds.go b/cmd/dumpRounds.go index 401d894ad..4aa2f7ee8 100644 --- a/cmd/dumpRounds.go +++ b/cmd/dumpRounds.go @@ -11,6 +11,7 @@ package cmd import ( "encoding/base64" "fmt" + "github.com/spf13/viper" "strconv" "time" @@ -32,7 +33,9 @@ var dumpRoundsCmd = &cobra.Command{ roundIDs := parseRoundIDs(args) cmixParams, e2eParams := initParams() - client := initE2e(cmixParams, e2eParams) + authCbs := makeAuthCallbacks( + viper.GetBool("unsafe-channel-creation"), e2eParams) + client := initE2e(cmixParams, e2eParams, authCbs) err := client.StartNetworkFollower(5 * time.Second) if err != nil { jww.FATAL.Panicf("%+v", err) diff --git a/cmd/fileTransfer.go b/cmd/fileTransfer.go index 20e8968bf..f9cdc7be8 100644 --- a/cmd/fileTransfer.go +++ b/cmd/fileTransfer.go @@ -36,7 +36,9 @@ var ftCmd = &cobra.Command{ Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { cmixParams, e2eParams := initParams() - client := initE2e(cmixParams, e2eParams) + authCbs := makeAuthCallbacks( + viper.GetBool("unsafe-channel-creation"), e2eParams) + client := initE2e(cmixParams, e2eParams, authCbs) // Print user's reception ID and save contact file user := client.GetReceptionIdentity() diff --git a/cmd/group.go b/cmd/group.go index 8564ded98..ba15c6d08 100644 --- a/cmd/group.go +++ b/cmd/group.go @@ -35,7 +35,9 @@ var groupCmd = &cobra.Command{ Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { cmixParams, e2eParams := initParams() - client := initE2e(cmixParams, e2eParams) + authCbs := makeAuthCallbacks( + viper.GetBool("unsafe-channel-creation"), e2eParams) + client := initE2e(cmixParams, e2eParams, authCbs) // Print user's reception ID user := client.GetReceptionIdentity() diff --git a/cmd/root.go b/cmd/root.go index ba5e285ac..cbe4a562e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -165,8 +165,6 @@ EnretBzQkeKeBwoB2u6NTiOmUjk= // 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 // appropriately. This is called by main.main(). It only needs to // happen once to the rootCmd. @@ -194,7 +192,9 @@ var rootCmd = &cobra.Command{ cmixParams, e2eParams := initParams() - client := initE2e(cmixParams, e2eParams) + authCbs := makeAuthCallbacks( + viper.GetBool("unsafe-channel-creation"), e2eParams) + client := initE2e(cmixParams, e2eParams, authCbs) jww.INFO.Printf("Client Initialized...") @@ -572,7 +572,8 @@ func initParams() (xxdk.CMIXParams, xxdk.E2EParams) { } // initE2e returns a fully-formed xxdk.E2e object -func initE2e(cmixParams xxdk.CMIXParams, e2eParams xxdk.E2EParams) *xxdk.E2e { +func initE2e(cmixParams xxdk.CMIXParams, e2eParams xxdk.E2EParams, + callbacks *authCallbacks) *xxdk.E2e { initLog(viper.GetUint("logLevel"), viper.GetString("log")) jww.INFO.Printf(Version()) @@ -588,22 +589,18 @@ func initE2e(cmixParams xxdk.CMIXParams, e2eParams xxdk.E2EParams) *xxdk.E2e { forceLegacy := viper.GetBool("force-legacy") jww.DEBUG.Printf("sessionDir: %v", storeDir) - // TODO: This probably shouldn't be initialized globally. - authCbs = makeAuthCallbacks( - viper.GetBool("unsafe-channel-creation"), e2eParams) - // Initialize the client of the proper type var messenger *xxdk.E2e if precanId != 0 { - messenger = loadOrInitPrecan(precanId, storePassword, storeDir, cmixParams, e2eParams, authCbs) + messenger = loadOrInitPrecan(precanId, storePassword, storeDir, cmixParams, e2eParams, callbacks) } else if protoUserPath != "" { - messenger = loadOrInitProto(protoUserPath, storePassword, storeDir, cmixParams, e2eParams, authCbs) + messenger = loadOrInitProto(protoUserPath, storePassword, storeDir, cmixParams, e2eParams, callbacks) } else if userIdPrefix != "" { - messenger = loadOrInitVanity(storePassword, storeDir, regCode, userIdPrefix, cmixParams, e2eParams, authCbs) + messenger = loadOrInitVanity(storePassword, storeDir, regCode, userIdPrefix, cmixParams, e2eParams, callbacks) } else if backupPath != "" { - messenger = loadOrInitBackup(backupPath, backupPass, storePassword, storeDir, cmixParams, e2eParams, authCbs) + messenger = loadOrInitBackup(backupPath, backupPass, storePassword, storeDir, cmixParams, e2eParams, callbacks) } else { - messenger = loadOrInitMessenger(forceLegacy, storePassword, storeDir, regCode, cmixParams, e2eParams, authCbs) + messenger = loadOrInitMessenger(forceLegacy, storePassword, storeDir, regCode, cmixParams, e2eParams, callbacks) } // Handle protoUser output diff --git a/cmd/single.go b/cmd/single.go index 6a7e99575..849c747e6 100644 --- a/cmd/single.go +++ b/cmd/single.go @@ -34,7 +34,9 @@ var singleCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { cmixParams, e2eParams := initParams() - client := initE2e(cmixParams, e2eParams) + authCbs := makeAuthCallbacks( + viper.GetBool("unsafe-channel-creation"), e2eParams) + client := initE2e(cmixParams, e2eParams, authCbs) // Write user contact to file user := client.GetReceptionIdentity() diff --git a/cmd/ud.go b/cmd/ud.go index d49b3d795..17a6c7466 100644 --- a/cmd/ud.go +++ b/cmd/ud.go @@ -35,7 +35,9 @@ var udCmd = &cobra.Command{ Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { cmixParams, e2eParams := initParams() - client := initE2e(cmixParams, e2eParams) + authCbs := makeAuthCallbacks( + viper.GetBool("unsafe-channel-creation"), e2eParams) + client := initE2e(cmixParams, e2eParams, authCbs) // get user and save contact to file user := client.GetReceptionIdentity() -- GitLab