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:
6 files changed
+55
-7
No files matched your search
+10
-3
@@ -38,9 +38,16 @@ var _ Message = (*Ping)(nil)
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (p *Ping) Decode(r io.Reader, pver uint32) error {
|
||||
return ReadElements(r,
|
||||
&p.NumPongBytes,
|
||||
&p.PaddingBytes)
|
||||
err := ReadElements(r, &p.NumPongBytes, &p.PaddingBytes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if p.NumPongBytes > MaxPongBytes {
|
||||
return ErrMaxPongBytesExceeded
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Encode serializes the target Ping into the passed io.Writer observing the
|
||||
|
||||
Reference in new issue
Block a user