discovery

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2018 License: GPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const K = 16
View Source
const N = 17
View Source
const NodeURLScheme = "vnode"

@section NodeURL

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Priv      ed25519.PrivateKey
	DBPath    string
	BootNodes []*Node
	Addr      *net.UDPAddr
	Self      *Node
	NetID     network.ID
}

@section Discovery

type Discovery

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

func New

func New(cfg *Config) (d *Discovery)

func (*Discovery) Block

func (d *Discovery) Block(ID NodeID, IP net.IP)

func (*Discovery) HandleMsg

func (d *Discovery) HandleMsg(res *packet)

func (*Discovery) Lookup

func (d *Discovery) Lookup(id NodeID) []*Node

func (*Discovery) Mark

func (d *Discovery) Mark(id NodeID, lifetime int64)

func (*Discovery) Need

func (d *Discovery) Need(n uint)

func (*Discovery) Nodes

func (d *Discovery) Nodes() []*Node

func (*Discovery) RandomNodes

func (d *Discovery) RandomNodes(result []*Node) int

func (*Discovery) RefreshTable

func (d *Discovery) RefreshTable()

func (*Discovery) Resolve

func (d *Discovery) Resolve(id NodeID) *Node

find Node who`s equal id

func (*Discovery) Start

func (d *Discovery) Start() (err error)

func (*Discovery) Stop

func (d *Discovery) Stop()

func (*Discovery) SubNodes

func (d *Discovery) SubNodes(ch chan<- *Node)

func (*Discovery) UnSubNodes

func (d *Discovery) UnSubNodes(ch chan<- *Node)

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
}

@message findnode

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
}

@message neighbors

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
	// contains filtered or unexported fields
}

func ParseNode

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

parse a url-like string to Node

func (*Node) Deserialize

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

func (*Node) Serialize

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

func (*Node) String

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

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

func (*Node) UDPAddr

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

func (*Node) Validate

func (n *Node) Validate() error

type NodeID

type NodeID [32]byte
var ZERO_NODE_ID NodeID

func Bytes2NodeID

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

func HexStr2NodeID

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

func Priv2NodeID

func Priv2NodeID(priv ed25519.PrivateKey) (NodeID, error)

func (NodeID) Brief

func (id NodeID) Brief() string

func (NodeID) Bytes

func (id NodeID) Bytes() []byte

func (NodeID) Equal

func (id NodeID) Equal(id2 NodeID) bool

func (NodeID) IsZero

func (id NodeID) IsZero() bool

func (NodeID) String

func (id NodeID) String() string

type Ping

type Ping struct {
	ID         NodeID
	IP         net.IP
	UDP        uint16
	TCP        uint16
	Expiration time.Time
}

message Ping

func (*Ping) String

func (p *Ping) String() string

type Pong

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

message Pong

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