Documentation ¶
Index ¶
- Constants
- func StartService(nodeDir string, myID common.Address, myAddr *net.UDPAddr, bootstrap []*Node, ...) (*Database, *UDP)
- type Database
- func (db *Database) FindByNodeID(id common.Address) (*Node, bool)
- func (db *Database) GetCopy() map[common.Hash]*Node
- func (db *Database) SaveNodes(nodeDir string)
- func (db *Database) SetHookForDeleteNode(hook NodeHook)
- func (db *Database) SetHookForNewNode(hook NodeHook)
- func (db *Database) StartSaveNodes(nodeDir string, done chan struct{})
- type Node
- func MustNewNodeWithAddr(id common.Address, addr string, shard uint) *Node
- func NewNode(id common.Address, ip net.IP, port int, shard uint) *Node
- func NewNodeFromIP(ip string) (*Node, error)
- func NewNodeFromString(id string) (*Node, error)
- func NewNodeWithAddr(id common.Address, addr *net.UDPAddr, shard uint) *Node
- func NewNodeWithAddrString(id common.Address, addr string, shard uint) (*Node, error)
- type NodeHook
- type Table
- type UDP
Constants ¶
const ( // NodesBackupInterval is the nodes info of backup interval time NodesBackupInterval = time.Minute * 20 // NodesBackupFileName is the nodes info of backup file name NodesBackupFileName = "nodes.json" )
const (
// UndefinedShardNumber indicates the shard number is undefined
UndefinedShardNumber = 0
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database definition
func (*Database) FindByNodeID ¶
FindByNodeID find node by its id
func (*Database) SetHookForDeleteNode ¶
SetHookForDeleteNode this hook will be called when we lost a Node's connection Note it will run in a new go routine
func (*Database) SetHookForNewNode ¶
SetHookForNewNode this hook will be called when find new Node Note it will run in a new go routine
func (*Database) StartSaveNodes ¶
StartSaveNodes will save to a file and open a timer to backup the nodes info
type Node ¶
type Node struct { ID common.Address //public key actually IP net.IP UDPPort, TCPPort int Shard uint //node shard number // contains filtered or unexported fields }
Node the node that contains its public key and network address
func MustNewNodeWithAddr ¶
MustNewNodeWithAddr new node with id and network address, and panics on any error.
func NewNodeFromIP ¶
NewNodeFromIP new node from ip address
func NewNodeFromString ¶
NewNodeFromString new node from id
func NewNodeWithAddr ¶
NewNodeWithAddr new node with id and network address
func NewNodeWithAddrString ¶
NewNodeWithAddrString new node with id and network address.
func (*Node) GetUDPAddr ¶
GetUDPAddr get UDPAddr from node struct
func (Node) MarshalText ¶
MarshalText marshal node to json
func (*Node) UnmarshalText ¶
UnmarshalText unmarshal json to node
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table used to save peers information
func (*Table) GetRandNodes ¶
type UDP ¶
type UDP struct {
// contains filtered or unexported fields
}
func (*UDP) AddTrustNode ¶
AddTrustedNode will add the node into the trustNodes, then the loop pingpong service will pingpong it.
func (*UDP) GetBlockListCount ¶
func (u *UDP) GetBlockListCount() int
func (*UDP) GetToTrustNodeCount ¶
func (u *UDP) GetToTrustNodeCount() int
func (*UDP) StartServe ¶
func (u *UDP) StartServe(nodeDir string)