2018-04-23 16:54:22 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2018-04-12 14:50:22 +01:00
|
|
|
package overlay
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2018-06-05 22:06:37 +01:00
|
|
|
"go.uber.org/zap"
|
|
|
|
monkit "gopkg.in/spacemonkeygo/monkit.v2"
|
|
|
|
"storj.io/storj/pkg/kademlia"
|
2018-04-23 16:54:22 +01:00
|
|
|
proto "storj.io/storj/protos/overlay" // naming proto to avoid confusion with this package
|
2018-06-05 22:06:37 +01:00
|
|
|
"storj.io/storj/storage/redis"
|
2018-04-12 14:50:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Overlay implements our overlay RPC service
|
2018-06-05 22:06:37 +01:00
|
|
|
type Overlay struct {
|
|
|
|
kad *kademlia.Kademlia
|
|
|
|
DB *redis.OverlayClient
|
|
|
|
logger *zap.Logger
|
|
|
|
metrics *monkit.Registry
|
|
|
|
}
|
2018-04-12 14:50:22 +01:00
|
|
|
|
|
|
|
// Lookup finds the address of a node in our overlay network
|
2018-04-23 16:54:22 +01:00
|
|
|
func (o *Overlay) Lookup(ctx context.Context, req *proto.LookupRequest) (*proto.LookupResponse, error) {
|
2018-06-05 22:06:37 +01:00
|
|
|
na, err := o.DB.Get(ctx, req.NodeID)
|
|
|
|
if err != nil {
|
|
|
|
o.logger.Error("Error looking up node", zap.Error(err), zap.String("nodeID", req.NodeID))
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &proto.LookupResponse{
|
|
|
|
NodeAddress: na,
|
|
|
|
}, nil
|
2018-04-12 14:50:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// FindStorageNodes searches the overlay network for nodes that meet the provided requirements
|
2018-04-23 16:54:22 +01:00
|
|
|
func (o *Overlay) FindStorageNodes(ctx context.Context, req *proto.FindStorageNodesRequest) (*proto.FindStorageNodesResponse, error) {
|
2018-06-05 22:06:37 +01:00
|
|
|
// NB: call FilterNodeReputation from node_reputation package to find nodes for storage
|
|
|
|
|
|
|
|
// TODO(coyle): need to determine if we will pull the startID and Limit from the request or just use hardcoded data
|
|
|
|
// for now just using 40 for demos and empty string which will default the Id to the kademlia node doing the lookup
|
|
|
|
nodes, err := o.kad.GetNodes(ctx, "", 40)
|
|
|
|
if err != nil {
|
|
|
|
o.logger.Error("Error getting nodes", zap.Error(err))
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &proto.FindStorageNodesResponse{
|
|
|
|
Node: nodes,
|
|
|
|
}, nil
|
2018-04-12 14:50:22 +01:00
|
|
|
}
|