Documentation
¶
Index ¶
- Constants
- type BlockHeader
- type Connection
- type DisconnectFunc
- type InvType
- type InvVect
- type Message
- type MsgGetData
- type MsgGetHeaders
- type MsgHeaders
- type MsgInv
- type MsgPing
- type MsgPong
- type MsgReject
- type MsgTx
- type MsgUnhandle
- type MsgVerAck
- type MsgVersion
- type ReceiveFunc
- type RejectCode
- type Stream
Constants ¶
const ( // CommandVersion is the command used when a node creates an outgoing connection. // it will immediately advertise its version. // The remote node will respond with its version. CommandVersion = "version" // CommandVersionAck message is sent in reply to version. CommandVersionAck = "verack" // CommandInventory Allows a node to advertise its knowledge of one or more objects // It can be received unsolicited, or in reply to getblocks. CommandInventory = "inv" // CommandPing is sent primarily to confirm that the TCP/IP connection is still valid. CommandPing = "ping" // CommandPong is sent in response to a CommandPing. CommandPong = "pong" // CommandBlock is sent in response to a getdata message which requests transaction information from a block hash CommandBlock = "block" // CommandGetBlocks returns an inv packet containing the list of blocks starting right after the // last known hash in the block locator object, up to stop value or 500 blocks (max). CommandGetBlocks = "getblocks" // CommandGetData is used in response to inv, to retrieve the content of a specific object (usually sent after receiving an inv packet). CommandGetData = "getdata" // CommandGetHeaders return a headers packet containing the headers of blocks starting right after the // last known hash in the block locator object, up to stop value or 2000 blocks (max). CommandGetHeaders = "getheaders" // CommandHeaders returns block headers in response to a getheaders packet CommandHeaders = "headers" // CommandTx describes a bitcoin transaction, in response to CommandGetData. CommandTx = "tx" // CommandReject is sent when messages are rejected. CommandReject = "reject" )
const MaxBlockHeadersPerMsg = 2000
MaxBlockHeadersPerMsg -- the maximum number of block headers that can be in a single bitcoin headers message.
const ( // MaxInvPerMsg -- the maximum number of inventory vectors that can be in a // single bitcoin inv message. MaxInvPerMsg = 50000 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockHeader ¶
type BlockHeader struct { // Version of the block. This is not the same as the protocol version. Version uint32 // Hash of the previous block header in the block chain. PrevBlock []byte // Merkle tree reference to hash of all transactions for the block. MerkleRoot []byte // Time the block was created. This is, unfortunately, encoded as a // uint32 on the wire and therefore is limited to 2106. Timestamp uint32 // Difficulty target for the block. Bits uint32 // Nonce used to generate the block. Nonce uint32 }
BlockHeader defines information about a block and is used in the bitcoin block (MsgBlock) and headers (MsgHeaders) messages.
func (*BlockHeader) BlockHash ¶
func (b *BlockHeader) BlockHash() []byte
BlockHash -- calc the block hash.
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection --
func NewConnection ¶
func NewConnection(net *network.Network, conn net.Conn, onReceive ReceiveFunc, onDisconnect DisconnectFunc) *Connection
NewConnection -- creates new Connection.
func (*Connection) LocalAddress ¶
func (c *Connection) LocalAddress() string
LocalAddress -- local address.
func (*Connection) ReadLoop ¶
func (c *Connection) ReadLoop()
ReadLoop -- ready for data received. This method must in go routine.
func (*Connection) RemoteAddress ¶
func (c *Connection) RemoteAddress() string
RemoteAddress -- remote address.
func (*Connection) Send ¶
func (c *Connection) Send(msg Message) error
Send -- send command and datas.
type InvVect ¶
InvVect -- defines a bitcoin inventory vector which is used to describe data.
func NewInvVect ¶
NewInvVect -- returns a new InvVect using the provided type and hash.
type MsgGetData ¶
type MsgGetData struct {
InvList []*InvVect
}
MsgGetData --
func (*MsgGetData) AddInvVect ¶
func (m *MsgGetData) AddInvVect(iv ...*InvVect) error
AddInvVect -- adds an inventory vector to the message.
func (*MsgGetData) Command ¶
func (m *MsgGetData) Command() string
Command -- returns the protocal command string of this message.
func (*MsgGetData) Decode ¶
func (m *MsgGetData) Decode(data []byte) error
Decode -- decoding data into MsgGetData.
type MsgGetHeaders ¶
type MsgGetHeaders struct {
// contains filtered or unexported fields
}
MsgGetHeaders --
func NewMsgGetHeaders ¶
func NewMsgGetHeaders(net *network.Network) *MsgGetHeaders
NewMsgGetHeaders -- creates new MsgGetHeaders.
func (*MsgGetHeaders) AddBlockLocatorHash ¶
func (m *MsgGetHeaders) AddBlockLocatorHash(hash []byte) error
AddBlockLocatorHash -- adds the block locator hash to message.
func (*MsgGetHeaders) Command ¶
func (m *MsgGetHeaders) Command() string
Command -- returns the protocol command of this message.
func (*MsgGetHeaders) Decode ¶
func (m *MsgGetHeaders) Decode(data []byte) error
Decode -- decoding bytes to MsgGetHeaders.
func (*MsgGetHeaders) Encode ¶
func (m *MsgGetHeaders) Encode() []byte
Encode -- encoding MsgGetHeaders.
type MsgHeaders ¶
type MsgHeaders struct {
Headers []*BlockHeader
}
MsgHeaders --
func (*MsgHeaders) AddBlockHeader ¶
func (m *MsgHeaders) AddBlockHeader(headers ...*BlockHeader) error
AddBlockHeader -- adds a new block header to the message.
func (*MsgHeaders) Command ¶
func (m *MsgHeaders) Command() string
Command -- returns the protocol command of this message.
func (*MsgHeaders) Decode ¶
func (m *MsgHeaders) Decode(data []byte) error
Decode -- decoding from the bitcoin protocol format.
func (*MsgHeaders) Encode ¶
func (m *MsgHeaders) Encode() []byte
Encode -- encoding to bitcoin protocol format.
type MsgInv ¶
type MsgInv struct {
Invs []*InvVect
}
MsgInv --
func (*MsgInv) AddInvVect ¶
AddInvVect -- adds an inventory vector to the message.
type MsgPing ¶
type MsgPing struct {
Nonce uint64
}
MsgPing --
type MsgPong ¶
type MsgPong struct {
Nonce uint64
}
MsgPong --
type MsgReject ¶
MsgReject --
func NewMsgReject ¶
func NewMsgReject(command string, code RejectCode, reason string) *MsgReject
NewMsgReject -- creates new MsgReject.
type MsgTx ¶
type MsgTx struct {
Data []byte
}
MsgTx --
type MsgUnhandle ¶
type MsgUnhandle struct {
// contains filtered or unexported fields
}
MsgUnhandle --
func NewMsgUnhandle ¶
func NewMsgUnhandle(command string) *MsgUnhandle
NewMsgUnhandle -- creates new MsgUnhandle.
func (*MsgUnhandle) Command ¶
func (m *MsgUnhandle) Command() string
Command -- returns the protocol command of this message.
func (*MsgUnhandle) Decode ¶
func (m *MsgUnhandle) Decode(data []byte) error
Decode -- decoding bytes to the message.
func (*MsgUnhandle) Encode ¶
func (m *MsgUnhandle) Encode() []byte
Encode -- encoding the message to bitcoin protocol format.
type MsgVerAck ¶
type MsgVerAck struct{}
MsgVerAck --
type MsgVersion ¶
type MsgVersion struct { // Version of the protocol the node is using. Version uint32 // Bitfield which identifies the enabled services. // 0: no services supported on this node. Services uint64 // Time the message was generated. Timestamp uint64 // Services of the remote peer. // Bitfield which identifies the services supported by the address. ServicesYou uint64 // Address of the remote peer. AddressYou []byte // Port of the remote peer. PortYou uint32 // Services of the local peer. // Bitfield which identifies the services supported by the address. ServicesMe uint64 // Address of the local peer. AddressMe []byte // Port of the local peer. PortMe uint32 // 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. UserAgent string // Last block seen by the generator of the version message. LastBlock uint32 // Announce transactions to peer. Relay byte }
MsgVersion --
func NewMsgVersion ¶
func NewMsgVersion(network *network.Network) *MsgVersion
NewMsgVersion -- creates new MsgVersion.
func (*MsgVersion) Command ¶
func (m *MsgVersion) Command() string
Command -- returns the protocol command of this message.
func (*MsgVersion) Decode ¶
func (m *MsgVersion) Decode(data []byte) error
Decode -- decoding from the bitcoin protocol format.
func (*MsgVersion) Encode ¶
func (m *MsgVersion) Encode() []byte
Encode -- encoding to bitcoin protocol format.
type RejectCode ¶
type RejectCode uint8
RejectCode --
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 )
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream --
func (*Stream) ReadMessage ¶
ReadMessage -- read a message from the network.
func (*Stream) WriteMessage ¶
WriteMessage -- write the message to the network.