5de5428d3a
* WIP First pass at node restrictions * adjustments to storage clients * fix cover * undo previous import change * adding copyright * fix the tests * check for keys * moar fixes to tests * linter * change how we handle restrictions * add generated pb.go file * PR comments addressed * MockKeyValueStore * pr comments addressed * missing ) * past my bedtime * moar merge issues * cleanup
58 lines
1.6 KiB
Go
58 lines
1.6 KiB
Go
// Copyright (C) 2018 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package kademlia
|
|
|
|
import (
|
|
"context"
|
|
|
|
"storj.io/storj/pkg/dht"
|
|
proto "storj.io/storj/protos/overlay"
|
|
)
|
|
|
|
// NewMockKademlia returns a newly intialized MockKademlia struct
|
|
func NewMockKademlia() *MockKademlia {
|
|
return &MockKademlia{}
|
|
}
|
|
|
|
// MockKademlia is a mock implementation of the DHT interface used solely for testing
|
|
type MockKademlia struct {
|
|
RoutingTable dht.RoutingTable
|
|
Nodes []*proto.Node
|
|
}
|
|
|
|
// GetNodes increments the GetNodesCalled field on MockKademlia
|
|
// returns the Nodes field on MockKademlia
|
|
func (k *MockKademlia) GetNodes(ctx context.Context, start string, limit int, restrictions ...proto.Restriction) ([]*proto.Node, error) {
|
|
return k.Nodes, nil
|
|
}
|
|
|
|
// GetRoutingTable increments the GetRoutingTableCalled field on MockKademlia
|
|
//
|
|
// returns the RoutingTable field on MockKademlia
|
|
func (k *MockKademlia) GetRoutingTable(ctx context.Context) (dht.RoutingTable, error) {
|
|
return k.RoutingTable, nil
|
|
}
|
|
|
|
// Bootstrap increments the BootstrapCalled field on MockKademlia
|
|
func (k *MockKademlia) Bootstrap(ctx context.Context) error {
|
|
return nil
|
|
}
|
|
|
|
// Ping increments the PingCalled field on MockKademlia
|
|
func (k *MockKademlia) Ping(ctx context.Context, node proto.Node) (proto.Node, error) {
|
|
return node, nil
|
|
}
|
|
|
|
// FindNode increments the FindNodeCalled field on MockKademlia
|
|
//
|
|
// returns the local kademlia node
|
|
func (k *MockKademlia) FindNode(ctx context.Context, ID dht.NodeID) (proto.Node, error) {
|
|
return k.RoutingTable.Local(), nil
|
|
}
|
|
|
|
// Disconnect increments the DisconnectCalled field on MockKademlia
|
|
func (k *MockKademlia) Disconnect() error {
|
|
return nil
|
|
}
|