discovery

package
v1.3.1-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2019 License: GPL-3.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const K = 128

K is the default bucketSize

View Source
const N = 16

N is the default number of buckets

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

func New

func New(cfg *Config) Discovery

New create a Discovery implementation

type Exception

type Exception struct {
	Code eCode
}

func (*Exception) String

func (n *Exception) String() string

type FindNode

type FindNode struct {
	ID         NodeID
	Target     NodeID
	Expiration time.Time
	N          uint32
}

func (*FindNode) String

func (f *FindNode) String() string

type Message

type Message interface {
	String() string
	// contains filtered or unexported methods
}

type Neighbors

type Neighbors struct {
	ID         NodeID
	Nodes      []*Node
	Expiration time.Time
}

func (*Neighbors) String

func (n *Neighbors) String() string

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 ParseNode

func ParseNode(u string) (*Node, error)

ParseNode parse a url-like string to Node

func (*Node) Deserialize

func (n *Node) Deserialize(bytes []byte) error

Deserialize encoded data, []byte, to a Node, you must create the Node first, like following:

n := new(Node)
err := n.Deserialize(buf)

func (*Node) Serialize

func (n *Node) Serialize() ([]byte, error)

Serialize a Node to []byte

func (*Node) String

func (n *Node) String() 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

func (n *Node) TCPAddr() *net.TCPAddr

TCPAddr return the address that can be connected with tcp

func (*Node) UDPAddr

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

UDPAddr return the address that can communication with udp

func (*Node) Update added in v1.2.0

func (n *Node) Update(n2 *Node)

func (*Node) Validate

func (n *Node) Validate() error

Validate whether a node has essential information

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

func Bytes2NodeID(buf []byte) (id NodeID, err error)

Bytes2NodeID turn a slice to NodeID

func HexStr2NodeID

func HexStr2NodeID(str string) (id NodeID, err error)

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

func (id NodeID) Brief() string

Brief return the front 4 bytes hex coded string of NodeID

func (NodeID) Bytes

func (id NodeID) Bytes() []byte

Bytes return a slice derived from NodeID

func (NodeID) Equal

func (id NodeID) Equal(id2 NodeID) bool

Equal validate whether two NodeID is equal

func (NodeID) IsZero

func (id NodeID) IsZero() bool

IsZero validate whether a NodeID is zero-value

func (NodeID) String

func (id NodeID) String() string

String return a hex coded string of NodeID

type Ping

type Ping struct {
	ID         NodeID
	TCP        uint16
	Expiration time.Time
	Net        network.ID
	Ext        []byte
}

func (*Ping) String

func (p *Ping) String() string

type Pong

type Pong struct {
	ID         NodeID
	Ping       types.Hash
	IP         net.IP
	Expiration time.Time
}

func (*Pong) String

func (p *Pong) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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