common

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HashSize                 = 32
	DefaultHashCacheMaxCount = 32768
)
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        = 2          //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_MSG_LEN     = 30 * 1024 * 1024 //the maximum message length
	MAX_PAYLOAD_LEN = MAX_MSG_LEN - MSG_HDR_LEN
)

msg cmd const

View Source
const (
	PROTOCOL_VERSION  = 0     //protocol version
	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   = 0     //max reconnect time of remote peer
	CHAN_CAPABILITY   = 10000 //channel capability of recv link

	PEER_SEND_CHAN_LENGTH = 1000 // send channel length for every peer
)

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 (
	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
	DISCONNECT_TYPE = "disconnect" //peer disconnect info raise by link

	CONSENSUS_TYPE  = "consensus"
	CHECKPOINT_TYPE = "checkpoint"

	REQUEST_OUT_OF_RANGE_IDS_TYPE = "future_ids"
	REQUEST_BLOCK_BATCH_TYPE      = "sigblk_batch"
	DETECT_FORMER_IDS_TYPE        = "former_ids"
	CLEAR_OUT_OF_RABGE_STATE      = "clear_state"
)

const channel msg id and type

View Source
const (
	MaxTrxCountInBloomFiler  = 1000000  // max cache trx count
	BloomFilterOfRecvTrxArgM = 14377588 // bloom filter bit size
	BloomFilterOfRecvTrxArgK = 10       // bloom filter hash func num

	BATCH_LENGTH      = 50 // length of id batch or block batch
	BLOCKS_SIZE_LIMIT = constants.MaxBlockSize + constants.MaxBlockSizeTolerance
	MAX_BLOCK_COUNT   = 50 // max block count
)
View Source
const (
	MAX_ADDR_NODE_CNT = 64 //the maximum peer address from msg
)

msg type const

Variables

View Source
var ErrTooLarge = errors.New("bytes.Buffer: too large")

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 HashCache added in v1.0.2

type HashCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewHashCache added in v1.0.2

func NewHashCache(maxSize int) *HashCache

func (*HashCache) Has added in v1.0.2

func (c *HashCache) Has(hash [HashSize]byte) bool

func (*HashCache) Put added in v1.0.2

func (c *HashCache) Put(hash [HashSize]byte)

func (*HashCache) PutIfNotFound added in v1.0.2

func (c *HashCache) PutIfNotFound(hash [HashSize]byte) (changed bool)

type RateLimiter added in v1.0.2

type RateLimiter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewRateLimiter added in v1.0.2

func NewRateLimiter(limit uint32) *RateLimiter

func (*RateLimiter) Request added in v1.0.2

func (r *RateLimiter) Request(amount uint32, allOrNothing bool) (approved uint32)

func (*RateLimiter) TryRequest added in v1.0.2

func (r *RateLimiter) TryRequest(amount uint32, allOrNothing bool) (approved uint32)

type ZeroCopySink added in v1.0.2

type ZeroCopySink struct {
	// contains filtered or unexported fields
}

func NewZeroCopySink added in v1.0.2

func NewZeroCopySink(b []byte) *ZeroCopySink

NewReader returns a new ZeroCopySink reading from b.

func (*ZeroCopySink) BackUp added in v1.0.2

func (self *ZeroCopySink) BackUp(n uint64)

Backs up a number of bytes, so that the next call to NextXXX() returns data again that was already returned by the last call to NextXXX().

func (*ZeroCopySink) Bytes added in v1.0.2

func (self *ZeroCopySink) Bytes() []byte

func (*ZeroCopySink) NextBytes added in v1.0.2

func (self *ZeroCopySink) NextBytes(n uint64) (data []byte)

func (*ZeroCopySink) Reset added in v1.0.2

func (self *ZeroCopySink) Reset()

func (*ZeroCopySink) Size added in v1.0.2

func (self *ZeroCopySink) Size() uint64

func (*ZeroCopySink) WriteBytes added in v1.0.2

func (self *ZeroCopySink) WriteBytes(p []byte)

func (*ZeroCopySink) WriteUint32 added in v1.0.2

func (self *ZeroCopySink) WriteUint32(data uint32)

type ZeroCopySource added in v1.0.2

type ZeroCopySource struct {
	// contains filtered or unexported fields
}

func NewZeroCopySource added in v1.0.2

func NewZeroCopySource(b []byte) *ZeroCopySource

NewReader returns a new ZeroCopySource reading from b.

func (*ZeroCopySource) Data added in v1.0.2

func (self *ZeroCopySource) Data() []byte

Jump to

Keyboard shortcuts

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