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
326bf81c
Commit
326bf81c
authored
2 years ago
by
Jake Taylor
Browse files
Options
Downloads
Patches
Plain Diff
refactor connect to use different callbacks for client and server
parent
d13cec97
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!510
Release
,
!252
Auth callbacks change
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
connect/authCallbacks.go
+146
-0
146 additions, 0 deletions
connect/authCallbacks.go
connect/connect.go
+4
-102
4 additions, 102 deletions
connect/connect.go
xxdk/e2e.go
+2
-0
2 additions, 0 deletions
xxdk/e2e.go
with
152 additions
and
102 deletions
connect/authCallbacks.go
0 → 100644
+
146
−
0
View file @
326bf81c
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2022 Privategrity Corporation /
// /
// All rights reserved. /
////////////////////////////////////////////////////////////////////////////////
package
connect
import
(
jww
"github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/auth"
"gitlab.com/elixxir/client/cmix/identity/receptionID"
"gitlab.com/elixxir/client/cmix/rounds"
clientE2e
"gitlab.com/elixxir/client/e2e"
"gitlab.com/elixxir/client/xxdk"
"gitlab.com/elixxir/crypto/contact"
)
// clientAuthCallback provides callback functionality for interfacing between
// auth.State and Connection. This is used both for blocking creation of a
// Connection object until the auth Request is confirmed and for dynamically
// building new Connection objects when an auth Request is received.
type
clientAuthCallback
struct
{
// Used for signaling confirmation of E2E partnership
confirmCallback
Callback
requestCallback
Callback
// Used for building new Connection objects
connectionE2e
clientE2e
.
Handler
connectionParams
Params
authState
auth
.
State
}
// getClientAuthCallback returns a callback interface to be passed into the creation
// of an auth.State object.
// it will accept requests only if a request callback is passed in
func
getClientAuthCallback
(
confirm
,
request
Callback
,
e2e
clientE2e
.
Handler
,
auth
auth
.
State
,
params
Params
)
*
clientAuthCallback
{
return
&
clientAuthCallback
{
confirmCallback
:
confirm
,
requestCallback
:
request
,
connectionE2e
:
e2e
,
connectionParams
:
params
,
authState
:
auth
,
}
}
// Confirm will be called when an auth Confirm message is processed.
func
(
a
clientAuthCallback
)
Confirm
(
requestor
contact
.
Contact
,
_
receptionID
.
EphemeralIdentity
,
_
rounds
.
Round
)
{
jww
.
DEBUG
.
Printf
(
"Connection auth request for %s confirmed"
,
requestor
.
ID
.
String
())
defer
a
.
authState
.
DeletePartnerCallback
(
requestor
.
ID
)
// After confirmation, get the new partner
newPartner
,
err
:=
a
.
connectionE2e
.
GetPartner
(
requestor
.
ID
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Unable to build connection with "
+
"partner %s: %+v"
,
requestor
.
ID
,
err
)
// Send a nil connection to avoid hold-ups down the line
if
a
.
confirmCallback
!=
nil
{
a
.
confirmCallback
(
nil
)
}
return
}
// Return the new Connection object
if
a
.
confirmCallback
!=
nil
{
a
.
confirmCallback
(
BuildConnection
(
newPartner
,
a
.
connectionE2e
,
a
.
authState
,
a
.
connectionParams
))
}
}
// Request will be called when an auth Request message is processed.
func
(
a
clientAuthCallback
)
Request
(
contact
.
Contact
,
receptionID
.
EphemeralIdentity
,
rounds
.
Round
)
{
}
// Reset will be called when an auth Reset operation occurs.
func
(
a
clientAuthCallback
)
Reset
(
contact
.
Contact
,
receptionID
.
EphemeralIdentity
,
rounds
.
Round
)
{
}
// serverAuthCallback provides callback functionality for interfacing between
// auth.State and Connection. This is used both for blocking creation of a
// Connection object until the auth Request is confirmed and for dynamically
// building new Connection objects when an auth Request is received.
type
serverAuthCallback
struct
{
// Used for signaling confirmation of E2E partnership
confirmCallback
Callback
requestCallback
Callback
// Used for building new Connection objects
connectionParams
Params
}
// getServerAuthCallback returns a callback interface to be passed into the creation
// of a xxdk.E2e object.
// it will accept requests only if a request callback is passed in
func
getServerAuthCallback
(
confirm
,
request
Callback
,
params
Params
)
*
serverAuthCallback
{
return
&
serverAuthCallback
{
confirmCallback
:
confirm
,
requestCallback
:
request
,
connectionParams
:
params
,
}
}
// Confirm will be called when an auth Confirm message is processed.
func
(
a
serverAuthCallback
)
Confirm
(
contact
.
Contact
,
receptionID
.
EphemeralIdentity
,
rounds
.
Round
,
*
xxdk
.
E2e
)
{
}
// Request will be called when an auth Request message is processed.
func
(
a
serverAuthCallback
)
Request
(
requestor
contact
.
Contact
,
_
receptionID
.
EphemeralIdentity
,
_
rounds
.
Round
,
e2e
*
xxdk
.
E2e
)
{
if
a
.
requestCallback
==
nil
{
jww
.
ERROR
.
Printf
(
"Received a request when requests are"
+
"not enable, will not accept"
)
}
_
,
err
:=
e2e
.
GetAuth
()
.
Confirm
(
requestor
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Unable to build connection with "
+
"partner %s: %+v"
,
requestor
.
ID
,
err
)
// Send a nil connection to avoid hold-ups down the line
a
.
requestCallback
(
nil
)
}
// After confirmation, get the new partner
newPartner
,
err
:=
e2e
.
GetE2E
()
.
GetPartner
(
requestor
.
ID
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Unable to build connection with "
+
"partner %s: %+v"
,
requestor
.
ID
,
err
)
// Send a nil connection to avoid hold-ups down the line
a
.
requestCallback
(
nil
)
return
}
// Return the new Connection object
a
.
requestCallback
(
BuildConnection
(
newPartner
,
e2e
.
GetE2E
(),
e2e
.
GetAuth
(),
a
.
connectionParams
))
}
// Reset will be called when an auth Reset operation occurs.
func
(
a
serverAuthCallback
)
Reset
(
contact
.
Contact
,
receptionID
.
EphemeralIdentity
,
rounds
.
Round
,
*
xxdk
.
E2e
)
{
}
This diff is collapsed.
Click to expand it.
connect/connect.go
+
4
−
102
View file @
326bf81c
...
@@ -16,8 +16,6 @@ import (
...
@@ -16,8 +16,6 @@ import (
jww
"github.com/spf13/jwalterweatherman"
jww
"github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/auth"
"gitlab.com/elixxir/client/auth"
"gitlab.com/elixxir/client/catalog"
"gitlab.com/elixxir/client/catalog"
"gitlab.com/elixxir/client/cmix/identity/receptionID"
"gitlab.com/elixxir/client/cmix/rounds"
clientE2e
"gitlab.com/elixxir/client/e2e"
clientE2e
"gitlab.com/elixxir/client/e2e"
"gitlab.com/elixxir/client/e2e/ratchet/partner"
"gitlab.com/elixxir/client/e2e/ratchet/partner"
"gitlab.com/elixxir/client/e2e/receive"
"gitlab.com/elixxir/client/e2e/receive"
...
@@ -122,7 +120,7 @@ func Connect(recipient contact.Contact, e2eClient *xxdk.E2e,
...
@@ -122,7 +120,7 @@ func Connect(recipient contact.Contact, e2eClient *xxdk.E2e,
cb
:=
func
(
connection
Connection
)
{
cb
:=
func
(
connection
Connection
)
{
signalChannel
<-
connection
signalChannel
<-
connection
}
}
callback
:=
getAuthCallback
(
cb
,
nil
,
e2eClient
.
GetE2E
(),
e2eClient
.
GetAuth
(),
p
)
callback
:=
get
Client
AuthCallback
(
cb
,
nil
,
e2eClient
.
GetE2E
(),
e2eClient
.
GetAuth
(),
p
)
e2eClient
.
GetAuth
()
.
AddPartnerCallback
(
recipient
.
ID
,
callback
)
e2eClient
.
GetAuth
()
.
AddPartnerCallback
(
recipient
.
ID
,
callback
)
// Perform the auth request
// Perform the auth request
...
@@ -164,16 +162,10 @@ func StartServer(identity xxdk.ReceptionIdentity, cb Callback, net *xxdk.Cmix,
...
@@ -164,16 +162,10 @@ func StartServer(identity xxdk.ReceptionIdentity, cb Callback, net *xxdk.Cmix,
p
Params
)
(
*
xxdk
.
E2e
,
error
)
{
p
Params
)
(
*
xxdk
.
E2e
,
error
)
{
// Build callback for E2E negotiation
// Build callback for E2E negotiation
callback
:=
getAuthCallback
(
nil
,
cb
,
nil
,
nil
,
p
)
callback
:=
get
Server
AuthCallback
(
nil
,
cb
,
p
)
client
,
err
:=
xxdk
.
LoginEphemeral
(
net
,
callback
,
identity
)
// Return an ephemeral E2e object
if
err
!=
nil
{
return
xxdk
.
LoginEphemeral
(
net
,
callback
,
identity
)
return
nil
,
err
}
callback
.
connectionE2e
=
client
.
GetE2E
()
callback
.
authState
=
client
.
GetAuth
()
return
client
,
nil
}
}
// handler provides an implementation for the Connection interface.
// handler provides an implementation for the Connection interface.
...
@@ -231,96 +223,6 @@ func (h *handler) Unregister(listenerID receive.ListenerID) {
...
@@ -231,96 +223,6 @@ func (h *handler) Unregister(listenerID receive.ListenerID) {
h
.
e2e
.
Unregister
(
listenerID
)
h
.
e2e
.
Unregister
(
listenerID
)
}
}
// authCallback provides callback functionality for interfacing between
// auth.State and Connection. This is used both for blocking creation of a
// Connection object until the auth Request is confirmed and for dynamically
// building new Connection objects when an auth Request is received.
type
authCallback
struct
{
// Used for signaling confirmation of E2E partnership
confirmCallback
Callback
requestCallback
Callback
// Used for building new Connection objects
connectionE2e
clientE2e
.
Handler
connectionParams
Params
authState
auth
.
State
}
// getAuthCallback returns a callback interface to be passed into the creation
// of an auth.State object.
// it will accept requests only if a request callback is passed in
func
getAuthCallback
(
confirm
,
request
Callback
,
e2e
clientE2e
.
Handler
,
auth
auth
.
State
,
params
Params
)
*
authCallback
{
return
&
authCallback
{
confirmCallback
:
confirm
,
requestCallback
:
request
,
connectionE2e
:
e2e
,
connectionParams
:
params
,
authState
:
auth
,
}
}
// Confirm will be called when an auth Confirm message is processed.
func
(
a
authCallback
)
Confirm
(
requestor
contact
.
Contact
,
receptionID
receptionID
.
EphemeralIdentity
,
round
rounds
.
Round
)
{
jww
.
DEBUG
.
Printf
(
"Connection auth request for %s confirmed"
,
requestor
.
ID
.
String
())
defer
a
.
authState
.
DeletePartnerCallback
(
requestor
.
ID
)
// After confirmation, get the new partner
newPartner
,
err
:=
a
.
connectionE2e
.
GetPartner
(
requestor
.
ID
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Unable to build connection with "
+
"partner %s: %+v"
,
requestor
.
ID
,
err
)
// Send a nil connection to avoid hold-ups down the line
if
a
.
confirmCallback
!=
nil
{
a
.
confirmCallback
(
nil
)
}
return
}
// Return the new Connection object
if
a
.
confirmCallback
!=
nil
{
a
.
confirmCallback
(
BuildConnection
(
newPartner
,
a
.
connectionE2e
,
a
.
authState
,
a
.
connectionParams
))
}
}
// Request will be called when an auth Request message is processed.
func
(
a
authCallback
)
Request
(
requestor
contact
.
Contact
,
receptionID
receptionID
.
EphemeralIdentity
,
round
rounds
.
Round
)
{
if
a
.
requestCallback
==
nil
{
jww
.
ERROR
.
Printf
(
"Received a request when requests are"
+
"not enable, will not accept"
)
}
_
,
err
:=
a
.
authState
.
Confirm
(
requestor
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Unable to build connection with "
+
"partner %s: %+v"
,
requestor
.
ID
,
err
)
// Send a nil connection to avoid hold-ups down the line
a
.
requestCallback
(
nil
)
}
// After confirmation, get the new partner
newPartner
,
err
:=
a
.
connectionE2e
.
GetPartner
(
requestor
.
ID
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Unable to build connection with "
+
"partner %s: %+v"
,
requestor
.
ID
,
err
)
// Send a nil connection to avoid hold-ups down the line
a
.
requestCallback
(
nil
)
return
}
// Return the new Connection object
a
.
requestCallback
(
BuildConnection
(
newPartner
,
a
.
connectionE2e
,
a
.
authState
,
a
.
connectionParams
))
}
// Reset will be called when an auth Reset operation occurs.
func
(
a
authCallback
)
Reset
(
requestor
contact
.
Contact
,
receptionID
receptionID
.
EphemeralIdentity
,
round
rounds
.
Round
)
{
}
// FirstPartitionSize returns the max partition payload size for the
// FirstPartitionSize returns the max partition payload size for the
// first payload
// first payload
func
(
h
*
handler
)
FirstPartitionSize
()
uint
{
func
(
h
*
handler
)
FirstPartitionSize
()
uint
{
...
...
This diff is collapsed.
Click to expand it.
xxdk/e2e.go
+
2
−
0
View file @
326bf81c
...
@@ -37,6 +37,8 @@ type E2e struct {
...
@@ -37,6 +37,8 @@ type E2e struct {
e2eIdentity
ReceptionIdentity
e2eIdentity
ReceptionIdentity
}
}
// AuthCallbacks is an adapter for the auth.Callbacks interface
// that allows for initializing an E2e object without an E2e-dependant auth.Callbacks
type
AuthCallbacks
interface
{
type
AuthCallbacks
interface
{
Request
(
partner
contact
.
Contact
,
receptionID
receptionID
.
EphemeralIdentity
,
Request
(
partner
contact
.
Contact
,
receptionID
receptionID
.
EphemeralIdentity
,
round
rounds
.
Round
,
e2e
*
E2e
)
round
rounds
.
Round
,
e2e
*
E2e
)
...
...
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