From c86790e55f371b48155aab34cc2c0a277e94c333 Mon Sep 17 00:00:00 2001 From: joshemb <josh@elixxir.io> Date: Tue, 23 Aug 2022 17:17:40 -0700 Subject: [PATCH] Propagate key residue for receiver --- e2e/parse/partition.go | 2 +- e2e/parse/partition/store.go | 13 +++++++++---- e2e/parse/partition_test.go | 7 +++++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/e2e/parse/partition.go b/e2e/parse/partition.go index 4850cafd7..0f3d18630 100644 --- a/e2e/parse/partition.go +++ b/e2e/parse/partition.go @@ -80,7 +80,7 @@ func (p *Partitioner) Partition(recipient *id.ID, mt catalog.MessageType, func (p *Partitioner) HandlePartition(sender *id.ID, contents []byte, relationshipFingerprint []byte, - residue e2eCrypto.KeyResidue) (receive.Message, bool) { + residue e2eCrypto.KeyResidue) (receive.Message, e2eCrypto.KeyResidue, bool) { if isFirst(contents) { // If it is the first message in a set, then handle it as so diff --git a/e2e/parse/partition/store.go b/e2e/parse/partition/store.go index 0f128c482..9db972575 100644 --- a/e2e/parse/partition/store.go +++ b/e2e/parse/partition/store.go @@ -54,7 +54,7 @@ func (s *Store) AddFirst(partner *id.ID, mt catalog.MessageType, messageID uint64, partNum, numParts uint8, senderTimestamp, storageTimestamp time.Time, part []byte, relationshipFingerprint []byte, residue e2e.KeyResidue) ( - receive.Message, bool) { + receive.Message, e2e.KeyResidue, bool) { mpm := s.load(partner, messageID) mpm.AddFirst(mt, partNum, numParts, senderTimestamp, storageTimestamp, part) @@ -64,34 +64,39 @@ func (s *Store) AddFirst(partner *id.ID, mt catalog.MessageType, s.mux.Lock() defer s.mux.Unlock() + keyRes := e2e.KeyResidue{} if !ok { s.activeParts[mpm] = true s.saveActiveParts() } else { + keyRes = mpm.KeyResidue mpID := getMultiPartID(mpm.Sender, mpm.MessageID) delete(s.multiParts, mpID) } - return msg, ok + return msg, keyRes, ok } func (s *Store) Add(partner *id.ID, messageID uint64, partNum uint8, - part []byte, relationshipFingerprint []byte) (receive.Message, bool) { + part []byte, relationshipFingerprint []byte) ( + receive.Message, e2e.KeyResidue, bool) { mpm := s.load(partner, messageID) mpm.Add(partNum, part) msg, ok := mpm.IsComplete(relationshipFingerprint) + keyRes := e2e.KeyResidue{} if !ok { s.activeParts[mpm] = true s.saveActiveParts() } else { + keyRes = mpm.KeyResidue mpID := getMultiPartID(mpm.Sender, mpm.MessageID) delete(s.multiParts, mpID) } - return msg, ok + return msg, keyRes, ok } // prune clears old messages on it's stored timestamp. diff --git a/e2e/parse/partition_test.go b/e2e/parse/partition_test.go index 22c1f238e..3abf6ff1f 100644 --- a/e2e/parse/partition_test.go +++ b/e2e/parse/partition_test.go @@ -8,6 +8,7 @@ package parse import ( + "gitlab.com/elixxir/crypto/e2e" "testing" "gitlab.com/elixxir/client/catalog" @@ -72,10 +73,11 @@ func TestPartitioner_HandlePartition(t *testing.T) { p := NewPartitioner(versioned.NewKV(ekv.MakeMemstore()), len(ipsumTestStr)) m := newMessagePart(1107, 1, []byte(ipsumTestStr), len(ipsumTestStr)+headerLen) - _, _ = p.HandlePartition( + _, _, _ = p.HandlePartition( &id.DummyUser, m.bytes(), []byte{'t', 'e', 's', 't', 'i', 'n', 'g', 's', 't', 'r', 'i', 'n', 'g'}, + e2e.KeyResidue{}, ) } @@ -85,9 +87,10 @@ func TestPartitioner_HandleFirstPartition(t *testing.T) { m := newFirstMessagePart( catalog.XxMessage, 1107, 1, netTime.Now(), []byte(ipsumTestStr), len([]byte(ipsumTestStr))+firstHeaderLen) - _, _ = p.HandlePartition( + _, _, _ = p.HandlePartition( &id.DummyUser, m.bytes(), []byte{'t', 'e', 's', 't', 'i', 'n', 'g', 's', 't', 'r', 'i', 'n', 'g'}, + e2e.KeyResidue{}, ) } -- GitLab