diff --git a/api/authenticatedChannel.go b/api/authenticatedChannel.go index d1b5aa3ef75e573c9e39c9aaff8001656ef5e476..8b898acaf44a3a7b5378e00c66cf33fad952a5f3 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 03f1cf27721fd0e34073201221ea293f12f03aca..4f2bcf53a8104097f209a27e4940e01edd55eac9 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)