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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
3d7e775c
Commit
3d7e775c
authored
Apr 21, 2022
by
Jake Taylor
Browse files
Options
Downloads
Patches
Plain Diff
added WaitForConnections
parent
a45b827b
No related branches found
No related tags found
4 merge requests
!510
Release
,
!207
WIP: Client Restructure
,
!206
Built the connection interface which wraps e2e and auth objects and manages a...
,
!203
Symmetric broadcast
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
connect/connect.go
+59
-6
59 additions, 6 deletions
connect/connect.go
with
59 additions
and
6 deletions
connect/connect.go
+
59
−
6
View file @
3d7e775c
...
...
@@ -28,9 +28,10 @@ import (
"time"
)
// Connection is a wrapper for the E2E and auth packages
// and automatically establishes an E2E partnership with a partner.
// You can then use this interface to send to and receive from the newly-established partner.
// Connection is a wrapper for the E2E and auth packages.
// It can be used to automatically establish an E2E partnership
// with a partner.Manager, or be built from an existing E2E partnership.
// You can then use this interface to send to and receive from the newly-established partner.Manager.
type
Connection
interface
{
// Closer deletes this Connection's partner.Manager and releases resources
io
.
Closer
...
...
@@ -75,14 +76,14 @@ func GetDefaultParams() Params {
// Connect performs auth key negotiation with the given recipient,
// and returns a Connection object for the newly-created partner.Manager
// This function is to be used sender-side and will block until the partner.Manager is confirmed
func
Connect
(
recipient
contact
.
Contact
,
myI
D
*
id
.
ID
,
rng
*
fastRNG
.
StreamGenerator
,
func
Connect
(
recipient
contact
.
Contact
,
myI
d
*
id
.
ID
,
rng
*
fastRNG
.
StreamGenerator
,
grp
*
cyclic
.
Group
,
net
cmix
.
Client
,
p
Params
)
(
Connection
,
error
)
{
// Build an ephemeral KV
kv
:=
versioned
.
NewKV
(
ekv
.
MakeMemstore
())
// Build E2e handler
e2eHandler
,
err
:=
clientE2e
.
Load
(
kv
,
net
,
myI
D
,
grp
,
rng
,
p
.
event
)
e2eHandler
,
err
:=
clientE2e
.
Load
(
kv
,
net
,
myI
d
,
grp
,
rng
,
p
.
event
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -122,8 +123,60 @@ func Connect(recipient contact.Contact, myID *id.ID, rng *fastRNG.StreamGenerato
},
nil
}
// WaitForConnections assembles a Connection object on the reception-side
// whenever an E2E partnership with a partner.Manager is established.
// and sends it to the given connectionListener. Should be run in its own thread.
func
WaitForConnections
(
connectionListener
chan
Connection
,
myId
*
id
.
ID
,
rng
*
fastRNG
.
StreamGenerator
,
grp
*
cyclic
.
Group
,
net
cmix
.
Client
,
p
Params
)
{
// Build an ephemeral KV
kv
:=
versioned
.
NewKV
(
ekv
.
MakeMemstore
())
// Build E2e handler
e2eHandler
,
err
:=
clientE2e
.
Load
(
kv
,
net
,
myId
,
grp
,
rng
,
p
.
event
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Unable to WaitForConnections: %+v"
,
err
)
return
}
// Build callback for E2E negotiation
callback
:=
GetConnectionCallback
()
// Build auth object for E2E negotiation
_
,
err
=
auth
.
NewState
(
kv
,
net
,
e2eHandler
,
rng
,
p
.
event
,
p
.
auth
,
callback
,
nil
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Unable to WaitForConnections: %+v"
,
err
)
return
}
for
{
// Block waiting for incoming auth request
jww
.
DEBUG
.
Printf
(
"Connection waiting for auth request to be received..."
)
select
{
case
newPartnerId
:=
<-
callback
.
confirmPartner
:
jww
.
DEBUG
.
Printf
(
"Connection auth request for %s confirmed"
,
newPartnerId
.
String
())
// After confirmation, get the new partner
newPartner
,
err
:=
e2eHandler
.
GetPartner
(
newPartnerId
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Unable to establish new Connection with partner %s: %+v"
,
err
,
newPartnerId
.
String
())
continue
}
connectionListener
<-
&
handler
{
partner
:
newPartner
,
params
:
p
,
net
:
net
,
e2e
:
e2eHandler
,
}
}
}
}
// ConnectWithPartner assembles a Connection object on the reception-side
// after an E2E partnership has already been confirmed
// after an E2E partnership has already been confirmed
with the given partner.Manager
func
ConnectWithPartner
(
partner
partner
.
Manager
,
e2eHandler
clientE2e
.
Handler
,
net
cmix
.
Client
,
p
Params
)
Connection
{
return
&
handler
{
...
...
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