Documentation ¶
Index ¶
- type Address
- func CommonBitsAddr(self, other Address, prox int) (addr Address)
- func CommonBitsAddrByte(self, other Address, b byte, prox int) (addr Address)
- func CommonBitsAddrF(self, other Address, f func() byte, p int) (addr Address)
- func KeyRange(one, other Address, proxLimit int) (start, stop Address)
- func RandomAddress() Address
- func RandomAddressAt(self Address, prox int) (addr Address)
- type KadDb
- type KadParams
- type Kademlia
- func (self *Kademlia) Add(nrs []*NodeRecord)
- func (self *Kademlia) Addr() Address
- func (self *Kademlia) Count() int
- func (self *Kademlia) DBCount() int
- func (self *Kademlia) FindClosest(target Address, max int) []Node
- func (self *Kademlia) KeyRange(other Address) (start, stop Address)
- func (self *Kademlia) Load(path string, cb func(*NodeRecord, Node) error) (err error)
- func (self *Kademlia) Off(node Node, cb func(*NodeRecord, Node)) (err error)
- func (self *Kademlia) On(node Node, cb func(*NodeRecord, Node) error) (err error)
- func (self *Kademlia) Save(path string, cb func(*NodeRecord, Node)) error
- func (self *Kademlia) String() string
- func (self *Kademlia) Suggest() (*NodeRecord, bool, int)
- type Node
- type NodeData
- type NodeRecord
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Address ¶
func CommonBitsAddr ¶
func CommonBitsAddrByte ¶
func CommonBitsAddrF ¶
func KeyRange ¶
KeyRange(a0, a1, proxLimit) returns the address inclusive address range that contain addresses closer to one than other
func RandomAddressAt ¶
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) MarshalJSON ¶
func (Address) ProxCmp ¶
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) UnmarshalJSON ¶
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 ¶ added in v1.5.0
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 ¶
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) FindClosest ¶
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) 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 ¶
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.
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