common

package
v1.14.4 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 License: LGPL-3.0 Imports: 16 Imported by: 45

Documentation

Overview

* Copyright (C) 2018 The ontology Authors * This file is part of The ontology library. * * The ontology is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The ontology is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with The ontology. If not, see <http://www.gnu.org/licenses/>.

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
	MAX_TX_CACHE_SIZE   = 100000     //the maximum txHash cache size
)

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_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
	SYNC_BLK_WAIT         = 2     //timespan for blk sync check
)

info update const

View Source
const (
	RECENT_TIMEOUT   = 60
	RECENT_FILE_NAME = "peers.recent"
)

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_HEADERS_TYPE   = "getheaders"  //req blk hdr
	HEADERS_TYPE       = "headers"     //blk hdr
	INV_TYPE           = "inv"         //inv payload
	GET_DATA_TYPE      = "getdata"     //req data from peer
	BLOCK_TYPE         = "block"       //blk payload
	TX_TYPE            = "tx"          //transaction
	CONSENSUS_TYPE     = "consensus"   //consensus payload
	GET_BLOCKS_TYPE    = "getblocks"   //req blks from peer
	NOT_FOUND_TYPE     = "notfound"    //peer can`t find blk according to the hash
	FINDNODE_TYPE      = "findnode"    // find node using dht
	FINDNODE_RESP_TYPE = "findnodeack" // find node using dht
	UPDATE_KADID_TYPE  = "updatekadid" //update node kadid

	GET_SUBNET_MEMBERS_TYPE = "getmembers" // request subnet members
	SUBNET_MEMBERS_TYPE     = "members"    // response subnet members
	SUBNET_OFFLINE_TYPE     = "offline"    // offline witness message
)

const channel msg id and type

View Source
const HTTP_INFO_FLAG = 0 //peer`s http info bit in cap field

cap flag

View Source
const MIN_VERSION_FOR_DHT = "1.9.1-beta"
View Source
const (
	RecentPeerElapseLimit = 60
)

Variables

View Source
var Difficulty = 18 //bit

Functions

func Checksum added in v1.0.3

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

func CommonPrefixLen added in v1.10.0

func CommonPrefixLen(a, b PeerId) int

CommonPrefixLen(cpl) calculate two ID's xor prefix 0

func NewChecksum added in v1.0.3

func NewChecksum() hash.Hash

func ParseIPAddr added in v0.9.2

func ParseIPAddr(s string) (string, error)

ParseIPAddr return ip address

Types

type GlobalLoggerWrapper added in v1.11.0

type GlobalLoggerWrapper struct{}

the global log.Log singletion will reinit periodically so must be accessed by function like log.Warn

func (*GlobalLoggerWrapper) Debug added in v1.11.0

func (self *GlobalLoggerWrapper) Debug(a ...interface{})

func (*GlobalLoggerWrapper) Debugf added in v1.11.0

func (self *GlobalLoggerWrapper) Debugf(format string, a ...interface{})

func (*GlobalLoggerWrapper) Error added in v1.11.0

func (self *GlobalLoggerWrapper) Error(a ...interface{})

func (*GlobalLoggerWrapper) Errorf added in v1.11.0

func (self *GlobalLoggerWrapper) Errorf(format string, a ...interface{})

func (*GlobalLoggerWrapper) Fatal added in v1.11.0

func (self *GlobalLoggerWrapper) Fatal(a ...interface{})

func (*GlobalLoggerWrapper) Fatalf added in v1.11.0

func (self *GlobalLoggerWrapper) Fatalf(format string, a ...interface{})

func (*GlobalLoggerWrapper) Info added in v1.11.0

func (self *GlobalLoggerWrapper) Info(a ...interface{})

func (*GlobalLoggerWrapper) Infof added in v1.11.0

func (self *GlobalLoggerWrapper) Infof(format string, a ...interface{})

func (*GlobalLoggerWrapper) Warn added in v1.11.0

func (self *GlobalLoggerWrapper) Warn(a ...interface{})

func (*GlobalLoggerWrapper) Warnf added in v1.11.0

func (self *GlobalLoggerWrapper) Warnf(format string, a ...interface{})

type Logger added in v1.11.0

type Logger interface {
	Debug(a ...interface{})
	Info(a ...interface{})
	Warn(a ...interface{})
	Error(a ...interface{})
	Fatal(a ...interface{})
	Debugf(format string, a ...interface{})
	Infof(format string, a ...interface{})
	Warnf(format string, a ...interface{})
	Errorf(format string, a ...interface{})
	Fatalf(format string, a ...interface{})
}

func LoggerWithContext added in v1.11.0

func LoggerWithContext(logger Logger, context string) Logger

func NewGlobalLoggerWrapper added in v1.11.0

func NewGlobalLoggerWrapper() Logger

type PeerAddr

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

PeerAddr represent peer`s net information

type PeerIDAddressPair added in v1.10.0

type PeerIDAddressPair struct {
	ID      PeerId
	Address string
}

type PeerId added in v1.10.0

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

func PseudoPeerIdFromUint64 added in v1.10.0

func PseudoPeerIdFromUint64(data uint64) PeerId

func (PeerId) Closer added in v1.10.0

func (self PeerId) Closer(a, b PeerId) bool

Closer returns true if a is closer to self than b is

func (*PeerId) Deserialization added in v1.10.0

func (self *PeerId) Deserialization(source *common.ZeroCopySource) error

func (PeerId) Distance added in v1.10.0

func (self PeerId) Distance(b PeerId) [20]byte

func (PeerId) GenRandPeerId added in v1.10.0

func (self PeerId) GenRandPeerId(prefix uint) PeerId

func (PeerId) IsEmpty added in v1.10.0

func (self PeerId) IsEmpty() bool

func (PeerId) IsPseudoPeerId added in v1.10.0

func (self PeerId) IsPseudoPeerId() bool

func (PeerId) Serialization added in v1.10.0

func (self PeerId) Serialization(sink *common.ZeroCopySink)

func (*PeerId) ToHexString added in v1.10.0

func (self *PeerId) ToHexString() string

func (PeerId) ToUint64 added in v1.10.0

func (self PeerId) ToUint64() uint64

type PeerKeyId added in v1.10.0

type PeerKeyId struct {
	PublicKey keypair.PublicKey

	Id PeerId
}

func RandPeerKeyId added in v1.10.0

func RandPeerKeyId() *PeerKeyId

func (*PeerKeyId) Deserialization added in v1.10.0

func (this *PeerKeyId) Deserialization(source *common.ZeroCopySource) error

func (*PeerKeyId) Serialization added in v1.10.0

func (this *PeerKeyId) Serialization(sink *common.ZeroCopySink)

type SubnetMemberInfo added in v1.11.0

type SubnetMemberInfo struct {
	PubKey     string `json:"pubKey"`
	ListenAddr string `json:"listenAddr"`
	Connected  bool   `json:"connected"`
	Height     uint64 `json:"height"`
	Version    string `json:"version"`
}

Jump to

Keyboard shortcuts

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