Skip to content
Snippets Groups Projects
Commit 8827efe0 authored by Benjamin Wenger's avatar Benjamin Wenger
Browse files

first pass at channel send logging

parent 68c03dbe
Branches
Tags
3 merge requests!510Release,!427Modify send code to use a debug tag that includes a msgDigest. This is set by...,!340Project/channels
...@@ -9,6 +9,7 @@ package channels ...@@ -9,6 +9,7 @@ package channels
import ( import (
"crypto/ed25519" "crypto/ed25519"
"fmt"
"github.com/pkg/errors" "github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/cmix" "gitlab.com/elixxir/client/cmix"
...@@ -18,6 +19,7 @@ import ( ...@@ -18,6 +19,7 @@ import (
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral" "gitlab.com/xx_network/primitives/id/ephemeral"
"gitlab.com/xx_network/primitives/netTime" "gitlab.com/xx_network/primitives/netTime"
"golang.org/x/crypto/blake2b"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
"time" "time"
) )
...@@ -40,6 +42,11 @@ func (m *manager) SendGeneric(channelID *id.ID, messageType MessageType, ...@@ -40,6 +42,11 @@ func (m *manager) SendGeneric(channelID *id.ID, messageType MessageType,
msg []byte, validUntil time.Duration, params cmix.CMIXParams) ( msg []byte, validUntil time.Duration, params cmix.CMIXParams) (
cryptoChannel.MessageID, rounds.Round, ephemeral.Id, error) { cryptoChannel.MessageID, rounds.Round, ephemeral.Id, error) {
sendPrint := fmt.Sprintf("Sending to ch %s type %d at %s - "+
"contentsHash %d", channelID, messageType, netTime.Now(), hashMsg(msg))
defer jww.INFO.Println(sendPrint)
//find the channel //find the channel
ch, err := m.getChannel(channelID) ch, err := m.getChannel(channelID)
if err != nil { if err != nil {
...@@ -110,22 +117,36 @@ func (m *manager) SendGeneric(channelID *id.ID, messageType MessageType, ...@@ -110,22 +117,36 @@ func (m *manager) SendGeneric(channelID *id.ID, messageType MessageType,
return usrMsgSerial, nil return usrMsgSerial, nil
} }
sendPrint += fmt.Sprintf("\n\tDenoting pending send at %s", netTime.Now())
uuid, err := m.st.denotePendingSend(channelID, &userMessageInternal{ uuid, err := m.st.denotePendingSend(channelID, &userMessageInternal{
userMessage: usrMsg, userMessage: usrMsg,
channelMessage: chMsg, channelMessage: chMsg,
messageID: msgId, messageID: msgId,
}) })
if err != nil {
sendPrint += fmt.Sprintf("\n\tDenoting pending send failed: %s",
err.Error())
return cryptoChannel.MessageID{}, rounds.Round{}, ephemeral.Id{}, err
}
sendPrint += fmt.Sprintf("\n\tBroadcasting message at %s", netTime.Now())
r, ephid, err := ch.broadcast.BroadcastWithAssembler(assemble, params) r, ephid, err := ch.broadcast.BroadcastWithAssembler(assemble, params)
if err != nil { if err != nil {
sendPrint += fmt.Sprintf("\n\tBroadcasting failed at %s, denoting "+
"failure: %s", netTime.Now(), err.Error())
errDenote := m.st.failedSend(uuid) errDenote := m.st.failedSend(uuid)
if errDenote != nil { if errDenote != nil {
jww.ERROR.Printf("Failed to update for a failed send to "+ sendPrint += fmt.Sprintf("\n\tFailed to denote failure of "+
"%s: %+v", channelID, err) "broadcast: %s", err.Error())
} }
return cryptoChannel.MessageID{}, rounds.Round{}, ephemeral.Id{}, err return cryptoChannel.MessageID{}, rounds.Round{}, ephemeral.Id{}, err
} }
sendPrint += fmt.Sprintf("\n\tBroadcast succeeded at %s, denoting "+
"send success", netTime.Now())
err = m.st.send(uuid, msgId, r) err = m.st.send(uuid, msgId, r)
if err != nil {
sendPrint += fmt.Sprintf("\n\tDenotation of send success failed: "+
"%s", err.Error())
}
return msgId, r, ephid, err return msgId, r, ephid, err
} }
...@@ -288,3 +309,9 @@ func (m *manager) SendReaction(channelID *id.ID, reaction string, ...@@ -288,3 +309,9 @@ func (m *manager) SendReaction(channelID *id.ID, reaction string,
return m.SendGeneric(channelID, Reaction, reactMarshaled, ValidForever, return m.SendGeneric(channelID, Reaction, reactMarshaled, ValidForever,
params) params)
} }
func hashMsg(msg []byte) []byte {
h, _ := blake2b.New256(nil)
h.Write(msg)
return h.Sum(nil)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment