Skip to content
Snippets Groups Projects
Commit 4215fa46 authored by Jake Taylor's avatar Jake Taylor
Browse files

add xxdk.E2e object to bindings

parent 5140db51
No related branches found
No related tags found
2 merge requests!510Release,!238Hotfix/e2e client
......@@ -24,17 +24,17 @@ 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 Identity and contact.Contact object
func (c *Client) ConnectWithAuthentication(recipientContact []byte, myIdentity []byte) (*AuthenticatedConnection, error) {
func (c *Cmix) ConnectWithAuthentication(e2eId int, recipientContact []byte) (*AuthenticatedConnection, error) {
cont, err := contact.Unmarshal(recipientContact)
if err != nil {
return nil, err
}
myID, rsaPriv, salt, myDHPriv, err := c.unmarshalIdentity(myIdentity)
e2eClient, err := e2eTrackerSingleton.get(e2eId)
if err != nil {
return nil, err
}
connection, err := connect.ConnectWithAuthentication(cont, myID, salt, rsaPriv, myDHPriv, c.api.GetRng(),
c.api.GetStorage().GetE2EGroup(), c.api.GetCmix(), connect.GetDefaultParams())
connection, err := connect.ConnectWithAuthentication(cont, e2eClient, connect.GetDefaultParams())
return authenticatedConnectionTrackerSingleton.make(connection), nil
}
......@@ -7,22 +7,22 @@ import (
"gitlab.com/elixxir/client/xxdk"
)
// sets the log level
// init sets the log level
func init() {
jww.SetLogThreshold(jww.LevelInfo)
jww.SetStdoutThreshold(jww.LevelInfo)
}
//client tracker singleton, used to track clients so they can be referenced by
//id back over the bindings
var clientTrackerSingleton = &clientTracker{
clients: make(map[int]*Client),
// cmixTrackerSingleton is used to track Cmix objects so that
// they can be referenced by id back over the bindings
var cmixTrackerSingleton = &cmixTracker{
clients: make(map[int]*Cmix),
count: 0,
}
// Client BindingsClient wraps the xxdk.Cmix, implementing additional functions
// to support the gomobile Client interface
type Client struct {
// Cmix BindingsClient wraps the xxdk.Cmix, implementing additional functions
// to support the gomobile Cmix interface
type Cmix struct {
api *xxdk.Cmix
id int
}
......@@ -49,16 +49,15 @@ func NewClient(network, storageDir string, password []byte, regCode string) erro
// Login does not block on network connection, and instead loads and
// starts subprocesses to perform network operations.
// TODO: add in custom parameters instead of the default
func Login(storageDir string, password []byte) (*Client, error) {
client, err := xxdk.Login(storageDir, password, xxdk.GetDefaultParams())
func Login(storageDir string, password []byte) (*Cmix, error) {
client, err := xxdk.LoadCmix(storageDir, password, xxdk.GetDefaultParams())
if err != nil {
return nil, errors.New(fmt.Sprintf("Failed to login: %+v", err))
}
return clientTrackerSingleton.make(client), nil
return cmixTrackerSingleton.make(client), nil
}
func (c *Client) GetID() int {
func (c *Cmix) GetID() int {
return c.id
}
......@@ -6,24 +6,24 @@ import (
"sync"
)
// clientTracker is a singleton used to keep track of extant clients, allowing
// for race condition free passing over the bindings
type clientTracker struct {
clients map[int]*Client
// cmixTracker is a singleton used to keep track of extant Cmix objects,
// preventing race conditions created by passing it over the bindings
type cmixTracker struct {
clients map[int]*Cmix
count int
mux sync.RWMutex
}
// make makes a client from an API client, assigning it a unique ID
func (ct *clientTracker) make(c *xxdk.Cmix) *Client {
// make a Cmix from an xxdk.Cmix, assigns it a unique ID,
// and adds it to the cmixTracker
func (ct *cmixTracker) make(c *xxdk.Cmix) *Cmix {
ct.mux.Lock()
defer ct.mux.Unlock()
id := ct.count
ct.count++
ct.clients[id] = &Client{
ct.clients[id] = &Cmix{
api: c,
id: id,
}
......@@ -31,8 +31,8 @@ func (ct *clientTracker) make(c *xxdk.Cmix) *Client {
return ct.clients[id]
}
//get returns a client given its ID
func (ct *clientTracker) get(id int) (*Client, error) {
// get a Cmix from the cmixTracker given its ID
func (ct *cmixTracker) get(id int) (*Cmix, error) {
ct.mux.RLock()
defer ct.mux.RUnlock()
......@@ -45,8 +45,8 @@ func (ct *clientTracker) get(id int) (*Client, error) {
return c, nil
}
//deletes a client if it exists
func (ct *clientTracker) delete(id int) {
// delete a Cmix if it exists in the cmixTracker
func (ct *cmixTracker) delete(id int) {
ct.mux.Lock()
defer ct.mux.Unlock()
......
......@@ -32,19 +32,19 @@ func (c *Connection) GetId() int {
// partner.Manager is confirmed.
// recipientContact - marshalled contact.Contact object
// myIdentity - marshalled Identity object
func (c *Client) Connect(e2eClientId int, recipientContact []byte) (
func (c *Cmix) Connect(e2eId int, recipientContact []byte) (
*Connection, error) {
cont, err := contact.Unmarshal(recipientContact)
if err != nil {
return nil, err
}
myID, _, _, myDHPriv, err := c.unmarshalIdentity(myIdentity)
e2eClient, err := e2eTrackerSingleton.get(e2eId)
if err != nil {
return nil, err
}
connection, err := connect.Connect(cont, "test", connect.GetDefaultParams())
connection, err := connect.Connect(cont, e2eClient, connect.GetDefaultParams())
if err != nil {
return nil, err
}
......
......@@ -28,10 +28,10 @@ type Identity struct {
}
// MakeIdentity generates a new cryptographic identity for receiving messages
func (c *Client) MakeIdentity() ([]byte, error) {
func (c *Cmix) MakeIdentity() ([]byte, error) {
s := c.api.GetRng().GetStream()
defer s.Close()
ident, err := xxdk.MakeIdentity(s, c.api.GetStorage().GetE2EGroup())
ident, err := xxdk.MakeTransmissionIdentity(s, c.api.GetStorage().GetE2EGroup())
dhPrivJson, err := ident.DHKeyPrivate.MarshalJSON()
if err != nil {
......@@ -49,7 +49,7 @@ func (c *Client) MakeIdentity() ([]byte, error) {
}
// GetContactFromIdentity accepts a marshalled Identity object and returns a marshalled contact.Contact object
func (c *Client) GetContactFromIdentity(identity []byte) ([]byte, error) {
func (c *Cmix) GetContactFromIdentity(identity []byte) ([]byte, error) {
uID, _, _, dhKey, err := c.unmarshalIdentity(identity)
if err != nil {
return nil, err
......@@ -69,7 +69,7 @@ func (c *Client) GetContactFromIdentity(identity []byte) ([]byte, error) {
return ct.Marshal(), nil
}
func (c *Client) unmarshalIdentity(marshaled []byte) (*id.ID, *rsa.PrivateKey, []byte,
func (c *Cmix) unmarshalIdentity(marshaled []byte) (*id.ID, *rsa.PrivateKey, []byte,
*cyclic.Int, error) {
I := Identity{}
err := json.Unmarshal(marshaled, &I)
......
......@@ -65,7 +65,7 @@ type MessageDeliveryCallback interface {
// This function takes the marshaled send report to ensure a memory leak does
// not occur as a result of both sides of the bindings holding a reference to
// the same pointer.
func (c *Client) WaitForMessageDelivery(roundList []byte,
func (c *Cmix) WaitForMessageDelivery(roundList []byte,
mdc MessageDeliveryCallback, timeoutMS int) error {
jww.INFO.Printf("WaitForMessageDelivery(%v, _, %v)",
roundList, timeoutMS)
......
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2022 Privategrity Corporation /
// /
// All rights reserved. /
////////////////////////////////////////////////////////////////////////////////
package bindings
import "gitlab.com/elixxir/client/xxdk"
// e2eTrackerSingleton is used to track E2e objects so that
// they can be referenced by id back over the bindings
var e2eTrackerSingleton = &e2eTracker{
clients: make(map[int]*E2e),
count: 0,
}
// E2e BindingsClient wraps the xxdk.E2e, implementing additional functions
// to support the gomobile E2e interface
type E2e struct {
api *xxdk.E2e
id int
}
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2022 Privategrity Corporation /
// /
// All rights reserved. /
////////////////////////////////////////////////////////////////////////////////
package bindings
import (
"github.com/pkg/errors"
"gitlab.com/elixxir/client/xxdk"
"sync"
)
// e2eTracker is a singleton used to keep track of extant E2e objects,
// preventing race conditions created by passing it over the bindings
type e2eTracker struct {
clients map[int]*E2e
count int
mux sync.RWMutex
}
// make a E2e from an xxdk.E2e, assigns it a unique ID,
// and adds it to the e2eTracker
func (ct *e2eTracker) make(c *xxdk.E2e) *E2e {
ct.mux.Lock()
defer ct.mux.Unlock()
id := ct.count
ct.count++
ct.clients[id] = &E2e{
api: c,
id: id,
}
return ct.clients[id]
}
// get an E2e from the e2eTracker given its ID
func (ct *e2eTracker) get(id int) (*E2e, error) {
ct.mux.RLock()
defer ct.mux.RUnlock()
c, exist := ct.clients[id]
if !exist {
return nil, errors.Errorf("Cannot get client for id %d, client "+
"does not exist", id)
}
return c, nil
}
// delete an E2e if it exists in the e2eTracker
func (ct *e2eTracker) delete(id int) {
ct.mux.Lock()
defer ct.mux.Unlock()
delete(ct.clients, id)
}
......@@ -35,7 +35,7 @@ import (
// Responds to sent rekeys and executes them
// - KeyExchange Confirm (/keyExchange/confirm.go)
// Responds to confirmations of successful rekey operations
func (c *Client) StartNetworkFollower(timeoutMS int) error {
func (c *Cmix) StartNetworkFollower(timeoutMS int) error {
timeout := time.Duration(timeoutMS) * time.Millisecond
return c.api.StartNetworkFollower(timeout)
}
......@@ -45,7 +45,7 @@ func (c *Client) StartNetworkFollower(timeoutMS int) error {
// fails to stop it.
// if the network follower is running and this fails, the client object will
// most likely be in an unrecoverable state and need to be trashed.
func (c *Client) StopNetworkFollower() error {
func (c *Cmix) StopNetworkFollower() error {
if err := c.api.StopNetworkFollower(); err != nil {
return errors.New(fmt.Sprintf("Failed to stop the "+
"network follower: %+v", err))
......@@ -55,7 +55,7 @@ func (c *Client) StopNetworkFollower() error {
// WaitForNewtwork will block until either the network is healthy or the
// passed timeout. It will return true if the network is healthy
func (c *Client) WaitForNetwork(timeoutMS int) bool {
func (c *Cmix) WaitForNetwork(timeoutMS int) bool {
start := netTime.Now()
timeout := time.Duration(timeoutMS) * time.Millisecond
for netTime.Since(start) < timeout {
......@@ -72,7 +72,7 @@ func (c *Client) WaitForNetwork(timeoutMS int) bool {
// Starting - 1000
// Running - 2000
// Stopping - 3000
func (c *Client) NetworkFollowerStatus() int {
func (c *Cmix) NetworkFollowerStatus() int {
return int(c.api.NetworkFollowerStatus())
}
......@@ -82,13 +82,13 @@ func (c *Client) NetworkFollowerStatus() int {
// Due to the handling of comms on iOS, where the OS can
// block indefiently, it may not enter the stopped
// state apropreatly. This can be used instead.
func (c *Client) HasRunningProcessies() bool {
func (c *Cmix) HasRunningProcessies() bool {
return c.api.HasRunningProcessies()
}
// IsNetworkHealthy returns true if the network is read to be in a healthy state where
// messages can be sent
func (c *Client) IsNetworkHealthy() bool {
func (c *Cmix) IsNetworkHealthy() bool {
return c.api.GetCmix().IsHealthy()
}
......@@ -101,11 +101,11 @@ type NetworkHealthCallback interface {
// RegisterNetworkHealthCB registers the network health callback to be called
// any time the network health changes. Returns a unique ID that can be used to
// unregister the network health callback.
func (c *Client) RegisterNetworkHealthCB(nhc NetworkHealthCallback) int64 {
func (c *Cmix) RegisterNetworkHealthCB(nhc NetworkHealthCallback) int64 {
return int64(c.api.GetCmix().AddHealthCallback(nhc.Callback))
}
func (c *Client) UnregisterNetworkHealthCB(funcID int64) {
func (c *Cmix) UnregisterNetworkHealthCB(funcID int64) {
c.api.GetCmix().RemoveHealthCallback(uint64(funcID))
}
......@@ -115,7 +115,7 @@ type ClientError interface {
// RegisterClientErrorCallback registers the callback to handle errors from the
// long running threads controlled by StartNetworkFollower and StopNetworkFollower
func (c *Client) RegisterClientErrorCallback(clientError ClientError) {
func (c *Cmix) RegisterClientErrorCallback(clientError ClientError) {
errChan := c.api.GetErrorsChannel()
go func() {
for report := range errChan {
......
......@@ -34,7 +34,7 @@ type RestlikeMessage struct {
// request - marshalled RestlikeMessage
// Returns marshalled result RestlikeMessage
func RestlikeRequest(clientID int, connectionID int, request []byte) ([]byte, error) {
cl, err := clientTrackerSingleton.get(clientID)
cl, err := cmixTrackerSingleton.get(clientID)
if err != nil {
return nil, err
}
......@@ -78,7 +78,7 @@ func RestlikeRequest(clientID int, connectionID int, request []byte) ([]byte, er
// request - marshalled RestlikeMessage
// Returns marshalled result RestlikeMessage
func RestlikeRequestAuth(clientID int, authConnectionID int, request []byte) ([]byte, error) {
cl, err := clientTrackerSingleton.get(clientID)
cl, err := cmixTrackerSingleton.get(clientID)
if err != nil {
return nil, err
}
......
......@@ -27,7 +27,7 @@ import (
"gitlab.com/elixxir/client/backup"
"gitlab.com/elixxir/client/e2e"
"gitlab.com/elixxir/client/xxdk/e2eApi"
"gitlab.com/elixxir/client/xxdk"
"gitlab.com/elixxir/client/catalog"
"gitlab.com/elixxir/client/cmix"
......@@ -36,7 +36,6 @@ import (
"github.com/spf13/cobra"
jww "github.com/spf13/jwalterweatherman"
"github.com/spf13/viper"
"gitlab.com/elixxir/client/xxdk"
backupCrypto "gitlab.com/elixxir/crypto/backup"
"gitlab.com/elixxir/crypto/contact"
"gitlab.com/elixxir/primitives/excludedRounds"
......@@ -559,7 +558,7 @@ func createClient() *xxdk.Cmix {
}
// Construct client from backup data
backupIdList, _, err := e2eApi.NewClientFromBackup(string(ndfJSON), storeDir,
backupIdList, _, err := xxdk.NewClientFromBackup(string(ndfJSON), storeDir,
pass, backupPass, backupFile)
if err != nil {
jww.FATAL.Panicf("%+v", err)
......@@ -593,7 +592,7 @@ func createClient() *xxdk.Cmix {
params := initParams()
client, err := xxdk.OpenClient(storeDir, pass, params)
client, err := xxdk.OpenCmix(storeDir, pass, params)
if err != nil {
jww.FATAL.Panicf("%+v", err)
}
......@@ -621,7 +620,7 @@ func initParams() xxdk.Params {
return p
}
func initClient() *e2eApi.E2e {
func initClient() *xxdk.E2e {
createClient()
pass := parsePassword(viper.GetString("password"))
......@@ -631,7 +630,7 @@ func initClient() *e2eApi.E2e {
params := initParams()
// load the client
baseclient, err := xxdk.Login(storeDir, pass, params)
baseclient, err := xxdk.LoadCmix(storeDir, pass, params)
if err != nil {
jww.FATAL.Panicf("%+v", err)
......@@ -640,7 +639,7 @@ func initClient() *e2eApi.E2e {
authCbs = makeAuthCallbacks(nil,
viper.GetBool("unsafe-channel-creation"))
client, err := e2eApi.LoginLegacy(baseclient, authCbs)
client, err := xxdk.LoginLegacy(baseclient, authCbs)
if err != nil {
jww.FATAL.Panicf("%+v", err)
}
......@@ -707,7 +706,7 @@ func initClient() *e2eApi.E2e {
return client
}
func acceptChannel(client *e2eApi.E2e, recipientID *id.ID) {
func acceptChannel(client *xxdk.E2e, recipientID *id.ID) {
recipientContact, err := client.GetAuth().GetReceivedRequest(
recipientID)
if err != nil {
......@@ -720,14 +719,14 @@ func acceptChannel(client *e2eApi.E2e, recipientID *id.ID) {
}
}
func deleteChannel(client *e2eApi.E2e, partnerId *id.ID) {
func deleteChannel(client *xxdk.E2e, partnerId *id.ID) {
err := client.DeleteContact(partnerId)
if err != nil {
jww.FATAL.Panicf("%+v", err)
}
}
func addAuthenticatedChannel(client *e2eApi.E2e, recipientID *id.ID,
func addAuthenticatedChannel(client *xxdk.E2e, recipientID *id.ID,
recipient contact.Contact) {
var allowed bool
if viper.GetBool("unsafe-channel-creation") {
......@@ -764,7 +763,7 @@ func addAuthenticatedChannel(client *e2eApi.E2e, recipientID *id.ID,
}
}
func resetAuthenticatedChannel(client *e2eApi.E2e, recipientID *id.ID,
func resetAuthenticatedChannel(client *xxdk.E2e, recipientID *id.ID,
recipient contact.Contact) {
var allowed bool
if viper.GetBool("unsafe-channel-creation") {
......
......@@ -120,10 +120,10 @@ func NewVanityClient(ndfJSON, storageDir string, password []byte,
return nil
}
// OpenClient session, but don't connect to the network or log in
func OpenClient(storageDir string, password []byte,
// OpenCmix session, but don't connect to the network or log in
func OpenCmix(storageDir string, password []byte,
parameters Params) (*Cmix, error) {
jww.INFO.Printf("OpenClient()")
jww.INFO.Printf("OpenCmix()")
rngStreamGen := fastRNG.NewStreamGenerator(12, 1024,
csprng.NewSystemRNG)
......@@ -210,11 +210,11 @@ func NewProtoClient_Unsafe(ndfJSON, storageDir string, password,
return nil
}
// Login initializes a client object from existing storage.
func Login(storageDir string, password []byte, parameters Params) (*Cmix, error) {
// LoadCmix initializes a Cmix object from existing storage
func LoadCmix(storageDir string, password []byte, parameters Params) (*Cmix, error) {
jww.INFO.Printf("Login()")
c, err := OpenClient(storageDir, password, parameters)
c, err := OpenCmix(storageDir, password, parameters)
if err != nil {
return nil, err
}
......@@ -277,7 +277,7 @@ func LoginWithNewBaseNDF_UNSAFE(storageDir string, password []byte,
return nil, err
}
c, err := OpenClient(storageDir, password, params)
c, err := OpenCmix(storageDir, password, params)
if err != nil {
return nil, err
}
......@@ -328,7 +328,7 @@ func LoginWithProtoClient(storageDir string, password []byte,
return nil, err
}
c, err := OpenClient(storageDir, password, params)
c, err := OpenCmix(storageDir, password, params)
if err != nil {
return nil, err
}
......
......@@ -32,21 +32,21 @@ type E2e struct {
e2eIdentity TransmissionIdentity
}
// Login creates a new e2eApi.E2e backed by the xxdk.Cmix persistent versioned.KV
// Login creates a new E2e backed by the xxdk.Cmix persistent versioned.KV
// If identity == nil, a new TransmissionIdentity will be generated automagically
func Login(client *Cmix, callbacks auth.Callbacks,
identity *TransmissionIdentity) (m *E2e, err error) {
return login(client, callbacks, identity, client.GetStorage().GetKV())
}
// LoginEphemeral creates a new e2eApi.E2e backed by a totally ephemeral versioned.KV
// LoginEphemeral creates a new E2e backed by a totally ephemeral versioned.KV
// If identity == nil, a new TransmissionIdentity will be generated automagically
func LoginEphemeral(client *Cmix, callbacks auth.Callbacks,
identity *TransmissionIdentity) (m *E2e, err error) {
return login(client, callbacks, identity, versioned.NewKV(ekv.MakeMemstore()))
}
// LoginLegacy creates a new e2eApi.E2e backed by the xxdk.Cmix persistent versioned.KV
// LoginLegacy creates a new E2e backed by the xxdk.Cmix persistent versioned.KV
// Uses the pre-generated transmission ID used by xxdk.Cmix
// This function is designed to maintain backwards compatibility with previous xx messenger designs
// and should not be used for other purposes
......
......@@ -45,7 +45,7 @@ func newTestingClient(face interface{}) (*Cmix, error) {
"Could not construct a mock client: %v", err)
}
c, err := OpenClient(storageDir, password, GetDefaultParams())
c, err := OpenCmix(storageDir, password, GetDefaultParams())
if err != nil {
return nil, errors.Errorf("Could not open a mock client: %v",
err)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment