Skip to content
Snippets Groups Projects
Commit 8897b74d authored by Richard T. Carback III's avatar Richard T. Carback III
Browse files

Fix formatting and error prints inside prepareSendE2E

parent 0f0d9270
No related branches found
No related tags found
2 merge requests!510Release,!353Figure out why bindings is not passing parameters correctly
...@@ -63,22 +63,25 @@ func (m *manager) prepareSendE2E(mt catalog.MessageType, recipient *id.ID, ...@@ -63,22 +63,25 @@ func (m *manager) prepareSendE2E(mt catalog.MessageType, recipient *id.ID,
partitions, internalMsgId, err := m.partitioner.Partition(recipient, partitions, internalMsgId, err := m.partitioner.Partition(recipient,
mt, ts, payload) mt, ts, payload)
if err != nil { if err != nil {
return nil, errors.WithMessage(err, "failed to send unsafe message") return nil, errors.WithMessage(err,
"failed to send unsafe message")
} }
jww.INFO.Printf("E2E sending %d messages to %s", len(partitions), recipient) jww.INFO.Printf("E2E sending %d messages to %s",
len(partitions), recipient)
// When sending E2E messages, we first partition into cMix packets and then // When sending E2E messages, we first partition into cMix
// send each partition over cMix // packets and then send each partition over cMix
roundIds := make([]id.Round, len(partitions)) roundIds := make([]id.Round, len(partitions))
errCh := make(chan error, len(partitions)) errCh := make(chan error, len(partitions))
// The Key manager for the partner (recipient) ensures single use of each // The Key manager for the partner (recipient) ensures single
// key negotiated for the ratchet // use of each key negotiated for the ratchet
partner, err := m.Ratchet.GetPartner(recipient) partner, err := m.Ratchet.GetPartner(recipient)
if err != nil { if err != nil {
return nil, errors.WithMessagef(err, return nil, errors.WithMessagef(err,
"cannot send E2E message no relationship found with %s", recipient) "cannot send E2E message no relationship found with %s",
recipient)
} }
msgID := e2e.NewMessageID( msgID := e2e.NewMessageID(
...@@ -89,15 +92,17 @@ func (m *manager) prepareSendE2E(mt catalog.MessageType, recipient *id.ID, ...@@ -89,15 +92,17 @@ func (m *manager) prepareSendE2E(mt catalog.MessageType, recipient *id.ID,
for i, p := range partitions { for i, p := range partitions {
if mt != catalog.KeyExchangeTrigger { if mt != catalog.KeyExchangeTrigger {
// Check if any rekeys need to happen and trigger them // Check if any rekeys need to happen and trigger them
rekeySendFunc := func(mt catalog.MessageType, recipient *id.ID, rekeySendFunc := func(mt catalog.MessageType,
recipient *id.ID,
payload []byte, cmixParams cmix.CMIXParams) ( payload []byte, cmixParams cmix.CMIXParams) (
[]id.Round, e2e.MessageID, time.Time, error) { []id.Round, e2e.MessageID, time.Time, error) {
par := params par := params
par.CMIXParams = cmixParams par.CMIXParams = cmixParams
return m.SendE2E(mt, recipient, payload, par) return m.SendE2E(mt, recipient, payload, par)
} }
rekey.CheckKeyExchanges(m.net.GetInstance(), m.grp, rekeySendFunc, rekey.CheckKeyExchanges(m.net.GetInstance(), m.grp,
m.events, partner, m.rekeyParams, 1*time.Minute) rekeySendFunc, m.events, partner,
m.rekeyParams, 1*time.Minute)
} }
var keyGetter func() (session.Cypher, error) var keyGetter func() (session.Cypher, error)
...@@ -107,23 +112,25 @@ func (m *manager) prepareSendE2E(mt catalog.MessageType, recipient *id.ID, ...@@ -107,23 +112,25 @@ func (m *manager) prepareSendE2E(mt catalog.MessageType, recipient *id.ID,
keyGetter = partner.PopSendCypher keyGetter = partner.PopSendCypher
} }
// FIXME: remove this wait, it is weird. Why is it here? we cant remember. // FIXME: remove this wait, it is weird. Why is it
// here? we cant remember.
key, err := waitForKey( key, err := waitForKey(
keyGetter, params.KeyGetRetryCount, params.KeyGeRetryDelay, keyGetter, params.KeyGetRetryCount,
params.KeyGeRetryDelay,
params.Stop, recipient, format.DigestContents(p), i) params.Stop, recipient, format.DigestContents(p), i)
if err != nil { if err != nil {
return nil, errors.WithMessagef(err, return nil, errors.WithMessagef(err,
"Failed to get key for end-to-end encryption") "Failed to get key for end-to-end encryption")
} }
// This does not encrypt for cMix but instead end-to-end encrypts the // This does not encrypt for cMix but instead
// cMix message // end-to-end encrypts the cMix message
contentsEnc, mac := key.Encrypt(p) contentsEnc, mac := key.Encrypt(p)
jww.INFO.Printf( jww.INFO.Printf("E2E sending %d/%d to %s with key fp: %s, "+
"E2E sending %d/%d to %s with key fp: %s, msgID: %s (msgDigest %s)", "msgID: %s (msgDigest %s)",
i+i, len(partitions), recipient, key.Fingerprint(), msgID, i+i, len(partitions), recipient, key.Fingerprint(),
format.DigestContents(p)) msgID, format.DigestContents(p))
var s message.Service var s message.Service
if i == len(partitions)-1 { if i == len(partitions)-1 {
...@@ -132,16 +139,20 @@ func (m *manager) prepareSendE2E(mt catalog.MessageType, recipient *id.ID, ...@@ -132,16 +139,20 @@ func (m *manager) prepareSendE2E(mt catalog.MessageType, recipient *id.ID,
s = partner.MakeService(params.ServiceTag) s = partner.MakeService(params.ServiceTag)
} }
// We send each partition in its own thread here; some may send in round // We send each partition in its own thread here; some
// X, others in X+1 or X+2, and so on // may send in round X, others in X+1 or X+2, and so
// on
localI := i localI := i
thisSendFunc := func() { thisSendFunc := func() {
wg.Add(1) wg.Add(1)
go func(i int) { go func(i int) {
var err error var err error
roundIds[i], _, err = m.net.Send(recipient, roundIds[i], _, err = m.net.Send(recipient,
key.Fingerprint(), s, contentsEnc, mac, params.CMIXParams) key.Fingerprint(), s, contentsEnc, mac,
params.CMIXParams)
if err != nil { if err != nil {
jww.DEBUG.Printf("[E2E] cMix error on "+
"Send: %+v", err)
errCh <- err errCh <- err
} }
wg.Done() wg.Done()
...@@ -166,11 +177,12 @@ func (m *manager) prepareSendE2E(mt catalog.MessageType, recipient *id.ID, ...@@ -166,11 +177,12 @@ func (m *manager) prepareSendE2E(mt catalog.MessageType, recipient *id.ID,
numFail, len(partitions), errRtn) numFail, len(partitions), errRtn)
} else { } else {
jww.INFO.Printf("Successfully E2E sent %d/%d to %s", jww.INFO.Printf("Successfully E2E sent %d/%d to %s",
len(partitions)-numFail, len(partitions), recipient) len(partitions)-numFail, len(partitions),
recipient)
} }
jww.INFO.Printf("Successful E2E Send of %d messages to %s with msgID %s", jww.INFO.Printf("Successful E2E Send of %d messages to %s "+
len(partitions), recipient, msgID) "with msgID %s", len(partitions), recipient, msgID)
return roundIds, msgID, ts, nil return roundIds, msgID, ts, nil
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment