2018-06-22 14:33:57 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package dht
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2018-09-18 05:39:06 +01:00
|
|
|
"storj.io/storj/pkg/pb"
|
2018-06-22 14:33:57 +01:00
|
|
|
)
|
|
|
|
|
2018-09-11 14:13:25 +01:00
|
|
|
// NodeID is the unique identifier used for Nodes in the DHT
|
2018-06-22 14:33:57 +01:00
|
|
|
type NodeID interface {
|
|
|
|
String() string
|
|
|
|
Bytes() []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
// DHT is the interface for the DHT in the Storj network
|
|
|
|
type DHT interface {
|
2018-09-18 05:39:06 +01:00
|
|
|
GetNodes(ctx context.Context, start string, limit int, restrictions ...pb.Restriction) ([]*pb.Node, error)
|
2018-06-22 14:33:57 +01:00
|
|
|
GetRoutingTable(ctx context.Context) (RoutingTable, error)
|
|
|
|
Bootstrap(ctx context.Context) error
|
2018-09-18 05:39:06 +01:00
|
|
|
Ping(ctx context.Context, node pb.Node) (pb.Node, error)
|
|
|
|
FindNode(ctx context.Context, ID NodeID) (pb.Node, error)
|
2018-06-22 14:33:57 +01:00
|
|
|
Disconnect() error
|
2018-11-20 16:54:52 +00:00
|
|
|
Seen() []*pb.Node
|
2018-06-22 14:33:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// RoutingTable contains information on nodes we have locally
|
|
|
|
type RoutingTable interface {
|
|
|
|
// local params
|
2018-09-18 05:39:06 +01:00
|
|
|
Local() pb.Node
|
2018-06-22 14:33:57 +01:00
|
|
|
K() int
|
|
|
|
CacheSize() int
|
2018-08-13 09:39:45 +01:00
|
|
|
|
2018-06-22 14:33:57 +01:00
|
|
|
GetBucket(id string) (bucket Bucket, ok bool)
|
|
|
|
GetBuckets() ([]Bucket, error)
|
|
|
|
|
2018-09-18 05:39:06 +01:00
|
|
|
FindNear(id NodeID, limit int) ([]*pb.Node, error)
|
2018-06-22 14:33:57 +01:00
|
|
|
|
2018-09-18 05:39:06 +01:00
|
|
|
ConnectionSuccess(node *pb.Node) error
|
|
|
|
ConnectionFailed(node *pb.Node) error
|
2018-06-22 14:33:57 +01:00
|
|
|
|
|
|
|
// 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 {
|
2018-09-18 05:39:06 +01:00
|
|
|
Routing() []pb.Node
|
|
|
|
Cache() []pb.Node
|
2018-06-22 14:33:57 +01:00
|
|
|
Midpoint() string
|
2018-09-18 05:39:06 +01:00
|
|
|
Nodes() []*pb.Node
|
2018-06-22 14:33:57 +01:00
|
|
|
}
|