Change the size limit type to an int64

This commit is contained in:
Sasha Koshka 2025-04-06 14:19:39 -04:00
parent f4f8039fa0
commit db10355c84
2 changed files with 8 additions and 10 deletions

View File

@ -4,7 +4,7 @@ import "io"
import "net" import "net"
// import "time" // import "time"
const defaultSizeLimit = 1024 * 1024 // 1 megabyte const defaultSizeLimit int64 = 1024 * 1024 // 1 megabyte
// Conn is a HOPP connection. // Conn is a HOPP connection.
type Conn interface { type Conn interface {
@ -25,7 +25,7 @@ type Conn interface {
// SetSizeLimit sets a limit (in bytes) for how large messages can be. // SetSizeLimit sets a limit (in bytes) for how large messages can be.
// By default, this limit is 1 megabyte. // By default, this limit is 1 megabyte.
SetSizeLimit(limit int) SetSizeLimit(limit int64)
} }
// Trans is a HOPP transaction. // Trans is a HOPP transaction.

View File

@ -5,12 +5,10 @@ import "net"
import "context" import "context"
import "git.tebibyte.media/sashakoshka/hopp/tape" 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 // B implements METADAPT-B over a multiplexed stream-oriented transport such as
// QUIC. // QUIC.
type b struct { type b struct {
sizeLimit int sizeLimit int64
underlying MultiConn underlying MultiConn
} }
@ -47,7 +45,7 @@ func (this *b) AcceptTrans() (Trans, error) {
return this.newTrans(stream), nil return this.newTrans(stream), nil
} }
func (this *b) SetSizeLimit(limit int) { func (this *b) SetSizeLimit(limit int64) {
this.sizeLimit = limit this.sizeLimit = limit
} }
@ -59,7 +57,7 @@ func (this *b) newTrans(underlying Stream) *transB {
} }
type transB struct { type transB struct {
sizeLimit int sizeLimit int64
underlying Stream underlying Stream
currentData io.Reader currentData io.Reader
} }
@ -127,8 +125,8 @@ type Stream interface {
ID() int64 ID() int64
} }
func encodeMessageB(writer io.Writer, sizeLimit int, method uint16, data []byte) error { func encodeMessageB(writer io.Writer, sizeLimit int64, method uint16, data []byte) error {
if len(data) > sizeLimit { if len(data) > int(sizeLimit) {
return ErrPayloadTooLarge return ErrPayloadTooLarge
} }
buffer := make([]byte, 10 + len(data)) buffer := make([]byte, 10 + len(data))
@ -141,7 +139,7 @@ func encodeMessageB(writer io.Writer, sizeLimit int, method uint16, data []byte)
func decodeMessageB( func decodeMessageB(
reader io.Reader, reader io.Reader,
sizeLimit int, sizeLimit int64,
) ( ) (
method uint16, method uint16,
size int64, size int64,