diff --git a/bindings/authenticatedConnection.go b/bindings/authenticatedConnection.go index 5f41453a5c7345e9cf461d6e7da5464b386761a2..95f60c71ad58c6abb031ae054f7c1be350b58096 100644 --- a/bindings/authenticatedConnection.go +++ b/bindings/authenticatedConnection.go @@ -11,6 +11,7 @@ import ( "sync" "github.com/pkg/errors" + jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/connect" "gitlab.com/elixxir/crypto/contact" ) @@ -34,8 +35,12 @@ func (_ *AuthenticatedConnection) IsAuthenticated() bool { // connection with the server). Once a connect.Connection has been established // with the server and then authenticate their identity to the server. // accepts a marshalled ReceptionIdentity and contact.Contact object -func (c *Cmix) ConnectWithAuthentication(e2eId int, recipientContact []byte) (*AuthenticatedConnection, error) { - paramsJSON := GetDefaultE2EParams() +func (c *Cmix) ConnectWithAuthentication(e2eId int, recipientContact, + e2eParamsJSON []byte) (*AuthenticatedConnection, error) { + if len(e2eParamsJSON) == 0 { + jww.WARN.Printf("e2e params not specified, using defaults...") + e2eParamsJSON = GetDefaultE2EParams() + } cont, err := contact.Unmarshal(recipientContact) if err != nil { @@ -47,7 +52,7 @@ func (c *Cmix) ConnectWithAuthentication(e2eId int, recipientContact []byte) (*A return nil, err } - params, err := parseE2EParams(paramsJSON) + params, err := parseE2EParams(e2eParamsJSON) if err != nil { return nil, err } diff --git a/bindings/e2e.go b/bindings/e2e.go index e4405f15a5907e106ccf4be3a5e0c63c94f916de..6edf2a9ff5d070bafcb32cee0a22c7e1a9977dc5 100644 --- a/bindings/e2e.go +++ b/bindings/e2e.go @@ -11,6 +11,7 @@ import ( "sync" "github.com/pkg/errors" + jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/cmix/identity/receptionID" "gitlab.com/elixxir/client/cmix/rounds" "gitlab.com/elixxir/client/xxdk" @@ -39,8 +40,13 @@ func (e *E2e) GetID() int { // LoginE2e creates and returns a new E2e object and adds it to the e2eTrackerSingleton // identity should be created via MakeIdentity() and passed in here // If callbacks is left nil, a default auth.Callbacks will be used -func LoginE2e(cmixId int, callbacks AuthCallbacks, identity []byte) (*E2e, error) { - paramsJSON := GetDefaultE2EParams() +func LoginE2e(cmixId int, callbacks AuthCallbacks, identity, + e2eParamsJSON []byte) (*E2e, error) { + if len(e2eParamsJSON) == 0 { + jww.WARN.Printf("e2e params not specified, using defaults...") + e2eParamsJSON = GetDefaultE2EParams() + } + cmix, err := cmixTrackerSingleton.get(cmixId) if err != nil { return nil, err @@ -58,7 +64,7 @@ func LoginE2e(cmixId int, callbacks AuthCallbacks, identity []byte) (*E2e, error authCallbacks = &authCallback{bindingsCbs: callbacks} } - params, err := parseE2EParams(paramsJSON) + params, err := parseE2EParams(e2eParamsJSON) if err != nil { return nil, err } @@ -74,8 +80,13 @@ func LoginE2e(cmixId int, callbacks AuthCallbacks, identity []byte) (*E2e, error // LoginE2eEphemeral creates and returns a new ephemeral E2e object and adds it to the e2eTrackerSingleton // identity should be created via MakeIdentity() and passed in here // If callbacks is left nil, a default auth.Callbacks will be used -func LoginE2eEphemeral(cmixId int, callbacks AuthCallbacks, identity []byte) (*E2e, error) { - paramsJSON := GetDefaultE2EParams() +func LoginE2eEphemeral(cmixId int, callbacks AuthCallbacks, identity, + e2eParamsJSON []byte) (*E2e, error) { + if len(e2eParamsJSON) == 0 { + jww.WARN.Printf("e2e params not specified, using defaults...") + e2eParamsJSON = GetDefaultE2EParams() + } + cmix, err := cmixTrackerSingleton.get(cmixId) if err != nil { return nil, err @@ -93,7 +104,7 @@ func LoginE2eEphemeral(cmixId int, callbacks AuthCallbacks, identity []byte) (*E authCallbacks = &authCallback{bindingsCbs: callbacks} } - params, err := parseE2EParams(paramsJSON) + params, err := parseE2EParams(e2eParamsJSON) if err != nil { return nil, err } @@ -111,8 +122,12 @@ func LoginE2eEphemeral(cmixId int, callbacks AuthCallbacks, identity []byte) (*E // If callbacks is left nil, a default auth.Callbacks will be used // This function is designed to maintain backwards compatibility with previous xx messenger designs // and should not be used for other purposes -func LoginE2eLegacy(cmixId int, callbacks AuthCallbacks) (*E2e, error) { - paramsJSON := GetDefaultE2EParams() +func LoginE2eLegacy(cmixId int, callbacks AuthCallbacks, e2eParamsJSON []byte) (*E2e, error) { + if len(e2eParamsJSON) == 0 { + jww.WARN.Printf("e2e params not specified, using defaults...") + e2eParamsJSON = GetDefaultE2EParams() + } + cmix, err := cmixTrackerSingleton.get(cmixId) if err != nil { return nil, err @@ -125,7 +140,7 @@ func LoginE2eLegacy(cmixId int, callbacks AuthCallbacks) (*E2e, error) { authCallbacks = &authCallback{bindingsCbs: callbacks} } - params, err := parseE2EParams(paramsJSON) + params, err := parseE2EParams(e2eParamsJSON) if err != nil { return nil, err } diff --git a/bindings/restlike.go b/bindings/restlike.go index 51201184b9020b7ce012e7e2e1575adc6767e4b2..b1a6fbd2167b681c51c71841c32260e07c8e9de6 100644 --- a/bindings/restlike.go +++ b/bindings/restlike.go @@ -10,7 +10,7 @@ package bindings import ( "encoding/json" - "gitlab.com/elixxir/client/e2e" + jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/restlike" "gitlab.com/elixxir/client/restlike/connect" ) @@ -35,8 +35,12 @@ type RestlikeMessage struct { // RestlikeRequest performs a normal restlike request // request - marshalled RestlikeMessage // Returns marshalled result RestlikeMessage -func RestlikeRequest(clientID, connectionID int, request []byte) ([]byte, error) { - paramsJSON := GetDefaultE2EParams() +func RestlikeRequest(clientID, connectionID int, request, + e2eParamsJSON []byte) ([]byte, error) { + if len(e2eParamsJSON) == 0 { + jww.WARN.Printf("restlike params unspecified, using defaults") + e2eParamsJSON = GetDefaultE2EParams() + } cl, err := cmixTrackerSingleton.get(clientID) if err != nil { @@ -47,7 +51,7 @@ func RestlikeRequest(clientID, connectionID int, request []byte) ([]byte, error) return nil, err } - params, err := parseE2EParams(paramsJSON) + params, err := parseE2EParams(e2eParamsJSON) if err != nil { return nil, err } @@ -86,7 +90,17 @@ func RestlikeRequest(clientID, connectionID int, request []byte) ([]byte, error) // RestlikeRequestAuth performs an authenticated restlike request // request - marshalled RestlikeMessage // Returns marshalled result RestlikeMessage -func RestlikeRequestAuth(clientID int, authConnectionID int, request []byte) ([]byte, error) { +func RestlikeRequestAuth(clientID int, authConnectionID int, request, + e2eParamsJSON []byte) ([]byte, error) { + if len(e2eParamsJSON) == 0 { + jww.WARN.Printf("restlike params unspecified, using defaults") + e2eParamsJSON = GetDefaultE2EParams() + } + params, err := parseE2EParams(e2eParamsJSON) + if err != nil { + return nil, err + } + cl, err := cmixTrackerSingleton.get(clientID) if err != nil { return nil, err @@ -111,7 +125,7 @@ func RestlikeRequestAuth(clientID int, authConnectionID int, request []byte) ([] result, err := c.Request(restlike.Method(msg.Method), restlike.URI(msg.URI), msg.Content, &restlike.Headers{ Headers: msg.Headers, Version: msg.Version, - }, e2e.GetDefaultParams()) + }, params.Base) if err != nil { return nil, err }