wire

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2018 License: BSD-2-Clause Imports: 15 Imported by: 31

Documentation

Index

Constants

View Source
const (
	CmdVersion     = "version"
	CmdVerAck      = "verack"
	CmdGetAddr     = "getaddr"
	CmdAddr        = "addr"
	CmdGetBlocks   = "getblocks"
	CmdInv         = "inv"
	CmdGetData     = "getdata"
	CmdNotFound    = "notfound"
	CmdBlock       = "block"
	CmdTx          = "tx"
	CmdGetHeaders  = "getheaders"
	CmdHeaders     = "headers"
	CmdPing        = "ping"
	CmdPong        = "pong"
	CmdAlert       = "alert"
	CmdMemPool     = "mempool"
	CmdFilterAdd   = "filteradd"
	CmdFilterClear = "filterclear"
	CmdFilterLoad  = "filterload"
	CmdMerkleBlock = "merkleblock"
	CmdReject      = "reject"
	CmdSendHeaders = "sendheaders"
	CmdFeeFilter   = "feefilter"
	CmdSendCmpct   = "sendcmpct"
	CmdCmpctBlock  = "cmpctblock"
	CmdGetBlockTxn = "getblocktxn"
	CmdBlockTxn    = "blocktxn"
)

Commands used in bitcoin message headers which describe the type of message.

View Source
const (
	// MaxFilterLoadHashFuncs is the maximum number of hash functions to
	// load into the Bloom filter.
	MaxFilterLoadHashFuncs = 50

	// MaxFilterLoadFilterSize is the maximum size in bytes a filter may be.
	MaxFilterLoadFilterSize = 36000
)
View Source
const (
	// ProtocolVersion is the latest protocol version this package supports.
	ProtocolVersion uint32 = 70013

	// MultipleAddressVersion is the protocol version which added multiple
	// addresses per message (pver >= MultipleAddressVersion).
	MultipleAddressVersion uint32 = 209

	// GetHeadersVersion is where 'getheaders' was introduced.
	GetHeadersVersion uint32 = 31800

	// NetAddressTimeVersion is the protocol version which added the
	// timestamp field (pver >= NetAddressTimeVersion).
	NetAddressTimeVersion uint32 = 31402

	// BIP0031Version is the protocol version AFTER which a pong message
	// and nonce field in ping were added (pver > BIP0031Version).
	BIP0031Version uint32 = 60000

	// BIP0035Version is the protocol version which added the mempool
	// message (pver >= BIP0035Version).
	BIP0035Version uint32 = 60002

	// BIP0037Version is the protocol version which added new connection
	// bloom filtering related messages and extended the version message
	// with a relay flag (pver >= BIP0037Version).
	BIP0037Version uint32 = 70001

	// RejectVersion is the protocol version which added a new reject
	// message.
	RejectVersion uint32 = 70002

	// BIP0111Version is the protocol version which added the SFNodeBloom
	// service flag.
	BIP0111Version uint32 = 70011

	// SendHeadersVersion is the protocol version which added a new
	// sendheaders message.
	SendHeadersVersion uint32 = 70012

	// FeeFilterVersion is the protocol version which added a new
	// feefilter message.
	FeeFilterVersion uint32 = 70013

	// ShortIdsBlocksVersion is the version which short-id-based block download starts with
	ShortIdsBlocksVersion uint32 = 70014

	//InvalidCBNoBanVersion is the version which not banning for invalid compact blocks starts with
	InvalidCBNoBanVersion uint32 = 70015
)
View Source
const CommandSize = 12

CommandSize is the fixed size of all commands in the common bitcoin message header. Shorter commands must be zero padded.

View Source
const DefaultUserAgent = "/copernicus/"

DefaultUserAgent for wire in the stack

View Source
const MaxAddrPerMsg = 1000

MaxAddrPerMsg is the maximum number of addresses that can be in a single bitcoin addr message (MsgAddr).

View Source
const MaxBlockHeaderPayload = 16 + (util.Hash256Size * 2)

MaxBlockHeaderPayload is the maximum number of bytes a block header can be. Version 4 bytes + Timestamp 4 bytes + Bits 4 bytes + Nonce 4 bytes + PrevBlock and MerkleRoot hashes.

View Source
const MaxBlockHeadersPerMsg = 2000

MaxBlockHeadersPerMsg is the maximum number of block headers that can be in a single bitcoin headers message.

View Source
const MaxBlockLocatorsPerMsg = 500

MaxBlockLocatorsPerMsg is the maximum number of block locator hashes allowed per message.

View Source
const MaxBlockPayload = 32 * util.OneMegaByte

MaxBlockPayload is the maximum bytes a block message can be in bytes.

View Source
const MaxBlocksPerMsg = 500

MaxBlocksPerMsg is the maximum number of blocks allowed per message.

View Source
const (
	// MaxFilterAddDataSize is the maximum byte size of a data
	// element to add to the Bloom filter.  It is equal to the
	// maximum element size of a script.
	MaxFilterAddDataSize = 520
)
View Source
const (
	// MaxInvPerMsg is the maximum number of inventory vectors that can be in a
	// single bitcoin inv message.
	MaxInvPerMsg = 50000
)
View Source
const MaxMessagePayload = (1024 * 1024 * 32) // 32MB

MaxMessagePayload is the maximum bytes a message can be regardless of other individual limits imposed by messages themselves.

View Source
const MaxProtocolMessageLength = 2 * 1024 * 1024

MaxProtocolMessageLength length of incoming protocol messages (Currently 2MB). NB: Messages propagating block content are not subject to this limit.

View Source
const MaxUserAgentLen = 256

MaxUserAgentLen is the maximum allowed length for the user agent field in a version message (MsgVersion).

View Source
const (
	// MaxVarIntPayload is the maximum payload size for a variable length integer.
	MaxVarIntPayload = 9
)
View Source
const MessageHeaderSize = 24

MessageHeaderSize is the number of bytes in a bitcoin message header. Bitcoin network (magic) 4 bytes + command 12 bytes + payload length 4 bytes + checksum 4 bytes.

Variables

View Source
var LatestEncoding = BaseEncoding

LatestEncoding is the most recently specified encoding for the Bitcoin wire protocol.

Functions

func WriteMessage

func WriteMessage(w io.Writer, msg Message, pver uint32, btcnet BitcoinNet) error

WriteMessage writes a bitcoin 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

func WriteMessageN(w io.Writer, msg Message, pver uint32, btcnet BitcoinNet) (int, error)

WriteMessageN writes a bitcoin 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.

func WriteMessageWithEncodingN

func WriteMessageWithEncodingN(w io.Writer, msg Message, pver uint32,
	btcnet BitcoinNet, encoding MessageEncoding) (int, error)

WriteMessageWithEncodingN writes a bitcoin Message to w including the necessary header information and returns the number of bytes written. This function is the same as WriteMessageN except it also allows the caller to specify the message encoding format to be used when serializing wire messages.

Types

type Alert

type Alert struct {
	// Alert format version
	Version int32

	// Timestamp beyond which nodes should stop relaying this alert
	RelayUntil int64

	// Timestamp beyond which this alert is no longer in effect and
	// should be ignored
	Expiration int64

	// A unique ID number for this alert
	ID int32

	// All alerts with an ID less than or equal to this number should
	// cancelled, deleted and not accepted in the future
	Cancel int32

	// All alert IDs contained in this set should be cancelled as above
	SetCancel []int32

	// This alert only applies to versions greater than or equal to this
	// version. Other versions should still relay it.
	MinVer int32

	// This alert only applies to versions less than or equal to this version.
	// Other versions should still relay it.
	MaxVer int32

	// If this set contains any elements, then only nodes that have their
	// subVer contained in this set are affected by the alert. Other versions
	// should still relay it.
	SetSubVer []string

	// Relative priority compared to other alerts
	Priority int32

	// A comment on the alert that is not displayed
	Comment string

	// The alert message that is displayed to the user
	StatusBar string

	// Reserved
	Reserved string
}

Alert contains the data deserialized from the MsgAlert payload.

func NewAlert

func NewAlert(version int32, relayUntil int64, expiration int64,
	id int32, cancel int32, setCancel []int32, minVer int32,
	maxVer int32, setSubVer []string, priority int32, comment string,
	statusBar string) *Alert

NewAlert returns an new Alert with values provided.

func NewAlertFromPayload

func NewAlertFromPayload(serializedPayload []byte, pver uint32) (*Alert, error)

NewAlertFromPayload returns an Alert with values deserialized from the serialized payload.

func (*Alert) Serialize

func (alert *Alert) Serialize(w io.Writer, pver uint32) error

Serialize encodes the alert to w using the alert protocol encoding format.

func (*Alert) Unserialize

func (alert *Alert) Unserialize(r io.Reader, pver uint32) error

Unserialize decodes from r into the receiver using the alert protocol encoding format.

type BitcoinNet

type BitcoinNet uint32

BitcoinNet represents which bitcoin network a message belongs to.

const (
	// MainNet represents the main bitcoin network.
	MainNet       BitcoinNet = 0xe8f3e1e3
	MainDiskMagic BitcoinNet = 0xd9b4bef9

	// RegTestNet represents the regression test network.
	RegTestNet   BitcoinNet = 0xfabfb5da
	RegDiskMagic BitcoinNet = 0xdab5bffa

	// TestNet3 represents the test network (version 3).
	TestNet3      BitcoinNet = 0xf4f3e5f4
	TestDiskMagic BitcoinNet = 0x0709110b
)

Constants used to indicate the message bitcoin 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.

func (BitcoinNet) String

func (n BitcoinNet) String() string

String returns the BitcoinNet in human-readable form.

type BloomUpdateType

type BloomUpdateType uint8

BloomUpdateType specifies how the filter is updated when a match is found

const (
	// BloomUpdateNone indicates the filter is not adjusted when a match is
	// found.
	BloomUpdateNone BloomUpdateType = 0

	// BloomUpdateAll indicates if the filter matches any data element in a
	// public key script, the outpoint is serialized and inserted into the
	// filter.
	BloomUpdateAll BloomUpdateType = 1

	// BloomUpdateP2PubkeyOnly indicates if the filter matches a data
	// element in a public key script and the script is of the standard
	// pay-to-pubkey or multisig, the outpoint is serialized and inserted
	// into the filter.
	BloomUpdateP2PubkeyOnly BloomUpdateType = 2
)

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
	//bip 152
	InvTypeCompatedBlock InvType = 4
	MsgExtFlag           InvType = 1 << 29
	MsgTypeMask          InvType = 0xffffffff >> 3
	//Extension block
	MsgExtTx    InvType = InvTypeTx | MsgExtFlag
	MsgExtBlock InvType = InvTypeBlock | MsgExtFlag
)

These constants define the various supported inventory vector types.

func (InvType) String

func (invtype InvType) String() string

String returns the InvType in human-readable form.

type InvVect

type InvVect struct {
	Type InvType   // Type of data
	Hash util.Hash // Hash of the data
}

InvVect defines a bitcoin 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.

func NewInvVect

func NewInvVect(typ InvType, hash *util.Hash) *InvVect

NewInvVect returns a new InvVect using the provided type and hash.

type Message

type Message interface {
	Decode(io.Reader, uint32, MessageEncoding) error
	Encode(io.Writer, uint32, MessageEncoding) error
	Command() string
	MaxPayloadLength(uint32) uint64
}

Message is an interface that describes a bitcoin 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

func ReadMessage(r io.Reader, pver uint32, btcnet BitcoinNet) (Message, []byte, error)

ReadMessage reads, validates, and parses the next bitcoin Message from r for the provided protocol version and bitcoin 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

func ReadMessageN(r io.Reader, pver uint32, btcnet BitcoinNet) (int, Message, []byte, error)

ReadMessageN reads, validates, and parses the next bitcoin Message from r for the provided protocol version and bitcoin 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.

func ReadMessageWithEncodingN

func ReadMessageWithEncodingN(r io.Reader, pver uint32, btcnet BitcoinNet,
	enc MessageEncoding) (int, Message, []byte, error)

ReadMessageWithEncodingN reads, validates, and parses the next bitcoin Message from r for the provided protocol version and bitcoin 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 ReadMessageN except it allows the caller to specify which message encoding is to to consult when decoding wire messages.

type MessageEncoding

type MessageEncoding uint32

MessageEncoding represents the wire message encoding format to be used.

const (
	// BaseEncoding encodes all messages in the default format specified
	// for the Bitcoin wire protocol.
	BaseEncoding MessageEncoding = 1 << iota
)

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 (*MessageError) Error

func (e *MessageError) Error() string

Error satisfies the error interface and prints human-readable errors.

type MsgAddr

type MsgAddr struct {
	AddrList []*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 *NetAddress) error

AddAddress adds a known active peer to the message.

func (*MsgAddr) AddAddresses

func (msg *MsgAddr) AddAddresses(netAddrs ...*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

func (msg *MsgAddr) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgAddr) Decode

func (msg *MsgAddr) Decode(r io.Reader, pver uint32, enc MessageEncoding) error

Decode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgAddr) Encode

func (msg *MsgAddr) Encode(w io.Writer, pver uint32, enc MessageEncoding) error

Encode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgAddr) MaxPayloadLength

func (msg *MsgAddr) MaxPayloadLength(pver uint32) uint64

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgAlert

type MsgAlert struct {
	// SerializedPayload is the alert payload serialized as a string so that the
	// version can change but the Alert can still be passed on by older
	// clients.
	SerializedPayload []byte

	// Signature is the ECDSA signature of the message.
	Signature []byte

	// Unserialized Payload
	Payload *Alert
}

MsgAlert implements the Message interface and defines a bitcoin alert message.

This is a signed message that provides notifications that the client should display if the signature matches the key. bitcoind/bitcoin-qt only checks against a signature from the core developers.

func NewMsgAlert

func NewMsgAlert(serializedPayload []byte, signature []byte) *MsgAlert

NewMsgAlert returns a new bitcoin alert message that conforms to the Message interface. See MsgAlert for details.

func (*MsgAlert) Command

func (msg *MsgAlert) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgAlert) Decode

func (msg *MsgAlert) Decode(r io.Reader, pver uint32, enc MessageEncoding) error

Decode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgAlert) Encode

func (msg *MsgAlert) Encode(w io.Writer, pver uint32, enc MessageEncoding) error

Encode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgAlert) MaxPayloadLength

func (msg *MsgAlert) MaxPayloadLength(pver uint32) uint64

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgBlock

type MsgBlock block.Block

func (*MsgBlock) Command

func (msg *MsgBlock) Command() string

func (*MsgBlock) Decode

func (msg *MsgBlock) Decode(r io.Reader, pver uint32, enc MessageEncoding) error

func (*MsgBlock) Encode

func (msg *MsgBlock) Encode(w io.Writer, pver uint32, enc MessageEncoding) error

func (*MsgBlock) MaxPayloadLength

func (msg *MsgBlock) MaxPayloadLength(pver uint32) uint64

type MsgFeeFilter

type MsgFeeFilter struct {
	MinFee int64
}

MsgFeeFilter implements the Message interface and represents a bitcoin feefilter message. It is used to request the receiving peer does not announce any transactions below the specified minimum fee rate.

This message was not added until protocol versions starting with FeeFilterVersion.

func NewMsgFeeFilter

func NewMsgFeeFilter(minfee int64) *MsgFeeFilter

NewMsgFeeFilter returns a new bitcoin feefilter message that conforms to the Message interface. See MsgFeeFilter for details.

func (*MsgFeeFilter) Command

func (msg *MsgFeeFilter) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgFeeFilter) Decode

func (msg *MsgFeeFilter) Decode(r io.Reader, pver uint32, enc MessageEncoding) error

Decode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgFeeFilter) Encode

func (msg *MsgFeeFilter) Encode(w io.Writer, pver uint32, enc MessageEncoding) error

Encode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgFeeFilter) MaxPayloadLength

func (msg *MsgFeeFilter) MaxPayloadLength(pver uint32) uint64

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgFilterAdd

type MsgFilterAdd struct {
	Data []byte
}

MsgFilterAdd implements the Message interface and represents a bitcoin filteradd message. It is used to add a data element to an existing Bloom filter.

This message was not added until protocol version BIP0037Version.

func NewMsgFilterAdd

func NewMsgFilterAdd(data []byte) *MsgFilterAdd

NewMsgFilterAdd returns a new bitcoin filteradd message that conforms to the Message interface. See MsgFilterAdd for details.

func (*MsgFilterAdd) Command

func (msg *MsgFilterAdd) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgFilterAdd) Decode

func (msg *MsgFilterAdd) Decode(r io.Reader, pver uint32, enc MessageEncoding) error

Decode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgFilterAdd) Encode

func (msg *MsgFilterAdd) Encode(w io.Writer, pver uint32, enc MessageEncoding) error

Encode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgFilterAdd) MaxPayloadLength

func (msg *MsgFilterAdd) MaxPayloadLength(pver uint32) uint64

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgFilterClear

type MsgFilterClear struct{}

MsgFilterClear implements the Message interface and represents a bitcoin filterclear message which is used to reset a Bloom filter.

This message was not added until protocol version BIP0037Version and has no payload.

func NewMsgFilterClear

func NewMsgFilterClear() *MsgFilterClear

NewMsgFilterClear returns a new bitcoin filterclear message that conforms to the Message interface. See MsgFilterClear for details.

func (*MsgFilterClear) Command

func (msg *MsgFilterClear) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgFilterClear) Decode

func (msg *MsgFilterClear) Decode(r io.Reader, pver uint32, enc MessageEncoding) error

Decode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgFilterClear) Encode

func (msg *MsgFilterClear) Encode(w io.Writer, pver uint32, enc MessageEncoding) error

Encode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgFilterClear) MaxPayloadLength

func (msg *MsgFilterClear) MaxPayloadLength(pver uint32) uint64

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgFilterLoad

type MsgFilterLoad struct {
	Filter    []byte
	HashFuncs uint32
	Tweak     uint32
	Flags     BloomUpdateType
}

MsgFilterLoad implements the Message interface and represents a bitcoin filterload message which is used to reset a Bloom filter.

This message was not added until protocol version BIP0037Version.

func NewMsgFilterLoad

func NewMsgFilterLoad(filter []byte, hashFuncs uint32, tweak uint32, flags BloomUpdateType) *MsgFilterLoad

NewMsgFilterLoad returns a new bitcoin filterload message that conforms to the Message interface. See MsgFilterLoad for details.

func (*MsgFilterLoad) Command

func (msg *MsgFilterLoad) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgFilterLoad) Decode

func (msg *MsgFilterLoad) Decode(r io.Reader, pver uint32, enc MessageEncoding) error

Decode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgFilterLoad) Encode

func (msg *MsgFilterLoad) Encode(w io.Writer, pver uint32, enc MessageEncoding) error

Encode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgFilterLoad) MaxPayloadLength

func (msg *MsgFilterLoad) MaxPayloadLength(pver uint32) uint64

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgGetAddr

type MsgGetAddr struct{}

MsgGetAddr implements the Message interface and represents a bitcoin 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 bitcoin 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, enc MessageEncoding) error

Decode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgGetAddr) Encode

func (msg *MsgGetAddr) Encode(w io.Writer, pver uint32, enc MessageEncoding) error

Encode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgGetAddr) MaxPayloadLength

func (msg *MsgGetAddr) MaxPayloadLength(pver uint32) uint64

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 []*util.Hash
	HashStop           util.Hash
}

MsgGetBlocks implements the Message interface and represents a bitcoin 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, which is currently 500.

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(hashStop *util.Hash) *MsgGetBlocks

NewMsgGetBlocks returns a new bitcoin 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 *util.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, enc MessageEncoding) error

Decode decodes r using the bitcoin 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, enc MessageEncoding) error

Encode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgGetBlocks) MaxPayloadLength

func (msg *MsgGetBlocks) MaxPayloadLength(pver uint32) uint64

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 bitcoin 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 bitcoin getdata message that conforms to the Message interface. See MsgGetData for details.

func NewMsgGetDataSizeHint

func NewMsgGetDataSizeHint(sizeHint uint) *MsgGetData

NewMsgGetDataSizeHint returns a new bitcoin 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, enc MessageEncoding) error

Decode decodes r using the bitcoin 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, enc MessageEncoding) error

Encode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgGetData) MaxPayloadLength

func (msg *MsgGetData) MaxPayloadLength(pver uint32) uint64

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 []*util.Hash
	HashStop           util.Hash
}

MsgGetHeaders implements the Message interface and represents a bitcoin 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, which is currently 2000.

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() *MsgGetHeaders

NewMsgGetHeaders returns a new bitcoin getheaders message that conforms to the Message interface. See MsgGetHeaders for details.

func (*MsgGetHeaders) AddBlockLocatorHash

func (msg *MsgGetHeaders) AddBlockLocatorHash(hash *util.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, enc MessageEncoding) error

Decode decodes r using the bitcoin 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, enc MessageEncoding) error

Encode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgGetHeaders) MaxPayloadLength

func (msg *MsgGetHeaders) MaxPayloadLength(pver uint32) uint64

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgHeaders

type MsgHeaders struct {
	Headers []*block.BlockHeader
}

MsgHeaders implements the Message interface and represents a bitcoin 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() *MsgHeaders

NewMsgHeaders returns a new bitcoin headers message that conforms to the Message interface. See MsgHeaders for details.

func (*MsgHeaders) AddBlockHeader

func (msg *MsgHeaders) AddBlockHeader(bh *block.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, enc MessageEncoding) error

Decode decodes r using the bitcoin 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, enc MessageEncoding) error

Encode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgHeaders) IsContinuousHeaders added in v0.0.7

func (msg *MsgHeaders) IsContinuousHeaders() bool

func (*MsgHeaders) MaxPayloadLength

func (msg *MsgHeaders) MaxPayloadLength(pver uint32) uint64

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgInv

type MsgInv struct {
	InvList []*InvVect
}

MsgInv implements the Message interface and represents a bitcoin 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 bitcoin inv message that conforms to the Message interface. See MsgInv for details.

func NewMsgInvSizeHint

func NewMsgInvSizeHint(sizeHint uint) *MsgInv

NewMsgInvSizeHint returns a new bitcoin 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

func (msg *MsgInv) AddInvVect(iv *InvVect) error

AddInvVect adds an inventory vector to the message.

func (*MsgInv) Command

func (msg *MsgInv) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgInv) Decode

func (msg *MsgInv) Decode(r io.Reader, pver uint32, enc MessageEncoding) error

Decode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgInv) Encode

func (msg *MsgInv) Encode(w io.Writer, pver uint32, enc MessageEncoding) error

Encode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgInv) MaxPayloadLength

func (msg *MsgInv) MaxPayloadLength(pver uint32) uint64

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{}

MsgMemPool implements the Message interface and represents a bitcoin mempool message. It is used to request a list of transactions still in the active memory pool of a relay.

This message has no payload and was not added until protocol versions starting with BIP0035Version.

func NewMsgMemPool

func NewMsgMemPool() *MsgMemPool

NewMsgMemPool returns a new bitcoin pong message that conforms to the Message interface. See MsgPong for details.

func (*MsgMemPool) Command

func (msg *MsgMemPool) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgMemPool) Decode

func (msg *MsgMemPool) Decode(r io.Reader, pver uint32, enc MessageEncoding) error

Decode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgMemPool) Encode

func (msg *MsgMemPool) Encode(w io.Writer, pver uint32, enc MessageEncoding) error

Encode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgMemPool) MaxPayloadLength

func (msg *MsgMemPool) MaxPayloadLength(pver uint32) uint64

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgMerkleBlock

type MsgMerkleBlock struct {
	Header       block.BlockHeader
	Transactions uint32
	Hashes       []*util.Hash
	Flags        []byte
}

MsgMerkleBlock implements the Message interface and represents a bitcoin merkleblock message which is used to reset a Bloom filter.

This message was not added until protocol version BIP0037Version.

func NewMsgMerkleBlock

func NewMsgMerkleBlock(bh *block.BlockHeader) *MsgMerkleBlock

NewMsgMerkleBlock returns a new bitcoin merkleblock message that conforms to the Message interface. See MsgMerkleBlock for details.

func (*MsgMerkleBlock) AddTxHash

func (msg *MsgMerkleBlock) AddTxHash(hash *util.Hash) error

AddTxHash adds a new transaction hash to the message.

func (*MsgMerkleBlock) Command

func (msg *MsgMerkleBlock) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgMerkleBlock) Decode

func (msg *MsgMerkleBlock) Decode(r io.Reader, pver uint32, enc MessageEncoding) error

Decode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgMerkleBlock) Encode

func (msg *MsgMerkleBlock) Encode(w io.Writer, pver uint32, enc MessageEncoding) error

Encode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgMerkleBlock) MaxPayloadLength

func (msg *MsgMerkleBlock) MaxPayloadLength(pver uint32) uint64

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 bitcoin 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 bitcoin 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, enc MessageEncoding) error

Decode decodes r using the bitcoin 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, enc MessageEncoding) error

Encode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgNotFound) MaxPayloadLength

func (msg *MsgNotFound) MaxPayloadLength(pver uint32) uint64

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 bitcoin ping message.

For versions BIP0031Version and earlier, it is used primarily to confirm that a connection is still valid. A transmission error is typically interpreted as a closed connection and that the peer should be removed. For versions AFTER BIP0031Version it contains an identifier which can be returned in the pong message to determine network timing.

The payload for this message just consists of a nonce used for identifying it later.

func NewMsgPing

func NewMsgPing(nonce uint64) *MsgPing

NewMsgPing returns a new bitcoin ping message that conforms to the Message interface. See MsgPing for details.

func (*MsgPing) Command

func (msg *MsgPing) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgPing) Decode

func (msg *MsgPing) Decode(r io.Reader, pver uint32, enc MessageEncoding) error

Decode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgPing) Encode

func (msg *MsgPing) Encode(w io.Writer, pver uint32, enc MessageEncoding) error

Encode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgPing) MaxPayloadLength

func (msg *MsgPing) MaxPayloadLength(pver uint32) uint64

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 bitcoin pong message which is used primarily to confirm that a connection is still valid in response to a bitcoin ping message (MsgPing).

This message was not added until protocol versions AFTER BIP0031Version.

func NewMsgPong

func NewMsgPong(nonce uint64) *MsgPong

NewMsgPong returns a new bitcoin pong message that conforms to the Message interface. See MsgPong for details.

func (*MsgPong) Command

func (msg *MsgPong) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgPong) Decode

func (msg *MsgPong) Decode(r io.Reader, pver uint32, enc MessageEncoding) error

Decode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgPong) Encode

func (msg *MsgPong) Encode(w io.Writer, pver uint32, enc MessageEncoding) error

Encode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgPong) MaxPayloadLength

func (msg *MsgPong) MaxPayloadLength(pver uint32) uint64

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 errcode.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 util.Hash
}

MsgReject implements the Message interface and represents a bitcoin reject message.

This message was not added until protocol version RejectVersion.

func NewMsgReject

func NewMsgReject(command string, code errcode.RejectCode, reason string) *MsgReject

NewMsgReject returns a new bitcoin reject message that conforms to the Message interface. See MsgReject for details.

func (*MsgReject) Command

func (msg *MsgReject) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgReject) Decode

func (msg *MsgReject) Decode(r io.Reader, pver uint32, enc MessageEncoding) error

Decode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgReject) Encode

func (msg *MsgReject) Encode(w io.Writer, pver uint32, enc MessageEncoding) error

Encode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgReject) MaxPayloadLength

func (msg *MsgReject) MaxPayloadLength(pver uint32) uint64

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgSendHeaders

type MsgSendHeaders struct{}

MsgSendHeaders implements the Message interface and represents a bitcoin sendheaders message. It is used to request the peer send block headers rather than inventory vectors.

This message has no payload and was not added until protocol versions starting with SendHeadersVersion.

func NewMsgSendHeaders

func NewMsgSendHeaders() *MsgSendHeaders

NewMsgSendHeaders returns a new bitcoin sendheaders message that conforms to the Message interface. See MsgSendHeaders for details.

func (*MsgSendHeaders) Command

func (msg *MsgSendHeaders) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgSendHeaders) Decode

func (msg *MsgSendHeaders) Decode(r io.Reader, pver uint32, enc MessageEncoding) error

Decode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgSendHeaders) Encode

func (msg *MsgSendHeaders) Encode(w io.Writer, pver uint32, enc MessageEncoding) error

Encode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgSendHeaders) MaxPayloadLength

func (msg *MsgSendHeaders) MaxPayloadLength(pver uint32) uint64

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgTx

type MsgTx tx.Tx

func (*MsgTx) Command

func (msg *MsgTx) Command() string

func (*MsgTx) Decode

func (msg *MsgTx) Decode(r io.Reader, pver uint32, enc MessageEncoding) error

func (*MsgTx) Encode

func (msg *MsgTx) Encode(w io.Writer, pver uint32, enc MessageEncoding) error

func (*MsgTx) MaxPayloadLength

func (msg *MsgTx) MaxPayloadLength(pver uint32) uint64

type MsgVerAck

type MsgVerAck struct{}

MsgVerAck defines a bitcoin 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 bitcoin verack message that conforms to the Message interface.

func (*MsgVerAck) Command

func (msg *MsgVerAck) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgVerAck) Decode

func (msg *MsgVerAck) Decode(r io.Reader, pver uint32, enc MessageEncoding) error

Decode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgVerAck) Encode

func (msg *MsgVerAck) Encode(w io.Writer, pver uint32, enc MessageEncoding) error

Encode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgVerAck) MaxPayloadLength

func (msg *MsgVerAck) MaxPayloadLength(pver uint32) uint64

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 ServiceFlag

	// Time the message was generated.  This is encoded as an int64 on the wire.
	Timestamp time.Time

	// Address of the remote peer.
	AddrYou NetAddress

	// Address of the local peer.
	AddrMe 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 block seen by the generator of the version message.
	LastBlock int32

	// Don't announce transactions to peer.
	DisableRelayTx bool
}

MsgVersion implements the Message interface and represents a bitcoin 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 *NetAddress, you *NetAddress, nonce uint64,
	lastBlock int32) *MsgVersion

NewMsgVersion returns a new bitcoin version message that conforms to the Message interface using the passed parameters and defaults for the remaining fields.

func (*MsgVersion) AddService

func (msg *MsgVersion) AddService(service ServiceFlag)

AddService adds service as a supported service by the peer generating the message.

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, enc MessageEncoding) error

Decode decodes r using the bitcoin protocol 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, enc MessageEncoding) error

Encode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgVersion) HasService

func (msg *MsgVersion) HasService(service 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) uint64

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

func (*MsgVersion) SetUserAgent added in v0.0.6

func (msg *MsgVersion) SetUserAgent(name string, version string, comments ...string) error

SetUserAgent sets 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".

type NetAddress

type NetAddress struct {
	// Last time the address was seen.  This is, unfortunately, encoded as a
	// uint32 on the wire and therefore is limited to 2106.  This field is
	// not present in the bitcoin version message (MsgVersion) nor was it
	// added until protocol version >= NetAddressTimeVersion.
	Timestamp time.Time

	// Bitfield which identifies the services supported by the address.
	Services ServiceFlag

	// IP address of the peer.
	IP net.IP

	// Port the peer is using.  This is encoded in big endian on the wire
	// which differs from most everything else.
	Port uint16
}

NetAddress defines information about a peer on the network including the time it was last seen, the services it supports, its IP address, and port.

func NewNetAddress

func NewNetAddress(addr *net.TCPAddr, services ServiceFlag) *NetAddress

NewNetAddress returns a new NetAddress using the provided TCP address and supported services with defaults for the remaining fields.

func NewNetAddressIPPort

func NewNetAddressIPPort(ip net.IP, port uint16, services ServiceFlag) *NetAddress

NewNetAddressIPPort returns a new NetAddress using the provided IP, port, and supported services with defaults for the remaining fields.

func NewNetAddressTimestamp

func NewNetAddressTimestamp(
	timestamp time.Time, services ServiceFlag, ip net.IP, port uint16) *NetAddress

NewNetAddressTimestamp returns a new NetAddress using the provided timestamp, IP, port, and supported services. The timestamp is rounded to single second precision.

func (*NetAddress) AddService

func (na *NetAddress) AddService(service ServiceFlag)

AddService adds service as a supported service by the peer generating the message.

func (*NetAddress) HasService

func (na *NetAddress) HasService(service ServiceFlag) bool

HasService returns whether the specified service is supported by the address.

func (*NetAddress) String

func (na *NetAddress) String() string

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 means the node supports Xtreme Thinblocks. If this is turned
	// off then the node will not service nor make xthin requests.
	SFNodeXthin

	// SFNodeCash means the node supports Bitcoin Cash and the
	// associated consensus rule changes.
	// This service bit is intended to be used prior until some time after the
	// UAHF activation when the Bitcoin Cash network has adequately separated.
	// TODO: remove (free up) the SFNodeCash service bit once no longer
	// needed.
	SFNodeCash
)

func (ServiceFlag) String

func (f ServiceFlag) String() string

String returns the ServiceFlag in human-readable form.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL