Documentation ¶
Index ¶
Constants ¶
View Source
const ( DefaultNetID = 3 DefaultListenAddress = "0.0.0.0:8483" PeerKeyFileName = "peerKey" DefaultPort = 8483 DefaultListenInterface = "0.0.0.0" DefaultBucketSize = 32 DefaultBucketCount = 32 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // ListenAddress is the network address where socket listen on, usually is the inner address // default value is "0.0.0.0:8483" ListenAddress string // PublicAddress is the network address can be access by other nodes, usually is the public Internet address PublicAddress string // DataDir is the directory to storing p2p data, if is null-string, will use memory as database DataDir string // PeerKey is to encrypt message, the corresponding public key use for NodeID, MUST NOT be revealed PeerKey string // BootNodes are roles as network entrance. Node can discovery more other nodes by send UDP query BootNodes, // but not create a TCP connection to BootNodes directly BootNodes []string // BootSeeds are the address where can query BootNodes, is a more flexible option than BootNodes BootSeeds []string // NetID is to mark which network our node in, nodes from different network can`t connect each other NetID int BucketCount int BucketSize int // contains filtered or unexported fields }
func (*Config) Ensure ¶
Ensure will set default value to missing fields and construct node. MUST be invoked before use. Will generate a random PeerKey and store in local file, `${DataDir}/peer.key`, if missing one.
func (*Config) PrivateKey ¶
func (cfg *Config) PrivateKey() ed25519.PrivateKey
type Discovery ¶
type Discovery interface { Start() error Stop() error Delete(id vnode.NodeID, reason error) GetNodes(count int) []*vnode.Node Resolve(id vnode.NodeID) *vnode.Node AllNodes() []*vnode.Node SubscribeNode(receiver func(n *vnode.Node)) (subId int) Unsubscribe(subId int) }
Discovery is the interface to discovery other node
type NodeDB ¶
type NodeDB interface { StoreNode(node *vnode.Node) (err error) RemoveNode(ID vnode.NodeID) ReadNodes(count int, expiration time.Duration) []*vnode.Node RetrieveActiveAt(id vnode.NodeID) int64 StoreActiveAt(id vnode.NodeID, v int64) RetrieveCheckAt(id vnode.NodeID) int64 StoreCheckAt(id vnode.NodeID, v int64) Close() error Clean(expiration time.Duration) }
type Observer ¶
type Observer interface { Sub(sub Subscriber) UnSub(sub Subscriber) }
type Result ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.