diff --git a/auth/partnerCallbacks.go b/auth/callbacks.go similarity index 56% rename from auth/partnerCallbacks.go rename to auth/callbacks.go index 79264cf16c607d0dfebf2fbbb79b158b80ce35c9..781164bb89e374f166b0ace4d4fb639e7c250d10 100644 --- a/auth/partnerCallbacks.go +++ b/auth/callbacks.go @@ -7,6 +7,10 @@ package auth import ( + jww "github.com/spf13/jwalterweatherman" + "gitlab.com/elixxir/client/cmix/identity/receptionID" + "gitlab.com/elixxir/client/cmix/rounds" + "gitlab.com/elixxir/crypto/contact" "gitlab.com/xx_network/primitives/id" "sync" ) @@ -40,3 +44,25 @@ func (p *partnerCallbacks) DeletePartnerCallback(partnerId *id.ID) { func (p *partnerCallbacks) getPartnerCallback(partnerId *id.ID) Callbacks { return p.callbacks[*partnerId] } + +// DefaultAuthCallbacks is a simple structure for providing a default Callbacks implementation +// It should generally not be used. +type DefaultAuthCallbacks struct{} + +// Confirm will be called when an auth Confirm message is processed. +func (a DefaultAuthCallbacks) Confirm(requestor contact.Contact, + receptionID receptionID.EphemeralIdentity, round rounds.Round) { + jww.ERROR.Printf("No valid auth callback assigned!") +} + +// Request will be called when an auth Request message is processed. +func (a DefaultAuthCallbacks) Request(requestor contact.Contact, + receptionID receptionID.EphemeralIdentity, round rounds.Round) { + jww.ERROR.Printf("No valid auth callback assigned!") +} + +// Reset will be called when an auth Reset operation occurs. +func (a DefaultAuthCallbacks) Reset(requestor contact.Contact, + receptionID receptionID.EphemeralIdentity, round rounds.Round) { + jww.ERROR.Printf("No valid auth callback assigned!") +} diff --git a/bindings/e2e.go b/bindings/e2e.go index c16162694c8df88b8447f163baaca30ed7a4ed6c..9c50ef82000e44dfd2c061e8f9c567da8297a02d 100644 --- a/bindings/e2e.go +++ b/bindings/e2e.go @@ -7,6 +7,7 @@ package bindings import ( + "gitlab.com/elixxir/client/auth" "gitlab.com/elixxir/client/cmix/identity/receptionID" "gitlab.com/elixxir/client/cmix/rounds" "gitlab.com/elixxir/client/xxdk" @@ -27,10 +28,9 @@ type E2e struct { id int } -// Login creates and returns a new E2e object -// and adds it to the e2eTrackerSingleton -// identity can be left nil such that a new -// TransmissionIdentity will be created automatically +// Login creates and returns a new E2e object and adds it to the e2eTrackerSingleton +// identity can be left nil such that a new TransmissionIdentity will be created automatically +// callbacks can be left nil and a default will be used func (e *E2e) Login(cmixId int, callbacks AuthCallbacks, identity []byte) (*E2e, error) { cmix, err := cmixTrackerSingleton.get(cmixId) if err != nil { @@ -47,12 +47,21 @@ func (e *E2e) Login(cmixId int, callbacks AuthCallbacks, identity []byte) (*E2e, } } - authCallbacks := authCallback{bindingsCbs: callbacks} - newE2e, err := xxdk.Login(cmix.api, authCallbacks, newIdentity) - if err != nil { - return nil, err + if callbacks == nil { + authCallbacks := auth.DefaultAuthCallbacks{} + newE2e, err := xxdk.Login(cmix.api, authCallbacks, newIdentity) + if err != nil { + return nil, err + } + return e2eTrackerSingleton.make(newE2e), nil + } else { + authCallbacks := authCallback{bindingsCbs: callbacks} + newE2e, err := xxdk.Login(cmix.api, authCallbacks, newIdentity) + if err != nil { + return nil, err + } + return e2eTrackerSingleton.make(newE2e), nil } - return e2eTrackerSingleton.make(newE2e), nil } // AuthCallbacks is the bindings-specific interface for auth.Callbacks methods.