mirror of
https://github.com/soypat/lneto.git
synced 2026-09-12 09:39:31 +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:
@@ -54,6 +54,7 @@ func (client *Client) Configure(cfg ClientConfig) error {
|
||||
}
|
||||
client.connid++
|
||||
internal.SliceReuse(&client.outgoingEcho, cfg.ResponseQueueLimit)
|
||||
internal.SliceReuse(&client.incomingEcho, cfg.ResponseQueueLimit)
|
||||
client.responseRing = internal.Ring{Buf: cfg.ResponseQueueBuffer}
|
||||
client.magic = cfg.HashSeed
|
||||
client.id = cfg.ID
|
||||
@@ -101,6 +102,10 @@ func (client *Client) Demux(carrierData []byte, frameOffset int) error {
|
||||
}
|
||||
switch tp {
|
||||
case TypeEcho:
|
||||
free := cap(client.incomingEcho) - len(client.incomingEcho)
|
||||
if free == 0 {
|
||||
return lneto.ErrExhausted
|
||||
}
|
||||
// We received a ping request; not handled client-side.
|
||||
efrm := FrameEcho{Frame: ifrm}
|
||||
data := efrm.Data()
|
||||
@@ -227,6 +232,10 @@ func (client *Client) PingStart(remoteAddr [4]byte, pattern []byte, size uint16)
|
||||
} else if remoteAddr == [4]byte{} {
|
||||
return 0, lneto.ErrZeroDestination
|
||||
}
|
||||
free := cap(client.outgoingEcho) - len(client.outgoingEcho)
|
||||
if free == 0 {
|
||||
return 0, lneto.ErrExhausted
|
||||
}
|
||||
key = client.magichash(pattern, int(size)) & keyHashBits
|
||||
v := internal.SliceReclaim(&client.outgoingEcho)
|
||||
v.key = key
|
||||
|
||||
@@ -59,7 +59,7 @@ const (
|
||||
|
||||
func NewFrame(buf []byte) (Frame, error) {
|
||||
if len(buf) < sizeHeader {
|
||||
return Frame{}, lneto.ErrShortBuffer
|
||||
return Frame{}, lneto.ErrTruncatedFrame
|
||||
}
|
||||
return Frame{buf: buf}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user