storj/pkg/dht/dht.go
Dylan Lott 0d05cb26bf
Kademlia Inspector CLI (#657)
* initial commit of inspector gadget wireup

* change name of comman dline tool, setup grpc server

* Get inspector cli working with grpc client

* Wired up CountNodes command

* WIP getting buckets response working

* Added GetBucket command

* WIP working on get buckets command

* WIP working on bucket list

* Still WIP

* WIP getting bucket counts to work

* Some clean up of unnecessary changes

* List Buckets and Get Bucket are working

* Removing logs, getting ready for review

* initial commit of inspector gadget wireup

* change name of comman dline tool, setup grpc server

* Get inspector cli working with grpc client

* Wired up CountNodes command

* WIP getting buckets response working

* Added GetBucket command

* WIP working on get buckets command

* WIP working on bucket list

* Still WIP

* WIP getting bucket counts to work

* Some clean up of unnecessary changes

* List Buckets and Get Bucket are working

* Removing logs, getting ready for review

* Fix error return

* Trying to get tests passing

* Adds method on dht mock for tests

* Add dbx files back

* Fix package import error in dbx file

* Adds copyrights to pass linter

* tidy go mod

* Updates from code review

* Updates inspector to take flag arguments for address

* Format list-buckets output more prettier
2018-11-21 10:31:27 -07:00

60 lines
1.4 KiB
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package dht
import (
"context"
"time"
"storj.io/storj/pkg/pb"
"storj.io/storj/storage"
)
// NodeID is the unique identifier used for Nodes in the DHT
type NodeID interface {
String() string
Bytes() []byte
}
// DHT is the interface for the DHT in the Storj network
type DHT interface {
GetNodes(ctx context.Context, start string, limit int, restrictions ...pb.Restriction) ([]*pb.Node, error)
GetRoutingTable(ctx context.Context) (RoutingTable, error)
Bootstrap(ctx context.Context) error
Ping(ctx context.Context, node pb.Node) (pb.Node, error)
FindNode(ctx context.Context, ID NodeID) (pb.Node, error)
Disconnect() error
Seen() []*pb.Node
}
// RoutingTable contains information on nodes we have locally
type RoutingTable interface {
// local params
Local() pb.Node
K() int
CacheSize() int
// Bucket methods
GetBucket(id string) (bucket Bucket, ok bool)
GetBuckets() ([]Bucket, error)
GetBucketIds() (storage.Keys, error)
FindNear(id NodeID, limit int) ([]*pb.Node, error)
ConnectionSuccess(node *pb.Node) error
ConnectionFailed(node *pb.Node) error
// these are for refreshing
SetBucketTimestamp(id string, now time.Time) error
GetBucketTimestamp(id string, bucket Bucket) (time.Time, error)
}
// Bucket is a set of methods to act on kademlia k buckets
type Bucket interface {
Routing() []pb.Node
Cache() []pb.Node
Midpoint() string
Nodes() []*pb.Node
}