kademlia

package
v0.19.1 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2019 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KademliaBucket is the string representing the bucket used for the kademlia routing table k-bucket ids
	KademliaBucket = "kbuckets"
	// NodeBucket is the string representing the bucket used for the kademlia routing table node ids
	NodeBucket = "nodes"
	// AntechamberBucket is the string representing the bucket used for the kademlia antechamber nodes
	AntechamberBucket = "antechamber"
)

Variables

View Source
var (
	// NodeErr is the class for all errors pertaining to node operations
	NodeErr = errs.Class("node error")
	// BootstrapErr is the class for all errors pertaining to bootstrapping a node
	BootstrapErr = errs.Class("bootstrap node error")
	// NodeNotFound is returned when a lookup can not produce the requested node
	NodeNotFound = errs.Class("node not found")
)
View Source
var AntechamberErr = errs.Class("antechamber error")

AntechamberErr is the class for all errors pertaining to antechamber operations

View Source
var EndpointError = errs.Class("kademlia endpoint error")

EndpointError defines errors class for Endpoint

View Source
var (
	// Error defines a Kademlia error
	Error = errs.Class("kademlia error")
)
View Source
var RoutingErr = errs.Class("routing table error")

RoutingErr is the class for all errors pertaining to routing table operations

Functions

This section is empty.

Types

type Config

type Config struct {
	BootstrapAddr        string        `help:"the Kademlia node to bootstrap against" releaseDefault:"bootstrap.storj.io:8888" devDefault:""`
	BootstrapBackoffMax  time.Duration `help:"the maximum amount of time to wait when retrying bootstrap" default:"30s"`
	BootstrapBackoffBase time.Duration `help:"the base interval to wait when retrying bootstrap" default:"1s"`
	DBPath               string        `help:"the path for storage node db services to be created on" default:"$CONFDIR/kademlia"`
	ExternalAddress      string        `user:"true" help:"the public address of the Kademlia node, useful for nodes behind NAT" default:""`
	Operator             OperatorConfig

	// TODO: reduce the number of flags here
	Alpha int `help:"alpha is a system wide concurrency parameter" default:"5"`
	RoutingTableConfig
}

Config defines all of the things that are needed to start up Kademlia server endpoints (and not necessarily client code).

func (Config) BootstrapNodes

func (c Config) BootstrapNodes() []pb.Node

BootstrapNodes returns bootstrap nodes defined in the config

func (Config) Verify

func (c Config) Verify(log *zap.Logger) error

Verify verifies whether kademlia config is valid.

type Endpoint

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

Endpoint implements the kademlia Endpoints

func NewEndpoint

func NewEndpoint(log *zap.Logger, service *Kademlia, routingTable *RoutingTable, trust SatelliteIDVerifier) *Endpoint

NewEndpoint returns a new kademlia endpoint

func (*Endpoint) Ping

func (endpoint *Endpoint) Ping(ctx context.Context, req *pb.PingRequest) (_ *pb.PingResponse, err error)

Ping provides an easy way to verify a node is online and accepting requests

func (*Endpoint) Query

func (endpoint *Endpoint) Query(ctx context.Context, req *pb.QueryRequest) (_ *pb.QueryResponse, err error)

Query is a node to node communication query

func (*Endpoint) RequestInfo

func (endpoint *Endpoint) RequestInfo(ctx context.Context, req *pb.InfoRequest) (_ *pb.InfoResponse, err error)

RequestInfo returns the node info

type Inspector

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

Inspector is a gRPC service for inspecting kademlia internals

func NewInspector

func NewInspector(kademlia *Kademlia, identity *identity.FullIdentity) *Inspector

NewInspector creates an Inspector

func (*Inspector) CountNodes

func (srv *Inspector) CountNodes(ctx context.Context, req *pb.CountNodesRequest) (_ *pb.CountNodesResponse, err error)

CountNodes returns the number of nodes in the routing table

func (*Inspector) DumpNodes

func (srv *Inspector) DumpNodes(ctx context.Context, req *pb.DumpNodesRequest) (_ *pb.DumpNodesResponse, err error)

DumpNodes returns all of the nodes in the routing table database.

func (*Inspector) FindNear

func (srv *Inspector) FindNear(ctx context.Context, req *pb.FindNearRequest) (_ *pb.FindNearResponse, err error)

FindNear sends back limit of near nodes

func (*Inspector) GetBucketList added in v0.10.0

func (srv *Inspector) GetBucketList(ctx context.Context, req *pb.GetBucketListRequest) (_ *pb.GetBucketListResponse, err error)

GetBucketList returns the list of buckets with their routing nodes and their cached nodes

func (*Inspector) GetBuckets

func (srv *Inspector) GetBuckets(ctx context.Context, req *pb.GetBucketsRequest) (_ *pb.GetBucketsResponse, err error)

GetBuckets returns all kademlia buckets for current kademlia instance

func (*Inspector) LookupNode

func (srv *Inspector) LookupNode(ctx context.Context, req *pb.LookupNodeRequest) (_ *pb.LookupNodeResponse, err error)

LookupNode triggers a Kademlia lookup and returns the node the network found.

func (*Inspector) NodeInfo

func (srv *Inspector) NodeInfo(ctx context.Context, req *pb.NodeInfoRequest) (_ *pb.NodeInfoResponse, err error)

NodeInfo sends a PING RPC to a node and returns its local info.

func (*Inspector) PingNode

func (srv *Inspector) PingNode(ctx context.Context, req *pb.PingNodeRequest) (_ *pb.PingNodeResponse, err error)

PingNode sends a PING RPC to the provided node ID in the Kad network.

type Kademlia

type Kademlia struct {
	RefreshBuckets sync2.Cycle
	// contains filtered or unexported fields
}

Kademlia is an implementation of kademlia network.

func NewService

func NewService(log *zap.Logger, transport transport.Client, rt *RoutingTable, config Config) (*Kademlia, error)

NewService returns a newly configured Kademlia instance

func (*Kademlia) Bootstrap

func (k *Kademlia) Bootstrap(ctx context.Context) (err error)

Bootstrap contacts one of a set of pre defined trusted nodes on the network and begins populating the local Kademlia node

func (*Kademlia) Close

func (k *Kademlia) Close() error

Close closes all kademlia connections and prevents new ones from being created.

func (*Kademlia) DumpNodes

func (k *Kademlia) DumpNodes(ctx context.Context) (_ []*pb.Node, err error)

DumpNodes returns all the nodes in the node database

func (*Kademlia) FetchInfo

func (k *Kademlia) FetchInfo(ctx context.Context, node pb.Node) (_ *pb.InfoResponse, err error)

FetchInfo connects to a node address and returns the node info

func (*Kademlia) FetchPeerIdentity

func (k *Kademlia) FetchPeerIdentity(ctx context.Context, nodeID storj.NodeID) (_ *identity.PeerIdentity, err error)

FetchPeerIdentity connects to a node and returns its peer identity

func (*Kademlia) FindNear

func (k *Kademlia) FindNear(ctx context.Context, start storj.NodeID, limit int) (_ []*pb.Node, err error)

FindNear returns all nodes from a starting node up to a maximum limit stored in the local routing table.

func (*Kademlia) FindNode

func (k *Kademlia) FindNode(ctx context.Context, nodeID storj.NodeID) (_ pb.Node, err error)

FindNode looks up the provided NodeID first in the local Node, and if it is not found begins searching the network for the NodeID. Returns and error if node was not found

func (*Kademlia) GetBootstrapNodes

func (k *Kademlia) GetBootstrapNodes() []pb.Node

GetBootstrapNodes gets the bootstrap nodes.

func (*Kademlia) GetBucketIds

func (k *Kademlia) GetBucketIds(ctx context.Context) (_ storage.Keys, err error)

GetBucketIds returns a storage.Keys type of bucket ID's in the Kademlia instance

func (*Kademlia) GetCachedNodesWithinKBucket added in v0.10.0

func (k *Kademlia) GetCachedNodesWithinKBucket(bID bucketID) []*pb.Node

GetCachedNodesWithinKBucket returns all the cached nodes in the specified k-bucket

func (*Kademlia) GetNodesWithinKBucket added in v0.10.0

func (k *Kademlia) GetNodesWithinKBucket(ctx context.Context, bID bucketID) (_ []*pb.Node, err error)

GetNodesWithinKBucket returns all the routing nodes in the specified k-bucket

func (*Kademlia) LastPinged

func (k *Kademlia) LastPinged() time.Time

LastPinged returns last time someone pinged this node.

func (*Kademlia) LastQueried

func (k *Kademlia) LastQueried() time.Time

LastQueried returns last time someone queried this node.

func (*Kademlia) Local

func (k *Kademlia) Local() overlay.NodeDossier

Local returns the local node

func (*Kademlia) Ping

func (k *Kademlia) Ping(ctx context.Context, node pb.Node) (_ pb.Node, err error)

Ping checks that the provided node is still accessible on the network

func (*Kademlia) Pinged

func (k *Kademlia) Pinged()

Pinged notifies the service it has been remotely pinged.

func (*Kademlia) Queried

func (k *Kademlia) Queried()

Queried notifies the service it has been remotely queried

func (*Kademlia) Run

func (k *Kademlia) Run(ctx context.Context) (err error)

Run occasionally refreshes stale kad buckets

func (*Kademlia) SetBootstrapNodes

func (k *Kademlia) SetBootstrapNodes(nodes []pb.Node)

SetBootstrapNodes sets the bootstrap nodes. Must be called before anything starting to use kademlia.

func (*Kademlia) SetBucketRefreshThreshold

func (k *Kademlia) SetBucketRefreshThreshold(threshold time.Duration)

SetBucketRefreshThreshold changes the threshold when buckets are considered stale and need refreshing.

func (*Kademlia) WaitForBootstrap

func (k *Kademlia) WaitForBootstrap()

WaitForBootstrap waits for bootstrap pinging has been completed.

type OperatorConfig

type OperatorConfig struct {
	Email  string `user:"true" help:"operator email address" default:""`
	Wallet string `user:"true" help:"operator wallet address" default:""`
}

OperatorConfig defines properties related to storage node operator metadata

func (OperatorConfig) Verify

func (c OperatorConfig) Verify(log *zap.Logger) error

Verify verifies whether operator config is valid.

type RoutingTable

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

RoutingTable implements the RoutingTable interface

func NewRoutingTable

func NewRoutingTable(logger *zap.Logger, localNode *overlay.NodeDossier, kdb, ndb, adb storage.KeyValueStore, config *RoutingTableConfig) (_ *RoutingTable, err error)

NewRoutingTable returns a newly configured instance of a RoutingTable

func (*RoutingTable) CacheSize

func (rt *RoutingTable) CacheSize() int

CacheSize returns the total current size of the replacement cache

func (*RoutingTable) Close

func (rt *RoutingTable) Close() error

Close closes without closing dependencies

func (*RoutingTable) ConnFailure

func (rt *RoutingTable) ConnFailure(ctx context.Context, node *pb.Node, err error)

ConnFailure implements the Transport failure function

func (*RoutingTable) ConnSuccess

func (rt *RoutingTable) ConnSuccess(ctx context.Context, node *pb.Node)

ConnSuccess implements the Transport success function

func (*RoutingTable) ConnectionFailed

func (rt *RoutingTable) ConnectionFailed(ctx context.Context, node *pb.Node) (err error)

ConnectionFailed removes a node from the routing table when a connection fails for the node on the network

func (*RoutingTable) ConnectionSuccess

func (rt *RoutingTable) ConnectionSuccess(ctx context.Context, node *pb.Node) (err error)

ConnectionSuccess updates or adds a node to the routing table when a successful connection is made to the node on the network

func (*RoutingTable) DumpNodes

func (rt *RoutingTable) DumpNodes(ctx context.Context) (_ []*pb.Node, err error)

DumpNodes iterates through all nodes in the nodeBucketDB and marshals them to &pb.Nodes, then returns them

func (*RoutingTable) FindNear

func (rt *RoutingTable) FindNear(ctx context.Context, target storj.NodeID, limit int) (_ []*pb.Node, err error)

FindNear returns the node corresponding to the provided nodeID returns all Nodes (excluding self) closest via XOR to the provided nodeID up to the provided limit

func (*RoutingTable) GetBucketIds

func (rt *RoutingTable) GetBucketIds(ctx context.Context) (_ storage.Keys, err error)

GetBucketIds returns a storage.Keys type of bucket ID's in the Kademlia instance

func (*RoutingTable) GetBucketTimestamp

func (rt *RoutingTable) GetBucketTimestamp(ctx context.Context, bIDBytes []byte) (_ time.Time, err error)

GetBucketTimestamp retrieves time of the last node lookup for a bucket

func (*RoutingTable) GetNodes

func (rt *RoutingTable) GetNodes(ctx context.Context, id storj.NodeID) ([]*pb.Node, bool)

GetNodes retrieves nodes within the same kbucket as the given node id Note: id doesn't need to be stored at time of search

func (*RoutingTable) K

func (rt *RoutingTable) K() int

K returns the currently configured maximum of nodes to store in a bucket

func (*RoutingTable) Local

func (rt *RoutingTable) Local() overlay.NodeDossier

Local returns the local node

func (*RoutingTable) SetBucketTimestamp

func (rt *RoutingTable) SetBucketTimestamp(ctx context.Context, bIDBytes []byte, now time.Time) (err error)

SetBucketTimestamp records the time of the last node lookup for a bucket

func (*RoutingTable) UpdateSelf

func (rt *RoutingTable) UpdateSelf(capacity *pb.NodeCapacity)

UpdateSelf updates the local node with the provided info

type RoutingTableConfig

type RoutingTableConfig struct {
	BucketSize           int `help:"size of each Kademlia bucket" default:"20"`
	ReplacementCacheSize int `help:"size of Kademlia replacement cache" default:"5"`
}

RoutingTableConfig configures the routing table

type SatelliteIDVerifier added in v0.17.0

type SatelliteIDVerifier interface {
	VerifySatelliteID(ctx context.Context, id storj.NodeID) error
}

SatelliteIDVerifier checks if the connection is from a trusted satellite

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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