Documentation ¶
Index ¶
- Constants
- Variables
- type Config
- type Conn
- type Dialer
- func (dialer *Dialer) Close() error
- func (dialer *Dialer) FetchInfo(ctx context.Context, target pb.Node) (*pb.InfoResponse, error)
- func (dialer *Dialer) FetchPeerIdentity(ctx context.Context, target pb.Node) (_ *identity.PeerIdentity, err error)
- func (dialer *Dialer) FetchPeerIdentityUnverified(ctx context.Context, address string, opts ...grpc.CallOption) (_ *identity.PeerIdentity, err error)
- func (dialer *Dialer) Lookup(ctx context.Context, self pb.Node, ask pb.Node, find pb.Node) ([]*pb.Node, error)
- func (dialer *Dialer) PingNode(ctx context.Context, target pb.Node) (bool, error)
- type Endpoint
- func (endpoint *Endpoint) Ping(ctx context.Context, req *pb.PingRequest) (*pb.PingResponse, error)
- func (endpoint *Endpoint) Query(ctx context.Context, req *pb.QueryRequest) (*pb.QueryResponse, error)
- func (endpoint *Endpoint) RequestInfo(ctx context.Context, req *pb.InfoRequest) (*pb.InfoResponse, error)
- type Inspector
- func (srv *Inspector) CountNodes(ctx context.Context, req *pb.CountNodesRequest) (*pb.CountNodesResponse, error)
- func (srv *Inspector) DumpNodes(ctx context.Context, req *pb.DumpNodesRequest) (*pb.DumpNodesResponse, error)
- func (srv *Inspector) FindNear(ctx context.Context, req *pb.FindNearRequest) (*pb.FindNearResponse, error)
- func (srv *Inspector) GetBucketList(ctx context.Context, req *pb.GetBucketListRequest) (*pb.GetBucketListResponse, error)
- func (srv *Inspector) GetBuckets(ctx context.Context, req *pb.GetBucketsRequest) (*pb.GetBucketsResponse, error)
- func (srv *Inspector) LookupNode(ctx context.Context, req *pb.LookupNodeRequest) (*pb.LookupNodeResponse, error)
- func (srv *Inspector) NodeInfo(ctx context.Context, req *pb.NodeInfoRequest) (*pb.NodeInfoResponse, error)
- func (srv *Inspector) PingNode(ctx context.Context, req *pb.PingNodeRequest) (*pb.PingNodeResponse, error)
- type Kademlia
- func (k *Kademlia) Bootstrap(ctx context.Context) error
- func (k *Kademlia) Close() error
- func (k *Kademlia) DumpNodes(ctx context.Context) ([]*pb.Node, error)
- func (k *Kademlia) FetchInfo(ctx context.Context, node pb.Node) (*pb.InfoResponse, error)
- func (k *Kademlia) FetchPeerIdentity(ctx context.Context, nodeID storj.NodeID) (*identity.PeerIdentity, error)
- func (k *Kademlia) FindNear(ctx context.Context, start storj.NodeID, limit int) ([]*pb.Node, error)
- func (k *Kademlia) FindNode(ctx context.Context, ID storj.NodeID) (pb.Node, error)
- func (k *Kademlia) GetBootstrapNodes() []pb.Node
- func (k *Kademlia) GetBucketIds() (storage.Keys, error)
- func (k *Kademlia) GetCachedNodesWithinKBucket(bID bucketID) []*pb.Node
- func (k *Kademlia) GetNodesWithinKBucket(bID bucketID) ([]*pb.Node, 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, error)
- func (k *Kademlia) Pinged()
- func (k *Kademlia) Queried()
- func (k *Kademlia) Run(ctx context.Context) error
- func (k *Kademlia) Seen() []*pb.Node
- 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(node *pb.Node) error
- func (rt *RoutingTable) ConnectionSuccess(node *pb.Node) error
- func (rt *RoutingTable) DumpNodes() ([]*pb.Node, error)
- func (rt *RoutingTable) FindNear(target storj.NodeID, limit int) ([]*pb.Node, error)
- func (rt *RoutingTable) GetBucketIds() (storage.Keys, error)
- func (rt *RoutingTable) GetBucketTimestamp(bIDBytes []byte) (time.Time, error)
- func (rt *RoutingTable) GetNodes(id storj.NodeID) ([]*pb.Node, bool)
- func (rt *RoutingTable) K() int
- func (rt *RoutingTable) Local() overlay.NodeDossier
- func (rt *RoutingTable) SetBucketTimestamp(bIDBytes []byte, now time.Time) 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" )
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 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 Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn represents a kademlia connection
type Dialer ¶
type Dialer struct {
// contains filtered or unexported fields
}
Dialer is a kademlia dialer
func (*Dialer) FetchPeerIdentity ¶
func (dialer *Dialer) FetchPeerIdentity(ctx context.Context, target pb.Node) (_ *identity.PeerIdentity, err error)
FetchPeerIdentity connects to a node and returns its peer identity
func (*Dialer) FetchPeerIdentityUnverified ¶
func (dialer *Dialer) FetchPeerIdentityUnverified(ctx context.Context, address string, opts ...grpc.CallOption) (_ *identity.PeerIdentity, err error)
FetchPeerIdentityUnverified connects to an address and returns its peer identity (no node ID verification).
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, 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, error)
Query is a node to node communication query
func (*Endpoint) RequestInfo ¶
func (endpoint *Endpoint) RequestInfo(ctx context.Context, req *pb.InfoRequest) (*pb.InfoResponse, 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, 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, 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, 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, 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, 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, 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, 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, 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, error)
FetchPeerIdentity connects to a node and returns its peer identity
func (*Kademlia) FindNear ¶
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
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) Seen ¶
Seen returns all nodes that this kademlia instance has successfully communicated with
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 adress" 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 storage.KeyValueStore, config *RoutingTableConfig) (*RoutingTable, 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 ¶
func (rt *RoutingTable) ConnectionFailed(node *pb.Node) 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(node *pb.Node) 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() ([]*pb.Node, error)
DumpNodes iterates through all nodes in the nodeBucketDB and marshals them to &pb.Nodes, then returns them
func (*RoutingTable) FindNear ¶
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() (storage.Keys, error)
GetBucketIds returns a storage.Keys type of bucket ID's in the Kademlia instance
func (*RoutingTable) GetBucketTimestamp ¶
func (rt *RoutingTable) GetBucketTimestamp(bIDBytes []byte) (time.Time, 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(bIDBytes []byte, now time.Time) 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