discovery

package
v0.0.0-...-4097cb8 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2020 License: LGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
const (

	// UndefinedShardNumber indicates the shard number is undefined
	UndefinedShardNumber = 0
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

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

Database definition

func NewDatabase

func NewDatabase(log *log.SeeleLog) *Database

NewDatabase new database

func StartService

func StartService(nodeDir string, myID common.Address, myAddr *net.UDPAddr, bootstrap []*Node, shard uint) *Database

StartService start node udp service

func (*Database) FindByNodeID

func (db *Database) FindByNodeID(id common.Address) (*Node, bool)

FindByNodeID find node by its id

func (*Database) GetCopy

func (db *Database) GetCopy() map[common.Hash]*Node

GetCopy get replica from db.nodes

func (*Database) SaveNodes

func (db *Database) SaveNodes(nodeDir string)

SaveNodes dump nodes info into disk file

func (*Database) SetHookForDeleteNode

func (db *Database) SetHookForDeleteNode(hook NodeHook)

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

func (db *Database) SetHookForNewNode(hook NodeHook)

SetHookForNewNode this hook will be called when find new Node Note it will run in a new go routine

func (*Database) StartSaveNodes

func (db *Database) StartSaveNodes(nodeDir string, done chan struct{})

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

func MustNewNodeWithAddr(id common.Address, addr string, shard uint) *Node

MustNewNodeWithAddr new node with id and network address, and panics on any error.

func NewNode

func NewNode(id common.Address, ip net.IP, port int, shard uint) *Node

NewNode new node with its value

func NewNodeFromIP

func NewNodeFromIP(ip string) (*Node, error)

NewNodeFromIP new node from ip address

func NewNodeFromString

func NewNodeFromString(id string) (*Node, error)

NewNodeFromString new node from id

func NewNodeWithAddr

func NewNodeWithAddr(id common.Address, addr *net.UDPAddr, shard uint) *Node

NewNodeWithAddr new node with id and network address

func NewNodeWithAddrString

func NewNodeWithAddrString(id common.Address, addr string, shard uint) (*Node, error)

NewNodeWithAddrString new node with id and network address.

func (*Node) GetUDPAddr

func (n *Node) GetUDPAddr() *net.UDPAddr

GetUDPAddr get UDPAddr from node struct

func (Node) MarshalText

func (n Node) MarshalText() ([]byte, error)

MarshalText marshal node to json

func (*Node) String

func (n *Node) String() string

func (*Node) UnmarshalText

func (n *Node) UnmarshalText(json []byte) error

UnmarshalText unmarshal json to node

type NodeHook

type NodeHook func(node *Node)

NodeHook some hook funcs

type Table

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

Table used to save peers information

func (*Table) GetRandNodes

func (t *Table) GetRandNodes(number int) []*Node

Jump to

Keyboard shortcuts

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