mirror of
https://github.com/soypat/lneto.git
synced 2026-09-10 08:39:30 +00:00
Add round-robin implementation (#66)
* add handler.encapsulateNode * implement round robin handler approach * simplify round robin implementation * leave TODO * internet.node touch up * fix conflict resolve f-up * replace certain ErrShortBuffer with ErrTruncatedFrame error
This commit is contained in:
+1
-1
@@ -329,7 +329,7 @@ func (conn *Conn) Demux(buf []byte, off int) (err error) {
|
||||
conn.mu.Lock()
|
||||
defer conn.mu.Unlock()
|
||||
if off >= len(buf) {
|
||||
return lneto.ErrShortBuffer
|
||||
return lneto.ErrTruncatedFrame // TODO: this check is bad.
|
||||
}
|
||||
raddr, _, id, _, err := internal.GetIPAddr(buf[:off])
|
||||
if err != nil {
|
||||
|
||||
+3
-3
@@ -12,13 +12,13 @@ const (
|
||||
sizeHeaderTCP = 20
|
||||
)
|
||||
|
||||
// NewFrame returns a new TCPFrame with data set to buf.
|
||||
// NewFrame returns a new [Frame] with data set to buf.
|
||||
// An error is returned if the buffer size is smaller than 20.
|
||||
// Users should still call [Frame.ValidateSize] before working
|
||||
// with payload/options of frames to avoid panics.
|
||||
func NewFrame(buf []byte) (Frame, error) {
|
||||
if len(buf) < sizeHeaderTCP {
|
||||
return Frame{buf: nil}, lneto.ErrShortBuffer
|
||||
return Frame{buf: nil}, lneto.ErrTruncatedFrame
|
||||
}
|
||||
return Frame{buf: buf}, nil
|
||||
}
|
||||
@@ -190,7 +190,7 @@ func (tfrm Frame) ValidateSize(v *lneto.Validator) {
|
||||
v.AddError(lneto.ErrInvalidLengthField)
|
||||
}
|
||||
if off > len(tfrm.RawData()) {
|
||||
v.AddError(lneto.ErrShortBuffer)
|
||||
v.AddError(lneto.ErrTruncatedFrame)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -111,13 +111,13 @@ func (op OptionCodec) ForEachOption(opts []byte, fn func(OptionKind, []byte) err
|
||||
continue
|
||||
}
|
||||
if len(opts[off:]) < 1 {
|
||||
return lneto.ErrShortBuffer
|
||||
return lneto.ErrTruncatedFrame
|
||||
}
|
||||
size := int(opts[off]) // Total option length including kind and length bytes.
|
||||
off++
|
||||
dataLen := size - 2 // Data bytes after kind and length.
|
||||
if dataLen < 0 || len(opts[off:]) < dataLen {
|
||||
return lneto.ErrShortBuffer
|
||||
return lneto.ErrTruncatedFrame
|
||||
}
|
||||
|
||||
if !skipSizeValidation {
|
||||
|
||||
Reference in New Issue
Block a user