Skip to content
Snippets Groups Projects
Commit 11a672d0 authored by Jake Taylor's avatar Jake Taylor
Browse files

fix cmd directory for new receptionId changes

parent 96034c6b
No related branches found
No related tags found
2 merge requests!510Release,!257change structure of identities in api and bindings
......@@ -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()
......
......@@ -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)
......
......@@ -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 {
......
......@@ -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())
},
}
......
......@@ -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)
......
......@@ -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)
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment