Export CommandSize constant.
This commit exports the CommandSize constant to provide callers with the ability to know the size of the command field in a bitcoin message header.
This commit is contained in:
parent
3a1009529f
commit
dd70618cc1
3 changed files with 8 additions and 12 deletions
|
@ -83,7 +83,7 @@ func readElement(r io.Reader, element interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
// Message header command.
|
// Message header command.
|
||||||
case *[commandSize]uint8:
|
case *[CommandSize]uint8:
|
||||||
_, err := io.ReadFull(r, e[:])
|
_, err := io.ReadFull(r, e[:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -233,7 +233,7 @@ func writeElement(w io.Writer, element interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
// Message header command.
|
// Message header command.
|
||||||
case [commandSize]uint8:
|
case [CommandSize]uint8:
|
||||||
_, err := w.Write(e[:])
|
_, err := w.Write(e[:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -31,10 +31,6 @@ const (
|
||||||
// MaxCountSetSubVer makes the internal maxCountSetSubVer constant
|
// MaxCountSetSubVer makes the internal maxCountSetSubVer constant
|
||||||
// available to the test package.
|
// available to the test package.
|
||||||
MaxCountSetSubVer = maxCountSetSubVer
|
MaxCountSetSubVer = maxCountSetSubVer
|
||||||
|
|
||||||
// CommandSize makes the internal commandSize constant available to the
|
|
||||||
// test package.
|
|
||||||
CommandSize = commandSize
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// TstRandomUint64 makes the internal randomUint64 function available to the
|
// TstRandomUint64 makes the internal randomUint64 function available to the
|
||||||
|
|
12
message.go
12
message.go
|
@ -16,9 +16,9 @@ import (
|
||||||
// checksum 4 bytes.
|
// checksum 4 bytes.
|
||||||
const MessageHeaderSize = 24
|
const MessageHeaderSize = 24
|
||||||
|
|
||||||
// commandSize is the fixed size of all commands in the common bitcoin message
|
// CommandSize is the fixed size of all commands in the common bitcoin message
|
||||||
// header. Shorter commands must be zero padded.
|
// header. Shorter commands must be zero padded.
|
||||||
const commandSize = 12
|
const CommandSize = 12
|
||||||
|
|
||||||
// MaxMessagePayload is the maximum bytes a message can be regardless of other
|
// MaxMessagePayload is the maximum bytes a message can be regardless of other
|
||||||
// individual limits imposed by messages themselves.
|
// individual limits imposed by messages themselves.
|
||||||
|
@ -157,7 +157,7 @@ func readMessageHeader(r io.Reader) (int, *messageHeader, error) {
|
||||||
|
|
||||||
// Create and populate a messageHeader struct from the raw header bytes.
|
// Create and populate a messageHeader struct from the raw header bytes.
|
||||||
hdr := messageHeader{}
|
hdr := messageHeader{}
|
||||||
var command [commandSize]byte
|
var command [CommandSize]byte
|
||||||
readElements(hr, &hdr.magic, &command, &hdr.length, &hdr.checksum)
|
readElements(hr, &hdr.magic, &command, &hdr.length, &hdr.checksum)
|
||||||
|
|
||||||
// Strip trailing zeros from command string.
|
// Strip trailing zeros from command string.
|
||||||
|
@ -193,11 +193,11 @@ func WriteMessageN(w io.Writer, msg Message, pver uint32, btcnet BitcoinNet) (in
|
||||||
totalBytes := 0
|
totalBytes := 0
|
||||||
|
|
||||||
// Enforce max command size.
|
// Enforce max command size.
|
||||||
var command [commandSize]byte
|
var command [CommandSize]byte
|
||||||
cmd := msg.Command()
|
cmd := msg.Command()
|
||||||
if len(cmd) > commandSize {
|
if len(cmd) > CommandSize {
|
||||||
str := fmt.Sprintf("command [%s] is too long [max %v]",
|
str := fmt.Sprintf("command [%s] is too long [max %v]",
|
||||||
cmd, commandSize)
|
cmd, CommandSize)
|
||||||
return totalBytes, messageError("WriteMessage", str)
|
return totalBytes, messageError("WriteMessage", str)
|
||||||
}
|
}
|
||||||
copy(command[:], []byte(cmd))
|
copy(command[:], []byte(cmd))
|
||||||
|
|
Loading…
Reference in a new issue