Documentation ¶
Index ¶
- Constants
- Variables
- func FromECDSA(priK *ecdsa.PrivateKey) []byte
- func GenerateKey() (*ecdsa.PrivateKey, error)
- func LoadECDSA(file string) (*ecdsa.PrivateKey, error)
- func P2pBigInt(sign int, abs []byte) *big.Int
- func P2pBigIntAbs2Bytes(bi *big.Int) []byte
- func P2pDefaultDataDir(flag bool) string
- func P2pGetLocalIpAddr() net.IP
- func P2pGetUserHomeDir() string
- func P2pIsValidNatType(natt string) bool
- func P2pNodeId2HexString(id NodeID) string
- func P2pNodeId2Pubkey(id []byte) *ecdsa.PublicKey
- func P2pSign(priKey *ecdsa.PrivateKey, data []byte) (r, s *big.Int, err error)
- func P2pSignBigInt(bi *big.Int) int
- func P2pSubNetId2HexString(id SubNetworkID) string
- func P2pVerify(pubKey *ecdsa.PublicKey, data []byte, r, s *big.Int) bool
- func S256() elliptic.Curve
- func SaveECDSA(file string, key *ecdsa.PrivateKey) error
- func ToECDSA(d []byte) (*ecdsa.PrivateKey, error)
- type Cfg4DhtConManager
- type Cfg4DhtFileDatastore
- type Cfg4DhtLsnManager
- type Cfg4DhtQryManager
- type Cfg4DhtRouteManager
- type Cfg4NatManager
- type Cfg4PeerListener
- type Cfg4PeerManager
- type Cfg4Protocols
- type Cfg4TabManager
- type Cfg4UdpNgbListener
- type Cfg4UdpNgbManager
- type Config
- type DsKey
- type Node
- type NodeID
- type P2pAppType
- type P2pCfgErrno
- func P2pSetConfig(name string, cfg *Config) (string, P2pCfgErrno)
- func P2pSetLocalDhtIpAddr(cfg *Config, ip string, port uint16) P2pCfgErrno
- func P2pSetLocalDhtPort(cfg *Config, port uint16) P2pCfgErrno
- func P2pSetLocalIpAddr(cfg *Config, ip string, udpp uint16, tcpp uint16) P2pCfgErrno
- func P2pSetLocalPort(cfg *Config, udpp uint16, tcpp uint16) P2pCfgErrno
- func P2pSetupLocalNodeId(cfg *Config) P2pCfgErrno
- func P2pSetupNatType(cfg *Config, natType string, gwIp string) P2pCfgErrno
- type Protocol
- type SubNetworkID
Constants ¶
const ( P2pNetworkTypeDynamic = 0 // neighbor discovering needed P2pNetworkTypeStatic = 1 // no discovering )
Node static Configuration parameters
const ( NATT_NONE = "none" NATT_PMP = "pmp" NATT_UPNP = "upnp" NATT_ANY = "any" )
Configuration about nat
const ( DftUdpPort = 30304 DftTcpPort = 30304 DftDhtPort = 40405 DftSnmBits = 0 )
Default configuration(notice that it's not a validated configuration and could never be applied), most of those defaults must be overided by higher lever module of system.
const DefaultNodeDatabase = "nodes"
Default node database name
const DefaultNodeName = "test"
Default p2p instance name
const DefaultVersion = "0.1.0.0"
Default version string, formated as "M.m0.m1.m2"
const DhtKeyLength = 32
DHT key length
const (
KeyFileName = "nodekey" // Path within the datadir to the node's private key
)
Some specific paths
const MaxInbounds = MaxPeers / 2 // +2
Max concurrency inboudn and outbound
const MaxOutbounds = MaxPeers / 2 // +2
const MaxPeers = 16
Max peers
const MaxProtocols = 32
Max protocols
const NodeIDBits = 512
Node ID length in bits
const NodeIDBytes = NodeIDBits / 8
const P2pMaxBootstrapNodes = 32
Bootstrap nodes, in a format like: node-identity-hex-string@ip:udp-port:tcp-port
const SubNetIdBytes = 2 // 2 bytes for sub network identity
Subnet
Variables ¶
var ( ZeroSubNet = SubNetworkID{0x80, 0x00} // zero sub network AnySubNet = SubNetworkID{0xff, 0xff} // any sub network VSubNet = SubNetworkID{0xef, 0xff} // validators' sub network identity )
var BootstrapNodeUrl = []string{
"4909CDF2A2C60BF1FE1E6BA849CC9297B06E00B54F0F8EB0F4B9A6AA688611FD7E43EDE402613761EC890AB46FE2218DC9B29FC47BE3AB8D1544B6C0559599AC@192.168.2.191:30303:30303",
}
var BootstrapNodes = P2pSetupDefaultBootstrapNodes()
Build "Node" struct for bootstraps
var DefaultDhtLocalNode = Node{ IP: P2pGetLocalIpAddr(), UDP: 0, TCP: DftDhtPort, ID: NodeID{0}, }
var DefaultLocalNode = Node{ IP: P2pGetLocalIpAddr(), UDP: DftUdpPort, TCP: DftTcpPort, ID: NodeID{0}, }
var DftDatDir = P2pDefaultDataDir(true)
Get default non-bootstrap node config
Functions ¶
func FromECDSA ¶
func FromECDSA(priK *ecdsa.PrivateKey) []byte
FromECDSA exports a private key into a binary dump.
func GenerateKey ¶
func GenerateKey() (*ecdsa.PrivateKey, error)
func LoadECDSA ¶
func LoadECDSA(file string) (*ecdsa.PrivateKey, error)
LoadECDSA loads a secp256k1 private key from the given file
func P2pBigIntAbs2Bytes ¶
Get bytes of big int absolute value
func P2pNodeId2Pubkey ¶
Trans node identity to public key
func P2pSubNetId2HexString ¶
func P2pSubNetId2HexString(id SubNetworkID) string
Sub network identity to hex string
Types ¶
type Cfg4DhtConManager ¶
type Cfg4DhtConManager struct { ChainId uint32 // chain identity Local *Node // pointer to local node specification BootstrapNode bool // bootstrap node flag MaxCon int // max number of connection MinCon int // min number of connection HsTimeout time.Duration // handshake timeout duration }
Configuration about dht connection manager
func P2pConfig4DhtConManager ¶
func P2pConfig4DhtConManager(name string) *Cfg4DhtConManager
Get configuration for dht connection manager
type Cfg4DhtFileDatastore ¶
type Cfg4DhtFileDatastore struct { Path string // data store path ShardFuncName string // shard function name PadLength int // padding length Sync bool // sync file store flag }
func P2pConfig4DhtFileDatastore ¶
func P2pConfig4DhtFileDatastore(name string) *Cfg4DhtFileDatastore
Get configuration for dht file data store
type Cfg4DhtLsnManager ¶
type Cfg4DhtLsnManager struct { IP net.IP // ip address PortTcp uint16 // port number for tcp PortUdp uint16 // port number for udp }
Configuration about dht listener management
func P2pConfig4DhtLsnManager ¶
func P2pConfig4DhtLsnManager(name string) *Cfg4DhtLsnManager
Get configuration for dht listener manager
type Cfg4DhtQryManager ¶
type Cfg4DhtQryManager struct { Local *Node // pointer to local node specification MaxPendings int // max pendings can be held in the list MaxActInsts int // max concurrent actived instances for one query QryExpired time.Duration // duration to get expired for a query QryInstExpired time.Duration // duration to get expired for a query instance }
Configuration about dht query manager
func P2pConfig4DhtQryManager ¶
func P2pConfig4DhtQryManager(name string) *Cfg4DhtQryManager
Get configuration for dht query manager
type Cfg4DhtRouteManager ¶
type Cfg4DhtRouteManager struct { BootstrapNode bool // bootstarp node flag NodeId NodeID // local node identity RandomQryNum int // times to try query for a random peer identity Period time.Duration // timer period to fire a bootstrap }
Configuration about dht route manager
func P2pConfig4DhtRouteManager ¶
func P2pConfig4DhtRouteManager(name string) *Cfg4DhtRouteManager
Get configuration for dht route manager
type Cfg4NatManager ¶
type Cfg4NatManager struct { NatType string // "pmp", "upnp", "none" GwIp net.IP // gateway ip address when "pmp" specified }
func P2pConfig4NatManager ¶
func P2pConfig4NatManager(name string) *Cfg4NatManager
Get configuration for nat
type Cfg4PeerListener ¶
type Cfg4PeerListener struct { IP net.IP // ip address Port uint16 // port numbers ID NodeID // the node's public key MaxInBounds int // max concurrency inbounds }
Configuration about peer listener on TCP
func P2pConfig4PeerListener ¶
func P2pConfig4PeerListener(name string) *Cfg4PeerListener
Get configuration of peer listener
type Cfg4PeerManager ¶
type Cfg4PeerManager struct { CfgName string // p2p configuration name ChainId uint32 // chain identity NetworkType int // p2p network type IP net.IP // ip address Port uint16 // tcp port number UDP uint16 // udp port number, used with handshake procedure ID NodeID // the node's public key StaticMaxPeers int // max peers would be StaticMaxOutbounds int // max concurrency outbounds StaticMaxInBounds int // max concurrency inbounds StaticNodes []*Node // static nodes StaticNetId SubNetworkID // static network identity SubNetMaxPeers map[SubNetworkID]int // max peers would be SubNetMaxOutbounds map[SubNetworkID]int // max concurrency outbounds SubNetMaxInBounds map[SubNetworkID]int // max concurrency inbounds SubNetKeyList map[SubNetworkID]ecdsa.PrivateKey // keys for sub-node SubNetNodeList map[SubNetworkID]Node // sub-node SubNetIdList []SubNetworkID // sub network identity list. do not put the identity // of the local node in this list. NoDial bool // do not dial outbound NoAccept bool // do not accept inbound BootstrapNode bool // local is a bootstrap node ProtoNum uint32 // local protocol number Protocols []Protocol // local protocol table }
Configuration about peer manager
func P2pConfig4PeerManager ¶
func P2pConfig4PeerManager(name string) *Cfg4PeerManager
Get configuration of peer manager
type Cfg4Protocols ¶
type Cfg4Protocols struct { ProtoNum uint32 // local protocol number Protocols []Protocol // local protocol table }
Configuration about protocols supported
type Cfg4TabManager ¶
type Cfg4TabManager struct { NetworkType int // Network type Local Node // local node BootstrapNodes []*Node // bootstrap nodes DataDir string // data directory Name string // node name NodeDB string // node database NoHistory bool // do not use history of nodes BootstrapNode bool // bootstrap node flag SnidMaskBits int // mask bits for subnet identity SubNetNodeList map[SubNetworkID]Node // sub network node identities SubNetIdList []SubNetworkID // sub network identity list. do not put the identity }
Configuration about table manager
func P2pConfig4TabManager ¶
func P2pConfig4TabManager(name string) *Cfg4TabManager
Get configuration of table manager
type Cfg4UdpNgbListener ¶
type Cfg4UdpNgbListener struct { IP net.IP // ip address UDP uint16 // udp port numbers TCP uint16 // tcp port numbers ID NodeID // the node's public key CheckAddr bool // check reported address against the source ip }
Configuration about neighbor listener on UDP
func P2pConfig4UdpNgbListener ¶
func P2pConfig4UdpNgbListener(name string) *Cfg4UdpNgbListener
Get configuration of neighbor discovering listener
type Cfg4UdpNgbManager ¶
type Cfg4UdpNgbManager struct { IP net.IP // ip address UDP uint16 // udp port numbers TCP uint16 // tcp port numbers ID NodeID // the node's public key NetworkType int // network type SubNetNodeList map[SubNetworkID]Node // sub-node identities SubNetIdList []SubNetworkID // sub network identity list }
Configuration about neighbor manager on UDP
func P2pConfig4UdpNgbManager ¶
func P2pConfig4UdpNgbManager(name string) *Cfg4UdpNgbManager
Get configuration of neighbor discovering manager
type Config ¶
type Config struct { AppType P2pAppType // application type CfgName string // configureation name Version string // p2p version Name string // node name ChainId uint32 // chain identity PrivateKey *ecdsa.PrivateKey // node private key PublicKey *ecdsa.PublicKey // node public key NetworkType int // p2p network type BootstrapNodes []*Node // bootstrap nodes StaticMaxPeers int // max peers would be StaticMaxOutbounds int // max concurrency outbounds StaticMaxInbounds int // max concurrency inbounds StaticNetId SubNetworkID // static network identity StaticNodes []*Node // static nodes NodeDataDir string // node data directory NodeDatabase string // node database NoNdbHistory bool // do not use history of nodes NoDial bool // do not dial out flag NoAccept bool // do not accept incoming dial flag BootstrapNode bool // bootstrap node flag Local Node // local node struct CheckAddress bool // check the neighbor reported address with the source ip ProtoNum uint32 // local protocol number Protocols []Protocol // local protocol table SnidMaskBits int // mask bits for subnet identity SubNetKeyList map[SubNetworkID]ecdsa.PrivateKey // keys for sub-node SubNetNodeList map[SubNetworkID]Node // sub-node identities SubNetMaxPeers map[SubNetworkID]int // max peers would be SubNetMaxOutbounds map[SubNetworkID]int // max concurrency outbounds SubNetMaxInBounds map[SubNetworkID]int // max concurrency inbounds SubNetIdList []SubNetworkID // sub network identity list DhtLocal Node // dht local node config DhtRutCfg Cfg4DhtRouteManager // for dht route manager DhtQryCfg Cfg4DhtQryManager // for dht query manager DhtConCfg Cfg4DhtConManager // for dht connection manager DhtFdsCfg Cfg4DhtFileDatastore // for dht file data store NatCfg Cfg4NatManager // for nat manager }
Total configuration
func P2pDefaultBootstrapConfig ¶
Get default bootstrap node config
func P2pDefaultConfig ¶
type DsKey ¶
type DsKey [DhtKeyLength]byte
type Node ¶
type Node struct { IP net.IP // ip address UDP, TCP uint16 // port numbers ID NodeID // the node's public key }
Node
func P2pSetupBootstrapNodes ¶
Setup bootstrap nodes
func P2pSetupDefaultBootstrapNodes ¶
func P2pSetupDefaultBootstrapNodes() []*Node
Setup default bootstrap nodes
type P2pAppType ¶
type P2pAppType int
Application type
const ( P2P_TYPE_CHAIN P2pAppType = 0 P2P_TYPE_DHT P2pAppType = 1 P2P_TYPE_ALL P2pAppType = 2 )
type P2pCfgErrno ¶
type P2pCfgErrno int
errno
const ( P2pCfgEnoNone P2pCfgErrno = iota P2pCfgEnoParameter P2pCfgEnoPublicKye P2pCfgEnoPrivateKye P2pCfgEnoDataDir P2pCfgEnoDatabase P2pCfgEnoIpAddr P2pCfgEnoNodeId P2pCfgEnoNat P2pCfgEnoUnknown )
func P2pSetConfig ¶
func P2pSetConfig(name string, cfg *Config) (string, P2pCfgErrno)
func P2pSetLocalDhtIpAddr ¶
func P2pSetLocalDhtIpAddr(cfg *Config, ip string, port uint16) P2pCfgErrno
Set local ip address and port for dht application
func P2pSetLocalDhtPort ¶
func P2pSetLocalDhtPort(cfg *Config, port uint16) P2pCfgErrno
Set local dht port
func P2pSetLocalIpAddr ¶
func P2pSetLocalIpAddr(cfg *Config, ip string, udpp uint16, tcpp uint16) P2pCfgErrno
Set local ip address and port for chain application
func P2pSetLocalPort ¶
func P2pSetLocalPort(cfg *Config, udpp uint16, tcpp uint16) P2pCfgErrno
Set local port
func P2pSetupLocalNodeId ¶
func P2pSetupLocalNodeId(cfg *Config) P2pCfgErrno
Setup local node identity
func P2pSetupNatType ¶
func P2pSetupNatType(cfg *Config, natType string, gwIp string) P2pCfgErrno
func (P2pCfgErrno) Error ¶
func (eno P2pCfgErrno) Error() string
type SubNetworkID ¶
type SubNetworkID [SubNetIdBytes]byte // sbu network identity