Skip to content
Snippets Groups Projects
Commit 9ace7715 authored by Benjamin Wenger's avatar Benjamin Wenger
Browse files

fixed connection so servers properly handle requests and confirmations

parent 83a501e6
No related branches found
No related tags found
3 merge requests!510Release,!226WIP: Api2.0,!207WIP: Client Restructure
...@@ -143,7 +143,7 @@ func Connect(recipient contact.Contact, myId *id.ID, privKey *cyclic.Int, ...@@ -143,7 +143,7 @@ func Connect(recipient contact.Contact, myId *id.ID, privKey *cyclic.Int,
cb := func(connection Connection) { cb := func(connection Connection) {
signalChannel <- connection signalChannel <- connection
} }
callback := getAuthCallback(cb, e2eHandler, p) callback := getAuthCallback(cb, nil, e2eHandler, p)
// Build auth object for E2E negotiation // Build auth object for E2E negotiation
authState, err := auth.NewState(kv, net, e2eHandler, authState, err := auth.NewState(kv, net, e2eHandler,
...@@ -200,7 +200,7 @@ func StartServer(cb Callback, myId *id.ID, privKey *cyclic.Int, ...@@ -200,7 +200,7 @@ func StartServer(cb Callback, myId *id.ID, privKey *cyclic.Int,
} }
// Build callback for E2E negotiation // Build callback for E2E negotiation
callback := getAuthCallback(cb, e2eHandler, p) callback := getAuthCallback(nil, cb, e2eHandler, p)
// Build auth object for E2E negotiation // Build auth object for E2E negotiation
authState, err := auth.NewState(kv, net, e2eHandler, authState, err := auth.NewState(kv, net, e2eHandler,
...@@ -265,7 +265,8 @@ func (h *handler) Unregister(listenerID receive.ListenerID) { ...@@ -265,7 +265,8 @@ func (h *handler) Unregister(listenerID receive.ListenerID) {
// building new Connection objects when an auth Request is received. // building new Connection objects when an auth Request is received.
type authCallback struct { type authCallback struct {
// Used for signaling confirmation of E2E partnership // Used for signaling confirmation of E2E partnership
connectionCallback Callback confrimCallback Callback
requestCallback Callback
// Used for building new Connection objects // Used for building new Connection objects
connectionE2e clientE2e.Handler connectionE2e clientE2e.Handler
...@@ -275,12 +276,14 @@ type authCallback struct { ...@@ -275,12 +276,14 @@ type authCallback struct {
// getAuthCallback returns a callback interface to be passed into the creation // getAuthCallback returns a callback interface to be passed into the creation
// of an auth.State object. // of an auth.State object.
func getAuthCallback(cb Callback, e2e clientE2e.Handler, // it will accept requests only if a request callback is passed in
func getAuthCallback(confirm, request Callback, e2e clientE2e.Handler,
params Params) *authCallback { params Params) *authCallback {
return &authCallback{ return &authCallback{
connectionCallback: cb, confrimCallback: confirm,
connectionE2e: e2e, requestCallback: request,
connectionParams: params, connectionE2e: e2e,
connectionParams: params,
} }
} }
...@@ -296,25 +299,49 @@ func (a authCallback) Confirm(requestor contact.Contact, ...@@ -296,25 +299,49 @@ func (a authCallback) Confirm(requestor contact.Contact,
jww.ERROR.Printf("Unable to build connection with "+ jww.ERROR.Printf("Unable to build connection with "+
"partner %s: %+v", requestor.ID, err) "partner %s: %+v", requestor.ID, err)
// Send a nil connection to avoid hold-ups down the line // Send a nil connection to avoid hold-ups down the line
a.connectionCallback(nil) if a.confrimCallback != nil {
a.confrimCallback(nil)
}
return return
} }
// Return the new Connection object // Return the new Connection object
a.connectionCallback(BuildConnection(newPartner, a.connectionE2e, if a.confrimCallback != nil {
a.connectionParams)) a.confrimCallback(BuildConnection(newPartner, a.connectionE2e,
a.connectionParams))
}
} }
// Request will be called when an auth Request message is processed. // Request will be called when an auth Request message is processed.
func (a authCallback) Request(requestor contact.Contact, func (a authCallback) Request(requestor contact.Contact,
receptionID receptionID.EphemeralIdentity, round rounds.Round) { receptionID receptionID.EphemeralIdentity, round rounds.Round) {
if a.requestCallback == nil {
jww.ERROR.Printf("Recieved a request when requests are" +
"not enable, will not accept")
}
_, err := a.authState.Confirm(requestor) _, err := a.authState.Confirm(requestor)
if err != nil { if err != nil {
jww.ERROR.Printf("Unable to build connection with "+ jww.ERROR.Printf("Unable to build connection with "+
"partner %s: %+v", requestor.ID, err) "partner %s: %+v", requestor.ID, err)
// Send a nil connection to avoid hold-ups down the line // Send a nil connection to avoid hold-ups down the line
a.connectionCallback(nil) 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.connectionParams))
} }
// Reset will be called when an auth Reset operation occurs. // Reset will be called when an auth Reset operation occurs.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment