routingtable

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxRetries int = 3
)
View Source
const RejectSecs = 100
View Source
const (
	RetryPoolLen = 10 // the length of the retry pool
)

Variables

View Source
var (
	ErrNotFound     = errors.New("bucket: id not found")
	ErrManipulation = errors.New("bucket: error while manipulation or casting")
)
View Source
var (
	ErrCplCompute = errors.New("error while cpl compute")
)

Functions

This section is empty.

Types

type Bucket

type Bucket struct {
	Cpl int // The cpl of the bucket
	// contains filtered or unexported fields
}

Bucket Individual bucket of the RoutingTable.

func NewBucket

func NewBucket(cpl, bucketSize int) *Bucket

NewBucket New returns a new Bucket

func (*Bucket) Access

func (b *Bucket) Access(id address.PeerId) error

Access Marks the access of a PeerId Updates the LRU list

func (*Bucket) AddOrUpdate

func (b *Bucket) AddOrUpdate(info PeerBucketInfo, abstainLock bool) error

AddOrUpdate Add or Update the existing PeerBucketInfo If it is greater than bucketSize then it is added to a retry list which will be invoked before next add The live-ness check worker should ping and delete the Dead nodes. there by clearing some space in the k bucket

func (*Bucket) CanAdd

func (b *Bucket) CanAdd() bool

CanAdd Can further elements be added to the bucket

func (*Bucket) Delete

func (b *Bucket) Delete(id address.PeerId) error

Delete deletes the id if it is present in the bucket.

func (*Bucket) GetAll

func (b *Bucket) GetAll() ([]PeerBucketInfo, error)

GetAll gets all the information from the bucket.

type EvictedElement added in v0.0.4

type EvictedElement struct {
	PeerId    address.PeerId
	EvictedAt int64
}

type PeerBucketInfo

type PeerBucketInfo struct {
	PeerAddr    address.PeerAddressInfo // The Peer Address info - for comm
	LastAliveAt int64                   // Epoch of the last PingResponse arrival.
	NumRetries  int64                   // Number of retries when the node is in suspicious/ suspected state.
}

PeerBucketInfo contains all the necessary information of the peer in k-bucket.

func WrapPeerAddrInfo

func WrapPeerAddrInfo(info address.PeerAddressInfo) PeerBucketInfo

WrapPeerAddrInfo Wraps PeerBucketInfo over PeerAddressInfo Helper Utility

func (*PeerBucketInfo) SyncWith added in v0.0.4

func (pbi *PeerBucketInfo) SyncWith(pbl PeerBucketInfo) PeerBucketInfo

type PeerBucketInfoList

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

PeerBucketInfoList Wrapper for slice of PeerBucketInfo Implements the sort interface for sort functionality

func (*PeerBucketInfoList) Len

func (pbl *PeerBucketInfoList) Len() int

func (*PeerBucketInfoList) Less

func (pbl *PeerBucketInfoList) Less(i, j int) bool

func (*PeerBucketInfoList) Swap

func (pbl *PeerBucketInfoList) Swap(i, j int)

type PeerStatus

type PeerStatus int

type RejectMap added in v0.0.4

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

func NewRejectMap added in v0.0.4

func NewRejectMap() *RejectMap

func (*RejectMap) Add added in v0.0.4

func (r *RejectMap) Add(id address.PeerId)

func (*RejectMap) IsPeerRecentlyEvicted added in v0.0.4

func (r *RejectMap) IsPeerRecentlyEvicted(id address.PeerId) bool

type RoutingTable

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

RoutingTable RoutingTable - The k-bucket ds. Currently the RoutingTable is in memory TODO: Add Persistent Routing table flavour as well

func NewRoutingTable

func NewRoutingTable(homeNodeId address.PeerId, k int) *RoutingTable

NewRoutingTable returns a new InMemory Routing table.

func (*RoutingTable) AccessPeer

func (rt *RoutingTable) AccessPeer(id address.PeerId) error

AccessPeer - should be called when a particular peer is "accessed" To maintain the LRU style listing. Currently Even if the List is maintained in LRU fashion, Ping/ eviction is decoupled from the bucket's responsibilities. If So then this Access API serves no use. TODO: Refactor this, see existing impls, and check if it is the bucket's job to evict? Alternate would be directly exposing the bucket for a cpl and feed it to the worker Like a "LookUp with Follow Up design"

func (*RoutingTable) Add

func (rt *RoutingTable) Add(info PeerBucketInfo) error

Add adds a Peer Bucket info to the RoutingTable

func (*RoutingTable) GetAllPeers

func (rt *RoutingTable) GetAllPeers() ([]PeerBucketInfo, error)

GetAllPeers gets all the peers from the peer store. Ordered by the distance from home node.

func (*RoutingTable) GetClosestTo

func (rt *RoutingTable) GetClosestTo(nodeTgt []byte) ([]PeerBucketInfo, error)

GetClosestTo gets the peers from the peer store and orders by the supplied nodeTgt.

func (*RoutingTable) Remove

func (rt *RoutingTable) Remove(id address.PeerId) error

Remove Removes the entry with the specified Id This is usually done when the node goes offline and the live-ness checker finds about it.

func (*RoutingTable) SortByDistanceFromTarget

func (rt *RoutingTable) SortByDistanceFromTarget(target []byte, list []PeerBucketInfo) []PeerBucketInfo

SortByDistanceFromTarget Utility method to sort the list by the "Distance from target" metric.

Jump to

Keyboard shortcuts

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