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,
partitions, internalMsgId, err := m.partitioner.Partition(recipient,
mt, ts, payload)
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
// send each partition over cMix
// When sending E2E messages, we first partition into cMix
// packets and then send each partition over cMix
roundIds := make([]id.Round, len(partitions))
errCh := make(chan error, len(partitions))
// The Key manager for the partner (recipient) ensures single use of each
// key negotiated for the ratchet
// The Key manager for the partner (recipient) ensures single
// use of each key negotiated for the ratchet
partner, err := m.Ratchet.GetPartner(recipient)
if err != nil {
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(
......@@ -89,15 +92,17 @@ func (m *manager) prepareSendE2E(mt catalog.MessageType, recipient *id.ID,
for i, p := range partitions {
if mt != catalog.KeyExchangeTrigger {
// 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) (
[]id.Round, e2e.MessageID, time.Time, error) {
par := params
par.CMIXParams = cmixParams
return m.SendE2E(mt, recipient, payload, par)
}
rekey.CheckKeyExchanges(m.net.GetInstance(), m.grp, rekeySendFunc,
m.events, partner, m.rekeyParams, 1*time.Minute)
rekey.CheckKeyExchanges(m.net.GetInstance(), m.grp,
rekeySendFunc, m.events, partner,
m.rekeyParams, 1*time.Minute)
}
var keyGetter func() (session.Cypher, error)
......@@ -107,23 +112,25 @@ func (m *manager) prepareSendE2E(mt catalog.MessageType, recipient *id.ID,
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(
keyGetter, params.KeyGetRetryCount, params.KeyGeRetryDelay,
keyGetter, params.KeyGetRetryCount,
params.KeyGeRetryDelay,
params.Stop, recipient, format.DigestContents(p), i)
if err != nil {
return nil, errors.WithMessagef(err,
"Failed to get key for end-to-end encryption")
}
// This does not encrypt for cMix but instead end-to-end encrypts the
// cMix message
// This does not encrypt for cMix but instead
// end-to-end encrypts the cMix message
contentsEnc, mac := key.Encrypt(p)
jww.INFO.Printf(
"E2E sending %d/%d to %s with key fp: %s, msgID: %s (msgDigest %s)",
i+i, len(partitions), recipient, key.Fingerprint(), msgID,
format.DigestContents(p))
jww.INFO.Printf("E2E sending %d/%d to %s with key fp: %s, "+
"msgID: %s (msgDigest %s)",
i+i, len(partitions), recipient, key.Fingerprint(),
msgID, format.DigestContents(p))
var s message.Service
if i == len(partitions)-1 {
......@@ -132,16 +139,20 @@ func (m *manager) prepareSendE2E(mt catalog.MessageType, recipient *id.ID,
s = partner.MakeService(params.ServiceTag)
}
// We send each partition in its own thread here; some may send in round
// X, others in X+1 or X+2, and so on
// We send each partition in its own thread here; some
// may send in round X, others in X+1 or X+2, and so
// on
localI := i
thisSendFunc := func() {
wg.Add(1)
go func(i int) {
var err error
roundIds[i], _, err = m.net.Send(recipient,
key.Fingerprint(), s, contentsEnc, mac, params.CMIXParams)
key.Fingerprint(), s, contentsEnc, mac,
params.CMIXParams)
if err != nil {
jww.DEBUG.Printf("[E2E] cMix error on "+
"Send: %+v", err)
errCh <- err
}
wg.Done()
......@@ -166,11 +177,12 @@ func (m *manager) prepareSendE2E(mt catalog.MessageType, recipient *id.ID,
numFail, len(partitions), errRtn)
} else {
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",
len(partitions), recipient, msgID)
jww.INFO.Printf("Successful E2E Send of %d messages to %s "+
"with msgID %s", len(partitions), recipient, msgID)
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