From 7701b13a53918e4ea0d91bda9adb1eb8f067ab55 Mon Sep 17 00:00:00 2001 From: Benjamin Wenger <ben@elixxir.ioo> Date: Fri, 23 Sep 2022 09:59:51 -0700 Subject: [PATCH] fixed eventModel.go --- channels/eventModel.go | 61 ++++++++++++++++++++++-------------------- go.mod | 2 +- go.sum | 2 ++ 3 files changed, 35 insertions(+), 30 deletions(-) diff --git a/channels/eventModel.go b/channels/eventModel.go index dbff99e5d..01501eb71 100644 --- a/channels/eventModel.go +++ b/channels/eventModel.go @@ -9,7 +9,6 @@ package channels import ( "github.com/golang/protobuf/proto" - "github.com/golang/protobuf/ptypes/timestamp" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/cmix/identity/receptionID" "gitlab.com/elixxir/primitives/states" @@ -59,7 +58,7 @@ type EventModel interface { // Nickname may be empty, in which case the UI is expected to display // the codename ReceiveMessage(channelID *id.ID, messageID cryptoChannel.MessageID, - nickname, codename, extension, color, text string, + nickname, text string, identity cryptoChannel.Identity, timestamp time.Time, lease time.Duration, round rounds.Round, status SentStatus) uint64 @@ -80,9 +79,9 @@ type EventModel interface { // Nickname may be empty, in which case the UI is expected to display // the codename ReceiveReply(channelID *id.ID, messageID cryptoChannel.MessageID, - reactionTo cryptoChannel.MessageID, nickname, codename, extension, - color, text string, timestamp time.Time, lease time.Duration, - round rounds.Round, status SentStatus) uint64 + reactionTo cryptoChannel.MessageID, nickname, text string, + identity cryptoChannel.Identity, timestamp time.Time, + lease time.Duration, round rounds.Round, status SentStatus) uint64 // ReceiveReaction is called whenever a reaction to a message is received // on a given channel. It may be called multiple times on the same reaction. @@ -103,9 +102,9 @@ type EventModel interface { // Nickname may be empty, in which case the UI is expected to display // the codename ReceiveReaction(channelID *id.ID, messageID cryptoChannel.MessageID, - reactionTo cryptoChannel.MessageID, nickname, codename, extension, - color, reaction string, timestamp time.Time, lease time.Duration, - round rounds.Round, status SentStatus) uint64 + reactionTo cryptoChannel.MessageID, nickname, reaction string, + identity cryptoChannel.Identity, timestamp time.Time, + lease time.Duration, round rounds.Round, status SentStatus) uint64 // UpdateSentStatus is called whenever the sent status of a message has // changed. @@ -127,7 +126,7 @@ type EventModel interface { // types. Default ones for Text, Reaction, and AdminText. type MessageTypeReceiveMessage func(channelID *id.ID, messageID cryptoChannel.MessageID, messageType MessageType, - nickname, codename, extension, color string, content []byte, + nickname string, content []byte, identity cryptoChannel.Identity, timestamp time.Time, lease time.Duration, round rounds.Round, status SentStatus) @@ -190,14 +189,15 @@ type triggerEventFunc func(chID *id.ID, umi *userMessageInternal, // // It will call the appropriate MessageTypeHandler assuming one exists. func (e *events) triggerEvent(chID *id.ID, umi *userMessageInternal, - Identity cryptoChannel.Identity, ts timestamp.Timestamp, - receptionID receptionID.EphemeralIdentity, + Identity cryptoChannel.Identity, ts time.Time, receptionID receptionID.EphemeralIdentity, round rounds.Round, status SentStatus) { um := umi.GetUserMessage() cm := umi.GetChannelMessage() messageType := MessageType(cm.PayloadType) + identity := cryptoChannel.ConstructIdentity(um.ECCPublicKey) + // Check if the type is already registered e.mux.RLock() listener, exists := e.registered[messageType] @@ -205,14 +205,14 @@ func (e *events) triggerEvent(chID *id.ID, umi *userMessageInternal, if !exists { jww.WARN.Printf("Received message from %s on channel %s in "+ "round %d which could not be handled due to unregistered message "+ - "type %s; Contents: %v", um.Username, chID, round.ID, messageType, + "type %s; Contents: %v", identity.Codename, chID, round.ID, messageType, cm.Payload) return } // Call the listener. This is already in an instanced event, no new thread needed. - listener(chID, umi.GetMessageID(), messageType, um.Username, - cm.Payload, ts, time.Duration(cm.Lease), round, status) + listener(chID, umi.GetMessageID(), messageType, cm.Nickname, cm.Payload, identity, + ts, time.Duration(cm.Lease), round, status) return } @@ -246,8 +246,9 @@ func (e *events) triggerAdminEvent(chID *id.ID, cm *ChannelMessage, ts := mutateTimestamp(round.Timestamps[states.QUEUED], messageID) // Call the listener. This is already in an instanced event, no new thread needed. - listener(chID, messageID, messageType, AdminUsername, - cm.Payload, ts, time.Duration(cm.Lease), round, status) + listener(chID, messageID, messageType, AdminUsername, cm.Payload, + cryptoChannel.Identity{Codename: AdminUsername}, ts, + time.Duration(cm.Lease), round, status) return } @@ -259,14 +260,15 @@ func (e *events) triggerAdminEvent(chID *id.ID, cm *ChannelMessage, // write to the log. func (e *events) receiveTextMessage(channelID *id.ID, messageID cryptoChannel.MessageID, messageType MessageType, - senderUsername string, content []byte, timestamp time.Time, - lease time.Duration, round rounds.Round, status SentStatus) { + nickname string, content []byte, identity cryptoChannel.Identity, + timestamp time.Time, lease time.Duration, round rounds.Round, + status SentStatus) { txt := &CMIXChannelText{} if err := proto.Unmarshal(content, txt); err != nil { jww.ERROR.Printf("Failed to text unmarshal message %s from %s on "+ "channel %s, type %s, ts: %s, lease: %s, round: %d: %+v", - messageID, senderUsername, channelID, messageType, timestamp, lease, + messageID, identity.Codename, channelID, messageType, timestamp, lease, round.ID, err) return } @@ -277,21 +279,21 @@ func (e *events) receiveTextMessage(channelID *id.ID, var replyTo cryptoChannel.MessageID copy(replyTo[:], txt.ReplyMessageID) e.model.ReceiveReply(channelID, messageID, replyTo, - senderUsername, txt.Text, timestamp, lease, round, status) + nickname, txt.Text, identity, timestamp, lease, round, status) return } else { jww.ERROR.Printf("Failed process reply to for message %s from %s on "+ "channel %s, type %s, ts: %s, lease: %s, round: %d, returning "+ "without reply", - messageID, senderUsername, channelID, messageType, timestamp, lease, + messageID, identity.Codename, channelID, messageType, timestamp, lease, round.ID) // Still process the message, but drop the reply because it is // malformed } } - e.model.ReceiveMessage(channelID, messageID, senderUsername, txt.Text, + e.model.ReceiveMessage(channelID, messageID, nickname, txt.Text, identity, timestamp, lease, round, status) } @@ -304,13 +306,14 @@ func (e *events) receiveTextMessage(channelID *id.ID, // reaction is dropped. func (e *events) receiveReaction(channelID *id.ID, messageID cryptoChannel.MessageID, messageType MessageType, - senderUsername string, content []byte, timestamp time.Time, - lease time.Duration, round rounds.Round, status SentStatus) { + nickname string, content []byte, identity cryptoChannel.Identity, + timestamp time.Time, lease time.Duration, round rounds.Round, + status SentStatus) { react := &CMIXChannelReaction{} if err := proto.Unmarshal(content, react); err != nil { jww.ERROR.Printf("Failed to text unmarshal message %s from %s on "+ "channel %s, type %s, ts: %s, lease: %s, round: %d: %+v", - messageID, senderUsername, channelID, messageType, timestamp, lease, + messageID, identity.Codename, channelID, messageType, timestamp, lease, round.ID, err) return } @@ -320,7 +323,7 @@ func (e *events) receiveReaction(channelID *id.ID, jww.ERROR.Printf("Failed process reaction %s from %s on channel "+ "%s, type %s, ts: %s, lease: %s, round: %d, due to malformed "+ "reaction (%s), ignoring reaction", - messageID, senderUsername, channelID, messageType, timestamp, lease, + messageID, identity.Codename, channelID, messageType, timestamp, lease, round.ID, err) return } @@ -328,13 +331,13 @@ func (e *events) receiveReaction(channelID *id.ID, if react.ReactionMessageID != nil && len(react.ReactionMessageID) == cryptoChannel.MessageIDLen { var reactTo cryptoChannel.MessageID copy(reactTo[:], react.ReactionMessageID) - e.model.ReceiveReaction(channelID, messageID, reactTo, senderUsername, - react.Reaction, timestamp, lease, round, status) + e.model.ReceiveReaction(channelID, messageID, reactTo, nickname, + react.Reaction, identity, timestamp, lease, round, status) } else { jww.ERROR.Printf("Failed process reaction %s from %s on channel "+ "%s, type %s, ts: %s, lease: %s, round: %d, reacting to "+ "invalid message, ignoring reaction", - messageID, senderUsername, channelID, messageType, timestamp, lease, + messageID, identity.Codename, channelID, messageType, timestamp, lease, round.ID) } } diff --git a/go.mod b/go.mod index b02daa4ba..08abf484e 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/stretchr/testify v1.8.0 gitlab.com/elixxir/bloomfilter v0.0.0-20211222005329-7d931ceead6f gitlab.com/elixxir/comms v0.0.4-0.20220913220502-eed192f654bd - gitlab.com/elixxir/crypto v0.0.7-0.20220923135535-fb10d313632a + gitlab.com/elixxir/crypto v0.0.7-0.20220923164228-3f5620181081 gitlab.com/elixxir/ekv v0.2.1 gitlab.com/elixxir/primitives v0.0.3-0.20220901220638-1acc75fabdc6 gitlab.com/xx_network/comms v0.0.4-0.20220913215811-c4bf83b27de3 diff --git a/go.sum b/go.sum index 662bf87b4..e092ab301 100644 --- a/go.sum +++ b/go.sum @@ -638,6 +638,8 @@ gitlab.com/elixxir/crypto v0.0.7-0.20220920002307-5541473e9aa7 h1:9IsBtL8zcUG86X gitlab.com/elixxir/crypto v0.0.7-0.20220920002307-5541473e9aa7/go.mod h1:QF8SzsrYh9Elip9EUYUDAhPjqO9DGrrrQxYHvn+VXok= gitlab.com/elixxir/crypto v0.0.7-0.20220923135535-fb10d313632a h1:n12oIGF9GzfA/0ZTggCjubTxOZPF8p9WINfkdko9e7E= gitlab.com/elixxir/crypto v0.0.7-0.20220923135535-fb10d313632a/go.mod h1:QF8SzsrYh9Elip9EUYUDAhPjqO9DGrrrQxYHvn+VXok= +gitlab.com/elixxir/crypto v0.0.7-0.20220923164228-3f5620181081 h1:xrTNr42Id8rvq6zH+pkoxxCrLhFMpkMC3f34y5mUfQE= +gitlab.com/elixxir/crypto v0.0.7-0.20220923164228-3f5620181081/go.mod h1:QF8SzsrYh9Elip9EUYUDAhPjqO9DGrrrQxYHvn+VXok= gitlab.com/elixxir/ekv v0.2.1 h1:dtwbt6KmAXG2Tik5d60iDz2fLhoFBgWwST03p7T+9Is= gitlab.com/elixxir/ekv v0.2.1/go.mod h1:USLD7xeDnuZEavygdrgzNEwZXeLQJK/w1a+htpN+JEU= gitlab.com/elixxir/primitives v0.0.0-20200731184040-494269b53b4d/go.mod h1:OQgUZq7SjnE0b+8+iIAT2eqQF+2IFHn73tOo+aV11mg= -- GitLab