Documentation ¶
Index ¶
Constants ¶
const ( CMDSize = 12 CMDOffset = 4 ChecksumSize = 4 HeaderSize = 24 BlocksCacheSize = 2 // MaxMessagePayload is the maximum bytes a message can be regardless of other // individual limits imposed by messages themselves. MaxMessagePayload = 1024 * 1024 * 32 // 32MB // WriteMessageTimeOut is the max time of write message, then the peer will // disconnect. WriteMessageTimeOut = 10 * time.Minute // WriteMessageTimeOut is the max time of read message, then the peer will // disconnect. ReadMessageTimeOut = 10 * time.Minute )
const ( CmdVersion = "version" CmdVerAck = "verack" CmdGetAddr = "getaddr" CmdAddr = "addr" CmdGetBlocks = "getblocks" CmdInv = "inv" CmdGetData = "getdata" CmdNotFound = "notfound" CmdBlock = "block" CmdTx = "tx" CmdPing = "ping" CmdPong = "pong" CmdMemPool = "mempool" CmdFilterAdd = "filteradd" CmdFilterClear = "filterclear" CmdFilterLoad = "filterload" CmdMerkleBlock = "merkleblock" CmdReject = "reject" CmdTxFilter = "txfilter" CmdDAddr = "daddr" )
Variables ¶
Functions ¶
Types ¶
type Header ¶
func (*Header) Deserialize ¶
type MakeEmptyMessage ¶
MakeEmptyMessage is a function to make message by the given command.
type Message ¶
type Message interface { // Get the message CMD parameter which is the type of this message CMD() string // Get the max payload size of this message MaxLength() uint32 // A message is a serializable instance common.Serializable }
The message flying in the peer to peer network
func ReadMessage ¶
ReadMessage reads, validates, and parse the Message from r for the provided magic.
type NAFilter ¶
type NAFilter interface { // Filter takes a NetAddress and return if this address is ok to use. Filter(na *NetAddress) bool }
NAFilter defines a NetAddress filter interface, it is used to filter inbound peer addresses and cached net addresses when responding to a getaddr message.
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 version message (Version) nor was it // added until protocol version >= NetAddressTimeVersion. Timestamp time.Time // Bitfield which identifies the services supported by the address. Services uint64 // IP address of the peer. IP net.IP // Port the peer is using. This is encoded in little endian. 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 uint64) *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 uint64) *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 uint64, 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 uint64)
AddService adds service as a supported service by the peer generating the message.
func (*NetAddress) Deserialize ¶
func (na *NetAddress) Deserialize(r io.Reader) error
readNetAddress reads an encoded NetAddress from r.
func (*NetAddress) HasService ¶
func (na *NetAddress) HasService(service uint64) bool
HasService returns whether the specified service is supported by the address.
func (*NetAddress) Serialize ¶
func (na *NetAddress) Serialize(w io.Writer) error
Serialize serializes a NetAddress to w.
func (NetAddress) String ¶
func (na NetAddress) String() string