diff --git a/bindings/authenticatedConnection.go b/bindings/authenticatedConnection.go index 9f3ceb9fcba7a87c9624c91f4f1fe5d94d8e3d7e..abbc556b79e88c4c12fb3ef679b5fc421f9fbb02 100644 --- a/bindings/authenticatedConnection.go +++ b/bindings/authenticatedConnection.go @@ -33,7 +33,7 @@ func (_ *AuthenticatedConnection) IsAuthenticated() bool { // ConnectWithAuthentication is called by the client (i.e., the one establishing // connection with the server). Once a connect.Connection has been established -// with the server and then authenticate their identity to the server. +// with the server, it then authenticates their identity to the server. // accepts a marshalled ReceptionIdentity and contact.Contact object func (c *Cmix) ConnectWithAuthentication(e2eId int, recipientContact, e2eParamsJSON []byte) (*AuthenticatedConnection, error) { @@ -47,7 +47,7 @@ func (c *Cmix) ConnectWithAuthentication(e2eId int, recipientContact, return nil, err } - e2eClient, err := e2eTrackerSingleton.get(e2eId) + messenger, err := e2eTrackerSingleton.get(e2eId) if err != nil { return nil, err } @@ -58,19 +58,19 @@ func (c *Cmix) ConnectWithAuthentication(e2eId int, recipientContact, } connection, err := connect.ConnectWithAuthentication(cont, - e2eClient.api, params) + messenger.api, params) return authenticatedConnectionTrackerSingleton.make(connection), err } // authenticatedConnectionTracker is a singleton used to keep track of extant -// clients, allowing for race condition-free passing over the bindings. +// AuthenticatedConnection, allowing for race condition-free passing over the bindings. type authenticatedConnectionTracker struct { connections map[int]*AuthenticatedConnection count int mux sync.RWMutex } -// make makes a client from an API client, assigning it a unique ID +// make makes a AuthenticatedConnection, assigning it a unique ID func (act *authenticatedConnectionTracker) make( c connect.AuthenticatedConnection) *AuthenticatedConnection { act.mux.Lock() @@ -89,7 +89,7 @@ func (act *authenticatedConnectionTracker) make( return act.connections[id] } -// get returns a client given its ID. +// get returns an AuthenticatedConnection given its ID. func (act *authenticatedConnectionTracker) get(id int) ( *AuthenticatedConnection, error) { act.mux.RLock() @@ -97,14 +97,14 @@ func (act *authenticatedConnectionTracker) get(id int) ( c, exist := act.connections[id] if !exist { - return nil, errors.Errorf("Cannot get client for ID %d, client "+ + return nil, errors.Errorf("Cannot get AuthenticatedConnection for ID %d, "+ "does not exist", id) } return c, nil } -// delete deletes a client, if it exists. +// delete deletes an AuthenticatedConnection, if it exists. func (act *authenticatedConnectionTracker) delete(id int) { act.mux.Lock() defer act.mux.Unlock() diff --git a/bindings/cmix.go b/bindings/cmix.go index fc74005a9562041efedd8e227c2c59a1789846c1..d925b4bb75bdacc0c3ddd985bfd924993ff78606 100644 --- a/bindings/cmix.go +++ b/bindings/cmix.go @@ -24,7 +24,7 @@ func init() { // 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), + tracked: make(map[int]*Cmix), count: 0, } @@ -44,7 +44,7 @@ type Cmix struct { func NewCmix(ndfJSON, storageDir string, password []byte, registrationCode string) error { err := xxdk.NewCmix(ndfJSON, storageDir, password, registrationCode) if err != nil { - return errors.Errorf("Failed to create new client: %+v", err) + return errors.Errorf("Failed to create new cmix: %+v", err) } return nil } @@ -69,12 +69,12 @@ func LoadCmix(storageDir string, password []byte, cmixParamsJSON []byte) (*Cmix, return nil, err } - client, err := xxdk.LoadCmix(storageDir, password, params) + net, err := xxdk.LoadCmix(storageDir, password, params) if err != nil { return nil, errors.Errorf("LoadCmix failed: %+v", err) } - return cmixTrackerSingleton.make(client), nil + return cmixTrackerSingleton.make(net), nil } // GetID returns the ID for this Cmix in the cmixTracker. @@ -85,7 +85,7 @@ func (c *Cmix) GetID() int { // 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 + tracked map[int]*Cmix count int mux sync.RWMutex } @@ -99,12 +99,12 @@ func (ct *cmixTracker) make(c *xxdk.Cmix) *Cmix { id := ct.count ct.count++ - ct.clients[id] = &Cmix{ + ct.tracked[id] = &Cmix{ api: c, id: id, } - return ct.clients[id] + return ct.tracked[id] } // get returns a Cmix from the cmixTracker given its ID. @@ -112,10 +112,10 @@ func (ct *cmixTracker) get(id int) (*Cmix, error) { ct.mux.RLock() defer ct.mux.RUnlock() - c, exist := ct.clients[id] + c, exist := ct.tracked[id] if !exist { return nil, errors.Errorf( - "Cannot get client for ID %d, client does not exist", id) + "Cannot get Cmix for ID %d, does not exist", id) } return c, nil @@ -126,5 +126,5 @@ func (ct *cmixTracker) delete(id int) { ct.mux.Lock() defer ct.mux.Unlock() - delete(ct.clients, id) + delete(ct.tracked, id) } diff --git a/bindings/connect.go b/bindings/connect.go index bccc8d267f64ac53e5d7e1522f89dffb17b5e682..1f02e5f6ae99b142218285e72c41347e0be0d6bd 100644 --- a/bindings/connect.go +++ b/bindings/connect.go @@ -60,7 +60,7 @@ func (c *Cmix) Connect(e2eId int, recipientContact, e2eParamsJSON []byte) ( return nil, err } - e2eClient, err := e2eTrackerSingleton.get(e2eId) + messenger, err := e2eTrackerSingleton.get(e2eId) if err != nil { return nil, err } @@ -70,7 +70,7 @@ func (c *Cmix) Connect(e2eId int, recipientContact, e2eParamsJSON []byte) ( return nil, err } - connection, err := connect.Connect(cont, e2eClient.api, p) + connection, err := connect.Connect(cont, messenger.api, p) if err != nil { return nil, err } @@ -149,7 +149,7 @@ func (ct *connectionTracker) get(id int) (*Connection, error) { c, exist := ct.connections[id] if !exist { - return nil, errors.Errorf("Cannot get client for ID %d, client "+ + return nil, errors.Errorf("Cannot get Connection for ID %d, "+ "does not exist", id) } diff --git a/bindings/e2e.go b/bindings/e2e.go index eab868feda8ff288a82ec6653756b8b99e1f3563..beef52f655626f9fead21961f60a5aedc78df966 100644 --- a/bindings/e2e.go +++ b/bindings/e2e.go @@ -21,11 +21,11 @@ import ( // 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), + tracked: make(map[int]*E2e), count: 0, } -// E2e BindingsClient wraps the xxdk.E2e, implementing additional functions +// E2e wraps the xxdk.E2e, implementing additional functions // to support the bindings E2e interface. type E2e struct { api *xxdk.E2e @@ -172,7 +172,7 @@ func (a *authCallback) Reset(partner contact.Contact, // preventing race conditions created by passing it over the bindings. type e2eTracker struct { // TODO: Key on Identity.ID to prevent duplication - clients map[int]*E2e + tracked map[int]*E2e count int mux sync.RWMutex } @@ -186,12 +186,12 @@ func (ct *e2eTracker) make(c *xxdk.E2e) *E2e { id := ct.count ct.count++ - ct.clients[id] = &E2e{ + ct.tracked[id] = &E2e{ api: c, id: id, } - return ct.clients[id] + return ct.tracked[id] } // get an E2e from the e2eTracker given its ID. @@ -199,9 +199,9 @@ func (ct *e2eTracker) get(id int) (*E2e, error) { ct.mux.RLock() defer ct.mux.RUnlock() - c, exist := ct.clients[id] + c, exist := ct.tracked[id] if !exist { - return nil, errors.Errorf("Cannot get client for ID %d, client "+ + return nil, errors.Errorf("Cannot get E2e for ID %d, "+ "does not exist", id) } @@ -213,5 +213,5 @@ func (ct *e2eTracker) delete(id int) { ct.mux.Lock() defer ct.mux.Unlock() - delete(ct.clients, id) + delete(ct.tracked, id) } diff --git a/bindings/e2eAuth.go b/bindings/e2eAuth.go index 77df3f8b10aeb6add590cf9886f5dcc557e60558..073dfd8ab6c1ea38838ac412f5c0548fe8953a2e 100644 --- a/bindings/e2eAuth.go +++ b/bindings/e2eAuth.go @@ -159,17 +159,17 @@ func (e *E2e) DeleteRequest(partnerID []byte) error { return e.api.GetAuth().DeleteRequest(partner) } -// DeleteAllRequests clears all requests from client's auth storage. +// DeleteAllRequests clears all requests from auth storage. func (e *E2e) DeleteAllRequests() error { return e.api.GetAuth().DeleteAllRequests() } -// DeleteSentRequests clears all sent requests from client's auth storage. +// DeleteSentRequests clears all sent requests from auth storage. func (e *E2e) DeleteSentRequests() error { return e.api.GetAuth().DeleteSentRequests() } -// DeleteReceiveRequests clears all received requests from client's auth +// DeleteReceiveRequests clears all received requests from auth // storage. func (e *E2e) DeleteReceiveRequests() error { return e.api.GetAuth().DeleteReceiveRequests() @@ -214,13 +214,13 @@ func (e *E2e) VerifyOwnership( return false, err } - e2eClient, err := e2eTrackerSingleton.get(e2eId) + messenger, err := e2eTrackerSingleton.get(e2eId) if err != nil { return false, err } return e.api.GetAuth().VerifyOwnership( - received, verified, e2eClient.api.GetE2E()), nil + received, verified, messenger.api.GetE2E()), nil } // AddPartnerCallback adds a new callback that overrides the generic auth diff --git a/bindings/fileTransfer.go b/bindings/fileTransfer.go index 7be3a93b91ebd935baadeacd0bc19d0af030d712..4dfd1d47c1407f20e756c5462ec5cd9d95d51d7a 100644 --- a/bindings/fileTransfer.go +++ b/bindings/fileTransfer.go @@ -125,19 +125,19 @@ type FileTransferReceiveProgressCallback interface { // InitFileTransfer creates a bindings-level file transfer manager. // // Parameters: -// - e2eID - e2e client ID +// - e2eID - e2e object ID in the tracker // - paramsJSON - JSON marshalled fileTransfer.Params func InitFileTransfer(e2eID int, paramsJSON []byte) (*FileTransfer, error) { - // Get bindings client from singleton - e2eCl, err := e2eTrackerSingleton.get(e2eID) + // Get messenger from singleton + messenger, err := e2eTrackerSingleton.get(e2eID) if err != nil { return nil, err } // Client info - myID := e2eCl.api.GetReceptionIdentity().ID - rng := e2eCl.api.GetRng() + myID := messenger.api.GetReceptionIdentity().ID + rng := messenger.api.GetRng() params, err := parseFileTransferParams(paramsJSON) if err != nil { @@ -146,16 +146,16 @@ func InitFileTransfer(e2eID int, paramsJSON []byte) (*FileTransfer, error) { // Create file transfer manager m, err := fileTransfer.NewManager(params, myID, - e2eCl.api.GetCmix(), e2eCl.api.GetStorage(), rng) + messenger.api.GetCmix(), messenger.api.GetStorage(), rng) // Add file transfer processes to client services tracking - err = e2eCl.api.AddService(m.StartProcesses) + err = messenger.api.AddService(m.StartProcesses) if err != nil { return nil, err } // Return wrapped manager - return &FileTransfer{ft: m, e2eCl: e2eCl}, nil + return &FileTransfer{ft: m, e2eCl: messenger}, nil } // Send is the bindings-level function for sending a file. diff --git a/bindings/restlike.go b/bindings/restlike.go index 4c6653af495b0b019a5ef02160f80c1eb07ce286..e3c87e1d8279f60833ae91a8e49f32597fcf8352 100644 --- a/bindings/restlike.go +++ b/bindings/restlike.go @@ -38,7 +38,7 @@ type RestlikeMessage struct { // RestlikeRequest performs a normal restlike request. // // Parameters: -// - clientID - ID of the cMix client in the tracker +// - cmixId - ID of the cMix object in the tracker // - connectionID - ID of the connection in the tracker // - request - JSON marshalled RestlikeMessage // - e2eParamsJSON - JSON marshalled xxdk.E2EParams @@ -46,13 +46,13 @@ type RestlikeMessage struct { // Returns: // - []byte - JSON marshalled RestlikeMessage func RestlikeRequest( - clientID, connectionID int, request, e2eParamsJSON []byte) ([]byte, error) { + cmixId, 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) + cl, err := cmixTrackerSingleton.get(cmixId) if err != nil { return nil, err } @@ -100,14 +100,14 @@ func RestlikeRequest( // RestlikeRequestAuth performs an authenticated restlike request. // // Parameters: -// - clientID - ID of the cMix client in the tracker +// - cmixId - ID of the cMix object in the tracker // - authConnectionID - ID of the authenticated connection in the tracker // - request - JSON marshalled RestlikeMessage // - e2eParamsJSON - JSON marshalled xxdk.E2EParams // // Returns: // - []byte - JSON marshalled RestlikeMessage -func RestlikeRequestAuth(clientID int, authConnectionID int, request, +func RestlikeRequestAuth(cmixId int, authConnectionID int, request, e2eParamsJSON []byte) ([]byte, error) { if len(e2eParamsJSON) == 0 { jww.WARN.Printf("restlike params unspecified, using defaults") @@ -118,7 +118,7 @@ func RestlikeRequestAuth(clientID int, authConnectionID int, request, return nil, err } - cl, err := cmixTrackerSingleton.get(clientID) + cl, err := cmixTrackerSingleton.get(cmixId) if err != nil { return nil, err } diff --git a/bindings/restlikeSingle.go b/bindings/restlikeSingle.go index 85db774067cee1f2f9d76446df9c2157ed9f6fc8..76431501a3f9393b8e954ca81ac0d9f004653ba9 100644 --- a/bindings/restlikeSingle.go +++ b/bindings/restlikeSingle.go @@ -28,7 +28,7 @@ type RestlikeCallback interface { // RequestRestLike sends a restlike request to a given contact. // // Parameters: -// - e2eID - ID of the e2e client in the tracker +// - e2eID - ID of the e2e object in the tracker // - recipient - marshalled contact.Contact object // - request - JSON marshalled RestlikeMessage // - paramsJSON - JSON marshalled single.RequestParams @@ -74,7 +74,7 @@ func RequestRestLike(e2eID int, recipient, request, paramsJSON []byte) ([]byte, // contact. // // Parameters: -// - e2eID - ID of the e2e client in the tracker +// - e2eID - ID of the e2e object in the tracker // - recipient - marshalled contact.Contact object // - request - JSON marshalled RestlikeMessage // - paramsJSON - JSON marshalled single.RequestParams diff --git a/bindings/single.go b/bindings/single.go index ddc2c559f4865d6cac05554824cd2dc376de1b56..e7949fd5f52059b0399db3dffba5f058a2eae16c 100644 --- a/bindings/single.go +++ b/bindings/single.go @@ -24,7 +24,7 @@ import ( // TransmitSingleUse transmits payload to recipient via single-use. // // Parameters: -// - e2eID - ID of the e2e client in the tracker +// - e2eID - ID of the e2e object in the tracker // - recipient - marshalled contact.Contact object // - tag - identifies the single-use message // - payload - message contents @@ -67,11 +67,11 @@ func TransmitSingleUse(e2eID int, recipient []byte, tag string, payload, return json.Marshal(sr) } -// Listen starts a single-use listener on a given tag using the passed in client +// Listen starts a single-use listener on a given tag using the passed in e2e object // and SingleUseCallback func. // // Parameters: -// - e2eID - ID of the e2e client in the tracker +// - e2eID - ID of the e2e object in the tracker // - tag - identifies the single-use message // - cb - the callback that will be called when a response is received // diff --git a/connect/authCallbacks.go b/connect/authCallbacks.go index 01eb5e90ff994f83d79e68a11a0285104307a6f4..5415267ca987a275644ddf09b113441109da074d 100644 --- a/connect/authCallbacks.go +++ b/connect/authCallbacks.go @@ -148,6 +148,7 @@ func (a serverAuthCallback) Request(requestor contact.Contact, } // Reset will be called when an auth Reset operation occurs. -func (a serverAuthCallback) Reset(contact.Contact, - receptionID.EphemeralIdentity, rounds.Round, *xxdk.E2e) { +func (a serverAuthCallback) Reset(requestor contact.Contact, + receptionId receptionID.EphemeralIdentity, round rounds.Round, messenger *xxdk.E2e) { + a.Request(requestor, receptionId, round, messenger) } diff --git a/connect/connect.go b/connect/connect.go index f6aace42dcd2d3f5170fd4cc4ef7fd8c105ca1c0..526d0780cda2eb6ae723d87157291c3875f61c20 100644 --- a/connect/connect.go +++ b/connect/connect.go @@ -93,7 +93,7 @@ func Connect(recipient contact.Contact, messenger *xxdk.E2e, messenger.GetAuth().AddPartnerCallback(recipient.ID, callback) // Perform the auth request - _, err := messenger.GetAuth().Request(recipient, nil) + _, err := messenger.GetAuth().Reset(recipient) if err != nil { return nil, err }