2018-06-22 14:33:57 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package kademlia
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"storj.io/storj/pkg/dht"
|
2018-09-18 05:39:06 +01:00
|
|
|
"storj.io/storj/pkg/pb"
|
2018-06-22 14:33:57 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
2018-09-18 05:39:06 +01:00
|
|
|
Nodes []*pb.Node
|
2018-06-22 14:33:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetNodes increments the GetNodesCalled field on MockKademlia
|
|
|
|
// returns the Nodes field on MockKademlia
|
2018-09-18 05:39:06 +01:00
|
|
|
func (k *MockKademlia) GetNodes(ctx context.Context, start string, limit int, restrictions ...pb.Restriction) ([]*pb.Node, error) {
|
2018-06-22 14:33:57 +01:00
|
|
|
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
|
2018-09-18 05:39:06 +01:00
|
|
|
func (k *MockKademlia) Ping(ctx context.Context, node pb.Node) (pb.Node, error) {
|
2018-06-22 14:33:57 +01:00
|
|
|
return node, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// FindNode increments the FindNodeCalled field on MockKademlia
|
|
|
|
//
|
|
|
|
// returns the local kademlia node
|
2018-09-18 05:39:06 +01:00
|
|
|
func (k *MockKademlia) FindNode(ctx context.Context, ID dht.NodeID) (pb.Node, error) {
|
2018-06-22 14:33:57 +01:00
|
|
|
return k.RoutingTable.Local(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disconnect increments the DisconnectCalled field on MockKademlia
|
|
|
|
func (k *MockKademlia) Disconnect() error {
|
|
|
|
return nil
|
|
|
|
}
|
2018-11-20 16:54:52 +00:00
|
|
|
|
|
|
|
//Seen __
|
|
|
|
func (k *MockKademlia) Seen() []*pb.Node {
|
|
|
|
return nil
|
|
|
|
}
|