Documentation
¶
Index ¶
- Constants
- Variables
- func HashToBig(hash *chainhash.Hash) *big.Int
- func RandomUint64() (uint64, error)
- func ReadElement(r io.Reader, element interface{}) error
- func ReadElements(r io.Reader, elements ...interface{}) error
- func ReadVarBytes(r io.Reader, pver uint32, maxAllowed uint32, fieldName string) ([]byte, error)
- func ReadVarInt(r io.Reader, pver uint32) (uint64, error)
- func ReadVarString(r io.Reader, pver uint32) (string, error)
- func SafeMul(x, y uint64) (uint64, bool)
- func VarIntSerializeSize(val uint64) int
- func WriteElement(w io.Writer, element interface{}) error
- func WriteElements(w io.Writer, elements ...interface{}) error
- func WriteVarBytes(w io.Writer, pver uint32, bytes []byte) error
- func WriteVarInt(w io.Writer, pver uint32, val uint64) error
- func WriteVarString(w io.Writer, pver uint32, str string) error
- type BloomUpdateType
- type Int64Time
- type InvType
- type MessageError
- type OmegaNet
- type RejectCode
- type ServiceFlag
- type Uint32Time
Constants ¶
const ( // MaxVarIntPayload is the maximum payload size for a variable length integer. MaxVarIntPayload = 9 // MinTxOutPayload is the minimum payload size for a transaction output. // Value 8 bytes + Varint for PkScript length 1 byte. MinTxOutPayload = 9 // binaryFreeListMaxItems is the number of buffers to keep in the free // list to use for binary serialization and deserialization. BinaryFreeListMaxItems = 1024 )
const ( // InvWitnessFlag denotes that the inventory vector type is requesting, // or sending a version which includes witness data. InvWitnessFlag = 1 << 30 InvTempFlag = 1 << 29 )
These constants define the various supported inventory vector types.
const CommandSize = 12
const MaxMessagePayload = (1024 * 1024 * 32) // 32MB
MaxMessagePayload is the maximum bytes a message can be regardless of other individual limits imposed by messages themselves.
const (
MaxUint64 = 1<<64 - 1
)
Variables ¶
var ( // littleEndian is a convenience variable since binary.LittleEndian is // quite long. LittleEndian = binary.LittleEndian // bigEndian is a convenience variable since binary.BigEndian is quite // long. BigEndian = binary.BigEndian )
var BinarySerializer binaryFreeList = make(chan []byte, BinaryFreeListMaxItems)
binarySerializer provides a free list of buffers to use for serializing and deserializing primitive integer values to and from io.Readers and io.Writers.
Functions ¶
func HashToBig ¶
HashToBig converts a chainhash.Hash into a big.Int that can be used to perform math comparisons.
func RandomUint64 ¶
RandomUint64 returns a cryptographically random uint64 value.
func ReadElement ¶
ReadElement reads the next sequence of bytes from r using little endian depending on the concrete type of element pointed to.
func ReadElements ¶
ReadElements reads multiple items from r. It is equivalent to multiple calls to readElement.
func ReadVarBytes ¶
ReadVarBytes reads a variable length byte array. A byte array is encoded as a varInt containing the length of the array followed by the bytes themselves. An error is returned if the length is greater than the passed maxAllowed parameter which helps protect against memory exhaustion attacks and forced panics through malformed messages. The fieldName parameter is only used for the error message so it provides more context in the error.
func ReadVarInt ¶
ReadVarInt reads a variable length integer from r and returns it as a uint64.
func ReadVarString ¶
ReadVarString reads a variable length string from r and returns it as a Go string. A variable length string is encoded as a variable length integer containing the length of the string followed by the bytes that represent the string itself. An error is returned if the length is greater than the maximum block payload size since it helps protect against memory exhaustion attacks and forced panics through malformed messages.
func VarIntSerializeSize ¶
VarIntSerializeSize returns the number of bytes it would take to serialize val as a variable length integer.
func WriteElement ¶
writeElement writes the little endian representation of element to w.
func WriteElements ¶
writeElements writes multiple items to w. It is equivalent to multiple calls to writeElement.
func WriteVarBytes ¶
WriteVarBytes serializes a variable length byte array to w as a varInt containing the number of bytes, followed by the bytes themselves.
func WriteVarInt ¶
WriteVarInt serializes val to w using a variable number of bytes depending on its value.
Types ¶
type BloomUpdateType ¶
type BloomUpdateType uint8
BloomUpdateType specifies how the filter is updated when a match is found
type Int64Time ¶
int64Time represents a unix timestamp encoded with an int64. It is used as a way to signal the readElement function how to decode a timestamp into a Go time.Time since it is otherwise ambiguous.
type InvType ¶
type InvType uint32
InvType represents the allowed types of inventory vectors. See InvVect.
const ( InvTypeError InvType = 0 InvTypeTx InvType = 1 InvTypeBlock InvType = 2 InvTypeFilteredBlock InvType = 3 InvTypeTempBlock InvType = InvTypeBlock | InvTempFlag InvTypeMinerBlock InvType = 5 InvTypeWitnessBlock InvType = InvTypeBlock | InvWitnessFlag InvTypeMask InvType = 7 InvTypeWitnessTx InvType = InvTypeTx | InvWitnessFlag )
These constants define the various supported inventory vector types.
type MessageError ¶
type MessageError struct { Func string // Function name Description string // Human readable description of the issue }
MessageError describes an issue with a message. An example of some potential issues are messages from the wrong bitcoin network, invalid commands, mismatched checksums, and exceeding max payloads.
This provides a mechanism for the caller to type assert the error to differentiate between general io errors such as io.EOF and issues that resulted from malformed messages.
func NewMessageError ¶
func NewMessageError(f string, desc string) *MessageError
messageError creates an error for the given function and description.
func (*MessageError) Error ¶
func (e *MessageError) Error() string
Error satisfies the error interface and prints human-readable errors.
type OmegaNet ¶
type OmegaNet uint32
OmegaNet represents which bitcoin network a message belongs to.
const ( // MainNet represents the main bitcoin network. MainNet OmegaNet = 0x956ca366 // RegNet represents the regression test network. RegNet OmegaNet = 0x6241456c // TestNet represents the test network. TestNet OmegaNet = 0x709c5fed // SimNet represents the simulation test network. SimNet OmegaNet = 0xe10b70ad )
Constants used to indicate the message network. They can also be used to seek to the next message when a stream's state is unknown, but this package does not provide that functionality since it's generally a better idea to simply disconnect clients that are misbehaving over TCP.
type RejectCode ¶
type RejectCode uint8
RejectCode represents a numeric value by which a remote peer indicates why a message was rejected.
const ( RejectMalformed RejectCode = 0x01 RejectInvalid RejectCode = 0x10 RejectObsolete RejectCode = 0x11 RejectDuplicate RejectCode = 0x12 RejectNonstandard RejectCode = 0x40 // RejectDust RejectCode = 0x41 RejectInsufficientFee RejectCode = 0x42 RejectCheckpoint RejectCode = 0x43 )
These constants define the various supported reject codes.
func (RejectCode) String ¶
func (code RejectCode) String() string
String returns the RejectCode in human-readable form.
type ServiceFlag ¶
type ServiceFlag uint64
ServiceFlag identifies services supported by a bitcoin peer.
const ( // SFNodeNetwork is a flag used to indicate a peer is a full node. SFNodeNetwork ServiceFlag = 1 << iota // SFNodeGetUTXO is a flag used to indicate a peer supports the // getutxos and utxos commands (BIP0064). SFNodeGetUTXO // SFNodeBloom is a flag used to indicate a peer supports bloom // filtering. SFNodeBloom // SFNodeXthin is a flag used to indicate a peer supports xthin blocks. SFNodeXthin // SFNodeBit5 is a flag used to indicate a peer supports a service // defined by bit 5. SFNodeBit5 // SFNodeCF is a flag used to indicate a peer supports committed // filters (CFs). SFNodeCF // SFNode2X is a flag used to indicate a peer is running the Segwit2X // software. SFNode2X )
func (ServiceFlag) String ¶
func (f ServiceFlag) String() string
String returns the ServiceFlag in human-readable form.
type Uint32Time ¶
uint32Time represents a unix timestamp encoded with a uint32. It is used as a way to signal the readElement function how to decode a timestamp into a Go time.Time since it is otherwise ambiguous.