Wire up SendMessageToGroupError #355
|
@ -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
|
// 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) {
|
func (p *Profile) AddGroupSentMessageError(groupID string, signature []byte, error string) {
|
||||||
for _, group := range p.Groups {
|
p.lock.Lock()
|
||||||
if group.GroupServer == groupServer {
|
defer p.lock.Unlock()
|
||||||
if group.ErrorSentMessage([]byte(signature), error) {
|
group, exists := p.Groups[groupID]
|
||||||
break
|
if exists {
|
||||||
}
|
group.ErrorSentMessage(signature, error)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -482,10 +482,10 @@ func (cp *cwtchPeer) SendMessageToGroupTracked(groupid string, message string) (
|
||||||
ct, sig, err := cp.Profile.EncryptMessageToGroup(message, groupid)
|
ct, sig, err := cp.Profile.EncryptMessageToGroup(message, groupid)
|
||||||
|
|
||||||
if err == nil {
|
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 {
|
func (cp *cwtchPeer) SendMessageToPeer(onion string, message string) string {
|
||||||
|
@ -702,7 +702,8 @@ func (cp *cwtchPeer) eventHandler() {
|
||||||
|
|
||||||
case event.SendMessageToGroupError:
|
case event.SendMessageToGroupError:
|
||||||
cp.mutex.Lock()
|
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()
|
cp.mutex.Unlock()
|
||||||
|
|
||||||
case event.SendMessageToPeerError:
|
case event.SendMessageToPeerError:
|
||||||
|
|
|
@ -54,6 +54,8 @@ type engine struct {
|
||||||
|
|
||||||
// Engine (ProtocolEngine) encapsulates the logic necessary to make and receive Cwtch connections.
|
// 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
|
// 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 {
|
type Engine interface {
|
||||||
ACN() connectivity.ACN
|
ACN() connectivity.ACN
|
||||||
EventManager() event.Manager
|
EventManager() event.Manager
|
||||||
|
@ -153,7 +155,7 @@ func (e *engine) eventHandler() {
|
||||||
signature, _ := base64.StdEncoding.DecodeString(ev.Data[event.Signature])
|
signature, _ := base64.StdEncoding.DecodeString(ev.Data[event.Signature])
|
||||||
err := e.sendMessageToGroup(ev.Data[event.GroupServer], ciphertext, signature)
|
err := e.sendMessageToGroup(ev.Data[event.GroupServer], ciphertext, signature)
|
||||||
if err != nil {
|
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:
|
case event.SendMessageToPeer:
|
||||||
// TODO: remove this passthrough once the UI is integrated.
|
// TODO: remove this passthrough once the UI is integrated.
|
||||||
|
|
Loading…
Reference in New Issue