From 93b9d13cf0f0bab6cd62d4a15d2067ce720a83a4 Mon Sep 17 00:00:00 2001 From: Benjamin Wenger <ben@elixxir.ioo> Date: Wed, 7 Oct 2020 17:12:58 -0700 Subject: [PATCH] made autnetication channel creation work --- api/authenticatedChannel.go | 16 ++++++++-------- storage/e2e/store.go | 6 +++++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/api/authenticatedChannel.go b/api/authenticatedChannel.go index d1b5aa3ef..8b898acaf 100644 --- a/api/authenticatedChannel.go +++ b/api/authenticatedChannel.go @@ -10,11 +10,11 @@ import ( // so this user can send messages to the desired recipient Contact. // To receive confirmation from the remote user, clients must // register a listener to do that. -func (c *Client) CreateAuthenticatedChannel(recipient contact.Contact, - payload []byte) error { - jww.INFO.Printf("CreateAuthenticatedChannel(%v, %v)", - recipient, payload) - return nil +func (c *Client) CreateAuthenticatedChannel(recipient contact.Contact) error { + jww.INFO.Printf("CreateAuthenticatedChannel(%v)", recipient) + sesParam := e2e.GetDefaultSessionParams() + return c.storage.E2e().AddPartner(recipient.ID, recipient.DhPubKey, + sesParam, sesParam) } // RegisterAuthConfirmationCb registers a callback for channel @@ -32,15 +32,15 @@ func (c *Client) RegisterAuthRequestCb(cb func(contact contact.Contact, } // Create an insecure e2e relationship with a precanned user -func (c *Client) MakePrecannedAuthenticatedChannel(precannedID uint) contact.Contact { +func (c *Client) MakePrecannedAuthenticatedChannel(precannedID uint) (contact.Contact, error) { precan := c.MakePrecannedContact(precannedID) //add the precanned user as a e2e contact sesParam := e2e.GetDefaultSessionParams() - c.storage.E2e().AddPartner(precan.ID, precan.DhPubKey, sesParam, sesParam) + err := c.storage.E2e().AddPartner(precan.ID, precan.DhPubKey, sesParam, sesParam) - return precan + return precan, err } // Create an insecure e2e contact object for a precanned user diff --git a/storage/e2e/store.go b/storage/e2e/store.go index 03f1cf277..4f2bcf53a 100644 --- a/storage/e2e/store.go +++ b/storage/e2e/store.go @@ -144,10 +144,14 @@ func (s *Store) save() error { } func (s *Store) AddPartner(partnerID *id.ID, partnerPubKey *cyclic.Int, - sendParams, receiveParams SessionParams) { + sendParams, receiveParams SessionParams) error { s.mux.Lock() defer s.mux.Unlock() + if _, ok := s.managers[*partnerID]; ok { + return errors.New("Cannot overwrite existing partner") + } + m := newManager(s.context, s.kv, partnerID, s.dhPrivateKey, partnerPubKey, sendParams, receiveParams) -- GitLab