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

clean up of cmd

parent c4c63b43
No related branches found
No related tags found
2 merge requests!510Release,!275Implement connection CLI
......@@ -71,7 +71,7 @@ func secureConnServer(forceLegacy bool, statePass []byte, statePath, regCode str
connChan := make(chan connect.Connection, 1)
// Load client state and identity------------------------------------------
net := loadOrInitNet(statePass, statePath, regCode, cmixParams)
net := loadOrInitCmix(statePass, statePath, regCode, cmixParams)
identity := loadOrInitReceptionIdentity(forceLegacy, net)
// Save contact file-------------------------------------------------------
......@@ -191,7 +191,7 @@ func insecureConnServer(forceLegacy bool, statePass []byte, statePath, regCode s
connChan := make(chan connect.Connection, 1)
// Load client state and identity------------------------------------------
net := loadOrInitNet(statePass, statePath, regCode, cmixParams)
net := loadOrInitCmix(statePass, statePath, regCode, cmixParams)
identity := loadOrInitReceptionIdentity(forceLegacy, net)
// Save contact file-------------------------------------------------------
......@@ -311,7 +311,7 @@ func secureConnClient(forceLegacy bool, statePass []byte, statePath, regCode str
var messenger *xxdk.E2e
if viper.GetBool(connectionEphemeralFlag) {
fmt.Println("Loading ephemerally")
messenger = loadOrInitMessengerEphemeral(forceLegacy, statePass, statePath, regCode,
messenger = loadOrInitEphemeral(forceLegacy, statePass, statePath, regCode,
cmixParams, e2eParams, xxdk.DefaultAuthCallbacks{})
} else {
fmt.Println("Loading non-ephemerally")
......@@ -385,7 +385,7 @@ func insecureConnClient(forceLegacy bool, statePass []byte, statePath, regCode s
var messenger *xxdk.E2e
if viper.GetBool(connectionEphemeralFlag) {
fmt.Println("Loading ephemerally")
messenger = loadOrInitMessengerEphemeral(forceLegacy, statePass, statePath, regCode,
messenger = loadOrInitEphemeral(forceLegacy, statePass, statePath, regCode,
cmixParams, e2eParams, xxdk.DefaultAuthCallbacks{})
} else {
fmt.Println("Loading non-ephemerally")
......
......@@ -71,12 +71,10 @@ func init() {
rootCmd.AddCommand(initCmd)
}
// loadOrInitMessenger will build a new xxdk.E2e from existing storage
// loadOrInitCmix will build a new xxdk.Cmix 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,
cmixParams xxdk.CMIXParams, e2eParams xxdk.E2EParams, cbs xxdk.AuthCallbacks) *xxdk.E2e {
jww.INFO.Printf("Using normal sender")
func loadOrInitCmix(password []byte, storeDir, regCode string,
cmixParams xxdk.CMIXParams) *xxdk.Cmix {
// create a new client if none exist
if _, err := os.Stat(storeDir); errors.Is(err, fs.ErrNotExist) {
// Initialize from scratch
......@@ -97,6 +95,12 @@ func loadOrInitMessenger(forceLegacy bool, password []byte, storeDir, regCode st
jww.FATAL.Panicf("%+v", err)
}
return net
}
// loadOrInitReceptionIdentity will build a new xxdk.ReceptionIdentity from existing storage
// or from a new storage that it will create if none already exists
func loadOrInitReceptionIdentity(forceLegacy bool, net *xxdk.Cmix) xxdk.ReceptionIdentity {
// Load or initialize xxdk.ReceptionIdentity storage
identity, err := xxdk.LoadReceptionIdentity(identityStorageKey, net)
if err != nil {
......@@ -115,116 +119,38 @@ func loadOrInitMessenger(forceLegacy bool, password []byte, storeDir, regCode st
jww.FATAL.Panicf("%+v", err)
}
}
messenger, err := xxdk.Login(net, cbs, identity, e2eParams)
if err != nil {
jww.FATAL.Panicf("%+v", err)
}
return messenger
return identity
}
// loadOrInitMessengerEphemeral will build a new ephemeral xxdk.E2e.
func loadOrInitMessengerEphemeral(forceLegacy bool, password []byte, storeDir, regCode string,
// loadOrInitMessenger 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,
cmixParams xxdk.CMIXParams, e2eParams xxdk.E2EParams, cbs xxdk.AuthCallbacks) *xxdk.E2e {
jww.INFO.Printf("Using normal sender")
// create a new client if none exist
if _, err := os.Stat(storeDir); errors.Is(err, fs.ErrNotExist) {
// Initialize from scratch
ndfJson, err := ioutil.ReadFile(viper.GetString("ndf"))
if err != nil {
jww.FATAL.Panicf("%+v", err)
}
err = xxdk.NewCmix(string(ndfJson), storeDir, password, regCode)
if err != nil {
jww.FATAL.Panicf("%+v", err)
}
}
net := loadOrInitCmix(password, storeDir, regCode, cmixParams)
identity := loadOrInitReceptionIdentity(forceLegacy, net)
// Initialize from storage
net, err := xxdk.LoadCmix(storeDir, password, cmixParams)
if err != nil {
jww.FATAL.Panicf("%+v", err)
}
// Load or initialize xxdk.ReceptionIdentity storage
identity, err := xxdk.LoadReceptionIdentity(identityStorageKey, net)
if err != nil {
if forceLegacy {
jww.INFO.Printf("Forcing legacy sender")
identity, err = xxdk.MakeLegacyReceptionIdentity(net)
} else {
identity, err = xxdk.MakeReceptionIdentity(net)
}
if err != nil {
jww.FATAL.Panicf("%+v", err)
}
err = xxdk.StoreReceptionIdentity(identityStorageKey, identity, net)
if err != nil {
jww.FATAL.Panicf("%+v", err)
}
}
messenger, err := xxdk.LoginEphemeral(net, cbs, identity, e2eParams)
messenger, err := xxdk.Login(net, cbs, identity, e2eParams)
if err != nil {
jww.FATAL.Panicf("%+v", err)
}
return messenger
}
// loadOrInitNet will build a new xxdk.Cmix from existing storage
// or from a new storage that it will create if none already exists
func loadOrInitNet(password []byte, storeDir, regCode string,
cmixParams xxdk.CMIXParams) *xxdk.Cmix {
// create a new client if none exist
if _, err := os.Stat(storeDir); errors.Is(err, fs.ErrNotExist) {
// Initialize from scratch
ndfJson, err := ioutil.ReadFile(viper.GetString("ndf"))
if err != nil {
jww.FATAL.Panicf("%+v", err)
}
// loadOrInitEphemeral will build a new ephemeral xxdk.E2e.
func loadOrInitEphemeral(forceLegacy bool, password []byte, storeDir, regCode string,
cmixParams xxdk.CMIXParams, e2eParams xxdk.E2EParams, cbs xxdk.AuthCallbacks) *xxdk.E2e {
jww.INFO.Printf("Using ephemeral sender")
err = xxdk.NewCmix(string(ndfJson), storeDir, password, regCode)
if err != nil {
jww.FATAL.Panicf("%+v", err)
}
}
net := loadOrInitCmix(password, storeDir, regCode, cmixParams)
identity := loadOrInitReceptionIdentity(forceLegacy, net)
// Initialize from storage
net, err := xxdk.LoadCmix(storeDir, password, cmixParams)
messenger, err := xxdk.LoginEphemeral(net, cbs, identity, e2eParams)
if err != nil {
jww.FATAL.Panicf("%+v", err)
}
return net
}
// loadOrInitReceptionIdentity will build a new xxdk.ReceptionIdentity from existing storage
// or from a new storage that it will create if none already exists
func loadOrInitReceptionIdentity(forceLegacy bool, net *xxdk.Cmix) xxdk.ReceptionIdentity {
// Load or initialize xxdk.ReceptionIdentity storage
identity, err := xxdk.LoadReceptionIdentity(identityStorageKey, net)
if err != nil {
if forceLegacy {
jww.INFO.Printf("Forcing legacy sender")
identity, err = xxdk.MakeLegacyReceptionIdentity(net)
} else {
identity, err = xxdk.MakeReceptionIdentity(net)
}
if err != nil {
jww.FATAL.Panicf("%+v", err)
}
err = xxdk.StoreReceptionIdentity(identityStorageKey, identity, net)
if err != nil {
jww.FATAL.Panicf("%+v", err)
}
}
return identity
return messenger
}
// loadOrInitVanity will build a new xxdk.E2e from existing storage
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment