diff --git a/auth/confirm.go b/auth/confirm.go index a23cf845d3efed5b52058b05672ced050be4d584..df3e8d367cc6ba572ab26ab29f8a303f7bdae9ba 100644 --- a/auth/confirm.go +++ b/auth/confirm.go @@ -171,7 +171,7 @@ func sendAuthConfirm(net cmixClient, partner *id.ID, } em := fmt.Sprintf("Confirm Request with %s (msgDigest: %s) sent on round %d", - partner, format.DigestContents(payload), sentRound) + partner, format.DigestContents(payload), sentRound.ID) jww.INFO.Print(em) event.Report(1, "Auth", "SendConfirm", em) return sentRound.ID, nil diff --git a/auth/request.go b/auth/request.go index 988d19480302ebbb362f99e4ee477bf7bcd9589b..17db1b2f64572d73a7601e606d72fa1d2fb5c2b1 100644 --- a/auth/request.go +++ b/auth/request.go @@ -164,7 +164,7 @@ func (s *state) request(partner contact.Contact, myfacts fact.FactList, } em := fmt.Sprintf("Auth Request with %s (msgDigest: %s) sent"+ - " on round %d", partner.ID, format.DigestContents(contents), round) + " on round %d", partner.ID, format.DigestContents(contents), round.ID) jww.INFO.Print(em) s.event.Report(1, "Auth", "RequestSent", em) return round.ID, nil diff --git a/bindings/group.go b/bindings/group.go index 8e0ddad214aadf94ff1bc907b952ff2e1cf00931..6b2041bdb548f3d3f9ccb5b6758e1be45c28faca 100644 --- a/bindings/group.go +++ b/bindings/group.go @@ -269,7 +269,7 @@ func (g *GroupChat) Send(groupId, message []byte, tag string) ([]byte, error) { // Construct send report sendReport := &GroupSendReport{ - RoundsList: makeRoundsList(round), + RoundsList: makeRoundsList(round.ID), Timestamp: timestamp.UnixNano(), MessageID: msgID.Bytes(), } diff --git a/broadcast/processor.go b/broadcast/processor.go index a0e768c2a850325d6bd63370edac0c572e68ab2f..04b00ba35b2ba84a4a691f77970f74cacb07e50e 100644 --- a/broadcast/processor.go +++ b/broadcast/processor.go @@ -53,7 +53,7 @@ func (p *processor) Process(msg format.Message, return } default: - jww.ERROR.Printf("Unrecognized broadcast method %d", p.method) + jww.FATAL.Panicf("Unrecognized broadcast method %d", p.method) } p.cb(payload, receptionID, round) diff --git a/broadcast/processor_test.go b/broadcast/processor_test.go index 6e0aa8edec9d054dc8c3283fc2689fd7eae71593..ae0df4b4e4cdcec92a9fea7d2bf607c5616ef038 100644 --- a/broadcast/processor_test.go +++ b/broadcast/processor_test.go @@ -37,7 +37,7 @@ func Test_processor_Process(t *testing.T) { RsaPubKey: rsaPrivKey.GetPublic(), } - cbChan := make(chan []byte) + cbChan := make(chan []byte, 1) cb := func(payload []byte, _ receptionID.EphemeralIdentity, _ rounds.Round) { cbChan <- payload } diff --git a/broadcast/utils_test.go b/broadcast/utils_test.go index abe2616156afdc065b3bd848993a9fe345bb7860..967cdb86947b4d9c87c8b0cca275a63d94ee5a7f 100644 --- a/broadcast/utils_test.go +++ b/broadcast/utils_test.go @@ -69,7 +69,7 @@ func (m *mockCmix) GetMaxMessageLength() int { } func (m *mockCmix) SendWithAssembler(recipient *id.ID, assembler cmix.MessageAssembler, - cmixParams cmix.CMIXParams) (id.Round, ephemeral.Id, error) { + cmixParams cmix.CMIXParams) (rounds.Round, ephemeral.Id, error) { fingerprint, service, payload, mac, err := assembler(42) if err != nil { @@ -88,7 +88,7 @@ func (m *mockCmix) SendWithAssembler(recipient *id.ID, assembler cmix.MessageAss p.Process(msg, receptionID.EphemeralIdentity{}, rounds.Round{}) } - return 0, ephemeral.Id{}, nil + return rounds.Round{}, ephemeral.Id{}, nil } func (m *mockCmix) Send(recipient *id.ID, fingerprint format.Fingerprint, diff --git a/channels/eventModel.go b/channels/eventModel.go index 403287adb7ab71fd3164d4bbbe5eb6931f357de4..1a244956b3a88237f1b11b188fc6a0ae40408232 100644 --- a/channels/eventModel.go +++ b/channels/eventModel.go @@ -8,6 +8,7 @@ package channels import ( + "fmt" "github.com/golang/protobuf/proto" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/cmix/identity/receptionID" @@ -46,8 +47,8 @@ type EventModel interface { // It may be called multiple times on the same message, it is incumbent on // the user of the API to filter such called by message ID ReceiveMessage(channelID *id.ID, messageID cryptoChannel.MessageID, - senderUsername string, text string, - timestamp time.Time, lease time.Duration, round rounds.Round) + senderUsername string, text string, timestamp time.Time, + lease time.Duration, round rounds.Round, status SentStatus) // ReceiveReply is called whenever a message is received which is a reply // on a given channel. It may be called multiple times on the same message, @@ -57,7 +58,7 @@ type EventModel interface { ReceiveReply(channelID *id.ID, messageID cryptoChannel.MessageID, reactionTo cryptoChannel.MessageID, senderUsername string, text string, timestamp time.Time, lease time.Duration, - round rounds.Round) + round rounds.Round, status SentStatus) // 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, @@ -67,26 +68,7 @@ type EventModel interface { ReceiveReaction(channelID *id.ID, messageID cryptoChannel.MessageID, reactionTo cryptoChannel.MessageID, senderUsername string, reaction string, timestamp time.Time, lease time.Duration, - round rounds.Round) - - // MessageSent is called whenever the user sends a message. It should be - //designated as "sent" and that delivery is unknown. - MessageSent(channelID *id.ID, messageID cryptoChannel.MessageID, - myUsername string, text string, timestamp time.Time, - lease time.Duration, round rounds.Round) - - // ReplySent is called whenever the user sends a reply. It should be - // designated as "sent" and that delivery is unknown. - ReplySent(channelID *id.ID, messageID cryptoChannel.MessageID, - replyTo cryptoChannel.MessageID, myUsername string, text string, - timestamp time.Time, lease time.Duration, round rounds.Round) - - // ReactionSent is called whenever the user sends a reply. It should be - // designated as "sent" and that delivery is unknown. - ReactionSent(channelID *id.ID, messageID cryptoChannel.MessageID, - reactionTo cryptoChannel.MessageID, senderUsername string, - reaction string, timestamp time.Time, lease time.Duration, - round rounds.Round) + round rounds.Round, status SentStatus) // UpdateSentStatus is called whenever the sent status of a message // has changed @@ -226,6 +208,7 @@ func (e *events) receiveTextMessage(channelID *id.ID, senderUsername string, content []byte, timestamp time.Time, lease time.Duration, round rounds.Round) { 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", @@ -235,9 +218,12 @@ func (e *events) receiveTextMessage(channelID *id.ID, } if txt.ReplyMessageID != nil { + if len(txt.ReplyMessageID) == cryptoChannel.MessageIDLen { var replyTo cryptoChannel.MessageID copy(replyTo[:], txt.ReplyMessageID) + e.model.ReceiveReply(channelID, messageID, replyTo, + senderUsername, txt.Text, timestamp, lease, round, Delivered) return } else { @@ -251,8 +237,10 @@ func (e *events) receiveTextMessage(channelID *id.ID, } } + fmt.Println(channelID) + e.model.ReceiveMessage(channelID, messageID, senderUsername, txt.Text, - timestamp, lease, round) + timestamp, lease, round, Delivered) } // receiveReaction is the internal function which handles the reception of @@ -288,7 +276,7 @@ func (e *events) receiveReaction(channelID *id.ID, var reactTo cryptoChannel.MessageID copy(reactTo[:], react.ReactionMessageID) e.model.ReceiveReaction(channelID, messageID, reactTo, senderUsername, - react.Reaction, timestamp, lease, round) + react.Reaction, timestamp, lease, round, Delivered) } else { jww.ERROR.Printf("Failed process reaction %s from %s on channel "+ "%s, type %s, ts: %s, lease: %s, round: %d, reacting to "+ diff --git a/channels/eventModel_test.go b/channels/eventModel_test.go index a144be353192276de837fac237de9a5e0ba3a5d2..5241c9fc6acb1796aa1af20a435c3d0b349aa279 100644 --- a/channels/eventModel_test.go +++ b/channels/eventModel_test.go @@ -9,6 +9,7 @@ package channels import ( "bytes" + "fmt" "github.com/golang/protobuf/proto" "gitlab.com/elixxir/client/cmix/identity/receptionID" "gitlab.com/elixxir/client/cmix/rounds" @@ -37,26 +38,6 @@ type MockEvent struct { eventReceive } -func (m *MockEvent) MessageSent(channelID *id.ID, messageID cryptoChannel.MessageID, - myUsername string, text string, timestamp time.Time, lease time.Duration, round rounds.Round) { - //TODO implement me - panic("implement me") -} - -func (m *MockEvent) ReplySent(channelID *id.ID, messageID cryptoChannel.MessageID, - replyTo cryptoChannel.MessageID, myUsername string, text string, - timestamp time.Time, lease time.Duration, round rounds.Round) { - //TODO implement me - panic("implement me") -} - -func (m *MockEvent) ReactionSent(channelID *id.ID, messageID cryptoChannel.MessageID, - reactionTo cryptoChannel.MessageID, senderUsername string, reaction string, - timestamp time.Time, lease time.Duration, round rounds.Round) { - //TODO implement me - panic("implement me") -} - func (m *MockEvent) UpdateSentStatus(messageID cryptoChannel.MessageID, status SentStatus) { //TODO implement me @@ -67,7 +48,7 @@ func (*MockEvent) JoinChannel(channel *cryptoBroadcast.Channel) {} func (*MockEvent) LeaveChannel(channelID *id.ID) {} func (m *MockEvent) ReceiveMessage(channelID *id.ID, messageID cryptoChannel.MessageID, senderUsername string, text string, - timestamp time.Time, lease time.Duration, round rounds.Round) { + timestamp time.Time, lease time.Duration, round rounds.Round, status SentStatus) { m.eventReceive = eventReceive{ channelID: channelID, messageID: messageID, @@ -82,7 +63,8 @@ func (m *MockEvent) ReceiveMessage(channelID *id.ID, messageID cryptoChannel.Mes func (m *MockEvent) ReceiveReply(channelID *id.ID, messageID cryptoChannel.MessageID, replyTo cryptoChannel.MessageID, senderUsername string, text string, timestamp time.Time, lease time.Duration, - round rounds.Round) { + round rounds.Round, status SentStatus) { + fmt.Println(replyTo) m.eventReceive = eventReceive{ channelID: channelID, messageID: messageID, @@ -97,7 +79,7 @@ func (m *MockEvent) ReceiveReply(channelID *id.ID, messageID cryptoChannel.Messa func (m *MockEvent) ReceiveReaction(channelID *id.ID, messageID cryptoChannel.MessageID, reactionTo cryptoChannel.MessageID, senderUsername string, reaction string, timestamp time.Time, lease time.Duration, - round rounds.Round) { + round rounds.Round, status SentStatus) { m.eventReceive = eventReceive{ channelID: channelID, messageID: messageID, @@ -537,7 +519,7 @@ func TestEvents_receiveTextMessage_Reply(t *testing.T) { r.Timestamps[states.QUEUED] = time.Now() //call the handler - e.receiveTextMessage(chID, msgID, 0, senderUsername, + e.receiveTextMessage(chID, msgID, Text, senderUsername, textMarshaled, ts, lease, r) //check the results on the model diff --git a/channels/joinedChannel_test.go b/channels/joinedChannel_test.go index 0ec8ee56684e2029c23e4e7213af17f6cfb51929..ba20c46dcece6249505c7d724286f5e40d0f0e1e 100644 --- a/channels/joinedChannel_test.go +++ b/channels/joinedChannel_test.go @@ -504,26 +504,6 @@ type mockEventModel struct { leftCh *id.ID } -func (m *mockEventModel) MessageSent(channelID *id.ID, messageID cryptoChannel.MessageID, - myUsername string, text string, timestamp time.Time, lease time.Duration, round rounds.Round) { - //TODO implement me - panic("implement me") -} - -func (m *mockEventModel) ReplySent(channelID *id.ID, messageID cryptoChannel.MessageID, - replyTo cryptoChannel.MessageID, myUsername string, text string, - timestamp time.Time, lease time.Duration, round rounds.Round) { - //TODO implement me - panic("implement me") -} - -func (m *mockEventModel) ReactionSent(channelID *id.ID, messageID cryptoChannel.MessageID, - reactionTo cryptoChannel.MessageID, senderUsername string, reaction string, - timestamp time.Time, lease time.Duration, round rounds.Round) { - //TODO implement me - panic("implement me") -} - func (m *mockEventModel) UpdateSentStatus(messageID cryptoChannel.MessageID, status SentStatus) { //TODO implement me @@ -537,13 +517,13 @@ func (m *mockEventModel) LeaveChannel(c *id.ID) { m.leftCh = c } func (m *mockEventModel) ReceiveMessage(*id.ID, cryptoChannel.MessageID, string, - string, time.Time, time.Duration, rounds.Round) { + string, time.Time, time.Duration, rounds.Round, SentStatus) { } func (m *mockEventModel) ReceiveReply(*id.ID, cryptoChannel.MessageID, cryptoChannel.MessageID, string, string, time.Time, time.Duration, - rounds.Round) { + rounds.Round, SentStatus) { } func (m *mockEventModel) ReceiveReaction(*id.ID, cryptoChannel.MessageID, cryptoChannel.MessageID, string, string, time.Time, time.Duration, - rounds.Round) { + rounds.Round, SentStatus) { } diff --git a/cmd/broadcast.go b/cmd/broadcast.go index 8cf3d4a5f355612a52d22fe1cfe8a89302696b36..15c01a99b3397ce4708eaba29021f7cc1f0c21e7 100644 --- a/cmd/broadcast.go +++ b/cmd/broadcast.go @@ -217,7 +217,7 @@ var broadcastCmd = &cobra.Command{ continue } fmt.Printf("Sent symmetric broadcast message: %s", symmetric) - jww.INFO.Printf("Sent symmetric broadcast message to %s over round %d", eid, rid) + jww.INFO.Printf("Sent symmetric broadcast message to %s over round %d", eid, rid.ID) } /* Send asymmetric broadcast */ @@ -237,7 +237,7 @@ var broadcastCmd = &cobra.Command{ continue } fmt.Printf("Sent asymmetric broadcast message: %s", asymmetric) - jww.INFO.Printf("Sent asymmetric broadcast message to %s over round %d", eid, rid) + jww.INFO.Printf("Sent asymmetric broadcast message to %s over round %d", eid, rid.ID) } wg.Done() diff --git a/cmd/group.go b/cmd/group.go index 8f8bb6a3932450fd9f68af0649ddb3b1ecef8f8a..0cf296b4cca2bdc8f2206eb40b4a15367df3a167 100644 --- a/cmd/group.go +++ b/cmd/group.go @@ -237,7 +237,7 @@ func sendGroup(groupIdString string, msg []byte, gm groupChat.GroupChat) { } jww.INFO.Printf("[GC] Sent to group %s on round %d at %s", - groupID, rid, timestamp) + groupID, rid.ID, timestamp) fmt.Printf("Sent message %q to group.\n", msg) } diff --git a/e2e/utils_test.go b/e2e/utils_test.go index a7ee89111403febb8f384df6fafde83284a5db5c..526ca4f7dc5fd34abd07405c4fbb185a10dd0d46 100644 --- a/e2e/utils_test.go +++ b/e2e/utils_test.go @@ -193,15 +193,15 @@ func (m *mockCmix) Send(_ *id.ID, fp format.Fingerprint, srv message.Service, if m.handler.processorMap[fp] != nil { m.handler.processorMap[fp].Process( msg, receptionID.EphemeralIdentity{}, rounds.Round{}) - return 0, ephemeral.Id{}, nil + return rounds.Round{}, ephemeral.Id{}, nil } else if m.handler.serviceMap[srv.Tag] != nil { m.handler.serviceMap[srv.Tag].Process( msg, receptionID.EphemeralIdentity{}, rounds.Round{}) - return 0, ephemeral.Id{}, nil + return rounds.Round{}, ephemeral.Id{}, nil } m.t.Errorf("No processor found for fingerprint %s", fp) - return 0, ephemeral.Id{}, + return rounds.Round{}, ephemeral.Id{}, errors.Errorf("No processor found for fingerprint %s", fp) } diff --git a/single/receivedRequest.go b/single/receivedRequest.go index f9ec7fea87d8e39f766ab2dd4adc757000749a4a..cc05610088cca70c26539b5df5a0a090616b67cc 100644 --- a/single/receivedRequest.go +++ b/single/receivedRequest.go @@ -104,7 +104,7 @@ func (r *Request) Respond(payload []byte, cMixParams cmix.CMIXParams, jww.DEBUG.Printf("[SU] Sent single-use response cMix message part "+ "%d of %d on round %d to %s (eph ID %d) (%s).", - i, len(parts), round, r.sender, ephID.Int64(), r.tag) + i, len(parts), round.ID, r.sender, ephID.Int64(), r.tag) rounds[i] = round.ID r.net.GetInstance().GetRoundEvents().AddRoundEventChan( diff --git a/single/request.go b/single/request.go index e38803915a4b561e82f89dce4db22bd833f46697..16429e835021a6eb5b570ba7d60362ae5ba0dca6 100644 --- a/single/request.go +++ b/single/request.go @@ -211,7 +211,7 @@ func TransmitRequest(recipient contact.Contact, tag string, payload []byte, jww.DEBUG.Printf("[SU] Sent single-use request cMix message part "+ "%d of %d on round %d to %s (eph ID %d) (%s).", - 0, len(parts)+1, rid, recipient.ID, ephID.Int64(), tag) + 0, len(parts)+1, rid.ID, recipient.ID, ephID.Int64(), tag) var wg sync.WaitGroup wg.Add(len(parts))