table

package
v0.0.0-...-42befb5 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2018 License: MIT, MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

type Bucket interface {
	Peers() []node.RemoteNodeData
	Has(n node.RemoteNodeData) bool
	Remove(n node.RemoteNodeData) bool
	MoveToFront(n node.RemoteNodeData)
	PushFront(n node.RemoteNodeData)
	PushBack(n node.RemoteNodeData)
	PopBack() node.RemoteNodeData
	Len() int
	Split(cpl int, target dht.ID) Bucket
	List() *list.List
}

Bucket is a dht k-bucket type. Bucket methods are NOT thread safe. RoutingTable (or other clients) is responsible for serializing access to Bucket's methods.

func NewBucket

func NewBucket() Bucket

NewBucket creates a new empty bucket.

type ChannelOfPeerChannel

type ChannelOfPeerChannel chan PeerChannel

ChannelOfPeerChannel is a channel of PeerChannels

type NearestPeersReq

type NearestPeersReq struct {
	ID       dht.ID
	Count    int
	Callback PeersOpChannel
}

NearestPeersReq includes one peer id, a count param and a callback PeersOpChannel.

type PeerByIDRequest

type PeerByIDRequest struct {
	ID       dht.ID
	Callback PeerOpChannel
}

PeerByIDRequest includes one peer id and a callback PeerOpChannel

type PeerChannel

type PeerChannel chan node.RemoteNodeData

PeerChannel is a channel of RemoteNodeData

type PeerOpChannel

type PeerOpChannel chan *PeerOpResult

PeerOpChannel is a channel that accept a peer op result.

type PeerOpResult

type PeerOpResult struct {
	Peer node.RemoteNodeData
}

PeerOpResult is used as a result of a method that returns nil or one peer.

type PeersOpChannel

type PeersOpChannel chan *PeersOpResult

PeersOpChannel is a channel of PeersOpResult.

type PeersOpResult

type PeersOpResult struct {
	Peers []node.RemoteNodeData
}

PeersOpResult is a result of a method that returns zero or more peers.

type RoutingTable

type RoutingTable interface {

	// table ops
	Update(p node.RemoteNodeData)      // adds a peer to the table
	Remove(p node.RemoteNodeData)      // remove a peer from the table
	Find(req PeerByIDRequest)          // find a specific peer by dht.ID
	NearestPeer(req PeerByIDRequest)   // nearest peer to a dht.ID
	NearestPeers(req NearestPeersReq)  // ip to n nearest peers to a dht.ID
	ListPeers(callback PeersOpChannel) // list all peers
	Size(callback chan int)            // total # of peers in the table

	// add/remove peers callbacks management - thread safe
	RegisterPeerRemovedCallback(c PeerChannel)   // get called when a  peer is removed
	RegisterPeerAddedCallback(c PeerChannel)     // get called when a peer is added
	UnregisterPeerRemovedCallback(c PeerChannel) // remove addition reg
	UnregisterPeerAddedCallback(c PeerChannel)   // remove removal reg

	Print()
}

RoutingTable manages routing to peers. All uppercase methods visible to externals packages are thread-safe. Don't call package-level methods (lower-case) - they are private not thread-safe. Design spec: 'Kademlia: A Design Specification' with most-recently active nodes at the front of each bucket and not the back. http://xlattice.sourceforge.net/components/protocol/kademlia/specs.html

func NewRoutingTable

func NewRoutingTable(bucketsize int, localID dht.ID) RoutingTable

NewRoutingTable creates a new routing table with a given bucket=size and local node dht.ID

Jump to

Keyboard shortcuts

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