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

Modify partioning to always produce messages of the cmix size

parent a438707b
No related branches found
No related tags found
3 merge requests!510Release,!207WIP: Client Restructure,!203Symmetric broadcast
...@@ -8,10 +8,11 @@ ...@@ -8,10 +8,11 @@
package conversation package conversation
import ( import (
"sync"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/client/storage/versioned"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"sync"
) )
const conversationKeyPrefix = "conversation" const conversationKeyPrefix = "conversation"
......
...@@ -9,8 +9,10 @@ package parse ...@@ -9,8 +9,10 @@ package parse
import ( import (
"encoding/binary" "encoding/binary"
"gitlab.com/elixxir/client/catalog"
"time" "time"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/catalog"
) )
// Sizes of message parts, in bytes. // Sizes of message parts, in bytes.
...@@ -36,10 +38,10 @@ type firstMessagePart struct { ...@@ -36,10 +38,10 @@ type firstMessagePart struct {
// newFirstMessagePart creates a new firstMessagePart for the passed in // newFirstMessagePart creates a new firstMessagePart for the passed in
// contents. Does no length checks. // contents. Does no length checks.
func newFirstMessagePart(mt catalog.MessageType, id uint32, numParts uint8, func newFirstMessagePart(mt catalog.MessageType, id uint32, numParts uint8,
timestamp time.Time, contents []byte) firstMessagePart { timestamp time.Time, contents []byte, size int) firstMessagePart {
// Create the message structure // Create the message structure
m := firstMessagePartFromBytes(make([]byte, len(contents)+firstHeaderLen)) m := firstMessagePartFromBytes(make([]byte, size))
// Set the message type // Set the message type
binary.BigEndian.PutUint32(m.Type, uint32(mt)) binary.BigEndian.PutUint32(m.Type, uint32(mt))
...@@ -81,6 +83,7 @@ func firstMessagePartFromBytes(data []byte) firstMessagePart { ...@@ -81,6 +83,7 @@ func firstMessagePartFromBytes(data []byte) firstMessagePart {
// Map the data according to its version // Map the data according to its version
version := data[len(data)-1] version := data[len(data)-1]
jww.INFO.Printf("Unsafeversion: %d", version)
mapFunc, exists := firstMessagePartFromBytesVersions[version] mapFunc, exists := firstMessagePartFromBytesVersions[version]
if exists { if exists {
return mapFunc(data) return mapFunc(data)
......
...@@ -34,9 +34,10 @@ type messagePart struct { ...@@ -34,9 +34,10 @@ type messagePart struct {
// newMessagePart creates a new messagePart for the passed in contents. Does no // newMessagePart creates a new messagePart for the passed in contents. Does no
// length checks. // length checks.
func newMessagePart(id uint32, part uint8, contents []byte) messagePart { func newMessagePart(id uint32, part uint8, contents []byte,
size int) messagePart {
// Create the message structure // Create the message structure
data := make([]byte, len(contents)+headerLen) data := make([]byte, size)
m := messagePartFromBytes(data) m := messagePartFromBytes(data)
// Set the message ID // Set the message ID
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
package parse package parse
import ( import (
"time"
"github.com/pkg/errors" "github.com/pkg/errors"
"gitlab.com/elixxir/client/catalog" "gitlab.com/elixxir/client/catalog"
"gitlab.com/elixxir/client/e2e/parse/conversation" "gitlab.com/elixxir/client/e2e/parse/conversation"
...@@ -16,7 +18,6 @@ import ( ...@@ -16,7 +18,6 @@ import (
"gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/client/storage/versioned"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/netTime" "gitlab.com/xx_network/primitives/netTime"
"time"
) )
const MaxMessageParts = 255 const MaxMessageParts = 255
...@@ -64,12 +65,13 @@ func (p Partitioner) Partition(recipient *id.ID, mt catalog.MessageType, ...@@ -64,12 +65,13 @@ func (p Partitioner) Partition(recipient *id.ID, mt catalog.MessageType,
// Create the first message part // Create the first message part
var sub []byte var sub []byte
sub, payload = splitPayload(payload, p.firstContentsSize) sub, payload = splitPayload(payload, p.firstContentsSize)
parts[0] = newFirstMessagePart(mt, messageID, numParts, timestamp, sub).bytes() parts[0] = newFirstMessagePart(mt, messageID, numParts,
timestamp, sub, p.baseMessageSize).bytes()
// Create all subsequent message parts // Create all subsequent message parts
for i := uint8(1); i < numParts; i++ { for i := uint8(1); i < numParts; i++ {
sub, payload = splitPayload(payload, p.partContentsSize) sub, payload = splitPayload(payload, p.partContentsSize)
parts[i] = newMessagePart(messageID, i, sub).bytes() parts[i] = newMessagePart(messageID, i, sub, p.baseMessageSize).bytes()
} }
return parts, fullMessageID, nil return parts, fullMessageID, 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