Skip to content
Snippets Groups Projects
Commit 288b0232 authored by Jake Taylor's avatar Jake Taylor :lips:
Browse files

Merge branch 'jonah/consistentNaming' into 'release'

Make naming more consistent

See merge request !279
parents f974b6f3 e4356e8f
No related branches found
No related tags found
2 merge requests!510Release,!279Make naming more consistent
......@@ -29,36 +29,35 @@ var cmixTrackerSingleton = &cmixTracker{
count: 0,
}
// Cmix BindingsClient wraps the xxdk.Cmix, implementing additional functions
// Cmix wraps the xxdk.Cmix struct, implementing additional functions
// to support the gomobile Cmix interface
type Cmix struct {
api *xxdk.Cmix
id int
}
// NewKeystore creates client storage, generates keys, connects, and registers
// NewCmix creates client storage, generates keys, connects, and registers
// with the network. Note that this does not register a username/identity, but
// merely creates a new cryptographic identity for adding such information
// at a later date.
//
// Users of this function should delete the storage directory on error.
func NewKeystore(network, storageDir string, password []byte, regCode string) error {
if err := xxdk.NewCmix(network, storageDir, password, regCode); err != nil {
func NewCmix(ndfJSON, storageDir string, password []byte, registrationCode string) error {
if err := xxdk.NewCmix(ndfJSON, storageDir, password, registrationCode); err != nil {
return errors.New(fmt.Sprintf("Failed to create new client: %+v",
err))
}
return nil
}
// Login will load an existing client from the storageDir
// LoadCmix will load an existing client from the storageDir
// using the password. This will fail if the client doesn't exist or
// the password is incorrect.
// The password is passed as a byte array so that it can be cleared from
// memory and stored as securely as possible using the memguard library.
// Login does not block on network connection, and instead loads and
// LoadCmix 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, cmixParamsJSON []byte) (*Cmix,
func LoadCmix(storageDir string, password []byte, cmixParamsJSON []byte) (*Cmix,
error) {
if len(cmixParamsJSON) == 0 {
jww.WARN.Printf("cmix params not specified, using defaults...")
......@@ -72,7 +71,7 @@ func Login(storageDir string, password []byte, cmixParamsJSON []byte) (*Cmix,
client, err := xxdk.LoadCmix(storageDir, password, params)
if err != nil {
return nil, errors.New(fmt.Sprintf("Failed to login: %+v", err))
return nil, errors.New(fmt.Sprintf("LoadCmix failed: %+v", err))
}
return cmixTrackerSingleton.make(client), nil
......
......@@ -37,10 +37,10 @@ func (e *E2e) GetID() int {
return e.id
}
// LoginE2e creates and returns a new E2e object and adds it to the e2eTrackerSingleton
// identity should be created via MakeIdentity() and passed in here
// Login creates and returns a new E2e object and adds it to the e2eTrackerSingleton
// identity should be created via MakeReceptionIdentity() and passed in here
// If callbacks is left nil, a default auth.Callbacks will be used
func LoginE2e(cmixId int, callbacks AuthCallbacks, identity,
func Login(cmixId int, callbacks AuthCallbacks, identity,
e2eParamsJSON []byte) (*E2e, error) {
if len(e2eParamsJSON) == 0 {
jww.WARN.Printf("e2e params not specified, using defaults...")
......@@ -77,10 +77,10 @@ func LoginE2e(cmixId int, callbacks AuthCallbacks, identity,
return e2eTrackerSingleton.make(newE2e), nil
}
// 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
// LoginEphemeral creates and returns a new ephemeral E2e object and adds it to the e2eTrackerSingleton
// identity should be created via MakeReceptionIdentity() or MakeLegacyReceptionIdentity() and passed in here
// If callbacks is left nil, a default auth.Callbacks will be used
func LoginE2eEphemeral(cmixId int, callbacks AuthCallbacks, identity,
func LoginEphemeral(cmixId int, callbacks AuthCallbacks, identity,
e2eParamsJSON []byte) (*E2e, error) {
if len(e2eParamsJSON) == 0 {
jww.WARN.Printf("e2e params not specified, using defaults...")
......
......@@ -94,9 +94,9 @@ func (c *Cmix) HasRunningProcessies() bool {
return c.api.HasRunningProcessies()
}
// IsNetworkHealthy returns true if the network is read to be in a healthy state where
// IsHealthy returns true if the network is read to be in a healthy state where
// messages can be sent
func (c *Cmix) IsNetworkHealthy() bool {
func (c *Cmix) IsHealthy() bool {
return c.api.GetCmix().IsHealthy()
}
......@@ -106,14 +106,14 @@ type NetworkHealthCallback interface {
Callback(bool)
}
// RegisterNetworkHealthCB registers the network health callback to be called
// AddHealthCallback 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 *Cmix) RegisterNetworkHealthCB(nhc NetworkHealthCallback) int64 {
func (c *Cmix) AddHealthCallback(nhc NetworkHealthCallback) int64 {
return int64(c.api.GetCmix().AddHealthCallback(nhc.Callback))
}
func (c *Cmix) UnregisterNetworkHealthCB(funcID int64) {
func (c *Cmix) RemoveHealthCallback(funcID int64) {
c.api.GetCmix().RemoveHealthCallback(uint64(funcID))
}
......
......@@ -32,8 +32,8 @@ type ReceptionIdentity struct {
DHKeyPrivate []byte
}
// MakeIdentity generates a new cryptographic identity for receiving messages
func (c *Cmix) MakeIdentity() ([]byte, error) {
// MakeReceptionIdentity generates a new cryptographic identity for receiving messages
func (c *Cmix) MakeReceptionIdentity() ([]byte, error) {
ident, err := xxdk.MakeReceptionIdentity(c.api)
if err != nil {
return nil, err
......@@ -42,8 +42,8 @@ func (c *Cmix) MakeIdentity() ([]byte, error) {
return ident.Marshal()
}
// MakeLegacyIdentity generates the legacy identity for receiving messages
func (c *Cmix) MakeLegacyIdentity() ([]byte, error) {
// MakeLegacyReceptionIdentity generates the legacy identity for receiving messages
func (c *Cmix) MakeLegacyReceptionIdentity() ([]byte, error) {
ident, err := xxdk.MakeLegacyReceptionIdentity(c.api)
if err != nil {
return nil, err
......
......@@ -127,8 +127,8 @@ func Connect(recipient contact.Contact, messenger *xxdk.E2e,
// no requests are missed.
// This call does an xxDK.ephemeralLogin under the hood and the connection
// server must be the only listener on auth.
func StartServer(identity xxdk.ReceptionIdentity, cb Callback, net *xxdk.Cmix,
p xxdk.E2EParams, clParams ConnectionListParams) (*ConnectionServer, error) {
func StartServer(identity xxdk.ReceptionIdentity, connectionCallback Callback,
net *xxdk.Cmix, params xxdk.E2EParams, clParams ConnectionListParams) (*ConnectionServer, error) {
// Create connection list and start cleanup thread
cl := NewConnectionList(clParams)
......@@ -138,9 +138,9 @@ func StartServer(identity xxdk.ReceptionIdentity, cb Callback, net *xxdk.Cmix,
}
// Build callback for E2E negotiation
callback := getServerAuthCallback(nil, cb, cl, p)
callback := getServerAuthCallback(nil, connectionCallback, cl, params)
e2eClient, err := xxdk.LoginEphemeral(net, callback, identity, p)
e2eClient, err := xxdk.LoginEphemeral(net, callback, identity, params)
if err != nil {
return nil, err
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment