Export MaxVarIntPayload.

This commit is contained in:
Dave Collins 2014-03-11 20:09:55 -05:00
parent b9c21bd518
commit e5d15b0fa8
9 changed files with 10 additions and 10 deletions

View file

@ -14,7 +14,7 @@ import (
) )
// Maximum payload size for a variable length integer. // Maximum payload size for a variable length integer.
const maxVarIntPayload = 9 const MaxVarIntPayload = 9
// readElement reads the next sequence of bytes from r using little endian // readElement reads the next sequence of bytes from r using little endian
// depending on the concrete type of element pointed to. // depending on the concrete type of element pointed to.

View file

@ -126,11 +126,11 @@ func (msg *MsgAddr) Command() string {
func (msg *MsgAddr) MaxPayloadLength(pver uint32) uint32 { func (msg *MsgAddr) MaxPayloadLength(pver uint32) uint32 {
if pver < MultipleAddressVersion { if pver < MultipleAddressVersion {
// Num addresses (varInt) + a single net addresses. // Num addresses (varInt) + a single net addresses.
return maxVarIntPayload + maxNetAddressPayload(pver) return MaxVarIntPayload + maxNetAddressPayload(pver)
} }
// Num addresses (varInt) + max allowed addresses. // Num addresses (varInt) + max allowed addresses.
return maxVarIntPayload + (MaxAddrPerMsg * maxNetAddressPayload(pver)) return MaxVarIntPayload + (MaxAddrPerMsg * maxNetAddressPayload(pver))
} }
// NewMsgAddr returns a new bitcoin addr message that conforms to the // NewMsgAddr returns a new bitcoin addr message that conforms to the

View file

@ -129,7 +129,7 @@ func (msg *MsgGetBlocks) Command() string {
func (msg *MsgGetBlocks) MaxPayloadLength(pver uint32) uint32 { func (msg *MsgGetBlocks) MaxPayloadLength(pver uint32) uint32 {
// Protocol version 4 bytes + num hashes (varInt) + max block locator // Protocol version 4 bytes + num hashes (varInt) + max block locator
// hashes + hash stop. // hashes + hash stop.
return 4 + maxVarIntPayload + (MaxBlockLocatorsPerMsg * HashSize) + HashSize return 4 + MaxVarIntPayload + (MaxBlockLocatorsPerMsg * HashSize) + HashSize
} }
// NewMsgGetBlocks returns a new bitcoin getblocks message that conforms to the // NewMsgGetBlocks returns a new bitcoin getblocks message that conforms to the

View file

@ -97,7 +97,7 @@ func (msg *MsgGetData) Command() string {
// receiver. This is part of the Message interface implementation. // receiver. This is part of the Message interface implementation.
func (msg *MsgGetData) MaxPayloadLength(pver uint32) uint32 { func (msg *MsgGetData) MaxPayloadLength(pver uint32) uint32 {
// Num inventory vectors (varInt) + max allowed inventory vectors. // Num inventory vectors (varInt) + max allowed inventory vectors.
return maxVarIntPayload + (MaxInvPerMsg * maxInvVectPayload) return MaxVarIntPayload + (MaxInvPerMsg * maxInvVectPayload)
} }
// NewMsgGetData returns a new bitcoin getdata message that conforms to the // NewMsgGetData returns a new bitcoin getdata message that conforms to the

View file

@ -127,7 +127,7 @@ func (msg *MsgGetHeaders) Command() string {
func (msg *MsgGetHeaders) MaxPayloadLength(pver uint32) uint32 { func (msg *MsgGetHeaders) MaxPayloadLength(pver uint32) uint32 {
// Version 4 bytes + num block locator hashes (varInt) + max allowed block // Version 4 bytes + num block locator hashes (varInt) + max allowed block
// locators + hash stop. // locators + hash stop.
return 4 + maxVarIntPayload + (MaxBlockLocatorsPerMsg * HashSize) + HashSize return 4 + MaxVarIntPayload + (MaxBlockLocatorsPerMsg * HashSize) + HashSize
} }
// NewMsgGetHeaders returns a new bitcoin getheaders message that conforms to // NewMsgGetHeaders returns a new bitcoin getheaders message that conforms to

View file

@ -121,7 +121,7 @@ func (msg *MsgHeaders) Command() string {
func (msg *MsgHeaders) MaxPayloadLength(pver uint32) uint32 { func (msg *MsgHeaders) MaxPayloadLength(pver uint32) uint32 {
// Num headers (varInt) + max allowed headers (header length + 1 byte // Num headers (varInt) + max allowed headers (header length + 1 byte
// for the number of transactions which is always 0). // for the number of transactions which is always 0).
return maxVarIntPayload + ((maxBlockHeaderPayload + 1) * return MaxVarIntPayload + ((maxBlockHeaderPayload + 1) *
MaxBlockHeadersPerMsg) MaxBlockHeadersPerMsg)
} }

View file

@ -105,7 +105,7 @@ func (msg *MsgInv) Command() string {
// receiver. This is part of the Message interface implementation. // receiver. This is part of the Message interface implementation.
func (msg *MsgInv) MaxPayloadLength(pver uint32) uint32 { func (msg *MsgInv) MaxPayloadLength(pver uint32) uint32 {
// Num inventory vectors (varInt) + max allowed inventory vectors. // Num inventory vectors (varInt) + max allowed inventory vectors.
return maxVarIntPayload + (MaxInvPerMsg * maxInvVectPayload) return MaxVarIntPayload + (MaxInvPerMsg * maxInvVectPayload)
} }
// NewMsgInv returns a new bitcoin inv message that conforms to the Message // NewMsgInv returns a new bitcoin inv message that conforms to the Message

View file

@ -95,7 +95,7 @@ func (msg *MsgNotFound) Command() string {
func (msg *MsgNotFound) MaxPayloadLength(pver uint32) uint32 { func (msg *MsgNotFound) MaxPayloadLength(pver uint32) uint32 {
// Max var int 9 bytes + max InvVects at 36 bytes each. // Max var int 9 bytes + max InvVects at 36 bytes each.
// Num inventory vectors (varInt) + max allowed inventory vectors. // Num inventory vectors (varInt) + max allowed inventory vectors.
return maxVarIntPayload + (MaxInvPerMsg * maxInvVectPayload) return MaxVarIntPayload + (MaxInvPerMsg * maxInvVectPayload)
} }
// NewMsgNotFound returns a new bitcoin notfound message that conforms to the // NewMsgNotFound returns a new bitcoin notfound message that conforms to the

View file

@ -167,7 +167,7 @@ func (msg *MsgVersion) MaxPayloadLength(pver uint32) uint32 {
// Protocol version 4 bytes + services 8 bytes + timestamp 8 bytes + remote // Protocol version 4 bytes + services 8 bytes + timestamp 8 bytes + remote
// and local net addresses + nonce 8 bytes + length of user agent (varInt) + // and local net addresses + nonce 8 bytes + length of user agent (varInt) +
// max allowed useragent length + last block 4 bytes. // max allowed useragent length + last block 4 bytes.
return 32 + (maxNetAddressPayload(pver) * 2) + maxVarIntPayload + MaxUserAgentLen return 32 + (maxNetAddressPayload(pver) * 2) + MaxVarIntPayload + MaxUserAgentLen
} }
// NewMsgVersion returns a new bitcoin version message that conforms to the // NewMsgVersion returns a new bitcoin version message that conforms to the