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
e93e7a9d
Commit
e93e7a9d
authored
4 years ago
by
Benjamin Wenger
Browse files
Options
Downloads
Patches
Plain Diff
made it possible to use client init without knowing the permissioning address
parent
4e6fe64d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
api/client.go
+117
-24
117 additions, 24 deletions
api/client.go
with
117 additions
and
24 deletions
api/client.go
+
117
−
24
View file @
e93e7a9d
...
...
@@ -180,53 +180,99 @@ func OpenClient(storageDir string, password []byte, parameters params.Network) (
func
Login
(
storageDir
string
,
password
[]
byte
,
parameters
params
.
Network
)
(
*
Client
,
error
)
{
jww
.
INFO
.
Printf
(
"Login()"
)
//Open the client
c
,
err
:=
OpenClient
(
storageDir
,
password
,
parameters
)
if
err
!=
nil
{
return
nil
,
err
}
//
execute the rest of the loading as normal
//
Attach the services interface
c
.
services
=
newServiceProcessiesList
(
c
.
runner
)
//get the user from session
u
:=
c
.
storage
.
User
()
cryptoUser
:=
u
.
GetCryptographicIdentity
()
//start comms
c
.
comms
,
err
=
client
.
NewClientComms
(
cryptoUser
.
GetUserID
(),
rsa
.
CreatePublicKeyPem
(
cryptoUser
.
GetRSA
()
.
GetPublic
()),
rsa
.
CreatePrivateKeyPem
(
cryptoUser
.
GetRSA
()),
cryptoUser
.
GetSalt
())
//initilize comms
err
=
c
.
initComms
()
if
err
!=
nil
{
return
nil
,
err
ors
.
WithMessage
(
err
,
"failed to load client"
)
return
nil
,
err
}
//get the NDF to pass into permissioning and the network manager
def
:=
c
.
storage
.
GetBaseNDF
()
//initialize permissioning
c
.
permissioning
,
err
=
permissioning
.
Init
(
c
.
comms
,
def
)
if
def
.
Registration
.
Address
!=
""
{
err
=
c
.
initPermissioning
(
def
)
if
err
!=
nil
{
return
nil
,
errors
.
WithMessage
(
err
,
"failed to init "
+
"permissioning handler"
)
return
nil
,
err
}
}
else
{
jww
.
WARN
.
Printf
(
"Registration with permissioning skipped due to "
+
"blank permissionign address. Client will not be able to register "
+
"or track network."
)
}
// check the client version is up to date to the network
err
=
c
.
checkVersion
()
// Initialize network and link it to context
c
.
network
,
err
=
network
.
NewManager
(
c
.
storage
,
c
.
switchboard
,
c
.
rng
,
c
.
comms
,
parameters
,
def
)
if
err
!=
nil
{
return
nil
,
err
ors
.
WithMessage
(
err
,
"failed to load client"
)
return
nil
,
err
}
//register with permissioning if necessary
if
c
.
storage
.
GetRegistrationStatus
()
==
storage
.
KeyGenComplete
{
jww
.
INFO
.
Printf
(
"Client has not registered yet, attempting registration"
)
err
=
c
.
registerWithPermissioning
()
//update gateway connections
err
=
c
.
network
.
GetInstance
()
.
UpdateGatewayConnections
()
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Client has failed registration: %s"
,
err
)
return
nil
,
errors
.
WithMessage
(
err
,
"failed to load client"
)
return
nil
,
err
}
jww
.
INFO
.
Printf
(
"Client sucsecfully registered with the network"
)
//initilize the auth tracker
c
.
auth
=
auth
.
NewManager
(
c
.
switchboard
,
c
.
storage
,
c
.
network
)
return
c
,
nil
}
// LoginWithNewBaseNDF_UNSAFE initializes a client object from existing storage
// while replacing the base NDF. This is designed for some specific deployment
// procedures and is generally unsafe.
func
LoginWithNewBaseNDF_UNSAFE
(
storageDir
string
,
password
[]
byte
,
newBaseNdf
string
,
parameters
params
.
Network
)
(
*
Client
,
error
)
{
jww
.
INFO
.
Printf
(
"LoginWithNewBaseNDF_UNSAFE()"
)
// Parse the NDF
def
,
err
:=
parseNDF
(
newBaseNdf
)
if
err
!=
nil
{
return
nil
,
err
}
//Open the client
c
,
err
:=
OpenClient
(
storageDir
,
password
,
parameters
)
if
err
!=
nil
{
return
nil
,
err
}
//Attach the services interface
c
.
services
=
newServiceProcessiesList
(
c
.
runner
)
//initialize comms
err
=
c
.
initComms
()
if
err
!=
nil
{
return
nil
,
err
}
//store the updated base NDF
c
.
storage
.
SetBaseNDF
(
def
)
//initialize permissioning
if
def
.
Registration
.
Address
!=
""
{
err
=
c
.
initPermissioning
(
def
)
if
err
!=
nil
{
return
nil
,
err
}
}
else
{
jww
.
WARN
.
Printf
(
"Registration with permissioning skipped due to "
+
"blank permissionign address. Client will not be able to register "
+
"or track network."
)
}
// Initialize network and link it to context
...
...
@@ -236,6 +282,7 @@ func Login(storageDir string, password []byte, parameters params.Network) (*Clie
return
nil
,
err
}
//update gateway connections
err
=
c
.
network
.
GetInstance
()
.
UpdateGatewayConnections
()
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -247,6 +294,52 @@ func Login(storageDir string, password []byte, parameters params.Network) (*Clie
return
c
,
nil
}
func
(
c
*
Client
)
initComms
()
error
{
var
err
error
//get the user from session
u
:=
c
.
storage
.
User
()
cryptoUser
:=
u
.
GetCryptographicIdentity
()
//start comms
c
.
comms
,
err
=
client
.
NewClientComms
(
cryptoUser
.
GetUserID
(),
rsa
.
CreatePublicKeyPem
(
cryptoUser
.
GetRSA
()
.
GetPublic
()),
rsa
.
CreatePrivateKeyPem
(
cryptoUser
.
GetRSA
()),
cryptoUser
.
GetSalt
())
if
err
!=
nil
{
return
errors
.
WithMessage
(
err
,
"failed to load client"
)
}
return
nil
}
func
(
c
*
Client
)
initPermissioning
(
def
*
ndf
.
NetworkDefinition
)
error
{
var
err
error
//initialize permissioning
c
.
permissioning
,
err
=
permissioning
.
Init
(
c
.
comms
,
def
)
if
err
!=
nil
{
return
errors
.
WithMessage
(
err
,
"failed to init "
+
"permissioning handler"
)
}
// check the client version is up to date to the network
err
=
c
.
checkVersion
()
if
err
!=
nil
{
return
errors
.
WithMessage
(
err
,
"failed to load client"
)
}
//register with permissioning if necessary
if
c
.
storage
.
GetRegistrationStatus
()
==
storage
.
KeyGenComplete
{
jww
.
INFO
.
Printf
(
"Client has not registered yet, attempting registration"
)
err
=
c
.
registerWithPermissioning
()
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Client has failed registration: %s"
,
err
)
return
errors
.
WithMessage
(
err
,
"failed to load client"
)
}
jww
.
INFO
.
Printf
(
"Client sucsecfully registered with the network"
)
}
return
nil
}
// ----- Client Functions -----
// StartNetworkFollower kicks off the tracking of the network. It starts
// long running network client threads and returns an object for checking
...
...
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