diff --git a/connect/connect.go b/connect/connect.go index 1f0a6db7449f9c3fac9db297114997bce803fdd1..00a1daa84d40b39d85452b44888efc7eec8d4441 100644 --- a/connect/connect.go +++ b/connect/connect.go @@ -7,6 +7,9 @@ package connect import ( + "io" + "time" + "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/auth" @@ -26,8 +29,6 @@ import ( "gitlab.com/elixxir/crypto/fastRNG" "gitlab.com/elixxir/ekv" "gitlab.com/xx_network/primitives/id" - "io" - "time" ) const ( @@ -59,6 +60,22 @@ type Connection interface { newListener receive.Listener) receive.ListenerID // Unregister listener for E2E reception Unregister(listenerID receive.ListenerID) + + // FirstPartitionSize returns the max partition payload size for the + // first payload + FirstPartitionSize() uint + + // SecondPartitionSize returns the max partition payload size for all + // payloads after the first payload + SecondPartitionSize() uint + + // PartitionSize returns the partition payload size for the given + // payload index. The first payload is index 0. + PartitionSize(payloadIndex uint) uint + + // PayloadSize Returns the max payload size for a partitionable E2E + // message + PayloadSize(payloadIndex uint) uint } // Callback is the callback format required to retrieve @@ -287,3 +304,27 @@ func (a authCallback) Request(requestor contact.Contact, func (a authCallback) Reset(requestor contact.Contact, receptionID receptionID.EphemeralIdentity, round rounds.Round) { } + +// FirstPartitionSize returns the max partition payload size for the +// first payload +func (h *handler) FirstPartitionSize() uint { + return h.e2e.FirstPartitionSize() +} + +// SecondPartitionSize returns the max partition payload size for all +// payloads after the first payload +func (h *handler) SecondPartitionSize() uint { + return h.e2e.SecondPartitionSize() +} + +// PartitionSize returns the partition payload size for the given +// payload index. The first payload is index 0. +func (h *handler) PartitionSize(payloadIndex uint) uint { + return h.e2e.PartitionSize(payloadIndex) +} + +// PayloadSize Returns the max payload size for a partitionable E2E +// message +func (h *handler) PayloadSize() uint { + return h.e2e.PayloadSize() +} diff --git a/e2e/interface.go b/e2e/interface.go index a24f285ce3b2046b8d838aa2826775b167f47bf9..40d7ea1695044411598c3f65ae4cbc9c9a3e1041 100644 --- a/e2e/interface.go +++ b/e2e/interface.go @@ -173,4 +173,20 @@ type Handler interface { // GetReceptionID returns the default IDs GetReceptionID() *id.ID + + // FirstPartitionSize returns the max partition payload size for the + // first payload + FirstPartitionSize() uint + + // SecondPartitionSize returns the max partition payload size for all + // payloads after the first payload + SecondPartitionSize() uint + + // PartitionSize returns the partition payload size for the given + // payload index. The first payload is index 0. + PartitionSize(payloadIndex uint) uint + + // PayloadSize Returns the max payload size for a partitionable E2E + // message + PayloadSize() uint } diff --git a/e2e/parse/partition.go b/e2e/parse/partition.go index e23649d3a18d0d455803b9484a051a1ec225d1c3..c0f5c0b95338bd6044063fbe7cecbac114fbbd3f 100644 --- a/e2e/parse/partition.go +++ b/e2e/parse/partition.go @@ -104,6 +104,24 @@ func (p Partitioner) HandlePartition(sender *id.ID, } } +// FirstPartitionSize returns the max partition payload size for the +// first payload +func (p Partitioner) FirstPartitionSize() uint { + return uint(p.firstContentsSize) +} + +// SecondPartitionSize returns the max partition payload size for all +// payloads after the first payload +func (p Partitioner) SecondPartitionSize() uint { + return uint(p.partContentsSize) +} + +// PayloadSize Returns the max payload size for a partitionable E2E +// message +func (p Partitioner) PayloadSize() uint { + return uint(p.maxSize) +} + func splitPayload(payload []byte, length int) ([]byte, []byte) { if len(payload) < length { return payload, payload diff --git a/e2e/sendE2E.go b/e2e/sendE2E.go index 2a50201de5e20d75eb41602f194d58e99a0d6af1..65cf98cdf63105298daebbc8eede2b21dc6e3d17 100644 --- a/e2e/sendE2E.go +++ b/e2e/sendE2E.go @@ -9,6 +9,7 @@ import ( "gitlab.com/elixxir/client/catalog" "gitlab.com/elixxir/client/cmix" "gitlab.com/elixxir/client/cmix/message" + "gitlab.com/elixxir/client/e2e/parse" "gitlab.com/elixxir/client/e2e/ratchet/partner/session" "gitlab.com/elixxir/client/e2e/rekey" "gitlab.com/elixxir/client/stoppable" @@ -199,3 +200,33 @@ func getSendErrors(c chan error) (numFail int, errRtn string) { } } } + +// FirstPartitionSize returns the max partition payload size for the +// first payload +func (m *manager) FirstPartitionSize() uint { + return m.partitioner.FirstPartitionSize() +} + +// SecondPartitionSize returns the max partition payload size for all +// payloads after the first payload +func (m *manager) SecondPartitionSize() uint { + return m.partitioner.SecondPartitionSize() +} + +// PartitionSize returns the partition payload size for the given +// payload index. The first payload is index 0. +func (m *manager) PartitionSize(payloadIndex uint) uint { + if payloadIndex == 0 { + return m.FirstPartitionSize() + } + if payloadIndex > parse.MaxMessageParts { + return 0 + } + return m.SecondPartitionSize() +} + +// PayloadSize Returns the max payload size for a partitionable E2E +// message +func (m *manager) PayloadSize() uint { + return m.partitioner.PayloadSize() +}