routing

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2018 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultMaxActivePeers returns the default number of maximum number of peers in a bucket.
	DefaultMaxActivePeers = uint(16)
)

Variables

This section is empty.

Functions

func NewClientBalancer

func NewClientBalancer(rt Table, clients client.Pool) client.SetBalancer

NewClientBalancer returns a new client.Balancer that uses the routing tables's Sample() method and returns a unique client on every Next() call.

Types

type Parameters

type Parameters struct {
	// MaxBucketPeers is the maximum number of peers in a bucket.
	MaxBucketPeers uint
}

Parameters are the parameters of the routing table.

func NewDefaultParameters

func NewDefaultParameters() *Parameters

NewDefaultParameters creates a new set of default parameters.

type PushStatus

type PushStatus int

PushStatus indicates different outcomes when adding a peer to the routing table.

const (
	// Existed denotes that the peer already existed in the table.
	Existed PushStatus = iota

	// Added denotes that the peer peer was added to the table.
	Added

	// Dropped denotes that the peer was dropped from the table.
	Dropped

	// Replaced denotes that the peer replaced another peer in the table.
	Replaced
)

func (PushStatus) String

func (p PushStatus) String() string

type Table

type Table interface {
	// SelfID returns the table's selfID.
	SelfID() id.ID

	// Push adds the peer into the appropriate bucket and returns an AddStatus result.
	Push(new peer.Peer) PushStatus

	// Find removes and returns the k peers in the bucket(s) closest to the given target.
	Find(target id.ID, k uint) []peer.Peer

	// Get returns the peer with the given ID or nil (if it doesn't exist) with a boolean
	// indicator for whether the peer existed.
	Get(peerID id.ID) (peer.Peer, bool)

	// Sample returns k peers in the table sampled (approximately) uniformly from the ID space.
	// Peers are sampled from buckets with probability proportional to the amount of ID
	// space the bucket covers.
	Sample(k uint, rng *rand.Rand) []peer.Peer

	// NumPeers returns the number of total peers in the routing table.
	NumPeers() int

	// NumBuckets returns the number of buckets in the routing table.
	NumBuckets() int

	// Save saves the table via the NamespaceStorer
	Save(ns storage.Storer) error
}

Table defines how routes to a particular target map to specific peers, held in a tree of buckets.

func Load

func Load(
	nl cstorage.Loader, preferer comm.Preferer, doctor comm.Doctor, params *Parameters,
) (Table, error)

Load retrieves the routing table form the KV DB.

func NewEmpty

func NewEmpty(selfID id.ID, preferer comm.Preferer, doctor comm.Doctor, params *Parameters) Table

NewEmpty creates a new routing table without peers.

func NewTestWithPeers

func NewTestWithPeers(rng *rand.Rand, n int) (Table, ecid.ID, int, comm.Preferer)

NewTestWithPeers creates a new test routing table with pseudo-random SelfID and n peers.

func NewWithPeers

func NewWithPeers(
	selfID id.ID,
	preferer comm.Preferer,
	doctor comm.Doctor,
	params *Parameters,
	peers []peer.Peer,
) (Table, int)

NewWithPeers creates a new routing table with peers, returning it and the number of peers added.

Jump to

Keyboard shortcuts

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