common

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2018 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VERIFY_NODE  = 1 //peer involved in consensus
	SERVICE_NODE = 2 //peer only sync with consensus peer
)

peer capability

View Source
const (
	PER_SEND_LEN        = 1024 * 256 //byte len per conn write
	MAX_BUF_LEN         = 1024 * 256 //the maximum buffer to receive message
	WRITE_DEADLINE      = 5          //deadline of conn write
	REQ_INTERVAL        = 3          //single request max interval in second
	MAX_REQ_RECORD_SIZE = 1000       //the maximum request record size
	MAX_RESP_CACHE_SIZE = 50         //the maximum response cache
)

link and concurrent const

View Source
const (
	MSG_CMD_LEN      = 12               //msg type length in byte
	CHECKSUM_LEN     = 4                //checksum length in byte
	MSG_HDR_LEN      = 24               //msg hdr length in byte
	MAX_BLK_HDR_CNT  = 500              //hdr count once when sync header
	MAX_INV_HDR_CNT  = 500              //inventory count once when req inv
	MAX_REQ_BLK_ONCE = 16               //req blk count once from one peer when sync blk
	MAX_MSG_LEN      = 30 * 1024 * 1024 //the maximum message length
	MAX_PAYLOAD_LEN  = MAX_MSG_LEN - MSG_HDR_LEN
)

msg cmd const

View Source
const (
	MAX_ADDR_NODE_CNT = 64 //the maximum peer address from msg
	MAX_INV_BLK_CNT   = 64 //the maximum blk hash cnt of inv msg
)

msg type const

View Source
const (
	PROTOCOL_VERSION      = 0     //protocol version
	UPDATE_RATE_PER_BLOCK = 2     //info update rate in one generate block period
	KEEPALIVE_TIMEOUT     = 15    //contact timeout in sec
	DIAL_TIMEOUT          = 6     //connect timeout in sec
	CONN_MONITOR          = 6     //time to retry connect in sec
	CONN_MAX_BACK         = 4000  //max backoff time in micro sec
	MAX_RETRY_COUNT       = 3     //max reconnect time of remote peer
	CHAN_CAPABILITY       = 10000 //channel capability of recv link

)

info update const

View Source
const (
	INIT        = 0 //initial
	HAND        = 1 //send verion to peer
	HAND_SHAKE  = 2 //haven`t send verion to peer and receive peer`s version
	HAND_SHAKED = 3 //send verion to peer and receive peer`s version
	ESTABLISH   = 4 //receive peer`s verack
	INACTIVITY  = 5 //link broken
)

The peer state

View Source
const (
	RECENT_TIMEOUT   = 60
	RECENT_FILE_NAME = "peers.recent"
	RECENT_LIMIT     = 10 //recent contact list limit
)

recent contact const

View Source
const (
	VERSION_TYPE    = "version"   //peer`s information
	VERACK_TYPE     = "verack"    //ack msg after version recv
	GetADDR_TYPE    = "getaddr"   //req nbr address from peer
	ADDR_TYPE       = "addr"      //nbr address
	PING_TYPE       = "ping"      //ping  sync height
	PONG_TYPE       = "pong"      //pong  recv nbr height
	GET_DATA_TYPE   = "getdata"   //req data from peer
	BLOCK_TYPE      = "sig_block" //blk payload
	ID_TYPE         = "id"
	REQ_ID_TYPE     = "req_id"
	TX_TYPE         = "sig_trx"    //transaction
	NOT_FOUND_TYPE  = "notfound"   //peer can`t find blk according to the hash
	DISCONNECT_TYPE = "disconnect" //peer disconnect info raise by link
)

const channel msg id and type

Variables

This section is empty.

Functions

func Checksum

func Checksum(data []byte) [CHECKSUM_LEN]byte

func NewChecksum

func NewChecksum() hash.Hash

func ParseIPAddr

func ParseIPAddr(s string) (string, error)

ParseIPAddr return ip address

func ParseIPPort

func ParseIPPort(s string) (string, error)

ParseIPPort return ip port

Types

type PeerAddr

type PeerAddr struct {
	Time          int64    //latest timestamp
	Services      uint64   //service type
	IpAddr        [16]byte //ip address
	Port          uint16   //sync port
	ConsensusPort uint16   //consensus port
	ID            uint64   //Unique ID
}

PeerAddr represent peer`s net information

Jump to

Keyboard shortcuts

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