Wire up SendMessageToGroupError
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details

(Also makes this flow much more efficient by including groupId in the round trip)
This commit is contained in:
Sarah Jamie Lewis 2021-05-08 12:03:09 -07:00
parent 014252f4b5
commit 00dc2e60e5
3 changed files with 13 additions and 11 deletions

View File

@ -216,13 +216,12 @@ func (p *Profile) AckSentMessageToPeer(onion string, eventID string) int {
}
// AddGroupSentMessageError searches matching groups for the message by sig and marks it as an error
func (p *Profile) AddGroupSentMessageError(groupServer string, signature string, error string) {
for _, group := range p.Groups {
if group.GroupServer == groupServer {
if group.ErrorSentMessage([]byte(signature), error) {
break
}
}
func (p *Profile) AddGroupSentMessageError(groupID string, signature []byte, error string) {
p.lock.Lock()
defer p.lock.Unlock()
group, exists := p.Groups[groupID]
if exists {
group.ErrorSentMessage(signature, error)
}
}

View File

@ -482,10 +482,10 @@ func (cp *cwtchPeer) SendMessageToGroupTracked(groupid string, message string) (
ct, sig, err := cp.Profile.EncryptMessageToGroup(message, groupid)
if err == nil {
cp.eventBus.Publish(event.NewEvent(event.SendMessageToGroup, map[event.Field]string{event.GroupServer: group.GroupServer, event.Ciphertext: base64.StdEncoding.EncodeToString(ct), event.Signature: base64.StdEncoding.EncodeToString(sig)}))
cp.eventBus.Publish(event.NewEvent(event.SendMessageToGroup, map[event.Field]string{event.GroupID: groupid, event.GroupServer: group.GroupServer, event.Ciphertext: base64.StdEncoding.EncodeToString(ct), event.Signature: base64.StdEncoding.EncodeToString(sig)}))
}
return string(sig), err
return base64.StdEncoding.EncodeToString(sig), err
}
func (cp *cwtchPeer) SendMessageToPeer(onion string, message string) string {
@ -702,7 +702,8 @@ func (cp *cwtchPeer) eventHandler() {
case event.SendMessageToGroupError:
cp.mutex.Lock()
cp.Profile.AddGroupSentMessageError(ev.Data[event.GroupServer], ev.Data[event.Signature], ev.Data[event.Error])
signature, _ := base64.StdEncoding.DecodeString(ev.Data[event.Signature])
cp.Profile.AddGroupSentMessageError(ev.Data[event.GroupID], signature, ev.Data[event.Error])
cp.mutex.Unlock()
case event.SendMessageToPeerError:

View File

@ -54,6 +54,8 @@ type engine struct {
// Engine (ProtocolEngine) encapsulates the logic necessary to make and receive Cwtch connections.
// Note: ProtocolEngine doesn't have access to any information necessary to encrypt or decrypt GroupMessages
// Protocol Engine *can* associate Group Identifiers with Group Servers, although we don't currently make use of this fact
// other than to route errors back to the UI.
type Engine interface {
ACN() connectivity.ACN
EventManager() event.Manager
@ -153,7 +155,7 @@ func (e *engine) eventHandler() {
signature, _ := base64.StdEncoding.DecodeString(ev.Data[event.Signature])
err := e.sendMessageToGroup(ev.Data[event.GroupServer], ciphertext, signature)
if err != nil {
e.eventManager.Publish(event.NewEvent(event.SendMessageToGroupError, map[event.Field]string{event.GroupServer: ev.Data[event.GroupServer], event.EventID: ev.EventID, event.Error: err.Error()}))
e.eventManager.Publish(event.NewEvent(event.SendMessageToGroupError, map[event.Field]string{event.GroupID: ev.Data[event.GroupID], event.GroupServer: ev.Data[event.GroupServer], event.EventID: ev.EventID, event.Error: err.Error(), event.Signature: ev.Data[event.Signature]}))
}
case event.SendMessageToPeer:
// TODO: remove this passthrough once the UI is integrated.