Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
4a08071a
Commit
4a08071a
authored
2 years ago
by
Josh Brooks
Browse files
Options
Downloads
Plain Diff
Merge branch 'ConnectionCLI' of git.xx.network:elixxir/client into ConnectionCLI
parents
6f5446dd
ebe429d6
No related branches found
No related tags found
2 merge requests
!510
Release
,
!275
Implement connection CLI
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cmd/connect.go
+4
-4
4 additions, 4 deletions
cmd/connect.go
cmd/init.go
+24
-98
24 additions, 98 deletions
cmd/init.go
with
28 additions
and
102 deletions
cmd/connect.go
+
4
−
4
View file @
4a08071a
...
@@ -71,7 +71,7 @@ func secureConnServer(forceLegacy bool, statePass []byte, statePath, regCode str
...
@@ -71,7 +71,7 @@ func secureConnServer(forceLegacy bool, statePass []byte, statePath, regCode str
connChan
:=
make
(
chan
connect
.
Connection
,
1
)
connChan
:=
make
(
chan
connect
.
Connection
,
1
)
// Load client state and identity------------------------------------------
// Load client state and identity------------------------------------------
net
:=
loadOrInit
Net
(
statePass
,
statePath
,
regCode
,
cmixParams
)
net
:=
loadOrInit
Cmix
(
statePass
,
statePath
,
regCode
,
cmixParams
)
identity
:=
loadOrInitReceptionIdentity
(
forceLegacy
,
net
)
identity
:=
loadOrInitReceptionIdentity
(
forceLegacy
,
net
)
// Save contact file-------------------------------------------------------
// Save contact file-------------------------------------------------------
...
@@ -191,7 +191,7 @@ func insecureConnServer(forceLegacy bool, statePass []byte, statePath, regCode s
...
@@ -191,7 +191,7 @@ func insecureConnServer(forceLegacy bool, statePass []byte, statePath, regCode s
connChan
:=
make
(
chan
connect
.
Connection
,
1
)
connChan
:=
make
(
chan
connect
.
Connection
,
1
)
// Load client state and identity------------------------------------------
// Load client state and identity------------------------------------------
net
:=
loadOrInit
Net
(
statePass
,
statePath
,
regCode
,
cmixParams
)
net
:=
loadOrInit
Cmix
(
statePass
,
statePath
,
regCode
,
cmixParams
)
identity
:=
loadOrInitReceptionIdentity
(
forceLegacy
,
net
)
identity
:=
loadOrInitReceptionIdentity
(
forceLegacy
,
net
)
// Save contact file-------------------------------------------------------
// Save contact file-------------------------------------------------------
...
@@ -311,7 +311,7 @@ func secureConnClient(forceLegacy bool, statePass []byte, statePath, regCode str
...
@@ -311,7 +311,7 @@ func secureConnClient(forceLegacy bool, statePass []byte, statePath, regCode str
var
messenger
*
xxdk
.
E2e
var
messenger
*
xxdk
.
E2e
if
viper
.
GetBool
(
connectionEphemeralFlag
)
{
if
viper
.
GetBool
(
connectionEphemeralFlag
)
{
fmt
.
Println
(
"Loading ephemerally"
)
fmt
.
Println
(
"Loading ephemerally"
)
messenger
=
loadOrInit
Messenger
Ephemeral
(
forceLegacy
,
statePass
,
statePath
,
regCode
,
messenger
=
loadOrInitEphemeral
(
forceLegacy
,
statePass
,
statePath
,
regCode
,
cmixParams
,
e2eParams
,
xxdk
.
DefaultAuthCallbacks
{})
cmixParams
,
e2eParams
,
xxdk
.
DefaultAuthCallbacks
{})
}
else
{
}
else
{
fmt
.
Println
(
"Loading non-ephemerally"
)
fmt
.
Println
(
"Loading non-ephemerally"
)
...
@@ -385,7 +385,7 @@ func insecureConnClient(forceLegacy bool, statePass []byte, statePath, regCode s
...
@@ -385,7 +385,7 @@ func insecureConnClient(forceLegacy bool, statePass []byte, statePath, regCode s
var
messenger
*
xxdk
.
E2e
var
messenger
*
xxdk
.
E2e
if
viper
.
GetBool
(
connectionEphemeralFlag
)
{
if
viper
.
GetBool
(
connectionEphemeralFlag
)
{
fmt
.
Println
(
"Loading ephemerally"
)
fmt
.
Println
(
"Loading ephemerally"
)
messenger
=
loadOrInit
Messenger
Ephemeral
(
forceLegacy
,
statePass
,
statePath
,
regCode
,
messenger
=
loadOrInitEphemeral
(
forceLegacy
,
statePass
,
statePath
,
regCode
,
cmixParams
,
e2eParams
,
xxdk
.
DefaultAuthCallbacks
{})
cmixParams
,
e2eParams
,
xxdk
.
DefaultAuthCallbacks
{})
}
else
{
}
else
{
fmt
.
Println
(
"Loading non-ephemerally"
)
fmt
.
Println
(
"Loading non-ephemerally"
)
...
...
This diff is collapsed.
Click to expand it.
cmd/init.go
+
24
−
98
View file @
4a08071a
...
@@ -71,12 +71,10 @@ func init() {
...
@@ -71,12 +71,10 @@ func init() {
rootCmd
.
AddCommand
(
initCmd
)
rootCmd
.
AddCommand
(
initCmd
)
}
}
// loadOrInit
Messenger
will build a new xxdk.
E2e
from existing storage
// loadOrInit
Cmix
will build a new xxdk.
Cmix
from existing storage
// or from a new storage that it will create if none already exists
// or from a new storage that it will create if none already exists
func
loadOrInitMessenger
(
forceLegacy
bool
,
password
[]
byte
,
storeDir
,
regCode
string
,
func
loadOrInitCmix
(
password
[]
byte
,
storeDir
,
regCode
string
,
cmixParams
xxdk
.
CMIXParams
,
e2eParams
xxdk
.
E2EParams
,
cbs
xxdk
.
AuthCallbacks
)
*
xxdk
.
E2e
{
cmixParams
xxdk
.
CMIXParams
)
*
xxdk
.
Cmix
{
jww
.
INFO
.
Printf
(
"Using normal sender"
)
// create a new client if none exist
// create a new client if none exist
if
_
,
err
:=
os
.
Stat
(
storeDir
);
errors
.
Is
(
err
,
fs
.
ErrNotExist
)
{
if
_
,
err
:=
os
.
Stat
(
storeDir
);
errors
.
Is
(
err
,
fs
.
ErrNotExist
)
{
// Initialize from scratch
// Initialize from scratch
...
@@ -97,6 +95,12 @@ func loadOrInitMessenger(forceLegacy bool, password []byte, storeDir, regCode st
...
@@ -97,6 +95,12 @@ func loadOrInitMessenger(forceLegacy bool, password []byte, storeDir, regCode st
jww
.
FATAL
.
Panicf
(
"%+v"
,
err
)
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
// Load or initialize xxdk.ReceptionIdentity storage
identity
,
err
:=
xxdk
.
LoadReceptionIdentity
(
identityStorageKey
,
net
)
identity
,
err
:=
xxdk
.
LoadReceptionIdentity
(
identityStorageKey
,
net
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -115,116 +119,38 @@ func loadOrInitMessenger(forceLegacy bool, password []byte, storeDir, regCode st
...
@@ -115,116 +119,38 @@ func loadOrInitMessenger(forceLegacy bool, password []byte, storeDir, regCode st
jww
.
FATAL
.
Panicf
(
"%+v"
,
err
)
jww
.
FATAL
.
Panicf
(
"%+v"
,
err
)
}
}
}
}
return
identity
messenger
,
err
:=
xxdk
.
Login
(
net
,
cbs
,
identity
,
e2eParams
)
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"%+v"
,
err
)
}
return
messenger
}
}
// loadOrInitMessengerEphemeral will build a new ephemeral xxdk.E2e.
// loadOrInitMessenger will build a new xxdk.E2e from existing storage
func
loadOrInitMessengerEphemeral
(
forceLegacy
bool
,
password
[]
byte
,
storeDir
,
regCode
string
,
// 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
{
cmixParams
xxdk
.
CMIXParams
,
e2eParams
xxdk
.
E2EParams
,
cbs
xxdk
.
AuthCallbacks
)
*
xxdk
.
E2e
{
jww
.
INFO
.
Printf
(
"Using normal sender"
)
jww
.
INFO
.
Printf
(
"Using normal sender"
)
// create a new client if none exist
net
:=
loadOrInitCmix
(
password
,
storeDir
,
regCode
,
cmixParams
)
if
_
,
err
:=
os
.
Stat
(
storeDir
);
errors
.
Is
(
err
,
fs
.
ErrNotExist
)
{
identity
:=
loadOrInitReceptionIdentity
(
forceLegacy
,
net
)
// 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
)
}
}
// Initialize from storage
messenger
,
err
:=
xxdk
.
Login
(
net
,
cbs
,
identity
,
e2eParams
)
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
)
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"%+v"
,
err
)
jww
.
FATAL
.
Panicf
(
"%+v"
,
err
)
}
}
return
messenger
return
messenger
}
}
// loadOrInitNet will build a new xxdk.Cmix from existing storage
// loadOrInitEphemeral will build a new ephemeral xxdk.E2e.
// or from a new storage that it will create if none already exists
func
loadOrInitEphemeral
(
forceLegacy
bool
,
password
[]
byte
,
storeDir
,
regCode
string
,
func
loadOrInitNet
(
password
[]
byte
,
storeDir
,
regCode
string
,
cmixParams
xxdk
.
CMIXParams
,
e2eParams
xxdk
.
E2EParams
,
cbs
xxdk
.
AuthCallbacks
)
*
xxdk
.
E2e
{
cmixParams
xxdk
.
CMIXParams
)
*
xxdk
.
Cmix
{
jww
.
INFO
.
Printf
(
"Using ephemeral 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
)
net
:=
loadOrInitCmix
(
password
,
storeDir
,
regCode
,
cmixParams
)
if
err
!=
nil
{
identity
:=
loadOrInitReceptionIdentity
(
forceLegacy
,
net
)
jww
.
FATAL
.
Panicf
(
"%+v"
,
err
)
}
}
// Initialize from storage
messenger
,
err
:=
xxdk
.
LoginEphemeral
(
net
,
cbs
,
identity
,
e2eParams
)
net
,
err
:=
xxdk
.
LoadCmix
(
storeDir
,
password
,
cmixParams
)
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"%+v"
,
err
)
jww
.
FATAL
.
Panicf
(
"%+v"
,
err
)
}
}
return
messenger
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
}
}
// loadOrInitVanity will build a new xxdk.E2e from existing storage
// loadOrInitVanity will build a new xxdk.E2e from existing storage
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment