Merge pull request #1072 from nspcc-dev/fix/payload

Allow NullPayload only for CMDGetAddr
This commit is contained in:
Roman Khimov 2020-06-19 15:58:40 +03:00 committed by GitHub
commit 75cc109837
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

View file

@ -106,7 +106,12 @@ func (m *Message) Decode(br *io.BinReader) error {
// check the length first in order not to allocate memory
// for an empty compressed payload
if l == 0 {
switch m.Command {
case CMDFilterClear, CMDGetAddr, CMDMempool:
m.Payload = payload.NewNullPayload()
default:
return errors.New("unexpected empty payload")
}
return nil
}
if l > PayloadMaxSize {

View file

@ -12,12 +12,12 @@ type NullPayload struct {
}
// NewNullPayload returns zero-sized stub payload.
func NewNullPayload() *NullPayload {
return &NullPayload{}
func NewNullPayload() NullPayload {
return NullPayload{}
}
// DecodeBinary implements Serializable interface.
func (p *NullPayload) DecodeBinary(r *io.BinReader) {}
func (p NullPayload) DecodeBinary(r *io.BinReader) {}
// EncodeBinary implements Serializable interface.
func (p *NullPayload) EncodeBinary(w *io.BinWriter) {}
func (p NullPayload) EncodeBinary(w *io.BinWriter) {}