2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-06-22 14:33:57 +01:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package dht
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2018-09-18 05:39:06 +01:00
|
|
|
"storj.io/storj/pkg/pb"
|
2018-11-29 18:39:27 +00:00
|
|
|
"storj.io/storj/pkg/storj"
|
2018-11-21 17:31:27 +00:00
|
|
|
"storj.io/storj/storage"
|
2018-06-22 14:33:57 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// DHT is the interface for the DHT in the Storj network
|
|
|
|
type DHT interface {
|
2019-01-28 22:53:37 +00:00
|
|
|
FindNear(ctx context.Context, start storj.NodeID, limit int, restrictions ...pb.Restriction) ([]*pb.Node, error)
|
2019-02-06 12:37:17 +00:00
|
|
|
GetRoutingTable() RoutingTable
|
2018-06-22 14:33:57 +01:00
|
|
|
Bootstrap(ctx context.Context) error
|
2018-09-18 05:39:06 +01:00
|
|
|
Ping(ctx context.Context, node pb.Node) (pb.Node, error)
|
2018-11-29 18:39:27 +00:00
|
|
|
FindNode(ctx context.Context, ID storj.NodeID) (pb.Node, 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-11-21 17:31:27 +00:00
|
|
|
GetBucketIds() (storage.Keys, error)
|
2018-11-29 18:39:27 +00:00
|
|
|
FindNear(id storj.NodeID, limit int) ([]*pb.Node, error)
|
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
|
2018-11-29 18:39:27 +00:00
|
|
|
SetBucketTimestamp(id []byte, now time.Time) error
|
2018-12-20 21:45:06 +00:00
|
|
|
GetBucketTimestamp(id []byte) (time.Time, error)
|
2018-06-22 14:33:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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-11-29 18:39:27 +00:00
|
|
|
// TODO: should this be a NodeID?
|
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
|
|
|
}
|