1ebd66d880
* wip post-demos cleanup * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Reorganize: storage ├── common │ └── common.go `package storage` ├── boltdb │ └── ... └── redis └── ... storage ├── common.go `package storage` ├── boltdb │ └── ... └── redis └── ... storage ├── common │ ├── common.go `package storage` │ └── testing.go `package storage` <-- └── ... internal ├── app │ └── cli ├── pkg │ └── readcloser └── test └── util.go `package test` <-- * remove comment * add and use goimports * add test types & fix some lint errors * better typing * fixing linter issues/comments * goimports * goimports * more linter fixes; replace panic with NoError assertions in tests * fix typo/more linter errors * moar better linter fixes * even moar better linter fixes * linter * add localPort back * fixing exports, imports, and add comments
52 lines
1.6 KiB
Go
52 lines
1.6 KiB
Go
// Copyright (C) 2018 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package overlay
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.uber.org/zap"
|
|
"gopkg.in/spacemonkeygo/monkit.v2"
|
|
"storj.io/storj/pkg/kademlia"
|
|
proto "storj.io/storj/protos/overlay" // naming proto to avoid confusion with this package
|
|
)
|
|
|
|
// Overlay implements our overlay RPC service
|
|
type Overlay struct {
|
|
kad *kademlia.Kademlia
|
|
cache *Cache
|
|
logger *zap.Logger
|
|
metrics *monkit.Registry
|
|
}
|
|
|
|
// Lookup finds the address of a node in our overlay network
|
|
func (o *Overlay) Lookup(ctx context.Context, req *proto.LookupRequest) (*proto.LookupResponse, error) {
|
|
na, err := o.cache.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
|
|
}
|
|
|
|
// FindStorageNodes searches the overlay network for nodes that meet the provided requirements
|
|
func (o *Overlay) FindStorageNodes(ctx context.Context, req *proto.FindStorageNodesRequest) (*proto.FindStorageNodesResponse, error) {
|
|
// 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
|
|
}
|