mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-30 07:35:07 +02:00
lnwire+peer: clamp pong bytes, make ping handler more effcieint
This was not properly enforced and would be a spec violation on the peer's end. Also re-use a pong buffer to save on heap allocations if there are a lot of peers. The pong buffer is only read from, so this is concurrent safe.
This commit is contained in:
@@ -2,9 +2,19 @@ package lnwire
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
// MaxPongBytes is the maximum number of extra bytes a pong can be requested to
|
||||
// send. The type of the message (19) takes 2 bytes, the length field takes up
|
||||
// 2 bytes, leaving 65531 bytes.
|
||||
const MaxPongBytes = 65531
|
||||
|
||||
// ErrMaxPongBytesExceeded indicates that the NumPongBytes field from the ping
|
||||
// message has exceeded MaxPongBytes.
|
||||
var ErrMaxPongBytesExceeded = fmt.Errorf("pong bytes exceeded")
|
||||
|
||||
// PongPayload is a set of opaque bytes sent in response to a ping message.
|
||||
type PongPayload []byte
|
||||
|
||||
|
Reference in New Issue
Block a user