Documentation ¶
Index ¶
Constants ¶
const K = 128
K is the default bucketSize
const N = 16
N is the default number of buckets
const NodeURLScheme = "vnode"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { PeerKey ed25519.PrivateKey DBPath string BootNodes []*Node Addr string NetID network.ID Self *Node }
Config is the essential configuration to create a Discovery implementation
type Discovery ¶
type Discovery interface { Start() error Stop() SubNodes(ch chan<- *Node, near bool) UnSubNodes(ch chan<- *Node) Mark(id NodeID, lifetime int64) UnMark(id NodeID) Block(id NodeID, ip net.IP) More(ch chan<- *Node, n int) Nodes() []string Delete(id NodeID) }
Discovery is the interface to discovery other node
type Exception ¶
type Exception struct {
Code eCode
}
type FindNode ¶
type Message ¶
type Message interface { String() string // contains filtered or unexported methods }
type Neighbors ¶
type Node ¶
type Node struct { ID NodeID IP net.IP UDP uint16 TCP uint16 Net network.ID Ext []byte // contains filtered or unexported fields }
Node mean a node in vite P2P network
func (*Node) Deserialize ¶
Deserialize encoded data, []byte, to a Node, you must create the Node first, like following:
n := new(Node) err := n.Deserialize(buf)
func (*Node) String ¶
String marshal node to url-like string which looks like:
vnode://<hex node id> vnode://<hex node id>@<ip>:<udpPort>#<tcpPort>
func (*Node) TCPAddr ¶
TCPAddr return the address that can be connected with tcp
func (*Node) UDPAddr ¶
UDPAddr return the address that can communication with udp
type NodeID ¶
type NodeID [32]byte
NodeID use to mark node, and build a structural network
var ZERO_NODE_ID NodeID
ZERO_NODE_ID is the zero-value of NodeID type
func Bytes2NodeID ¶
Bytes2NodeID turn a slice to NodeID
func HexStr2NodeID ¶
HexStr2NodeID parse a hex coded string to NodeID
func Priv2NodeID ¶
func Priv2NodeID(priv ed25519.PrivateKey) (NodeID, error)
Priv2NodeID got the corresponding NodeID from ed25519.PeerKey
func (NodeID) Brief ¶
Brief return the front 4 bytes hex coded string of NodeID
func (NodeID) Equal ¶
Equal validate whether two NodeID is equal
func (NodeID) IsZero ¶
IsZero validate whether a NodeID is zero-value