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
ed63be57
Commit
ed63be57
authored
2 years ago
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Constant flags and clean exit code
parent
16c3db3f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!510
Release
,
!275
Implement connection CLI
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cmd/connect.go
+51
-38
51 additions, 38 deletions
cmd/connect.go
with
51 additions
and
38 deletions
cmd/connect.go
+
51
−
38
View file @
ed63be57
...
@@ -17,6 +17,9 @@ import (
...
@@ -17,6 +17,9 @@ import (
"gitlab.com/elixxir/client/e2e"
"gitlab.com/elixxir/client/e2e"
"gitlab.com/elixxir/client/e2e/receive"
"gitlab.com/elixxir/client/e2e/receive"
"gitlab.com/elixxir/client/xxdk"
"gitlab.com/elixxir/client/xxdk"
"os"
"os/signal"
"syscall"
"time"
"time"
)
)
...
@@ -36,8 +39,8 @@ var connectionCmd = &cobra.Command{
...
@@ -36,8 +39,8 @@ var connectionCmd = &cobra.Command{
regCode
:=
viper
.
GetString
(
"regcode"
)
regCode
:=
viper
.
GetString
(
"regcode"
)
cmixParams
,
e2eParams
:=
initParams
()
cmixParams
,
e2eParams
:=
initParams
()
forceLegacy
:=
viper
.
GetBool
(
"force-legacy"
)
forceLegacy
:=
viper
.
GetBool
(
"force-legacy"
)
if
viper
.
GetBool
(
"s
tartServer
"
)
{
if
viper
.
GetBool
(
connectionS
tartServer
Flag
)
{
if
viper
.
GetBool
(
"a
uthenticated
"
)
{
if
viper
.
GetBool
(
connectionA
uthenticated
Flag
)
{
secureConnServer
(
forceLegacy
,
statePass
,
statePath
,
regCode
,
secureConnServer
(
forceLegacy
,
statePass
,
statePath
,
regCode
,
cmixParams
,
e2eParams
)
cmixParams
,
e2eParams
)
}
else
{
}
else
{
...
@@ -45,7 +48,7 @@ var connectionCmd = &cobra.Command{
...
@@ -45,7 +48,7 @@ var connectionCmd = &cobra.Command{
cmixParams
,
e2eParams
)
cmixParams
,
e2eParams
)
}
}
}
else
{
}
else
{
if
viper
.
GetBool
(
"a
uthenticated
"
)
{
if
viper
.
GetBool
(
connectionA
uthenticated
Flag
)
{
secureConnClient
(
forceLegacy
,
statePass
,
statePath
,
regCode
,
secureConnClient
(
forceLegacy
,
statePass
,
statePath
,
regCode
,
cmixParams
,
e2eParams
)
cmixParams
,
e2eParams
)
}
else
{
}
else
{
...
@@ -152,7 +155,7 @@ func secureConnServer(forceLegacy bool, statePass []byte, statePath, regCode str
...
@@ -152,7 +155,7 @@ func secureConnServer(forceLegacy bool, statePass []byte, statePath, regCode str
}
}
// Keep server running to receive messages------------------------------------
// Keep server running to receive messages------------------------------------
serverTimeout
:=
viper
.
GetDuration
(
"s
erverTimeout
"
)
serverTimeout
:=
viper
.
GetDuration
(
connectionS
erverTimeout
Flag
)
if
serverTimeout
!=
0
{
if
serverTimeout
!=
0
{
timer
:=
time
.
NewTimer
(
serverTimeout
)
timer
:=
time
.
NewTimer
(
serverTimeout
)
select
{
select
{
...
@@ -163,8 +166,21 @@ func secureConnServer(forceLegacy bool, statePass []byte, statePath, regCode str
...
@@ -163,8 +166,21 @@ func secureConnServer(forceLegacy bool, statePass []byte, statePath, regCode str
}
}
}
}
// If timeout is not specified, leave as long-running thread
// Keep app running to receive messages------------------------------------
select
{}
// Wait until the user terminates the program
c
:=
make
(
chan
os
.
Signal
)
signal
.
Notify
(
c
,
os
.
Interrupt
,
syscall
.
SIGTERM
)
<-
c
err
=
connectServer
.
Messenger
.
StopNetworkFollower
()
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Failed to stop network follower: %+v"
,
err
)
}
else
{
jww
.
INFO
.
Printf
(
"Stopped network follower."
)
}
os
.
Exit
(
0
)
}
}
...
@@ -257,8 +273,8 @@ func insecureConnServer(forceLegacy bool, statePass []byte, statePath, regCode s
...
@@ -257,8 +273,8 @@ func insecureConnServer(forceLegacy bool, statePass []byte, statePath, regCode s
}
}
// Keep server running to receive messages------------------------------------
// Keep server running to receive messages------------------------------------
if
viper
.
GetDuration
(
"s
erverTimeout
"
)
!=
0
{
if
viper
.
GetDuration
(
connectionS
erverTimeout
Flag
)
!=
0
{
timer
:=
time
.
NewTimer
(
viper
.
GetDuration
(
"s
erverTimeout
"
))
timer
:=
time
.
NewTimer
(
viper
.
GetDuration
(
connectionS
erverTimeout
Flag
))
select
{
select
{
case
<-
timer
.
C
:
case
<-
timer
.
C
:
fmt
.
Println
(
"Shutting down connection server"
)
fmt
.
Println
(
"Shutting down connection server"
)
...
@@ -266,9 +282,21 @@ func insecureConnServer(forceLegacy bool, statePass []byte, statePath, regCode s
...
@@ -266,9 +282,21 @@ func insecureConnServer(forceLegacy bool, statePass []byte, statePath, regCode s
return
return
}
}
}
}
// Keep app running to receive messages------------------------------------
// If timeout is not specified, leave as long-running thread
// Wait until the user terminates the program
select
{}
c
:=
make
(
chan
os
.
Signal
)
signal
.
Notify
(
c
,
os
.
Interrupt
,
syscall
.
SIGTERM
)
<-
c
err
=
connectServer
.
Messenger
.
StopNetworkFollower
()
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Failed to stop network follower: %+v"
,
err
)
}
else
{
jww
.
INFO
.
Printf
(
"Stopped network follower."
)
}
os
.
Exit
(
0
)
}
}
...
@@ -321,7 +349,7 @@ func secureConnClient(forceLegacy bool, statePass []byte, statePath, regCode str
...
@@ -321,7 +349,7 @@ func secureConnClient(forceLegacy bool, statePass []byte, statePath, regCode str
waitUntilConnected
(
connected
)
waitUntilConnected
(
connected
)
// Connect with the server-------------------------------------------------
// Connect with the server-------------------------------------------------
contactPath
:=
viper
.
GetString
(
"
connect
"
)
contactPath
:=
viper
.
GetString
(
connect
ionFlag
)
serverContact
:=
getContactFromFile
(
contactPath
)
serverContact
:=
getContactFromFile
(
contactPath
)
fmt
.
Println
(
"Sending connection request"
)
fmt
.
Println
(
"Sending connection request"
)
...
@@ -387,7 +415,7 @@ func insecureConnClient(forceLegacy bool, statePass []byte, statePath, regCode s
...
@@ -387,7 +415,7 @@ func insecureConnClient(forceLegacy bool, statePass []byte, statePath, regCode s
waitUntilConnected
(
connected
)
waitUntilConnected
(
connected
)
// Connect with the server-------------------------------------------------
// Connect with the server-------------------------------------------------
contactPath
:=
viper
.
GetString
(
"
connect
"
)
contactPath
:=
viper
.
GetString
(
connect
ionFlag
)
serverContact
:=
getContactFromFile
(
contactPath
)
serverContact
:=
getContactFromFile
(
contactPath
)
fmt
.
Println
(
"Sending connection request"
)
fmt
.
Println
(
"Sending connection request"
)
jww
.
INFO
.
Printf
(
"[CONN] Sending connection request to %s"
,
jww
.
INFO
.
Printf
(
"[CONN] Sending connection request to %s"
,
...
@@ -445,7 +473,7 @@ func miscConnectionFunctions(client *xxdk.E2e, conn connect.Connection) {
...
@@ -445,7 +473,7 @@ func miscConnectionFunctions(client *xxdk.E2e, conn connect.Connection) {
}
}
// Disconnect from connection partner--------------------------------------------
// Disconnect from connection partner--------------------------------------------
if
viper
.
GetBool
(
"d
isconnect
"
)
{
if
viper
.
GetBool
(
connectionD
isconnect
Flag
)
{
// Close the connection
// Close the connection
if
err
:=
conn
.
Close
();
err
!=
nil
{
if
err
:=
conn
.
Close
();
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"Failed to disconnect with %s: %v"
,
jww
.
FATAL
.
Panicf
(
"Failed to disconnect with %s: %v"
,
...
@@ -486,7 +514,7 @@ func (l listener) Name() string {
...
@@ -486,7 +514,7 @@ func (l listener) Name() string {
// init initializes commands and flags for Cobra.
// init initializes commands and flags for Cobra.
func
init
()
{
func
init
()
{
connectionCmd
.
Flags
()
.
String
(
"
connect
"
,
""
,
connectionCmd
.
Flags
()
.
String
(
connect
ionFlag
,
""
,
"This flag is a client side operation. "
+
"This flag is a client side operation. "
+
"This flag expects a path to a contact file (similar "
+
"This flag expects a path to a contact file (similar "
+
"to destfile). It will parse this into an contact object,"
+
"to destfile). It will parse this into an contact object,"
+
...
@@ -495,51 +523,36 @@ func init() {
...
@@ -495,51 +523,36 @@ func init() {
"If a connection already exists between "
+
"If a connection already exists between "
+
"the client and the server, this will be used instead of "
+
"the client and the server, this will be used instead of "
+
"resending a connection request to the server."
)
"resending a connection request to the server."
)
err
:=
viper
.
BindPFlag
(
"connect"
,
connectionCmd
.
Flags
()
.
Lookup
(
"connect"
))
bindFlagHelper
(
connectionFlag
,
connectionCmd
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"viper.BindPFlag failed for %q: %+v"
,
"connect"
,
err
)
}
connectionCmd
.
Flags
()
.
Bool
(
"s
tartServer
"
,
false
,
connectionCmd
.
Flags
()
.
Bool
(
connectionS
tartServer
Flag
,
false
,
"This flag is a server-side operation and takes no arguments. "
+
"This flag is a server-side operation and takes no arguments. "
+
"This initiates a connection server. "
+
"This initiates a connection server. "
+
"Calling this flag will have this process call "
+
"Calling this flag will have this process call "
+
"connection.StartServer()."
)
"connection.StartServer()."
)
err
=
viper
.
BindPFlag
(
"startServer"
,
connectionCmd
.
Flags
()
.
Lookup
(
"startServer"
))
bindFlagHelper
(
connectionStartServerFlag
,
connectionCmd
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"viper.BindPFlag failed for %q: %+v"
,
"startServer"
,
err
)
}
connectionCmd
.
Flags
()
.
Duration
(
"s
erverTimeout
"
,
time
.
Duration
(
0
),
connectionCmd
.
Flags
()
.
Duration
(
connectionS
erverTimeout
Flag
,
time
.
Duration
(
0
),
"This flag is a connection parameter. "
+
"This flag is a connection parameter. "
+
"This takes as an argument a time.Duration. "
+
"This takes as an argument a time.Duration. "
+
"This duration specifies how long a server will run before "
+
"This duration specifies how long a server will run before "
+
"closing. Without this flag present, a server will be "
+
"closing. Without this flag present, a server will be "
+
"long-running."
)
"long-running."
)
err
=
viper
.
BindPFlag
(
"serverTimeout"
,
connectionCmd
.
Flags
()
.
Lookup
(
"serverTimeout"
))
bindFlagHelper
(
connectionServerTimeoutFlag
,
connectionCmd
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"viper.BindPFlag failed for %q: %+v"
,
"serverTimeout"
,
err
)
}
connectionCmd
.
Flags
()
.
Bool
(
"d
isconnect
"
,
false
,
connectionCmd
.
Flags
()
.
Bool
(
connectionD
isconnect
Flag
,
false
,
"This flag is available to both server and client. "
+
"This flag is available to both server and client. "
+
"This uses a contact object from a file specified by --destfile."
+
"This uses a contact object from a file specified by --destfile."
+
"This will close the connection with the given contact "
+
"This will close the connection with the given contact "
+
"if it exists."
)
"if it exists."
)
err
=
viper
.
BindPFlag
(
"disconnect"
,
connectionCmd
.
Flags
()
.
Lookup
(
"disconnect"
))
bindFlagHelper
(
connectionDisconnectFlag
,
connectionCmd
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"viper.BindPFlag failed for %q: %+v"
,
"disconnect"
,
err
)
}
connectionCmd
.
Flags
()
.
Bool
(
"a
uthenticated
"
,
false
,
connectionCmd
.
Flags
()
.
Bool
(
connectionA
uthenticated
Flag
,
false
,
"This flag is available to both server and client. "
+
"This flag is available to both server and client. "
+
"This flag operates as a switch for the authenticated code-path. "
+
"This flag operates as a switch for the authenticated code-path. "
+
"With this flag present, any additional connection related flags"
+
"With this flag present, any additional connection related flags"
+
" will call the applicable authenticated counterpart"
)
" will call the applicable authenticated counterpart"
)
err
=
viper
.
BindPFlag
(
"authenticated"
,
connectionCmd
.
Flags
()
.
Lookup
(
"authenticated"
))
bindFlagHelper
(
connectionAuthenticatedFlag
,
connectionCmd
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"viper.BindPFlag failed for %q: %+v"
,
"authenticated"
,
err
)
}
rootCmd
.
AddCommand
(
connectionCmd
)
rootCmd
.
AddCommand
(
connectionCmd
)
}
}
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