From 23e22f0260503f9540ca584a661a3f99c792bd89 Mon Sep 17 00:00:00 2001 From: John Brooks Date: Fri, 11 Aug 2017 18:04:28 -0600 Subject: [PATCH] core: Minor fixes for inbound contact requests --- core/contactlist.go | 6 +++--- core/inboundcontactrequest.go | 12 ++++++++++++ core/rpcserver.go | 5 +++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/core/contactlist.go b/core/contactlist.go index ef379af..3313b14 100644 --- a/core/contactlist.go +++ b/core/contactlist.go @@ -22,8 +22,9 @@ type ContactList struct { func LoadContactList(core *Ricochet) (*ContactList, error) { list := &ContactList{ - core: core, - events: utils.CreatePublisher(), + core: core, + events: utils.CreatePublisher(), + inboundRequests: make(map[string]*InboundContactRequest), } config := core.Config.OpenRead() @@ -46,7 +47,6 @@ func LoadContactList(core *Ricochet) (*ContactList, error) { list.contacts[id] = contact } - // XXX Requests aren't implemented return list, nil } diff --git a/core/inboundcontactrequest.go b/core/inboundcontactrequest.go index 14f522f..b17c419 100644 --- a/core/inboundcontactrequest.go +++ b/core/inboundcontactrequest.go @@ -82,6 +82,18 @@ func (cr *InboundContactRequest) Update(nickname, message string) { } } +func (cr *InboundContactRequest) SetNickname(nickname string) error { + cr.mutex.Lock() + defer cr.mutex.Unlock() + + if IsNicknameAcceptable(nickname) { + cr.data.FromNickname = nickname + } else { + return errors.New("Invalid nickname") + } + return nil +} + func (cr *InboundContactRequest) Accept() (*Contact, error) { cr.mutex.Lock() defer cr.mutex.Unlock() diff --git a/core/rpcserver.go b/core/rpcserver.go index f7a8f58..41c269c 100644 --- a/core/rpcserver.go +++ b/core/rpcserver.go @@ -159,6 +159,11 @@ func (s *RpcServer) AcceptInboundRequest(ctx context.Context, req *ricochet.Cont if request == nil { return nil, errors.New("Request does not exist") } + if len(req.FromNickname) > 0 { + if err := request.SetNickname(req.FromNickname); err != nil { + return nil, err + } + } contact, err := request.Accept() if err != nil { return nil, err