message

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2019 License: Apache-2.0 Imports: 8 Imported by: 7

Documentation

Index

Constants

View Source
const (
	NIL              = MessageType(iota) // nil message type
	VERSION_TYPE                         //peer`s information
	VERACK_TYPE                          //ack msg after version recv
	GETADDR_TYPE                         //req nbr address from peer
	ADDR_TYPE                            //nbr address
	PING_TYPE                            //ping  sync height
	PONG_TYPE                            //pong  recv nbr height
	GET_HEADERS_TYPE                     //req blk hdr
	HEADERS_TYPE                         //blk hdr
	BLOCK_TYPE                           //blk payload
	TX_TYPE                              //transaction
	GET_BLOCK_TYPE                       //req blks from peer
	NOT_FOUND_TYPE                       //peer can`t find blk according to the hash
	REJECT_TYPE
	DISCONNECT_TYPE //peer disconnect info raise by link
	TRACE_TYPE      //trace message
)
View Source
const (
	MAX_BLOCK_HEADER_NUM = 100
)

Variables

View Source
var EmptyHash = types.Hash{}

Functions

func EncodeMessage

func EncodeMessage(msg Message) ([]byte, error)

EncodeMessage encode message to byte array.

Types

type Addr

type Addr struct {
	NetAddresses []*common.NetAddress `json:"net_addresses"`
}

func (*Addr) MsgId

func (this *Addr) MsgId() types.Hash

func (*Addr) MsgType

func (this *Addr) MsgType() MessageType

func (*Addr) ResponseMsgType

func (this *Addr) ResponseMsgType() MessageType

type AddrReq

type AddrReq struct{}

func (*AddrReq) MsgId

func (this *AddrReq) MsgId() types.Hash

func (*AddrReq) MsgType

func (this *AddrReq) MsgType() MessageType

func (*AddrReq) ResponseMsgType

func (this *AddrReq) ResponseMsgType() MessageType

type Block

type Block struct {
	Block *types.Block `json:"block"`
}

Block block message

func (*Block) MsgId

func (this *Block) MsgId() types.Hash

func (*Block) MsgType

func (this *Block) MsgType() MessageType

func (*Block) ResponseMsgType

func (this *Block) ResponseMsgType() MessageType

type BlockHeaderReq

type BlockHeaderReq struct {
	Len       uint8      `json:"len"`
	HashStart types.Hash `json:"hash_start"`
	HashStop  types.Hash `json:"hash_stop"`
}

BlockHeaderReq block request message

func (*BlockHeaderReq) MsgId

func (this *BlockHeaderReq) MsgId() types.Hash

func (*BlockHeaderReq) MsgType

func (this *BlockHeaderReq) MsgType() MessageType

func (*BlockHeaderReq) ResponseMsgType

func (this *BlockHeaderReq) ResponseMsgType() MessageType

type BlockHeaders

type BlockHeaders struct {
	Headers []*types.Header `json:"headers"`
}

BlockHeaders block header message

func (*BlockHeaders) MsgId

func (this *BlockHeaders) MsgId() types.Hash

func (*BlockHeaders) MsgType

func (this *BlockHeaders) MsgType() MessageType

func (*BlockHeaders) ResponseMsgType

func (this *BlockHeaders) ResponseMsgType() MessageType

type BlockReq

type BlockReq struct {
	HeaderHash types.Hash `json:"header_hash"`
}

BlockReq block request message

func (*BlockReq) MsgId

func (this *BlockReq) MsgId() types.Hash

func (*BlockReq) MsgType

func (this *BlockReq) MsgType() MessageType

func (*BlockReq) ResponseMsgType

func (this *BlockReq) ResponseMsgType() MessageType

type Message

type Message interface {
	MsgId() types.Hash
	MsgType() MessageType
	ResponseMsgType() MessageType
}

func ReadMessage

func ReadMessage(reader io.Reader) (Message, error)

ReadMessage read message

type MessageType

type MessageType uint32

MessageType is the message type in p2p network

type PingMsg

type PingMsg struct {
	State uint64
}

PingMsg ping message

func (*PingMsg) MsgId

func (this *PingMsg) MsgId() types.Hash

func (*PingMsg) MsgType

func (this *PingMsg) MsgType() MessageType

func (*PingMsg) ResponseMsgType

func (this *PingMsg) ResponseMsgType() MessageType

type PongMsg

type PongMsg struct {
	State uint64
}

PongMsg pong message

func (*PongMsg) MsgId

func (this *PongMsg) MsgId() types.Hash

func (*PongMsg) MsgType

func (this *PongMsg) MsgType() MessageType

func (*PongMsg) ResponseMsgType

func (this *PongMsg) ResponseMsgType() MessageType

type RejectMsg

type RejectMsg struct {
	Reason string
}

RejectMsg reject message

func (*RejectMsg) MsgId

func (this *RejectMsg) MsgId() types.Hash

func (*RejectMsg) MsgType

func (this *RejectMsg) MsgType() MessageType

func (*RejectMsg) ResponseMsgType

func (this *RejectMsg) ResponseMsgType() MessageType

type TraceMsg

type TraceMsg struct {
	ID     types.Hash           `json:"id"`
	Routes []*common.NetAddress `json:"routes"`
}

DebugP2P is a test message, used to trace the message route in p2p.

func (*TraceMsg) MsgId

func (this *TraceMsg) MsgId() types.Hash

func (*TraceMsg) MsgType

func (this *TraceMsg) MsgType() MessageType

func (*TraceMsg) ResponseMsgType

func (this *TraceMsg) ResponseMsgType() MessageType

type Transaction

type Transaction struct {
	Tx *types.Transaction `json:"tx"`
}

Transaction message

func (*Transaction) MsgId

func (this *Transaction) MsgId() types.Hash

func (*Transaction) MsgType

func (this *Transaction) MsgType() MessageType

func (*Transaction) ResponseMsgType

func (this *Transaction) ResponseMsgType() MessageType

type Version

type Version struct {
	Version string             `json:"version"`
	PortMe  int32              `json:"port_me"`
	Service config.ServiceFlag `json:"service"`
}

Version version message

func (*Version) MsgId

func (this *Version) MsgId() types.Hash

func (*Version) MsgType

func (this *Version) MsgType() MessageType

func (*Version) ResponseMsgType

func (this *Version) ResponseMsgType() MessageType

type VersionAck

type VersionAck struct {
}

Version ack message

func (*VersionAck) MsgId

func (this *VersionAck) MsgId() types.Hash

func (*VersionAck) MsgType

func (this *VersionAck) MsgType() MessageType

func (*VersionAck) ResponseMsgType

func (this *VersionAck) ResponseMsgType() MessageType

Jump to

Keyboard shortcuts

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