config

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2019 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	P2pNetworkTypeDynamic = 0 // neighbor discovering needed
	P2pNetworkTypeStatic  = 1 // no discovering
)

Node static Configuration parameters

View Source
const (
	NATT_NONE = "none"
	NATT_PMP  = "pmp"
	NATT_UPNP = "upnp"
	NATT_ANY  = "any"
)

Configuration about nat

View Source
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.

View Source
const DefaultNodeDatabase = "nodes"

Default node database name

View Source
const DefaultNodeName = "test"

Default p2p instance name

View Source
const DefaultVersion = "0.1.0.0"

Default version string, formated as "M.m0.m1.m2"

View Source
const DhtKeyLength = 32

DHT key length

View Source
const (
	KeyFileName = "nodekey" // Path within the datadir to the node's private key

)

Some specific paths

View Source
const MaxInbounds = MaxPeers / 2 // +2

Max concurrency inboudn and outbound

View Source
const MaxOutbounds = MaxPeers / 2 // +2
View Source
const MaxPeers = 16

Max peers

View Source
const MaxProtocols = 32

Max protocols

View Source
const NodeIDBits = 512

Node ID length in bits

View Source
const NodeIDBytes = NodeIDBits / 8
View Source
const P2pMaxBootstrapNodes = 32

Bootstrap nodes, in a format like: node-identity-hex-string@ip:udp-port:tcp-port

View Source
const SubNetIdBytes = 2 // 2 bytes for sub network identity

Subnet

Variables

View Source
var (
	ZeroSubNet = SubNetworkID{0x80, 0x00} // zero sub network
	AnySubNet  = SubNetworkID{0xff, 0xff} // any sub network
	VSubNet    = SubNetworkID{0xef, 0xff} // validators' sub network identity
)
View Source
var BootstrapNodeUrl = []string{
	"4909CDF2A2C60BF1FE1E6BA849CC9297B06E00B54F0F8EB0F4B9A6AA688611FD7E43EDE402613761EC890AB46FE2218DC9B29FC47BE3AB8D1544B6C0559599AC@192.168.2.191:30303:30303",
}

Build "Node" struct for bootstraps

View Source
var DefaultDhtLocalNode = Node{
	IP:  P2pGetLocalIpAddr(),
	UDP: 0,
	TCP: DftDhtPort,
	ID:  NodeID{0},
}
View Source
var DefaultLocalNode = Node{
	IP:  P2pGetLocalIpAddr(),
	UDP: DftUdpPort,
	TCP: DftTcpPort,
	ID:  NodeID{0},
}

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 P2pBigInt

func P2pBigInt(sign int, abs []byte) *big.Int

Construct big integer by sign and absolute value

func P2pBigIntAbs2Bytes

func P2pBigIntAbs2Bytes(bi *big.Int) []byte

Get bytes of big int absolute value

func P2pDefaultDataDir

func P2pDefaultDataDir(flag bool) string

Get default data directory

func P2pGetLocalIpAddr

func P2pGetLocalIpAddr() net.IP

Get local ip address

func P2pGetUserHomeDir

func P2pGetUserHomeDir() string

Get user directory

func P2pIsValidNatType

func P2pIsValidNatType(natt string) bool

Setup nat configuration

func P2pNodeId2HexString

func P2pNodeId2HexString(id NodeID) string

Node identity to hex string

func P2pNodeId2Pubkey

func P2pNodeId2Pubkey(id []byte) *ecdsa.PublicKey

Trans node identity to public key

func P2pSign

func P2pSign(priKey *ecdsa.PrivateKey, data []byte) (r, s *big.Int, err error)

Sign

func P2pSignBigInt

func P2pSignBigInt(bi *big.Int) int

Get sign value of big int

func P2pSubNetId2HexString

func P2pSubNetId2HexString(id SubNetworkID) string

Sub network identity to hex string

func P2pVerify

func P2pVerify(pubKey *ecdsa.PublicKey, data []byte, r, s *big.Int) bool

Verify

func S256

func S256() elliptic.Curve

elliptic.P256

func SaveECDSA

func SaveECDSA(file string, key *ecdsa.PrivateKey) error

SaveECDSA saves a secp256k1 private key to the given file with restrictive permissions. The key data is saved hex-encoded.

func ToECDSA

func ToECDSA(d []byte) (*ecdsa.PrivateKey, error)

ToECDSA creates a private key with the given D value.

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

func P2pConfig4Protocols

func P2pConfig4Protocols(name string) *Cfg4Protocols

Get protocols

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

func P2pDefaultBootstrapConfig(bsUrls []string) *Config

Get default bootstrap node config

func P2pDefaultConfig

func P2pDefaultConfig(bsUrls []string) *Config

func P2pGetConfig

func P2pGetConfig(name string) *Config

Get global configuration pointer

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

func P2pSetupBootstrapNodes(urls []string) []*Node

Setup bootstrap nodes

func P2pSetupDefaultBootstrapNodes

func P2pSetupDefaultBootstrapNodes() []*Node

Setup default bootstrap nodes

type NodeID

type NodeID [NodeIDBytes]byte

Node identity

func P2pHexString2NodeId

func P2pHexString2NodeId(hex string) *NodeID

Hex-string to node identity

func P2pPubkey2NodeId

func P2pPubkey2NodeId(pub *ecdsa.PublicKey) *NodeID

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 Protocol

type Protocol struct {
	Pid uint32  // protocol identity
	Ver [4]byte // protocol version: M.m0.m1.m2
}

type SubNetworkID

type SubNetworkID [SubNetIdBytes]byte // sbu network identity

Jump to

Keyboard shortcuts

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