From db10355c84ed3cefdd8427b445b4e6df9263a3d2 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sun, 6 Apr 2025 14:19:39 -0400 Subject: [PATCH] Change the size limit type to an int64 --- connection.go | 4 ++-- metadaptb.go | 14 ++++++-------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/connection.go b/connection.go index 56154a7..a2f2080 100644 --- a/connection.go +++ b/connection.go @@ -4,7 +4,7 @@ import "io" import "net" // import "time" -const defaultSizeLimit = 1024 * 1024 // 1 megabyte +const defaultSizeLimit int64 = 1024 * 1024 // 1 megabyte // Conn is a HOPP connection. type Conn interface { @@ -25,7 +25,7 @@ type Conn interface { // SetSizeLimit sets a limit (in bytes) for how large messages can be. // By default, this limit is 1 megabyte. - SetSizeLimit(limit int) + SetSizeLimit(limit int64) } // Trans is a HOPP transaction. diff --git a/metadaptb.go b/metadaptb.go index f78bb26..18776da 100644 --- a/metadaptb.go +++ b/metadaptb.go @@ -5,12 +5,10 @@ import "net" import "context" import "git.tebibyte.media/sashakoshka/hopp/tape" -// TODO: change size limit to be int64 - // B implements METADAPT-B over a multiplexed stream-oriented transport such as // QUIC. type b struct { - sizeLimit int + sizeLimit int64 underlying MultiConn } @@ -47,7 +45,7 @@ func (this *b) AcceptTrans() (Trans, error) { return this.newTrans(stream), nil } -func (this *b) SetSizeLimit(limit int) { +func (this *b) SetSizeLimit(limit int64) { this.sizeLimit = limit } @@ -59,7 +57,7 @@ func (this *b) newTrans(underlying Stream) *transB { } type transB struct { - sizeLimit int + sizeLimit int64 underlying Stream currentData io.Reader } @@ -127,8 +125,8 @@ type Stream interface { ID() int64 } -func encodeMessageB(writer io.Writer, sizeLimit int, method uint16, data []byte) error { - if len(data) > sizeLimit { +func encodeMessageB(writer io.Writer, sizeLimit int64, method uint16, data []byte) error { + if len(data) > int(sizeLimit) { return ErrPayloadTooLarge } buffer := make([]byte, 10 + len(data)) @@ -141,7 +139,7 @@ func encodeMessageB(writer io.Writer, sizeLimit int, method uint16, data []byte) func decodeMessageB( reader io.Reader, - sizeLimit int, + sizeLimit int64, ) ( method uint16, size int64,