diff --git a/bindings/autheticatedConnection.go b/bindings/autheticatedConnection.go index 27200082483a02f1a9dbaa7e8a4f995b5cf41cfe..837580897b1bb71f8faf9a6d916075731bad527f 100644 --- a/bindings/autheticatedConnection.go +++ b/bindings/autheticatedConnection.go @@ -2,7 +2,6 @@ package bindings import ( "gitlab.com/elixxir/client/connect" - "gitlab.com/elixxir/client/xxdk" "gitlab.com/elixxir/crypto/contact" ) @@ -26,6 +25,8 @@ func (_ *AuthenticatedConnection) IsAuthenticated() bool { // 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() + cont, err := contact.Unmarshal(recipientContact) if err != nil { return nil, err @@ -36,7 +37,12 @@ func (c *Cmix) ConnectWithAuthentication(e2eId int, recipientContact []byte) (*A return nil, err } - connection, err := connect.ConnectWithAuthentication(cont, e2eClient.api, - xxdk.GetDefaultE2EParams()) - return authenticatedConnectionTrackerSingleton.make(connection), nil + params, err := parseE2EParams(paramsJSON) + if err != nil { + return nil, err + } + + connection, err := connect.ConnectWithAuthentication(cont, + e2eClient.api, params) + return authenticatedConnectionTrackerSingleton.make(connection), err } diff --git a/bindings/cmix.go b/bindings/cmix.go index bed5669b14e912f635aed5e494975661e05ef2f1..5c1790738b07c8ca143ee34e24b16b083be88836 100644 --- a/bindings/cmix.go +++ b/bindings/cmix.go @@ -51,7 +51,13 @@ func NewKeystore(network, storageDir string, password []byte, regCode string) er // starts subprocesses to perform network operations. // TODO: add in custom parameters instead of the default func Login(storageDir string, password []byte) (*Cmix, error) { - client, err := xxdk.LoadCmix(storageDir, password, xxdk.GetDefaultCMixParams()) + paramsJSON := GetDefaultCMixParams() + params, err := parseCMixParams(paramsJSON) + if err != nil { + return nil, err + } + + client, err := xxdk.LoadCmix(storageDir, password, params) if err != nil { return nil, errors.New(fmt.Sprintf("Failed to login: %+v", err)) } diff --git a/bindings/connect.go b/bindings/connect.go index 6c9e034867cf71c2c67cb147869d4ed215191f4b..94d13cba8ec571c07da43b0fd286a06731eb7ee3 100644 --- a/bindings/connect.go +++ b/bindings/connect.go @@ -3,12 +3,8 @@ package bindings import ( "encoding/json" - "time" - "gitlab.com/elixxir/client/catalog" "gitlab.com/elixxir/client/connect" - e2e2 "gitlab.com/elixxir/client/e2e" - "gitlab.com/elixxir/client/xxdk" "gitlab.com/elixxir/crypto/contact" ) @@ -38,6 +34,7 @@ func (c *Connection) GetId() int { // myIdentity - marshalled ReceptionIdentity object func (c *Cmix) Connect(e2eId int, recipientContact []byte) ( *Connection, error) { + paramsJSON := GetDefaultE2EParams() cont, err := contact.Unmarshal(recipientContact) if err != nil { return nil, err @@ -48,8 +45,11 @@ func (c *Cmix) Connect(e2eId int, recipientContact []byte) ( return nil, err } - p := xxdk.GetDefaultE2EParams() - p.Base.Timeout = 45 * time.Second + p, err := parseE2EParams(paramsJSON) + if err != nil { + return nil, err + } + connection, err := connect.Connect(cont, e2eClient.api, p) if err != nil { return nil, err @@ -61,8 +61,15 @@ func (c *Cmix) Connect(e2eId int, recipientContact []byte) ( // SendE2E is a wrapper for sending specifically to the Connection's partner.Manager // Returns marshalled E2ESendReport func (c *Connection) SendE2E(mt int, payload []byte) ([]byte, error) { + paramsJSON := GetDefaultE2EParams() + + params, err := parseE2EParams(paramsJSON) + if err != nil { + return nil, err + } + rounds, mid, ts, err := c.connection.SendE2E(catalog.MessageType(mt), payload, - e2e2.GetDefaultParams()) + params.Base) if err != nil { return nil, err diff --git a/bindings/e2e.go b/bindings/e2e.go index 5d33a8441910457b55cea6cfef130eec8aa5bb58..b2e9984d5f3759cf90eb4f6d111d37ee91b97a05 100644 --- a/bindings/e2e.go +++ b/bindings/e2e.go @@ -36,6 +36,7 @@ func (e *E2e) GetID() int { // 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() cmix, err := cmixTrackerSingleton.get(cmixId) if err != nil { return nil, err @@ -53,7 +54,10 @@ func LoginE2e(cmixId int, callbacks AuthCallbacks, identity []byte) (*E2e, error authCallbacks = &authCallback{bindingsCbs: callbacks} } - params := xxdk.GetDefaultE2EParams() + params, err := parseE2EParams(paramsJSON) + if err != nil { + return nil, err + } newE2e, err := xxdk.Login(cmix.api, authCallbacks, newIdentity, params) if err != nil { @@ -67,6 +71,7 @@ func LoginE2e(cmixId int, callbacks AuthCallbacks, identity []byte) (*E2e, error // 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() cmix, err := cmixTrackerSingleton.get(cmixId) if err != nil { return nil, err @@ -84,9 +89,13 @@ func LoginE2eEphemeral(cmixId int, callbacks AuthCallbacks, identity []byte) (*E authCallbacks = &authCallback{bindingsCbs: callbacks} } - params := xxdk.GetDefaultE2EParams() + params, err := parseE2EParams(paramsJSON) + if err != nil { + return nil, err + } - newE2e, err := xxdk.LoginEphemeral(cmix.api, authCallbacks, newIdentity, params) + newE2e, err := xxdk.LoginEphemeral(cmix.api, authCallbacks, + newIdentity, params) if err != nil { return nil, err } @@ -99,6 +108,7 @@ func LoginE2eEphemeral(cmixId int, callbacks AuthCallbacks, identity []byte) (*E // 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() cmix, err := cmixTrackerSingleton.get(cmixId) if err != nil { return nil, err @@ -111,7 +121,10 @@ func LoginE2eLegacy(cmixId int, callbacks AuthCallbacks) (*E2e, error) { authCallbacks = &authCallback{bindingsCbs: callbacks} } - params := xxdk.GetDefaultE2EParams() + params, err := parseE2EParams(paramsJSON) + if err != nil { + return nil, err + } newE2e, err := xxdk.LoginLegacy(cmix.api, params, authCallbacks) if err != nil { diff --git a/bindings/e2eHandler.go b/bindings/e2eHandler.go index 043b69ce352fb51653608f56e1dce09af7a62c02..3fe81a225c31f4fef7aade2361943a95f44817ae 100644 --- a/bindings/e2eHandler.go +++ b/bindings/e2eHandler.go @@ -9,6 +9,7 @@ package bindings import ( "encoding/json" "fmt" + "gitlab.com/elixxir/client/catalog" "gitlab.com/elixxir/client/cmix/identity/receptionID" "gitlab.com/elixxir/client/cmix/rounds" @@ -120,7 +121,7 @@ func (e *E2e) RemoveService(tag string) error { // - []byte - the marshalled bytes of the E2ESendReport object. func (e *E2e) SendE2E(messageType int, recipientId, payload, e2eParams []byte) ([]byte, error) { - + // Note that specifically these are the .Base params from xxdk.E2EParams params := e2e.GetDefaultParams() err := params.UnmarshalJSON(e2eParams) if err != nil { diff --git a/bindings/params.go b/bindings/params.go new file mode 100644 index 0000000000000000000000000000000000000000..860c1fbcd1077201c2d285d84af37881fe54e8eb --- /dev/null +++ b/bindings/params.go @@ -0,0 +1,51 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright © 2020 xx network SEZC // +// // +// Use of this source code is governed by a license that can be found in the // +// LICENSE file // +/////////////////////////////////////////////////////////////////////////////// + +// params.go provides functions for getting and setting parameters in bindings. + +package bindings + +import ( + jww "github.com/spf13/jwalterweatherman" + "gitlab.com/elixxir/client/xxdk" +) + +// GetDefaultCMixParams returns a JSON serialized object with all of the +// CMIX parameters and their default values. Call this function and modify +// the json to change CMIX settings. +func GetDefaultCMixParams() []byte { + defaultParams := xxdk.GetDefaultCMixParams() + data, err := defaultParams.Marshal() + if err != nil { + jww.FATAL.Panicf("Unexpected error: %+v", err) + } + return data +} + +// GetDefaultE2EParams returns a JSON serialized object with all of the +// E2E parameters and their default values. Call this function and modify +// the json to change E2E settings. +func GetDefaultE2EParams() []byte { + defaultParams := xxdk.GetDefaultE2EParams() + data, err := defaultParams.Marshal() + if err != nil { + jww.FATAL.Panicf("Unexpected error: %+v", err) + } + return data +} + +func parseCMixParams(data []byte) (xxdk.CMIXParams, error) { + p := &xxdk.CMIXParams{} + err := p.Unmarshal(data) + return *p, err +} + +func parseE2EParams(data []byte) (xxdk.E2EParams, error) { + p := &xxdk.E2EParams{} + err := p.Unmarshal(data) + return *p, err +} diff --git a/bindings/restlike.go b/bindings/restlike.go index c6c31c7ae744e644747a8da6018471fd03b8680e..be0bd004f7bce59111e3c347ceecb7b5eab5bfcf 100644 --- a/bindings/restlike.go +++ b/bindings/restlike.go @@ -8,6 +8,7 @@ package bindings import ( "encoding/json" + "gitlab.com/elixxir/client/e2e" "gitlab.com/elixxir/client/restlike" "gitlab.com/elixxir/client/restlike/connect" @@ -34,6 +35,8 @@ type RestlikeMessage struct { // request - marshalled RestlikeMessage // Returns marshalled result RestlikeMessage func RestlikeRequest(clientID int, connectionID int, request []byte) ([]byte, error) { + paramsJSON := GetDefaultE2EParams() + cl, err := cmixTrackerSingleton.get(clientID) if err != nil { return nil, err @@ -43,6 +46,11 @@ func RestlikeRequest(clientID int, connectionID int, request []byte) ([]byte, er return nil, err } + params, err := parseE2EParams(paramsJSON) + if err != nil { + return nil, err + } + msg := &RestlikeMessage{} err = json.Unmarshal(request, msg) if err != nil { @@ -58,7 +66,7 @@ func RestlikeRequest(clientID int, connectionID int, request []byte) ([]byte, er 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 }