2018-02-04 19:54:51 +00:00
|
|
|
package payload
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/core"
|
2019-09-16 09:18:13 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/io"
|
2019-08-29 17:11:03 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
2018-02-04 19:54:51 +00:00
|
|
|
)
|
|
|
|
|
2019-10-22 14:56:03 +00:00
|
|
|
// Headers payload.
|
2018-02-04 19:54:51 +00:00
|
|
|
type Headers struct {
|
|
|
|
Hdrs []*core.Header
|
|
|
|
}
|
|
|
|
|
2019-10-22 14:56:03 +00:00
|
|
|
// Users can at most request 2k header.
|
2019-08-29 17:11:03 +00:00
|
|
|
const (
|
2019-11-29 08:08:22 +00:00
|
|
|
MaxHeadersAllowed = 2000
|
2019-08-29 17:11:03 +00:00
|
|
|
)
|
|
|
|
|
2019-09-16 16:31:49 +00:00
|
|
|
// DecodeBinary implements Serializable interface.
|
|
|
|
func (p *Headers) DecodeBinary(br *io.BinReader) {
|
2019-08-28 12:43:56 +00:00
|
|
|
lenHeaders := br.ReadVarUint()
|
2019-09-16 16:31:49 +00:00
|
|
|
|
2019-08-29 17:11:03 +00:00
|
|
|
// C# node does it silently
|
2019-11-29 08:08:22 +00:00
|
|
|
if lenHeaders > MaxHeadersAllowed {
|
|
|
|
log.Warnf("received %d headers, capping to %d", lenHeaders, MaxHeadersAllowed)
|
|
|
|
lenHeaders = MaxHeadersAllowed
|
2019-08-29 17:11:03 +00:00
|
|
|
}
|
2018-02-04 19:54:51 +00:00
|
|
|
|
|
|
|
p.Hdrs = make([]*core.Header, lenHeaders)
|
|
|
|
|
|
|
|
for i := 0; i < int(lenHeaders); i++ {
|
|
|
|
header := &core.Header{}
|
2019-09-16 16:31:49 +00:00
|
|
|
header.DecodeBinary(br)
|
2018-02-04 19:54:51 +00:00
|
|
|
p.Hdrs[i] = header
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-16 16:31:49 +00:00
|
|
|
// EncodeBinary implements Serializable interface.
|
|
|
|
func (p *Headers) EncodeBinary(bw *io.BinWriter) {
|
2019-11-13 07:36:29 +00:00
|
|
|
bw.WriteArray(p.Hdrs)
|
2018-02-04 19:54:51 +00:00
|
|
|
}
|