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:
Olaoluwa Osuntokun
2022-01-10 19:11:59 -08:00
parent ae16f2b631
commit 3481286ea0
6 changed files with 55 additions and 7 deletions

View File

@@ -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