Skip to content
Snippets Groups Projects
Commit c34d9586 authored by Richard T. Carback III's avatar Richard T. Carback III
Browse files

Add param helper functions to bindings and add code in preparation for accepting params json files

parent e532c644
No related branches found
No related tags found
2 merge requests!510Release,!253General Cleanup
...@@ -2,7 +2,6 @@ package bindings ...@@ -2,7 +2,6 @@ package bindings
import ( import (
"gitlab.com/elixxir/client/connect" "gitlab.com/elixxir/client/connect"
"gitlab.com/elixxir/client/xxdk"
"gitlab.com/elixxir/crypto/contact" "gitlab.com/elixxir/crypto/contact"
) )
...@@ -26,6 +25,8 @@ func (_ *AuthenticatedConnection) IsAuthenticated() bool { ...@@ -26,6 +25,8 @@ func (_ *AuthenticatedConnection) IsAuthenticated() bool {
// with the server and then authenticate their identity to the server. // with the server and then authenticate their identity to the server.
// accepts a marshalled ReceptionIdentity and contact.Contact object // accepts a marshalled ReceptionIdentity and contact.Contact object
func (c *Cmix) ConnectWithAuthentication(e2eId int, recipientContact []byte) (*AuthenticatedConnection, error) { func (c *Cmix) ConnectWithAuthentication(e2eId int, recipientContact []byte) (*AuthenticatedConnection, error) {
paramsJSON := GetDefaultE2EParams()
cont, err := contact.Unmarshal(recipientContact) cont, err := contact.Unmarshal(recipientContact)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -36,7 +37,12 @@ func (c *Cmix) ConnectWithAuthentication(e2eId int, recipientContact []byte) (*A ...@@ -36,7 +37,12 @@ func (c *Cmix) ConnectWithAuthentication(e2eId int, recipientContact []byte) (*A
return nil, err return nil, err
} }
connection, err := connect.ConnectWithAuthentication(cont, e2eClient.api, params, err := parseE2EParams(paramsJSON)
xxdk.GetDefaultE2EParams()) if err != nil {
return authenticatedConnectionTrackerSingleton.make(connection), nil return nil, err
}
connection, err := connect.ConnectWithAuthentication(cont,
e2eClient.api, params)
return authenticatedConnectionTrackerSingleton.make(connection), err
} }
...@@ -51,7 +51,13 @@ func NewKeystore(network, storageDir string, password []byte, regCode string) er ...@@ -51,7 +51,13 @@ func NewKeystore(network, storageDir string, password []byte, regCode string) er
// starts subprocesses to perform network operations. // starts subprocesses to perform network operations.
// TODO: add in custom parameters instead of the default // TODO: add in custom parameters instead of the default
func Login(storageDir string, password []byte) (*Cmix, error) { 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 { if err != nil {
return nil, errors.New(fmt.Sprintf("Failed to login: %+v", err)) return nil, errors.New(fmt.Sprintf("Failed to login: %+v", err))
} }
......
...@@ -3,12 +3,8 @@ package bindings ...@@ -3,12 +3,8 @@ package bindings
import ( import (
"encoding/json" "encoding/json"
"time"
"gitlab.com/elixxir/client/catalog" "gitlab.com/elixxir/client/catalog"
"gitlab.com/elixxir/client/connect" "gitlab.com/elixxir/client/connect"
e2e2 "gitlab.com/elixxir/client/e2e"
"gitlab.com/elixxir/client/xxdk"
"gitlab.com/elixxir/crypto/contact" "gitlab.com/elixxir/crypto/contact"
) )
...@@ -38,6 +34,7 @@ func (c *Connection) GetId() int { ...@@ -38,6 +34,7 @@ func (c *Connection) GetId() int {
// myIdentity - marshalled ReceptionIdentity object // myIdentity - marshalled ReceptionIdentity object
func (c *Cmix) Connect(e2eId int, recipientContact []byte) ( func (c *Cmix) Connect(e2eId int, recipientContact []byte) (
*Connection, error) { *Connection, error) {
paramsJSON := GetDefaultE2EParams()
cont, err := contact.Unmarshal(recipientContact) cont, err := contact.Unmarshal(recipientContact)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -48,8 +45,11 @@ func (c *Cmix) Connect(e2eId int, recipientContact []byte) ( ...@@ -48,8 +45,11 @@ func (c *Cmix) Connect(e2eId int, recipientContact []byte) (
return nil, err return nil, err
} }
p := xxdk.GetDefaultE2EParams() p, err := parseE2EParams(paramsJSON)
p.Base.Timeout = 45 * time.Second if err != nil {
return nil, err
}
connection, err := connect.Connect(cont, e2eClient.api, p) connection, err := connect.Connect(cont, e2eClient.api, p)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -61,8 +61,15 @@ func (c *Cmix) Connect(e2eId int, recipientContact []byte) ( ...@@ -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 // SendE2E is a wrapper for sending specifically to the Connection's partner.Manager
// Returns marshalled E2ESendReport // Returns marshalled E2ESendReport
func (c *Connection) SendE2E(mt int, payload []byte) ([]byte, error) { 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, rounds, mid, ts, err := c.connection.SendE2E(catalog.MessageType(mt), payload,
e2e2.GetDefaultParams()) params.Base)
if err != nil { if err != nil {
return nil, err return nil, err
......
...@@ -36,6 +36,7 @@ func (e *E2e) GetID() int { ...@@ -36,6 +36,7 @@ func (e *E2e) GetID() int {
// identity should be created via MakeIdentity() and passed in here // identity should be created via MakeIdentity() and passed in here
// If callbacks is left nil, a default auth.Callbacks will be used // If callbacks is left nil, a default auth.Callbacks will be used
func LoginE2e(cmixId int, callbacks AuthCallbacks, identity []byte) (*E2e, error) { func LoginE2e(cmixId int, callbacks AuthCallbacks, identity []byte) (*E2e, error) {
paramsJSON := GetDefaultE2EParams()
cmix, err := cmixTrackerSingleton.get(cmixId) cmix, err := cmixTrackerSingleton.get(cmixId)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -53,7 +54,10 @@ func LoginE2e(cmixId int, callbacks AuthCallbacks, identity []byte) (*E2e, error ...@@ -53,7 +54,10 @@ func LoginE2e(cmixId int, callbacks AuthCallbacks, identity []byte) (*E2e, error
authCallbacks = &authCallback{bindingsCbs: callbacks} 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) newE2e, err := xxdk.Login(cmix.api, authCallbacks, newIdentity, params)
if err != nil { if err != nil {
...@@ -67,6 +71,7 @@ func LoginE2e(cmixId int, callbacks AuthCallbacks, identity []byte) (*E2e, error ...@@ -67,6 +71,7 @@ func LoginE2e(cmixId int, callbacks AuthCallbacks, identity []byte) (*E2e, error
// identity should be created via MakeIdentity() and passed in here // identity should be created via MakeIdentity() and passed in here
// If callbacks is left nil, a default auth.Callbacks will be used // If callbacks is left nil, a default auth.Callbacks will be used
func LoginE2eEphemeral(cmixId int, callbacks AuthCallbacks, identity []byte) (*E2e, error) { func LoginE2eEphemeral(cmixId int, callbacks AuthCallbacks, identity []byte) (*E2e, error) {
paramsJSON := GetDefaultE2EParams()
cmix, err := cmixTrackerSingleton.get(cmixId) cmix, err := cmixTrackerSingleton.get(cmixId)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -84,9 +89,13 @@ func LoginE2eEphemeral(cmixId int, callbacks AuthCallbacks, identity []byte) (*E ...@@ -84,9 +89,13 @@ func LoginE2eEphemeral(cmixId int, callbacks AuthCallbacks, identity []byte) (*E
authCallbacks = &authCallback{bindingsCbs: callbacks} 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 { if err != nil {
return nil, err return nil, err
} }
...@@ -99,6 +108,7 @@ func LoginE2eEphemeral(cmixId int, callbacks AuthCallbacks, identity []byte) (*E ...@@ -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 // This function is designed to maintain backwards compatibility with previous xx messenger designs
// and should not be used for other purposes // and should not be used for other purposes
func LoginE2eLegacy(cmixId int, callbacks AuthCallbacks) (*E2e, error) { func LoginE2eLegacy(cmixId int, callbacks AuthCallbacks) (*E2e, error) {
paramsJSON := GetDefaultE2EParams()
cmix, err := cmixTrackerSingleton.get(cmixId) cmix, err := cmixTrackerSingleton.get(cmixId)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -111,7 +121,10 @@ func LoginE2eLegacy(cmixId int, callbacks AuthCallbacks) (*E2e, error) { ...@@ -111,7 +121,10 @@ func LoginE2eLegacy(cmixId int, callbacks AuthCallbacks) (*E2e, error) {
authCallbacks = &authCallback{bindingsCbs: callbacks} 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) newE2e, err := xxdk.LoginLegacy(cmix.api, params, authCallbacks)
if err != nil { if err != nil {
......
...@@ -9,6 +9,7 @@ package bindings ...@@ -9,6 +9,7 @@ package bindings
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"gitlab.com/elixxir/client/catalog" "gitlab.com/elixxir/client/catalog"
"gitlab.com/elixxir/client/cmix/identity/receptionID" "gitlab.com/elixxir/client/cmix/identity/receptionID"
"gitlab.com/elixxir/client/cmix/rounds" "gitlab.com/elixxir/client/cmix/rounds"
...@@ -120,7 +121,7 @@ func (e *E2e) RemoveService(tag string) error { ...@@ -120,7 +121,7 @@ func (e *E2e) RemoveService(tag string) error {
// - []byte - the marshalled bytes of the E2ESendReport object. // - []byte - the marshalled bytes of the E2ESendReport object.
func (e *E2e) SendE2E(messageType int, recipientId, payload, func (e *E2e) SendE2E(messageType int, recipientId, payload,
e2eParams []byte) ([]byte, error) { e2eParams []byte) ([]byte, error) {
// Note that specifically these are the .Base params from xxdk.E2EParams
params := e2e.GetDefaultParams() params := e2e.GetDefaultParams()
err := params.UnmarshalJSON(e2eParams) err := params.UnmarshalJSON(e2eParams)
if err != nil { if err != nil {
......
///////////////////////////////////////////////////////////////////////////////
// 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
}
...@@ -8,6 +8,7 @@ package bindings ...@@ -8,6 +8,7 @@ package bindings
import ( import (
"encoding/json" "encoding/json"
"gitlab.com/elixxir/client/e2e" "gitlab.com/elixxir/client/e2e"
"gitlab.com/elixxir/client/restlike" "gitlab.com/elixxir/client/restlike"
"gitlab.com/elixxir/client/restlike/connect" "gitlab.com/elixxir/client/restlike/connect"
...@@ -34,6 +35,8 @@ type RestlikeMessage struct { ...@@ -34,6 +35,8 @@ type RestlikeMessage struct {
// request - marshalled RestlikeMessage // request - marshalled RestlikeMessage
// Returns marshalled result RestlikeMessage // Returns marshalled result RestlikeMessage
func RestlikeRequest(clientID int, connectionID int, request []byte) ([]byte, error) { func RestlikeRequest(clientID int, connectionID int, request []byte) ([]byte, error) {
paramsJSON := GetDefaultE2EParams()
cl, err := cmixTrackerSingleton.get(clientID) cl, err := cmixTrackerSingleton.get(clientID)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -43,6 +46,11 @@ func RestlikeRequest(clientID int, connectionID int, request []byte) ([]byte, er ...@@ -43,6 +46,11 @@ func RestlikeRequest(clientID int, connectionID int, request []byte) ([]byte, er
return nil, err return nil, err
} }
params, err := parseE2EParams(paramsJSON)
if err != nil {
return nil, err
}
msg := &RestlikeMessage{} msg := &RestlikeMessage{}
err = json.Unmarshal(request, msg) err = json.Unmarshal(request, msg)
if err != nil { if err != nil {
...@@ -58,7 +66,7 @@ func RestlikeRequest(clientID int, connectionID int, request []byte) ([]byte, er ...@@ -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{ result, err := c.Request(restlike.Method(msg.Method), restlike.URI(msg.URI), msg.Content, &restlike.Headers{
Headers: msg.Headers, Headers: msg.Headers,
Version: msg.Version, Version: msg.Version,
}, e2e.GetDefaultParams()) }, params.Base)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
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