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

Merge branch 'Ursula/AuthCallbacks' into 'peppa/newClient'

made a more complex and flexible auth callback registration systems

See merge request !454
parents 3ad802c0 8fd12dca
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/auth" "gitlab.com/elixxir/client/auth"
"gitlab.com/elixxir/client/interfaces"
"gitlab.com/elixxir/client/interfaces/contact" "gitlab.com/elixxir/client/interfaces/contact"
"gitlab.com/elixxir/client/storage/e2e" "gitlab.com/elixxir/client/storage/e2e"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
...@@ -30,26 +31,12 @@ func (c *Client) RequestAuthenticatedChannel(recipient, me contact.Contact, ...@@ -30,26 +31,12 @@ func (c *Client) RequestAuthenticatedChannel(recipient, me contact.Contact,
c.storage, c.network) c.storage, c.network)
} }
// RegisterAuthCallbacks registers both callbacks for authenticated channels. // GetAuthRegistrar gets the object which allows the registration of auth
// This can only be called once // callbacks
func (c *Client) RegisterAuthCallbacks(request auth.RequestCallback, func (c *Client) GetAuthRegistrar() interfaces.Auth {
confirm auth.ConfirmCallback) error { jww.INFO.Printf("GetAuthRegistrar(...)")
jww.INFO.Printf("RegisterAuthCallbacks(...)")
exicuted := false return c.auth
c.authOnce.Do(func() {
stop := auth.RegisterCallbacks(request, confirm, c.switchboard,
c.storage, c.network)
c.runner.Add(stop)
exicuted = true
})
if !exicuted {
return errors.New("Cannot register auth callbacks more than " +
"once")
}
return nil
} }
// GetAuthenticatedChannelRequest returns the contact received in a request if // GetAuthenticatedChannelRequest returns the contact received in a request if
......
...@@ -9,6 +9,7 @@ package api ...@@ -9,6 +9,7 @@ package api
import ( import (
"github.com/pkg/errors" "github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/auth"
"gitlab.com/elixxir/client/interfaces" "gitlab.com/elixxir/client/interfaces"
"gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/client/interfaces/params"
"gitlab.com/elixxir/client/interfaces/user" "gitlab.com/elixxir/client/interfaces/user"
...@@ -25,7 +26,6 @@ import ( ...@@ -25,7 +26,6 @@ import (
"gitlab.com/elixxir/crypto/large" "gitlab.com/elixxir/crypto/large"
"gitlab.com/xx_network/crypto/signature/rsa" "gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/ndf" "gitlab.com/xx_network/primitives/ndf"
"sync"
"time" "time"
) )
...@@ -46,14 +46,12 @@ type Client struct { ...@@ -46,14 +46,12 @@ type Client struct {
network interfaces.NetworkManager network interfaces.NetworkManager
//object used to register and communicate with permissioning //object used to register and communicate with permissioning
permissioning *permissioning.Permissioning permissioning *permissioning.Permissioning
//object containing auth interactions
auth *auth.Manager
//contains stopables for all running threads //contains stopables for all running threads
runner *stoppable.Multi runner *stoppable.Multi
status *statusTracker status *statusTracker
// contains the sync once used to ensure authenticated channel callbacks are
// only registered once
authOnce sync.Once
} }
// NewClient creates client storage, generates keys, connects, and registers // NewClient creates client storage, generates keys, connects, and registers
...@@ -224,6 +222,9 @@ func loadClient(session *storage.Session, rngStreamGen *fastRNG.StreamGenerator) ...@@ -224,6 +222,9 @@ func loadClient(session *storage.Session, rngStreamGen *fastRNG.StreamGenerator)
return nil, err return nil, err
} }
//initilize the auth tracker
c.auth = auth.NewManager(c.switchboard, c.storage, c.network)
return c, nil return c, nil
} }
...@@ -256,6 +257,8 @@ func loadClient(session *storage.Session, rngStreamGen *fastRNG.StreamGenerator) ...@@ -256,6 +257,8 @@ func loadClient(session *storage.Session, rngStreamGen *fastRNG.StreamGenerator)
// Responds to sent rekeys and executes them // Responds to sent rekeys and executes them
// - KeyExchange Confirm (/keyExchange/confirm.go) // - KeyExchange Confirm (/keyExchange/confirm.go)
// Responds to confirmations of successful rekey operations // Responds to confirmations of successful rekey operations
// - Auth Callback (/auth/callback.go)
// Handles both auth confirm and requests
func (c *Client) StartNetworkFollower() error { func (c *Client) StartNetworkFollower() error {
jww.INFO.Printf("StartNetworkFollower()") jww.INFO.Printf("StartNetworkFollower()")
...@@ -264,6 +267,9 @@ func (c *Client) StartNetworkFollower() error { ...@@ -264,6 +267,9 @@ func (c *Client) StartNetworkFollower() error {
return errors.WithMessage(err, "Failed to Start the Network Follower") return errors.WithMessage(err, "Failed to Start the Network Follower")
} }
stopAuth := c.auth.StartProcessies()
c.runner.Add(stopAuth)
stopFollow, err := c.network.Follow() stopFollow, err := c.network.Follow()
if err != nil { if err != nil {
return errors.WithMessage(err, "Failed to start following "+ return errors.WithMessage(err, "Failed to start following "+
......
...@@ -5,37 +5,26 @@ import ( ...@@ -5,37 +5,26 @@ import (
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/interfaces" "gitlab.com/elixxir/client/interfaces"
"gitlab.com/elixxir/client/interfaces/contact" "gitlab.com/elixxir/client/interfaces/contact"
"gitlab.com/elixxir/client/interfaces/message"
"gitlab.com/elixxir/client/stoppable" "gitlab.com/elixxir/client/stoppable"
"gitlab.com/elixxir/client/storage"
"gitlab.com/elixxir/client/storage/auth" "gitlab.com/elixxir/client/storage/auth"
"gitlab.com/elixxir/client/storage/e2e" "gitlab.com/elixxir/client/storage/e2e"
"gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/cyclic"
cAuth "gitlab.com/elixxir/crypto/e2e/auth" cAuth "gitlab.com/elixxir/crypto/e2e/auth"
"gitlab.com/elixxir/primitives/format" "gitlab.com/elixxir/primitives/format"
"gitlab.com/xx_network/primitives/id"
"strings" "strings"
) )
type RequestCallback func(requestor contact.Contact, message string) func (m *Manager) StartProcessies() stoppable.Stoppable {
type ConfirmCallback func(partner contact.Contact)
func RegisterCallbacks(rcb RequestCallback, ccb ConfirmCallback,
sw interfaces.Switchboard, storage *storage.Session,
net interfaces.NetworkManager) stoppable.Stoppable {
rawMessages := make(chan message.Receive, 1000)
sw.RegisterChannel("Auth", &id.ID{}, message.Raw, rawMessages)
stop := stoppable.NewSingle("Auth") stop := stoppable.NewSingle("Auth")
authStore := storage.Auth() authStore := m.storage.Auth()
grp := storage.E2e().GetGroup() grp := m.storage.E2e().GetGroup()
go func() { go func() {
select { select {
case <-stop.Quit(): case <-stop.Quit():
return return
case msg := <-rawMessages: case msg := <-m.rawMessages:
//lookup the message, check if it is an auth request //lookup the message, check if it is an auth request
cmixMsg := format.Unmarshal(msg.Payload) cmixMsg := format.Unmarshal(msg.Payload)
fp := cmixMsg.GetKeyFP() fp := cmixMsg.GetKeyFP()
...@@ -50,26 +39,24 @@ func RegisterCallbacks(rcb RequestCallback, ccb ConfirmCallback, ...@@ -50,26 +39,24 @@ func RegisterCallbacks(rcb RequestCallback, ccb ConfirmCallback,
} }
//denote that the message is not garbled //denote that the message is not garbled
storage.GetGarbledMessages().Remove(cmixMsg) m.storage.GetGarbledMessages().Remove(cmixMsg)
switch fpType { switch fpType {
// if it is general, that means a new request has been received // if it is general, that means a new request has been received
case auth.General: case auth.General:
handleRequest(cmixMsg, myHistoricalPrivKey, grp, storage, rcb, m.handleRequest(cmixMsg, myHistoricalPrivKey, grp)
ccb, net)
// if it is specific, that means the original request was sent // if it is specific, that means the original request was sent
// by this users and a confirmation has been received // by this users and a confirmation has been received
case auth.Specific: case auth.Specific:
handleConfirm(cmixMsg, sr, ccb, storage, grp, net) m.handleConfirm(cmixMsg, sr, grp)
} }
} }
}() }()
return stop return stop
} }
func handleRequest(cmixMsg format.Message, myHistoricalPrivKey *cyclic.Int, func (m *Manager) handleRequest(cmixMsg format.Message,
grp *cyclic.Group, storage *storage.Session, rcb RequestCallback, myHistoricalPrivKey *cyclic.Int, grp *cyclic.Group) {
ccb ConfirmCallback, net interfaces.NetworkManager) {
//decode the outer format //decode the outer format
baseFmt, partnerPubKey, err := handleBaseFormat(cmixMsg, grp) baseFmt, partnerPubKey, err := handleBaseFormat(cmixMsg, grp)
if err != nil { if err != nil {
...@@ -116,14 +103,14 @@ func handleRequest(cmixMsg format.Message, myHistoricalPrivKey *cyclic.Int, ...@@ -116,14 +103,14 @@ func handleRequest(cmixMsg format.Message, myHistoricalPrivKey *cyclic.Int,
// if it does and the keys used are the same as we have, send a // if it does and the keys used are the same as we have, send a
// confirmation in case there are state issues. // confirmation in case there are state issues.
// do not store // do not store
if _, err := storage.E2e().GetPartner(partnerID); err == nil { if _, err := m.storage.E2e().GetPartner(partnerID); err == nil {
jww.WARN.Printf("Recieved Auth request for %s, "+ jww.WARN.Printf("Recieved Auth request for %s, "+
"channel already exists. Ignoring", partnerID) "channel already exists. Ignoring", partnerID)
//exit //exit
return return
} else { } else {
//check if the relationship already exists, //check if the relationship already exists,
rType, sr2, _, err := storage.Auth().GetRequest(partnerID) rType, sr2, _, err := m.storage.Auth().GetRequest(partnerID)
if err != nil && !strings.Contains(err.Error(), auth.NoRequest) { if err != nil && !strings.Contains(err.Error(), auth.NoRequest) {
// if another error is recieved, print it and exist // if another error is recieved, print it and exist
jww.WARN.Printf("Recieved new Auth request for %s, "+ jww.WARN.Printf("Recieved new Auth request for %s, "+
...@@ -142,8 +129,8 @@ func handleRequest(cmixMsg format.Message, myHistoricalPrivKey *cyclic.Int, ...@@ -142,8 +129,8 @@ func handleRequest(cmixMsg format.Message, myHistoricalPrivKey *cyclic.Int,
// then exit, nothing else needed // then exit, nothing else needed
case auth.Sent: case auth.Sent:
// do the confirmation // do the confirmation
if err := doConfirm(sr2, grp, partnerPubKey, ecrFmt.GetOwnership(), if err := m.doConfirm(sr2, grp, partnerPubKey,
storage, ccb, net); err != nil { ecrFmt.GetOwnership()); err != nil {
jww.WARN.Printf("Confirmation failed: %s", err) jww.WARN.Printf("Confirmation failed: %s", err)
} }
//exit //exit
...@@ -172,26 +159,29 @@ func handleRequest(cmixMsg format.Message, myHistoricalPrivKey *cyclic.Int, ...@@ -172,26 +159,29 @@ func handleRequest(cmixMsg format.Message, myHistoricalPrivKey *cyclic.Int,
// fixme: the client will never be notified of the channel creation if a // fixme: the client will never be notified of the channel creation if a
// crash occurs after the store but before the conclusion of the callback // crash occurs after the store but before the conclusion of the callback
//create the auth storage //create the auth storage
if err = storage.Auth().AddReceived(c); err != nil { if err = m.storage.Auth().AddReceived(c); err != nil {
jww.WARN.Printf("failed to store contact Auth "+ jww.WARN.Printf("failed to store contact Auth "+
"Request: %s", err) "Request: %s", err)
return return
} }
//call the callback // fixme: if a crash occurs before or during the calls, the notification
// will never be sent.
cbList := m.requestCallbacks.Get(c.ID)
for _, cb := range cbList {
rcb := cb.(interfaces.RequestCallback)
go rcb(c, msg) go rcb(c, msg)
}
return return
} }
func handleConfirm(cmixMsg format.Message, sr *auth.SentRequest, func (m *Manager) handleConfirm(cmixMsg format.Message, sr *auth.SentRequest,
ccb ConfirmCallback, storage *storage.Session, grp *cyclic.Group, grp *cyclic.Group) {
net interfaces.NetworkManager) {
// check if relationship already exists // check if relationship already exists
if m, err := storage.E2e().GetPartner(sr.GetPartner()); m != nil || err == nil { if mgr, err := m.storage.E2e().GetPartner(sr.GetPartner()); mgr != nil || err == nil {
jww.WARN.Printf("Cannot confirm auth for %s, channel already "+ jww.WARN.Printf("Cannot confirm auth for %s, channel already "+
"exists.", sr.GetPartner()) "exists.", sr.GetPartner())
storage.Auth().Fail(sr.GetPartner()) m.storage.Auth().Fail(sr.GetPartner())
return return
} }
...@@ -199,7 +189,7 @@ func handleConfirm(cmixMsg format.Message, sr *auth.SentRequest, ...@@ -199,7 +189,7 @@ func handleConfirm(cmixMsg format.Message, sr *auth.SentRequest,
baseFmt, partnerPubKey, err := handleBaseFormat(cmixMsg, grp) baseFmt, partnerPubKey, err := handleBaseFormat(cmixMsg, grp)
if err != nil { if err != nil {
jww.WARN.Printf("Failed to handle auth confirm: %s", err) jww.WARN.Printf("Failed to handle auth confirm: %s", err)
storage.Auth().Fail(sr.GetPartner()) m.storage.Auth().Fail(sr.GetPartner())
return return
} }
...@@ -211,7 +201,7 @@ func handleConfirm(cmixMsg format.Message, sr *auth.SentRequest, ...@@ -211,7 +201,7 @@ func handleConfirm(cmixMsg format.Message, sr *auth.SentRequest,
if !success { if !success {
jww.WARN.Printf("Recieved auth confirmation failed its mac " + jww.WARN.Printf("Recieved auth confirmation failed its mac " +
"check") "check")
storage.Auth().Fail(sr.GetPartner()) m.storage.Auth().Fail(sr.GetPartner())
return return
} }
...@@ -219,22 +209,20 @@ func handleConfirm(cmixMsg format.Message, sr *auth.SentRequest, ...@@ -219,22 +209,20 @@ func handleConfirm(cmixMsg format.Message, sr *auth.SentRequest,
if err != nil { if err != nil {
jww.WARN.Printf("Failed to unmarshal auth confirmation's "+ jww.WARN.Printf("Failed to unmarshal auth confirmation's "+
"encrypted payload: %s", err) "encrypted payload: %s", err)
storage.Auth().Fail(sr.GetPartner()) m.storage.Auth().Fail(sr.GetPartner())
return return
} }
// finalize the confirmation // finalize the confirmation
if err := doConfirm(sr, grp, partnerPubKey, ecrFmt.GetOwnership(), if err := m.doConfirm(sr, grp, partnerPubKey, ecrFmt.GetOwnership()); err != nil {
storage, ccb, net); err != nil {
jww.WARN.Printf("Confirmation failed: %s", err) jww.WARN.Printf("Confirmation failed: %s", err)
storage.Auth().Fail(sr.GetPartner()) m.storage.Auth().Fail(sr.GetPartner())
return return
} }
} }
func doConfirm(sr *auth.SentRequest, grp *cyclic.Group, func (m *Manager) doConfirm(sr *auth.SentRequest, grp *cyclic.Group,
partnerPubKey *cyclic.Int, ownershipProof []byte, storage *storage.Session, partnerPubKey *cyclic.Int, ownershipProof []byte) error {
ccb ConfirmCallback, net interfaces.NetworkManager) error {
// verify the message came from the intended recipient // verify the message came from the intended recipient
if !cAuth.VerifyOwnershipProof(sr.GetMyPrivKey(), if !cAuth.VerifyOwnershipProof(sr.GetMyPrivKey(),
sr.GetPartnerHistoricalPubKey(), grp, ownershipProof) { sr.GetPartnerHistoricalPubKey(), grp, ownershipProof) {
...@@ -245,7 +233,7 @@ func doConfirm(sr *auth.SentRequest, grp *cyclic.Group, ...@@ -245,7 +233,7 @@ func doConfirm(sr *auth.SentRequest, grp *cyclic.Group,
// fixme: channel can get into a bricked state if the first save occurs and // fixme: channel can get into a bricked state if the first save occurs and
// the second does not // the second does not
p := e2e.GetDefaultSessionParams() p := e2e.GetDefaultSessionParams()
if err := storage.E2e().AddPartner(sr.GetPartner(), if err := m.storage.E2e().AddPartner(sr.GetPartner(),
partnerPubKey, sr.GetMyPrivKey(), p, p); err != nil { partnerPubKey, sr.GetMyPrivKey(), p, p); err != nil {
return errors.Errorf("Failed to create channel with partner (%s) "+ return errors.Errorf("Failed to create channel with partner (%s) "+
"after confirmation: %+v", "after confirmation: %+v",
...@@ -254,7 +242,7 @@ func doConfirm(sr *auth.SentRequest, grp *cyclic.Group, ...@@ -254,7 +242,7 @@ func doConfirm(sr *auth.SentRequest, grp *cyclic.Group,
// delete the in progress negotiation // delete the in progress negotiation
// this undoes the request lock // this undoes the request lock
if err := storage.Auth().Delete(sr.GetPartner()); err != nil { if err := m.storage.Auth().Delete(sr.GetPartner()); err != nil {
return errors.Errorf("UNRECOVERABLE! Failed to delete in "+ return errors.Errorf("UNRECOVERABLE! Failed to delete in "+
"progress negotiation with partner (%s) after confirmation: %+v", "progress negotiation with partner (%s) after confirmation: %+v",
sr.GetPartner(), err) sr.GetPartner(), err)
...@@ -268,11 +256,15 @@ func doConfirm(sr *auth.SentRequest, grp *cyclic.Group, ...@@ -268,11 +256,15 @@ func doConfirm(sr *auth.SentRequest, grp *cyclic.Group,
Facts: make([]contact.Fact, 0), Facts: make([]contact.Fact, 0),
} }
// fixme: if a crash occurs before or during the call, the notification // fixme: if a crash occurs before or during the calls, the notification
// will never be sent. // will never be sent.
cbList := m.confirmCallbacks.Get(c.ID)
for _, cb := range cbList {
ccb := cb.(interfaces.ConfirmCallback)
go ccb(c) go ccb(c)
}
net.CheckGarbledMessages() m.net.CheckGarbledMessages()
return nil return nil
} }
......
package auth
import (
"gitlab.com/xx_network/primitives/id"
"sync"
)
type callbackMap struct {
generalCallback []interface{}
specificCallback map[id.ID]interface{}
overrideCallback []interface{}
mux sync.RWMutex
}
func newCallbackMap() *callbackMap {
return &callbackMap{
generalCallback: make([]interface{}, 0),
specificCallback: make(map[id.ID]interface{}),
overrideCallback: make([]interface{}, 0),
}
}
//adds a general callback. This will be preempted by any specific callback
func (cm *callbackMap) AddGeneral(cb interface{}) {
cm.mux.Lock()
cm.generalCallback = append(cm.generalCallback, cb)
cm.mux.Unlock()
}
//adds an override callback. This will NOT be preempted by any callback
func (cm *callbackMap) AddOverride(cb interface{}) {
cm.mux.Lock()
cm.overrideCallback = append(cm.overrideCallback, cb)
cm.mux.Unlock()
}
// adds a callback for a specific user ID. Only only callback can exist for a
// user ID. False will be returned if a callback already exists and the new
// one was not added
func (cm *callbackMap) AddSpecific(id *id.ID, cb interface{}) bool {
cm.mux.Lock()
defer cm.mux.Unlock()
if _, ok := cm.specificCallback[*id]; ok {
return false
}
cm.specificCallback[*id] = cb
return true
}
// removes a callback for a specific user ID if it exists.
func (cm *callbackMap) RemoveSpecific(id *id.ID) {
cm.mux.Lock()
defer cm.mux.Unlock()
delete(cm.specificCallback, *id)
}
//get all callback which fit with the passed id
func (cm *callbackMap) Get(id *id.ID) []interface{} {
cm.mux.RLock()
defer cm.mux.RUnlock()
cbList := cm.overrideCallback
if specific, ok := cm.specificCallback[*id]; ok {
cbList = append(cbList, specific)
} else {
cbList = append(cbList, cm.generalCallback)
}
return cbList
}
package auth
import (
"gitlab.com/elixxir/client/interfaces"
"gitlab.com/elixxir/client/interfaces/message"
"gitlab.com/elixxir/client/storage"
"gitlab.com/xx_network/primitives/id"
)
type Manager struct {
requestCallbacks *callbackMap
confirmCallbacks *callbackMap
rawMessages chan message.Receive
storage *storage.Session
net interfaces.NetworkManager
}
func NewManager(sw interfaces.Switchboard, storage *storage.Session,
net interfaces.NetworkManager) *Manager {
m := &Manager{
requestCallbacks: newCallbackMap(),
confirmCallbacks: newCallbackMap(),
rawMessages: make(chan message.Receive, 1000),
storage: storage,
net: net,
}
sw.RegisterChannel("Auth", &id.ID{}, message.Raw, m.rawMessages)
return m
}
// Adds a general callback to be used on auth requests. This will be preempted
// by any specific callback
func (m *Manager) AddGeneralRequestCallback(cb interfaces.RequestCallback) {
m.requestCallbacks.AddGeneral(cb)
}
// Adds a general callback to be used on auth requests. This will not be
// preempted by any specific callback. It is recommended that the specific
// callbacks are used, this is primarily for debugging.
func (m *Manager) AddOverrideRequestCallback(cb interfaces.RequestCallback) {
m.requestCallbacks.AddOverride(cb)
}
// Adds a specific callback to be used on auth requests. This will preempt a
// general callback, meaning the request will be heard on this callback and not
// the general. Request will still be heard on override callbacks.
func (m *Manager) AddSpecificRequestCallback(id *id.ID, cb interfaces.RequestCallback) {
m.requestCallbacks.AddSpecific(id, cb)
}
// Removes a specific callback to be used on auth requests.
func (m *Manager) RemoveSpecificRequestCallback(id *id.ID) {
m.requestCallbacks.RemoveSpecific(id)
}
// Adds a general callback to be used on auth confirms. This will be preempted
// by any specific callback
func (m *Manager) AddGeneralConfirmCallback(cb interfaces.ConfirmCallback) {
m.confirmCallbacks.AddGeneral(cb)
}
// Adds a general callback to be used on auth confirms. This will not be
// preempted by any specific callback. It is recommended that the specific
// callbacks are used, this is primarily for debugging.
func (m *Manager) AddOverrideConfirmCallback(cb interfaces.ConfirmCallback) {
m.confirmCallbacks.AddOverride(cb)
}
// Adds a specific callback to be used on auth confirms. This will preempt a
// general callback, meaning the request will be heard on this callback and not
// the general. Request will still be heard on override callbacks.
func (m *Manager) AddSpecificConfirmCallback(id *id.ID, cb interfaces.ConfirmCallback) {
m.confirmCallbacks.AddSpecific(id, cb)
}
// Removes a specific callback to be used on auth confirm.
func (m *Manager) RemoveSpecificConfirmCallback(id *id.ID) {
m.confirmCallbacks.RemoveSpecific(id)
}
...@@ -50,7 +50,7 @@ func (c *Client) RequestAuthenticatedChannel(recipientMarshaled, ...@@ -50,7 +50,7 @@ func (c *Client) RequestAuthenticatedChannel(recipientMarshaled,
// RegisterAuthCallbacks registers both callbacks for authenticated channels. // RegisterAuthCallbacks registers both callbacks for authenticated channels.
// This can only be called once // This can only be called once
func (c *Client) RegisterAuthCallbacks(request AuthRequestCallback, func (c *Client) RegisterAuthCallbacks(request AuthRequestCallback,
confirm AuthConfirmCallback) error { confirm AuthConfirmCallback) {
requestFunc := func(requestor contact.Contact, message string) { requestFunc := func(requestor contact.Contact, message string) {
requestorBind := &Contact{c: &requestor} requestorBind := &Contact{c: &requestor}
...@@ -62,7 +62,10 @@ func (c *Client) RegisterAuthCallbacks(request AuthRequestCallback, ...@@ -62,7 +62,10 @@ func (c *Client) RegisterAuthCallbacks(request AuthRequestCallback,
confirm.Callback(partnerBind) confirm.Callback(partnerBind)
} }
return c.api.RegisterAuthCallbacks(requestFunc, confirmFunc) c.api.GetAuthRegistrar().AddGeneralConfirmCallback(confirmFunc)
c.api.GetAuthRegistrar().AddGeneralRequestCallback(requestFunc)
return
} }
// ConfirmAuthenticatedChannel creates an authenticated channel out of a valid // ConfirmAuthenticatedChannel creates an authenticated channel out of a valid
......
package interfaces
import (
"gitlab.com/elixxir/client/interfaces/contact"
"gitlab.com/xx_network/primitives/id"
)
type RequestCallback func(requestor contact.Contact, message string)
type ConfirmCallback func(partner contact.Contact)
type Auth interface {
// Adds a general callback to be used on auth requests. This will be preempted
// by any specific callback
AddGeneralRequestCallback(cb RequestCallback)
// Adds a general callback to be used on auth requests. This will not be
// preempted by any specific callback. It is recommended that the specific
// callbacks are used, this is primarily for debugging.
AddOverrideRequestCallback(cb RequestCallback)
// Adds a specific callback to be used on auth requests. This will preempt a
// general callback, meaning the request will be heard on this callback and not
// the general. Request will still be heard on override callbacks.
AddSpecificRequestCallback(id *id.ID, cb RequestCallback)
// Removes a specific callback to be used on auth requests.
RemoveSpecificRequestCallback(id *id.ID)
// Adds a general callback to be used on auth confirms. This will be preempted
// by any specific callback
AddGeneralConfirmCallback(cb ConfirmCallback)
// Adds a general callback to be used on auth confirms. This will not be
// preempted by any specific callback. It is recommended that the specific
// callbacks are used, this is primarily for debugging.
AddOverrideConfirmCallback(cb ConfirmCallback)
// Adds a specific callback to be used on auth confirms. This will preempt a
// general callback, meaning the request will be heard on this callback and not
// the general. Request will still be heard on override callbacks.
AddSpecificConfirmCallback(id *id.ID, cb ConfirmCallback)
// Removes a specific callback to be used on auth confirm.
RemoveSpecificConfirmCallback(id *id.ID)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment