Documentation ¶
Overview ¶
Copyright (c) 2020-2021 The bitcoinpay developers
Index ¶
- Constants
- Variables
- func Summary(msg Message) string
- func ToHex(msg Message) (string, error)
- func WriteMessage(w io.Writer, msg Message, pver uint32, net protocol.Network) error
- func WriteMessageN(w io.Writer, msg Message, pver uint32, net protocol.Network) (int, error)
- type InvType
- type InvVect
- type Message
- type MessageError
- type MsgAddr
- func (msg *MsgAddr) AddAddress(na *types.NetAddress) error
- func (msg *MsgAddr) AddAddresses(netAddrs ...*types.NetAddress) error
- func (msg *MsgAddr) ClearAddresses()
- func (msg *MsgAddr) Command() string
- func (msg *MsgAddr) Decode(r io.Reader, pver uint32) error
- func (msg *MsgAddr) Encode(w io.Writer, pver uint32) error
- func (msg *MsgAddr) MaxPayloadLength(pver uint32) uint32
- type MsgBlock
- func (msg *MsgBlock) AddTransaction(tx *MsgTx) error
- func (msg *MsgBlock) Bytes() ([]byte, error)
- func (msg *MsgBlock) ClearTransactions()
- func (msg *MsgBlock) Command() string
- func (msg *MsgBlock) Decode(r io.Reader, pver uint32) error
- func (msg *MsgBlock) Encode(w io.Writer, pver uint32) error
- func (msg *MsgBlock) FromBytes(b []byte) error
- func (msg *MsgBlock) MaxPayloadLength(pver uint32) uint32
- func (msg *MsgBlock) SerializeSize() int
- type MsgFeeFilter
- type MsgGetAddr
- type MsgGetBlocks
- type MsgGetData
- type MsgGetHeaders
- func (msg *MsgGetHeaders) AddBlockLocatorHash(hash *hash.Hash) error
- func (msg *MsgGetHeaders) Command() string
- func (msg *MsgGetHeaders) Decode(r io.Reader, pver uint32) error
- func (msg *MsgGetHeaders) Encode(w io.Writer, pver uint32) error
- func (msg *MsgGetHeaders) MaxPayloadLength(pver uint32) uint32
- func (msg *MsgGetHeaders) String() string
- type MsgGetMiningState
- type MsgGraphState
- type MsgHeaders
- func (msg *MsgHeaders) AddBlockHeader(bh *types.BlockHeader) error
- func (msg *MsgHeaders) Command() string
- func (msg *MsgHeaders) Decode(r io.Reader, pver uint32) error
- func (msg *MsgHeaders) Encode(w io.Writer, pver uint32) error
- func (msg *MsgHeaders) MaxPayloadLength(pver uint32) uint32
- func (msg *MsgHeaders) String() string
- type MsgInv
- type MsgMemPool
- type MsgMiningState
- func (msg *MsgMiningState) AddBlockHash(hash *hash.Hash) error
- func (msg *MsgMiningState) Command() string
- func (msg *MsgMiningState) Decode(r io.Reader, pver uint32) error
- func (msg *MsgMiningState) Encode(w io.Writer, pver uint32) error
- func (msg *MsgMiningState) MaxPayloadLength(pver uint32) uint32
- type MsgNotFound
- type MsgPing
- type MsgPong
- type MsgReject
- type MsgSyncDAG
- type MsgSyncPoint
- type MsgSyncResult
- type MsgTx
- type MsgVerAck
- type MsgVersion
- func (msg *MsgVersion) AddService(service protocol.ServiceFlag)
- func (msg *MsgVersion) AddUserAgent(name string, version string, comments ...string) error
- func (msg *MsgVersion) Command() string
- func (msg *MsgVersion) Decode(r io.Reader, pver uint32) error
- func (msg *MsgVersion) Encode(w io.Writer, pver uint32) error
- func (msg *MsgVersion) HasService(service protocol.ServiceFlag) bool
- func (msg *MsgVersion) MaxPayloadLength(pver uint32) uint32
- type RejectCode
Constants ¶
const ( CmdVersion = "version" CmdVerAck = "verack" CmdGetAddr = "getaddr" CmdAddr = "addr" CmdReject = "reject" CmdPing = "ping" CmdPong = "pong" CmdInv = "inv" CmdBlock = "block" CmdGetBlocks = "getblocks" CmdHeaders = "headers" CmdGetHeaders = "getheaders" CmdTx = "tx" CmdGetData = "getdata" CmdNotFound = "notfound" CmdMiningState = "miningstate" CmdGetMiningState = "getminings" CmdMemPool = "mempool" CmdGraphState = "graphstate" CmdSyncResult = "syncresult" CmdSyncDAG = "syncdag" CmdSyncPoint = "syncpoint" CmdSendHeaders = "sendheaders" CmdFeeFilter = "feefilter" CmdGetCFilter = "getcfilter" CmdGetCFHeaders = "getcfheaders" CmdGetCFTypes = "getcftypes" CmdCFilter = "cfilter" CmdCFHeaders = "cfheaders" CmdCFTypes = "cftypes" )
Commands used in message headers which describe the type of message.
const CommandSize = 12
CommandSize is the fixed size of all commands in the common message header. Shorter commands must be zero padded.
const MaxAddrPerMsg = 1000
MaxAddrPerMsg is the maximum number of addresses that can be in a single bitcoin addr message (MsgAddr).
const MaxBlockHeadersPerMsg = 2000
MaxBlockHeadersPerMsg is the maximum number of block headers that can be in a single headers message.
const MaxBlockLocatorsPerMsg = 500
MaxBlockLocatorsPerMsg is the maximum number of block locator hashes allowed per message.
const MaxBlocksPerMsg = 500
MaxBlocksPerMsg is the maximum number of blocks allowed per message.
const ( // MaxInvPerMsg is the maximum number of inventory vectors that can be in a // single inv message. MaxInvPerMsg = 50000 )
const MaxMSBlocksAtHeadPerMsg = 8
MaxMSBlocksAtHeadPerMsg is the maximum number of block hashes allowed per message.
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 MaxUserAgentLen = 256
MaxUserAgentLen is the maximum allowed length for the user agent field in a version message (MsgVersion).
const MaxVarIntPayload = 9
MaxVarIntPayload is the maximum payload size for a variable length integer.
const MessageHeaderSize = 24
MessageHeaderSize is the number of bytes in a message header. bitcoinpay network (magic) 4 bytes + command 12 bytes + payload length 4 bytes + checksum 4 bytes.
Variables ¶
var UUID = uuid.NewV4()
UUID for peer
Functions ¶
func Summary ¶
message.Summary returns a human-readable string which summarizes a message. Not all messages have or need a summary. This is used for debug logging.
func WriteMessage ¶
WriteMessage writes a Message to w including the necessary header information. This function is the same as WriteMessageN except it doesn't doesn't return the number of bytes written. This function is mainly provided for backwards compatibility with the original API, but it's also useful for callers that don't care about byte counts.
func WriteMessageN ¶
WriteMessageN writes a Message to w including the necessary header information and returns the number of bytes written. This function is the same as WriteMessage except it also returns the number of bytes written.
Types ¶
type InvType ¶
type InvType uint32
InvType represents the allowed types of inventory vectors. See InvVect.
type InvVect ¶
InvVect defines a inventory vector which is used to describe data, as specified by the Type field, that a peer wants, has, or does not have to another peer.
type Message ¶
type Message interface { Decode(io.Reader, uint32) error Encode(io.Writer, uint32) error Command() string MaxPayloadLength(uint32) uint32 }
Message is an interface that describes a Bitcoinpay message. A type that implements Message has complete control over the representation of its data and may therefore contain additional or fewer fields than those which are used directly in the protocol encoded message.
func ReadMessage ¶
ReadMessage reads, validates, and parses the next Message from r for the provided protocol version and network. It returns the parsed Message and raw bytes which comprise the message. This function only differs from ReadMessageN in that it doesn't return the number of bytes read. This function is mainly provided for backwards compatibility with the original API, but it's also useful for callers that don't care about byte counts.
func ReadMessageN ¶
ReadMessageN reads, validates, and parses the next Message from r for the provided protocol version and network. It returns the number of bytes read in addition to the parsed Message and raw bytes which comprise the message. This function is the same as ReadMessage except it also returns the number of bytes read.
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 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 (*MessageError) Error ¶
func (e *MessageError) Error() string
Error satisfies the error interface and prints human-readable errors.
type MsgAddr ¶
type MsgAddr struct {
AddrList []*types.NetAddress
}
MsgAddr implements the Message interface and represents a bitcoin addr message. It is used to provide a list of known active peers on the network. An active peer is considered one that has transmitted a message within the last 3 hours. Nodes which have not transmitted in that time frame should be forgotten. Each message is limited to a maximum number of addresses, which is currently 1000. As a result, multiple messages must be used to relay the full list.
Use the AddAddress function to build up the list of known addresses when sending an addr message to another peer.
func NewMsgAddr ¶
func NewMsgAddr() *MsgAddr
NewMsgAddr returns a new bitcoin addr message that conforms to the Message interface. See MsgAddr for details.
func (*MsgAddr) AddAddress ¶
func (msg *MsgAddr) AddAddress(na *types.NetAddress) error
AddAddress adds a known active peer to the message.
func (*MsgAddr) AddAddresses ¶
func (msg *MsgAddr) AddAddresses(netAddrs ...*types.NetAddress) error
AddAddresses adds multiple known active peers to the message.
func (*MsgAddr) ClearAddresses ¶
func (msg *MsgAddr) ClearAddresses()
ClearAddresses removes all addresses from the message.
func (*MsgAddr) Command ¶
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgAddr) Decode ¶
Decode decodes r into the receiver. This is part of the Message interface implementation.
func (*MsgAddr) Encode ¶
ncode encodes the receiver to w. This is part of the Message interface implementation.
func (*MsgAddr) MaxPayloadLength ¶
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgBlock ¶
MsgBlock implements the Message interface and represents a block message. It is used to deliver block and transaction information in response to a getdata message (MsgGetData) for a given block hash.
func NewMsgBlock ¶
func NewMsgBlock(blockHeader *types.BlockHeader) *MsgBlock
NewMsgBlock returns a new block message that conforms to the Message interface. See MsgBlock for details.
func (*MsgBlock) AddTransaction ¶
AddTransaction adds a transaction to the message.
func (*MsgBlock) ClearTransactions ¶
func (msg *MsgBlock) ClearTransactions()
ClearTransactions removes all transactions from the message.
func (*MsgBlock) Command ¶
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgBlock) Decode ¶
Decode decodes r using the protocol encoding into the receiver. This is part of the Message interface implementation. See Deserialize for decoding blocks stored to disk, such as in a database, as opposed to decoding blocks from the wire.
func (*MsgBlock) Encode ¶
Encode encodes the receiver to w using the protocol encoding. This is part of the Message interface implementation. See Serialize for encoding blocks to be stored to disk, such as in a database, as opposed to encoding blocks for the wire.
func (*MsgBlock) MaxPayloadLength ¶
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
func (*MsgBlock) SerializeSize ¶
SerializeSize returns the number of bytes it would take to serialize the the block.
type MsgFeeFilter ¶
type MsgFeeFilter struct {
MinFee int64
}
func NewMsgFeeFilter ¶
func NewMsgFeeFilter(minfee int64) *MsgFeeFilter
func (*MsgFeeFilter) Command ¶
func (msg *MsgFeeFilter) Command() string
func (*MsgFeeFilter) MaxPayloadLength ¶
func (msg *MsgFeeFilter) MaxPayloadLength(pver uint32) uint32
type MsgGetAddr ¶
type MsgGetAddr struct{}
MsgGetAddr implements the Message interface and represents a GetAddr message. It is used to request a list of known active peers on the network from a peer to help identify potential nodes. The list is returned via one or more addr messages (MsgAddr).
This message has no payload.
func NewMsgGetAddr ¶
func NewMsgGetAddr() *MsgGetAddr
NewMsgGetAddr returns a new GetAddr message that conforms to the Message interface. See MsgGetAddr for details.
func (*MsgGetAddr) Command ¶
func (msg *MsgGetAddr) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgGetAddr) Decode ¶
func (msg *MsgGetAddr) Decode(r io.Reader, pver uint32) error
Decode decodes r into the receiver. This is part of the Message interface implementation.
func (*MsgGetAddr) Encode ¶
func (msg *MsgGetAddr) Encode(w io.Writer, pver uint32) error
Encode encodes the receiver to w. This is part of the Message interface implementation.
func (*MsgGetAddr) MaxPayloadLength ¶
func (msg *MsgGetAddr) MaxPayloadLength(pver uint32) uint32
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgGetBlocks ¶
type MsgGetBlocks struct { ProtocolVersion uint32 BlockLocatorHashes []*hash.Hash GS *blockdag.GraphState }
MsgGetBlocks implements the Message interface and represents a getblocks message. It is used to request a list of blocks starting after the last known hash in the slice of block locator hashes. The list is returned via an inv message (MsgInv) and is limited by a specific hash to stop at or the maximum number of blocks per message.
Set the HashStop field to the hash at which to stop and use AddBlockLocatorHash to build up the list of block locator hashes.
The algorithm for building the block locator hashes should be to add the hashes in reverse order until you reach the genesis block. In order to keep the list of locator hashes to a reasonable number of entries, first add the most recent 10 block hashes, then double the step each loop iteration to exponentially decrease the number of hashes the further away from head and closer to the genesis block you get.
func NewMsgGetBlocks ¶
func NewMsgGetBlocks(gs *blockdag.GraphState) *MsgGetBlocks
NewMsgGetBlocks returns a new getblocks message that conforms to the Message interface using the passed parameters and defaults for the remaining fields.
func (*MsgGetBlocks) AddBlockLocatorHash ¶
func (msg *MsgGetBlocks) AddBlockLocatorHash(hash *hash.Hash) error
AddBlockLocatorHash adds a new block locator hash to the message.
func (*MsgGetBlocks) Command ¶
func (msg *MsgGetBlocks) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgGetBlocks) Decode ¶
func (msg *MsgGetBlocks) Decode(r io.Reader, pver uint32) error
Decode decodes r using the protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgGetBlocks) Encode ¶
func (msg *MsgGetBlocks) Encode(w io.Writer, pver uint32) error
Encode encodes the receiver to w using the protocol encoding. This is part of the Message interface implementation.
func (*MsgGetBlocks) MaxPayloadLength ¶
func (msg *MsgGetBlocks) MaxPayloadLength(pver uint32) uint32
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgGetData ¶
type MsgGetData struct {
InvList []*InvVect
}
MsgGetData implements the Message interface and represents a getdata message. It is used to request data such as blocks and transactions from another peer. It should be used in response to the inv (MsgInv) message to request the actual data referenced by each inventory vector the receiving peer doesn't already have. Each message is limited to a maximum number of inventory vectors, which is currently 50,000. As a result, multiple messages must be used to request larger amounts of data.
Use the AddInvVect function to build up the list of inventory vectors when sending a getdata message to another peer.
func NewMsgGetData ¶
func NewMsgGetData() *MsgGetData
NewMsgGetData returns a new getdata message that conforms to the Message interface. See MsgGetData for details.
func NewMsgGetDataSizeHint ¶
func NewMsgGetDataSizeHint(sizeHint uint) *MsgGetData
NewMsgGetDataSizeHint returns a new getdata message that conforms to the Message interface. See MsgGetData for details. This function differs from NewMsgGetData in that it allows a default allocation size for the backing array which houses the inventory vector list. This allows callers who know in advance how large the inventory list will grow to avoid the overhead of growing the internal backing array several times when appending large amounts of inventory vectors with AddInvVect. Note that the specified hint is just that - a hint that is used for the default allocation size. Adding more (or less) inventory vectors will still work properly. The size hint is limited to MaxInvPerMsg.
func (*MsgGetData) AddInvVect ¶
func (msg *MsgGetData) AddInvVect(iv *InvVect) error
AddInvVect adds an inventory vector to the message.
func (*MsgGetData) Command ¶
func (msg *MsgGetData) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgGetData) Decode ¶
func (msg *MsgGetData) Decode(r io.Reader, pver uint32) error
BtcDecode decodes r using the protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgGetData) Encode ¶
func (msg *MsgGetData) Encode(w io.Writer, pver uint32) error
BtcEncode encodes the receiver to w using the protocol encoding. This is part of the Message interface implementation.
func (*MsgGetData) MaxPayloadLength ¶
func (msg *MsgGetData) MaxPayloadLength(pver uint32) uint32
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgGetHeaders ¶
type MsgGetHeaders struct { ProtocolVersion uint32 BlockLocatorHashes []*hash.Hash GS *blockdag.GraphState }
MsgGetHeaders implements the Message interface and represents a getheaders message. It is used to request a list of block headers for blocks starting after the last known hash in the slice of block locator hashes. The list is returned via a headers message (MsgHeaders) and is limited by a specific hash to stop at or the maximum number of block headers per message,
Set the HashStop field to the hash at which to stop and use AddBlockLocatorHash to build up the list of block locator hashes.
The algorithm for building the block locator hashes should be to add the hashes in reverse order until you reach the genesis block. In order to keep the list of locator hashes to a resonable number of entries, first add the most recent 10 block hashes, then double the step each loop iteration to exponentially decrease the number of hashes the further away from head and closer to the genesis block you get.
func NewMsgGetHeaders ¶
func NewMsgGetHeaders(gs *blockdag.GraphState) *MsgGetHeaders
NewMsgGetHeaders returns a new getheaders message that conforms to the Message interface. See MsgGetHeaders for details.
func (*MsgGetHeaders) AddBlockLocatorHash ¶
func (msg *MsgGetHeaders) AddBlockLocatorHash(hash *hash.Hash) error
AddBlockLocatorHash adds a new block locator hash to the message.
func (*MsgGetHeaders) Command ¶
func (msg *MsgGetHeaders) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgGetHeaders) Decode ¶
func (msg *MsgGetHeaders) Decode(r io.Reader, pver uint32) error
Decode decodes r using the protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgGetHeaders) Encode ¶
func (msg *MsgGetHeaders) Encode(w io.Writer, pver uint32) error
Encode encodes the receiver to w using the protocol encoding. This is part of the Message interface implementation.
func (*MsgGetHeaders) MaxPayloadLength ¶
func (msg *MsgGetHeaders) MaxPayloadLength(pver uint32) uint32
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
func (*MsgGetHeaders) String ¶
func (msg *MsgGetHeaders) String() string
type MsgGetMiningState ¶
type MsgGetMiningState struct{}
MsgGetMiningState implements the Message interface and represents a getminingstate message. It is used to request the current mining state from a peer.
func NewMsgGetMiningState ¶
func NewMsgGetMiningState() *MsgGetMiningState
NewMsgGetMiningState returns a new getminingstate message that conforms to the Message interface. See MsgPong for details.
func (*MsgGetMiningState) Command ¶
func (msg *MsgGetMiningState) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgGetMiningState) Decode ¶
func (msg *MsgGetMiningState) Decode(r io.Reader, pver uint32) error
Decode decodes r using the protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgGetMiningState) Encode ¶
func (msg *MsgGetMiningState) Encode(w io.Writer, pver uint32) error
Encode encodes the receiver to w using the protocol encoding. This is part of the Message interface implementation.
func (*MsgGetMiningState) MaxPayloadLength ¶
func (msg *MsgGetMiningState) MaxPayloadLength(pver uint32) uint32
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgGraphState ¶
type MsgGraphState struct {
GS *blockdag.GraphState
}
func NewMsgGraphState ¶
func NewMsgGraphState(gs *blockdag.GraphState) *MsgGraphState
func (*MsgGraphState) Command ¶
func (msg *MsgGraphState) Command() string
func (*MsgGraphState) MaxPayloadLength ¶
func (msg *MsgGraphState) MaxPayloadLength(pver uint32) uint32
type MsgHeaders ¶
type MsgHeaders struct { Headers []*types.BlockHeader GS *blockdag.GraphState }
MsgHeaders implements the Message interface and represents a headers message. It is used to deliver block header information in response to a getheaders message (MsgGetHeaders). The maximum number of block headers per message is currently 2000. See MsgGetHeaders for details on requesting the headers.
func NewMsgHeaders ¶
func NewMsgHeaders(gs *blockdag.GraphState) *MsgHeaders
NewMsgHeaders returns a new headers message that conforms to the Message interface. See MsgHeaders for details.
func (*MsgHeaders) AddBlockHeader ¶
func (msg *MsgHeaders) AddBlockHeader(bh *types.BlockHeader) error
AddBlockHeader adds a new block header to the message.
func (*MsgHeaders) Command ¶
func (msg *MsgHeaders) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgHeaders) Decode ¶
func (msg *MsgHeaders) Decode(r io.Reader, pver uint32) error
Decode decodes r using the protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgHeaders) Encode ¶
func (msg *MsgHeaders) Encode(w io.Writer, pver uint32) error
Encode encodes the receiver to w using the protocol encoding. This is part of the Message interface implementation.
func (*MsgHeaders) MaxPayloadLength ¶
func (msg *MsgHeaders) MaxPayloadLength(pver uint32) uint32
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
func (*MsgHeaders) String ¶
func (msg *MsgHeaders) String() string
type MsgInv ¶
type MsgInv struct { GS *blockdag.GraphState InvList []*InvVect }
MsgInv implements the Message interface and represents a inv message. It is used to advertise a peer's known data such as blocks and transactions through inventory vectors. It may be sent unsolicited to inform other peers of the data or in response to a getblocks message (MsgGetBlocks). Each message is limited to a maximum number of inventory vectors, which is currently 50,000.
Use the AddInvVect function to build up the list of inventory vectors when sending an inv message to another peer.
func NewMsgInv ¶
func NewMsgInv() *MsgInv
NewMsgInv returns a new inv message that conforms to the Message interface. See MsgInv for details.
func NewMsgInvSizeHint ¶
NewMsgInvSizeHint returns a new inv message that conforms to the Message interface. See MsgInv for details. This function differs from NewMsgInv in that it allows a default allocation size for the backing array which houses the inventory vector list. This allows callers who know in advance how large the inventory list will grow to avoid the overhead of growing the internal backing array several times when appending large amounts of inventory vectors with AddInvVect. Note that the specified hint is just that - a hint that is used for the default allocation size. Adding more (or less) inventory vectors will still work properly. The size hint is limited to MaxInvPerMsg.
func (*MsgInv) AddInvVect ¶
AddInvVect adds an inventory vector to the message.
func (*MsgInv) Command ¶
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgInv) Decode ¶
Decode decodes r using the protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgInv) Encode ¶
Encode encodes the receiver to w using the protocol encoding. This is part of the Message interface implementation.
func (*MsgInv) MaxPayloadLength ¶
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgMemPool ¶
type MsgMemPool struct{}
func NewMsgMemPool ¶
func NewMsgMemPool() *MsgMemPool
func (*MsgMemPool) Command ¶
func (msg *MsgMemPool) Command() string
func (*MsgMemPool) MaxPayloadLength ¶
func (msg *MsgMemPool) MaxPayloadLength(pver uint32) uint32
type MsgMiningState ¶
MsgMiningState implements the Message interface and represents a mining state message. It is used to request a list of blocks located at the chain tip The list is returned is limited by the maximum number of blocks per message message.
func NewMsgMiningState ¶
func NewMsgMiningState() *MsgMiningState
NewMsgMiningState returns a new miningstate message that conforms to the Message interface using the defaults for the fields.
func (*MsgMiningState) AddBlockHash ¶
func (msg *MsgMiningState) AddBlockHash(hash *hash.Hash) error
AddBlockHash adds a new block hash to the message.
func (*MsgMiningState) Command ¶
func (msg *MsgMiningState) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgMiningState) Decode ¶
func (msg *MsgMiningState) Decode(r io.Reader, pver uint32) error
Decode decodes r using the protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgMiningState) Encode ¶
func (msg *MsgMiningState) Encode(w io.Writer, pver uint32) error
Encode encodes the receiver to w using the protocol encoding. This is part of the Message interface implementation.
func (*MsgMiningState) MaxPayloadLength ¶
func (msg *MsgMiningState) MaxPayloadLength(pver uint32) uint32
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgNotFound ¶
type MsgNotFound struct {
InvList []*InvVect
}
MsgNotFound defines a notfound message which is sent in response to a getdata message if any of the requested data in not available on the peer. Each message is limited to a maximum number of inventory vectors, which is currently 50,000.
Use the AddInvVect function to build up the list of inventory vectors when sending a notfound message to another peer.
func NewMsgNotFound ¶
func NewMsgNotFound() *MsgNotFound
NewMsgNotFound returns a new notfound message that conforms to the Message interface. See MsgNotFound for details.
func (*MsgNotFound) AddInvVect ¶
func (msg *MsgNotFound) AddInvVect(iv *InvVect) error
AddInvVect adds an inventory vector to the message.
func (*MsgNotFound) Command ¶
func (msg *MsgNotFound) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgNotFound) Decode ¶
func (msg *MsgNotFound) Decode(r io.Reader, pver uint32) error
Decode decodes r using the protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgNotFound) Encode ¶
func (msg *MsgNotFound) Encode(w io.Writer, pver uint32) error
Encode encodes the receiver to w using the protocol encoding. This is part of the Message interface implementation.
func (*MsgNotFound) MaxPayloadLength ¶
func (msg *MsgNotFound) MaxPayloadLength(pver uint32) uint32
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgPing ¶
type MsgPing struct { // Unique value associated with message that is used to identify // specific ping message. Nonce uint64 }
MsgPing implements the Message interface and represents a ping message.
The payload for this message just consists of a nonce used for identifying it later.
func NewMsgPing ¶
NewMsgPing returns a new ping message that conforms to the Message interface. See MsgPing for details.
func (*MsgPing) Command ¶
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgPing) Decode ¶
Decode decodes r using the protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgPing) Encode ¶
Encode encodes the receiver to w using the protocol encoding. This is part of the Message interface implementation.
func (*MsgPing) MaxPayloadLength ¶
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgPong ¶
type MsgPong struct { // Unique value associated with message that is used to identify // specific ping message. Nonce uint64 }
MsgPong implements the Message interface and represents a pong message which is used primarily to confirm that a connection is still valid in response to a ping message (MsgPing).
func NewMsgPong ¶
NewMsgPong returns a new pong message that conforms to the Message interface. See MsgPong for details.
func (*MsgPong) Command ¶
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgPong) Decode ¶
BtcDecode decodes r using the protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgPong) Encode ¶
BtcEncode encodes the receiver to w using the protocol encoding. This is part of the Message interface implementation.
func (*MsgPong) MaxPayloadLength ¶
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgReject ¶
type MsgReject struct { // Cmd is the command for the message which was rejected such as // as CmdBlock or CmdTx. This can be obtained from the Command function // of a Message. Cmd string // RejectCode is a code indicating why the command was rejected. It // is encoded as a uint8 on the wire. Code RejectCode // Reason is a human-readable string with specific details (over and // above the reject code) about why the command was rejected. Reason string // Hash identifies a specific block or transaction that was rejected // and therefore only applies the MsgBlock and MsgTx messages. Hash hash.Hash }
MsgReject implements the Message interface and represents an reject message.
This message was not added until protocol version RejectVersion.
func NewMsgReject ¶
func NewMsgReject(command string, code RejectCode, reason string) *MsgReject
NewMsgReject returns a new reject message that conforms to the Message interface. See MsgReject for details.
func (*MsgReject) Command ¶
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgReject) Decode ¶
Decode decodes r encoding into the receiver. This is part of the Message interface implementation.
func (*MsgReject) Encode ¶
Encode encodes the receiver to w. This is part of the Message interface implementation.
func (*MsgReject) MaxPayloadLength ¶
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgSyncDAG ¶
type MsgSyncDAG struct { MainLocator []*hash.Hash GS *blockdag.GraphState }
func NewMsgSyncDAG ¶
func NewMsgSyncDAG(gs *blockdag.GraphState, locator []*hash.Hash) *MsgSyncDAG
func (*MsgSyncDAG) Command ¶
func (msg *MsgSyncDAG) Command() string
func (*MsgSyncDAG) MaxPayloadLength ¶
func (msg *MsgSyncDAG) MaxPayloadLength(pver uint32) uint32
type MsgSyncPoint ¶
type MsgSyncPoint struct { SyncPoint *hash.Hash GS *blockdag.GraphState }
func NewMsgSyncPoint ¶
func NewMsgSyncPoint(gs *blockdag.GraphState, point *hash.Hash) *MsgSyncPoint
func (*MsgSyncPoint) Command ¶
func (msg *MsgSyncPoint) Command() string
func (*MsgSyncPoint) MaxPayloadLength ¶
func (msg *MsgSyncPoint) MaxPayloadLength(pver uint32) uint32
type MsgSyncResult ¶
type MsgSyncResult struct { GS *blockdag.GraphState Mode blockdag.SyncMode }
func NewMsgSyncResult ¶
func NewMsgSyncResult(gs *blockdag.GraphState, mode blockdag.SyncMode) *MsgSyncResult
func (*MsgSyncResult) Command ¶
func (msg *MsgSyncResult) Command() string
func (*MsgSyncResult) MaxPayloadLength ¶
func (msg *MsgSyncResult) MaxPayloadLength(pver uint32) uint32
type MsgTx ¶
type MsgTx struct {
Tx *types.Transaction
}
func (*MsgTx) Command ¶
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgTx) Decode ¶
Decode decodes r into the receiver. This is part of the Message interface implementation.
See Deserialize for decoding transactions stored to disk, such as in a database, as opposed to decoding transactions from the wire.
func (*MsgTx) Encode ¶
Encode encodes the receiver to w. This is part of the Message interface implementation.
See Serialize for encoding transactions to be stored to disk, such as in a database, as opposed to encoding transactions for the wire.
func (*MsgTx) MaxPayloadLength ¶
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgVerAck ¶
type MsgVerAck struct{}
MsgVerAck defines a Verack message which is used for a peer to acknowledge a version message (MsgVersion) after it has used the information to negotiate parameters.
It implements the Message interface. This message has no payload.
func NewMsgVerAck ¶
func NewMsgVerAck() *MsgVerAck
NewMsgVerAck returns a new VerAck message that conforms to the Message interface.
func (*MsgVerAck) Command ¶
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgVerAck) Decode ¶
Decode decodes r into the receiver. This is part of the Message interface implementation.
func (*MsgVerAck) Encode ¶
Encode encodes the receiver to w. This is part of the Message interface implementation.
func (*MsgVerAck) MaxPayloadLength ¶
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgVersion ¶
type MsgVersion struct { // Version of the protocol the node is using. ProtocolVersion int32 // Bitfield which identifies the enabled services. Services protocol.ServiceFlag // Time the message was generated. This is encoded as an int64 on the wire. Timestamp time.Time // Address of the remote peer. AddrYou types.NetAddress // Address of the local peer. AddrMe types.NetAddress // Unique value associated with message that is used to detect self // connections. Nonce uint64 // The user agent that generated messsage. This is a encoded as a varString // on the wire. This has a max length of MaxUserAgentLen. UserAgent string // Last DAG graph state seen by the generator of the version message. LastGS *blockdag.GraphState // Don't announce transactions to peer. DisableRelayTx bool }
MsgVersion implements the Message interface and represents a version message. It is used for a peer to advertise itself as soon as an outbound connection is made. The remote peer then uses this information along with its own to negotiate. The remote peer must then respond with a version message of its own containing the negotiated values followed by a verack message (MsgVerAck). This exchange must take place before any further communication is allowed to proceed.
func NewMsgVersion ¶
func NewMsgVersion(me *types.NetAddress, you *types.NetAddress, nonce uint64, lastGS *blockdag.GraphState) *MsgVersion
NewMsgVersion returns a new Version message that conforms to the Message interface using the passed parameters and defaults for the remaining fields.
func NewMsgVersionFromConn ¶
func NewMsgVersionFromConn(conn net.Conn, nonce uint64, lastGS *blockdag.GraphState) (*MsgVersion, error)
NewMsgVersionFromConn is a convenience function that extracts the remote and local address from conn and returns a new version message that conforms to the Message interface. See NewMsgVersion.
func (*MsgVersion) AddService ¶
func (msg *MsgVersion) AddService(service protocol.ServiceFlag)
AddService adds service as a supported service by the peer generating the message.
func (*MsgVersion) AddUserAgent ¶
func (msg *MsgVersion) AddUserAgent(name string, version string, comments ...string) error
AddUserAgent adds a user agent to the user agent string for the version message. The version string is not defined to any strict format, although it is recommended to use the form "major.minor.revision" e.g. "2.6.41".
func (*MsgVersion) Command ¶
func (msg *MsgVersion) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgVersion) Decode ¶
func (msg *MsgVersion) Decode(r io.Reader, pver uint32) error
Decode decodes r encoding into the receiver. The version message is special in that the protocol version hasn't been negotiated yet. As a result, the pver field is ignored and any fields which are added in new versions are optional. This also mean that r must be a *bytes.Buffer so the number of remaining bytes can be ascertained.
This is part of the Message interface implementation.
func (*MsgVersion) Encode ¶
func (msg *MsgVersion) Encode(w io.Writer, pver uint32) error
Encode encodes the receiver to w This is part of the Message interface implementation.
func (*MsgVersion) HasService ¶
func (msg *MsgVersion) HasService(service protocol.ServiceFlag) bool
HasService returns whether the specified service is supported by the peer that generated the message.
func (*MsgVersion) MaxPayloadLength ¶
func (msg *MsgVersion) MaxPayloadLength(pver uint32) uint32
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
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 RejectBan RejectCode = 0x50 RejectMaxInbound RejectCode = 0x51 )
These constants define the various supported reject codes.
func (RejectCode) String ¶
func (code RejectCode) String() string
String returns the RejectCode in human-readable form.
Source Files ¶
- error.go
- invvect.go
- message.go
- message_summary.go
- msgaddr.go
- msgblock.go
- msgfeefilter.go
- msggetaddr.go
- msggetblocks.go
- msggetdata.go
- msggetheaders.go
- msggetminingstate.go
- msggraphstate.go
- msgheaders.go
- msginv.go
- msgmempool.go
- msgminingstate.go
- msgnotfound.go
- msgping.go
- msgpong.go
- msgreject.go
- msgsyncdag.go
- msgsyncpoint.go
- msgsyncresult.go
- msgtx.go
- msgverack.go
- msgversion.go