kademlia

package
v2.1.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2018 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address common.Hash

func CommonBitsAddr

func CommonBitsAddr(self, other Address, prox int) (addr Address)

func CommonBitsAddrByte

func CommonBitsAddrByte(self, other Address, b byte, prox int) (addr Address)

func CommonBitsAddrF

func CommonBitsAddrF(self, other Address, f func() byte, p int) (addr Address)

func KeyRange

func KeyRange(one, other Address, proxLimit int) (start, stop Address)

KeyRange(a0, a1, proxLimit) returns the address inclusive address range that contain addresses closer to one than other

func RandomAddress

func RandomAddress() Address

randomAddressAt() generates a random address

func RandomAddressAt

func RandomAddressAt(self Address, prox int) (addr Address)

randomAddressAt(address, prox) generates a random address at proximity order prox relative to address if prox is negative a random address is generated

func (Address) Bin

func (a Address) Bin() string

the string form of the binary representation of an address (only first 8 bits)

func (*Address) MarshalJSON

func (a *Address) MarshalJSON() (out []byte, err error)

func (Address) ProxCmp

func (target Address) ProxCmp(a, b Address) int

Address.ProxCmp compares the distances a->target and b->target. Returns -1 if a is closer to target, 1 if b is closer to target and 0 if they are equal.

func (Address) String

func (a Address) String() string

func (*Address) UnmarshalJSON

func (a *Address) UnmarshalJSON(value []byte) error

type KadDb

type KadDb struct {
	Address Address
	Nodes   [][]*NodeRecord
	// contains filtered or unexported fields
}

persisted node record database ()

type KadParams

type KadParams struct {
	// adjustable parameters
	MaxProx              int
	ProxBinSize          int
	BucketSize           int
	PurgeInterval        time.Duration
	InitialRetryInterval time.Duration
	MaxIdleInterval      time.Duration
	ConnRetryExp         int
}

func NewKadParams

func NewKadParams() *KadParams

type Kademlia

type Kademlia struct {
	*KadParams // Kademlia configuration parameters
	// contains filtered or unexported fields
}

Kademlia is a table of active nodes

func New

func New(addr Address, params *KadParams) *Kademlia

public constructor add is the base address of the table params is KadParams configuration

func (*Kademlia) Add

func (self *Kademlia) Add(nrs []*NodeRecord)

adds node records to kaddb (persisted node record db)

func (*Kademlia) Addr

func (self *Kademlia) Addr() Address

accessor for KAD base address

func (*Kademlia) Count

func (self *Kademlia) Count() int

accessor for KAD active node count

func (*Kademlia) DBCount

func (self *Kademlia) DBCount() int

accessor for KAD active node count

func (*Kademlia) FindClosest

func (self *Kademlia) FindClosest(target Address, max int) []Node

returns the list of nodes belonging to the same proximity bin as the target. The most proximate bin will be the union of the bins between proxLimit and MaxProx.

func (*Kademlia) KeyRange

func (self *Kademlia) KeyRange(other Address) (start, stop Address)

provides keyrange for chunk db iteration

func (*Kademlia) Load

func (self *Kademlia) Load(path string, cb func(*NodeRecord, Node) error) (err error)

Load(path) loads the node record database (kaddb) from file on path.

func (*Kademlia) Off

func (self *Kademlia) Off(node Node, cb func(*NodeRecord, Node)) (err error)

Off is the called when a node is taken offline (from the protocol main loop exit)

func (*Kademlia) On

func (self *Kademlia) On(node Node, cb func(*NodeRecord, Node) error) (err error)

On is the entry point called when a new nodes is added unsafe in that node is not checked to be already active node (to be called once)

func (*Kademlia) Save

func (self *Kademlia) Save(path string, cb func(*NodeRecord, Node)) error

save persists kaddb on disk (written to file on path in json format.

func (*Kademlia) String

func (self *Kademlia) String() string

kademlia table + kaddb table displayed with ascii

func (*Kademlia) Suggest

func (self *Kademlia) Suggest() (*NodeRecord, bool, int)

type Node

type Node interface {
	Addr() Address
	Url() string
	LastActive() time.Time
	Drop()
}

type NodeData

type NodeData interface {
	json.Marshaler
	json.Unmarshaler
}

type NodeRecord

type NodeRecord struct {
	Addr  Address          // address of node
	Url   string           // Url, used to connect to node
	After time.Time        // next call after time
	Seen  time.Time        // last connected at time
	Meta  *json.RawMessage // arbitrary metadata saved for a peer
	// contains filtered or unexported fields
}

allow inactive peers under

func (*NodeRecord) String

func (self *NodeRecord) String() string

Jump to

Keyboard shortcuts

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