xprotocol

package
v0.0.0-...-d2b8996 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2019 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
const MaxBlockHeadersPerMsg = 2000

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

View Source
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.

func (*BlockHeader) Size

func (b *BlockHeader) Size() int

Size -- the size of the blockheader.

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) Close

func (c *Connection) Close()

Close -- close the 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 DisconnectFunc

type DisconnectFunc func(*Connection)

DisconnectFunc --

type InvType

type InvType uint32

InvType -- the allowed types of inventory vectors. See InvVect.

const (
	InvTypeError         InvType = 0
	InvTypeTx            InvType = 1
	InvTypeBlock         InvType = 2
	InvTypeFilteredBlock InvType = 3
)

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 []byte  // Hash of the data
}

InvVect -- defines a bitcoin inventory vector which is used to describe data.

func NewInvVect

func NewInvVect(typ InvType, hash []byte) *InvVect

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

func (*InvVect) Size

func (inv *InvVect) Size() int

Size -- size of the InvVect.

type Message

type Message interface {
	Encode() []byte
	Decode([]byte) error
	Command() string
	Size() int
}

Message --

type MsgGetData

type MsgGetData struct {
	InvList []*InvVect
}

MsgGetData --

func NewMsgGetData

func NewMsgGetData() *MsgGetData

NewMsgGetData -- creates new 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.

func (*MsgGetData) Encode

func (m *MsgGetData) Encode() []byte

Encode -- encoding MsgGetData.

func (*MsgGetData) Size

func (m *MsgGetData) Size() int

Size -- the size of the message.

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.

func (*MsgGetHeaders) Size

func (m *MsgGetHeaders) Size() int

Size -- the size of the message.

type MsgHeaders

type MsgHeaders struct {
	Headers []*BlockHeader
}

MsgHeaders --

func NewMsgHeaders

func NewMsgHeaders() *MsgHeaders

NewMsgHeaders -- creates new 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.

func (*MsgHeaders) Size

func (m *MsgHeaders) Size() int

Size -- the size of the message.

type MsgInv

type MsgInv struct {
	Invs []*InvVect
}

MsgInv --

func NewMsgInv

func NewMsgInv() *MsgInv

NewMsgInv -- creates new MsgInv.

func (*MsgInv) AddInvVect

func (m *MsgInv) AddInvVect(iv ...*InvVect) error

AddInvVect -- adds an inventory vector to the message.

func (*MsgInv) Command

func (m *MsgInv) Command() string

Command -- returns the protocol command of this message.

func (*MsgInv) Decode

func (m *MsgInv) Decode(data []byte) error

Decode -- decoding data to MsgInv.

func (*MsgInv) Encode

func (m *MsgInv) Encode() []byte

Encode -- encoding MsgInv.

func (*MsgInv) Size

func (m *MsgInv) Size() int

Size -- the size of the message.

type MsgPing

type MsgPing struct {
	Nonce uint64
}

MsgPing --

func NewMsgPing

func NewMsgPing(nonce uint64) *MsgPing

NewMsgPing -- creates new MsgPing.

func (*MsgPing) Command

func (m *MsgPing) Command() string

Command -- returns the protocal command string of this message.

func (*MsgPing) Decode

func (m *MsgPing) Decode(data []byte) error

Decode -- decoding from the bitcoin protocol format.

func (*MsgPing) Encode

func (m *MsgPing) Encode() []byte

Encode -- encoding to bitcoin protocol format.

func (*MsgPing) Size

func (m *MsgPing) Size() int

Size -- the size of the message.

type MsgPong

type MsgPong struct {
	Nonce uint64
}

MsgPong --

func NewMsgPong

func NewMsgPong(nonce uint64) *MsgPong

NewMsgPong -- creates new MsgPong.

func (*MsgPong) Command

func (m *MsgPong) Command() string

Command -- returns the protocal command string of this message.

func (*MsgPong) Decode

func (m *MsgPong) Decode(data []byte) error

Decode -- decoding from the bitcoin protocol format.

func (*MsgPong) Encode

func (m *MsgPong) Encode() []byte

Encode -- encoding to bitcoin protocol format.

func (*MsgPong) Size

func (m *MsgPong) Size() int

Size -- the size of the message.

type MsgReject

type MsgReject struct {
	Cmd    string
	Code   uint8
	Reason string
	Hash   []byte
}

MsgReject --

func NewMsgReject

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

NewMsgReject -- creates new MsgReject.

func (*MsgReject) Command

func (m *MsgReject) Command() string

Command -- returns the protocal command string of this message.

func (*MsgReject) Decode

func (m *MsgReject) Decode(data []byte) error

Decode -- decoding from the bitcoin protocol format.

func (*MsgReject) Encode

func (m *MsgReject) Encode() []byte

Encode -- encoding to bitcoin protocol format.

func (*MsgReject) Size

func (m *MsgReject) Size() int

Size -- the size of the message.

type MsgTx

type MsgTx struct {
	Data []byte
}

MsgTx --

func NewMsgTx

func NewMsgTx(data []byte) *MsgTx

NewMsgTx -- creates new MsgTx.

func (*MsgTx) Command

func (m *MsgTx) Command() string

Command -- returns the protocol command of this message.

func (*MsgTx) Decode

func (m *MsgTx) Decode(data []byte) error

Decode -- decoding bytes to the message.

func (*MsgTx) Encode

func (m *MsgTx) Encode() []byte

Encode -- encoding the message to bitcoin protocol format.

func (*MsgTx) Size

func (m *MsgTx) Size() int

Size -- the size of the message.

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.

func (*MsgUnhandle) Size

func (m *MsgUnhandle) Size() int

Size -- the size of the message.

type MsgVerAck

type MsgVerAck struct{}

MsgVerAck --

func NewMsgVerAck

func NewMsgVerAck() *MsgVerAck

NewMsgVerAck -- creates new MsgVerAck.

func (*MsgVerAck) Command

func (m *MsgVerAck) Command() string

Command -- returns the protocol command of this message.

func (*MsgVerAck) Decode

func (m *MsgVerAck) Decode(data []byte) error

Decode -- decoding bytes to MsgVerAck message.

func (*MsgVerAck) Encode

func (m *MsgVerAck) Encode() []byte

Encode -- encoding MsgVersion message to bitcoin protocol format.

func (*MsgVerAck) Size

func (m *MsgVerAck) Size() int

Size -- the size of the message.

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.

func (*MsgVersion) Size

func (m *MsgVersion) Size() int

Size -- the size of the message.

type ReceiveFunc

type ReceiveFunc func(*Connection, Message)

ReceiveFunc --

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 NewStream

func NewStream(conn net.Conn, magic []byte) *Stream

NewStream -- creates a new stream.

func (*Stream) ReadMessage

func (s *Stream) ReadMessage() (Message, error)

ReadMessage -- read a message from the network.

func (*Stream) WriteMessage

func (s *Stream) WriteMessage(msg Message) error

WriteMessage -- write the message to the network.

Jump to

Keyboard shortcuts

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