Documentation ¶
Index ¶
- Constants
- Variables
- type Config
- type Endpoint
- func (endpoint *Endpoint) Ping(ctx context.Context, req *pb.PingRequest) (_ *pb.PingResponse, err error)
- func (endpoint *Endpoint) Query(ctx context.Context, req *pb.QueryRequest) (_ *pb.QueryResponse, err error)
- func (endpoint *Endpoint) RequestInfo(ctx context.Context, req *pb.InfoRequest) (_ *pb.InfoResponse, err error)
- type Inspector
- func (srv *Inspector) CountNodes(ctx context.Context, req *pb.CountNodesRequest) (_ *pb.CountNodesResponse, err error)
- func (srv *Inspector) DumpNodes(ctx context.Context, req *pb.DumpNodesRequest) (_ *pb.DumpNodesResponse, err error)
- func (srv *Inspector) FindNear(ctx context.Context, req *pb.FindNearRequest) (_ *pb.FindNearResponse, err error)
- func (srv *Inspector) GetBucketList(ctx context.Context, req *pb.GetBucketListRequest) (_ *pb.GetBucketListResponse, err error)
- func (srv *Inspector) GetBuckets(ctx context.Context, req *pb.GetBucketsRequest) (_ *pb.GetBucketsResponse, err error)
- func (srv *Inspector) LookupNode(ctx context.Context, req *pb.LookupNodeRequest) (_ *pb.LookupNodeResponse, err error)
- func (srv *Inspector) NodeInfo(ctx context.Context, req *pb.NodeInfoRequest) (_ *pb.NodeInfoResponse, err error)
- func (srv *Inspector) PingNode(ctx context.Context, req *pb.PingNodeRequest) (_ *pb.PingNodeResponse, err error)
- type Kademlia
- func (k *Kademlia) Bootstrap(ctx context.Context) (err error)
- func (k *Kademlia) Close() error
- func (k *Kademlia) DumpNodes(ctx context.Context) (_ []*pb.Node, err error)
- func (k *Kademlia) FetchInfo(ctx context.Context, node pb.Node) (_ *pb.InfoResponse, err error)
- func (k *Kademlia) FetchPeerIdentity(ctx context.Context, nodeID storj.NodeID) (_ *identity.PeerIdentity, err error)
- func (k *Kademlia) FindNear(ctx context.Context, start storj.NodeID, limit int) (_ []*pb.Node, err error)
- func (k *Kademlia) FindNode(ctx context.Context, nodeID storj.NodeID) (_ pb.Node, err error)
- func (k *Kademlia) GetBootstrapNodes() []pb.Node
- func (k *Kademlia) GetBucketIds(ctx context.Context) (_ storage.Keys, err error)
- func (k *Kademlia) GetCachedNodesWithinKBucket(bID bucketID) []*pb.Node
- func (k *Kademlia) GetNodesWithinKBucket(ctx context.Context, bID bucketID) (_ []*pb.Node, err error)
- func (k *Kademlia) LastPinged() time.Time
- func (k *Kademlia) LastQueried() time.Time
- func (k *Kademlia) Local() overlay.NodeDossier
- func (k *Kademlia) Ping(ctx context.Context, node pb.Node) (_ pb.Node, err error)
- func (k *Kademlia) Pinged()
- func (k *Kademlia) Queried()
- func (k *Kademlia) Run(ctx context.Context) (err error)
- func (k *Kademlia) SetBootstrapNodes(nodes []pb.Node)
- func (k *Kademlia) SetBucketRefreshThreshold(threshold time.Duration)
- func (k *Kademlia) WaitForBootstrap()
- type OperatorConfig
- type RoutingTable
- func (rt *RoutingTable) CacheSize() int
- func (rt *RoutingTable) Close() error
- func (rt *RoutingTable) ConnFailure(ctx context.Context, node *pb.Node, err error)
- func (rt *RoutingTable) ConnSuccess(ctx context.Context, node *pb.Node)
- func (rt *RoutingTable) ConnectionFailed(ctx context.Context, node *pb.Node) (err error)
- func (rt *RoutingTable) ConnectionSuccess(ctx context.Context, node *pb.Node) (err error)
- func (rt *RoutingTable) DumpNodes(ctx context.Context) (_ []*pb.Node, err error)
- func (rt *RoutingTable) FindNear(ctx context.Context, target storj.NodeID, limit int) (_ []*pb.Node, err error)
- func (rt *RoutingTable) GetBucketIds(ctx context.Context) (_ storage.Keys, err error)
- func (rt *RoutingTable) GetBucketTimestamp(ctx context.Context, bIDBytes []byte) (_ time.Time, err error)
- func (rt *RoutingTable) GetNodes(ctx context.Context, id storj.NodeID) ([]*pb.Node, bool)
- func (rt *RoutingTable) K() int
- func (rt *RoutingTable) Local() overlay.NodeDossier
- func (rt *RoutingTable) SetBucketTimestamp(ctx context.Context, bIDBytes []byte, now time.Time) (err error)
- func (rt *RoutingTable) UpdateSelf(capacity *pb.NodeCapacity)
- type RoutingTableConfig
Constants ¶
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 ¶
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") )
var AntechamberErr = errs.Class("antechamber error")
AntechamberErr is the class for all errors pertaining to antechamber operations
var EndpointError = errs.Class("kademlia endpoint error")
EndpointError defines errors class for Endpoint
var ErrMaxRetries = errs.Class("max retries exceeded for id:")
ErrMaxRetries is used when a lookup has been retried the max number of times
var ( // Error defines a Kademlia error Error = errs.Class("kademlia error") )
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 ¶
BootstrapNodes returns bootstrap nodes defined in the config
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) *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(kad *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 ¶
Kademlia is an implementation of kademlia adhering to the DHT interface.
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 ¶
Bootstrap contacts one of a set of pre defined trusted nodes on the network and begins populating the local Kademlia node
func (*Kademlia) Close ¶
Close closes all kademlia connections and prevents new ones from being created.
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 ¶
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 ¶
GetBootstrapNodes gets the bootstrap nodes.
func (*Kademlia) GetBucketIds ¶
GetBucketIds returns a storage.Keys type of bucket ID's in the Kademlia instance
func (*Kademlia) GetCachedNodesWithinKBucket ¶ added in v0.10.0
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 ¶
LastPinged returns last time someone pinged this node.
func (*Kademlia) LastQueried ¶
LastQueried returns last time someone queried this node.
func (*Kademlia) Local ¶
func (k *Kademlia) Local() overlay.NodeDossier
Local returns the local node
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) SetBootstrapNodes ¶
SetBootstrapNodes sets the bootstrap nodes. Must be called before anything starting to use kademlia.
func (*Kademlia) SetBucketRefreshThreshold ¶
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
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 ¶
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 ¶
ConnectionFailed removes a node from the routing table when a connection fails for the node on the network
func (*RoutingTable) ConnectionSuccess ¶
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 ¶
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 ¶
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 ¶
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