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
-2
@@ -19,8 +19,7 @@ var (
|
||||
errQueryNotFound = errors.New("arp: query not found")
|
||||
|
||||
// errGeneric aliases for common ARP errors.
|
||||
errARPBufferFull = lneto.ErrBufferFull
|
||||
errShortARP = lneto.ErrShortBuffer
|
||||
errShortARP = lneto.ErrTruncatedFrame
|
||||
errARPUnsupported = lneto.ErrUnsupported
|
||||
errLargeSizes = lneto.ErrPacketDrop
|
||||
)
|
||||
|
||||
+3
-3
@@ -10,13 +10,13 @@ import (
|
||||
"github.com/soypat/lneto/ethernet"
|
||||
)
|
||||
|
||||
// NewARPFrame returns a ARPFrame with data set to buf.
|
||||
// NewFrame returns a Frame with data set to buf.
|
||||
// An error is returned if the buffer size is smaller than 28 (IPv4 min size).
|
||||
// Users should still call [ARPFrame.ValidateSize] before working
|
||||
// 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) < sizeHeaderv4 {
|
||||
return Frame{buf: nil}, lneto.ErrShortBuffer
|
||||
return Frame{buf: nil}, lneto.ErrTruncatedFrame
|
||||
}
|
||||
return Frame{buf: buf}, nil
|
||||
}
|
||||
|
||||
+2
-2
@@ -149,7 +149,7 @@ func (h *Handler) StartQuery(dstHWAddr, proto []byte) error {
|
||||
if len(h.queries) == cap(h.queries) {
|
||||
h.compactQueries()
|
||||
if len(h.queries) == cap(h.queries) {
|
||||
return lneto.ErrBufferFull
|
||||
return lneto.ErrExhausted
|
||||
}
|
||||
}
|
||||
if len(proto) != len(h.ourProtoAddr) {
|
||||
@@ -214,7 +214,7 @@ func (h *Handler) Encapsulate(carrierData []byte, offsetToIP, offsetToFrame int)
|
||||
|
||||
func (h *Handler) Demux(ethFrame []byte, frameOffset int) error {
|
||||
if len(h.pendingResponse) == cap(h.pendingResponse) {
|
||||
return errARPBufferFull
|
||||
return lneto.ErrExhausted
|
||||
}
|
||||
|
||||
b := ethFrame[frameOffset:]
|
||||
|
||||
Reference in New Issue
Block a user