098cbc9c67
all of the packages and tests work with both grpc and drpc. we'll probably need to do some jenkins pipelines to run the tests with drpc as well. most of the changes are really due to a bit of cleanup of the pkg/transport.Client api into an rpc.Dialer in the spirit of a net.Dialer. now that we don't need observers, we can pass around stateless configuration to everything rather than stateful things that issue observations. it also adds a DialAddressID for the case where we don't have a pb.Node, but we do have an address and want to assert some ID. this happened pretty frequently, and now there's no more weird contortions creating custom tls options, etc. a lot of the other changes are being consistent/using the abstractions in the rpc package to do rpc style things like finding peer information, or checking status codes. Change-Id: Ief62875e21d80a21b3c56a5a37f45887679f9412
76 lines
2.1 KiB
Go
76 lines
2.1 KiB
Go
// Copyright (C) 2019 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package contact
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"storj.io/storj/pkg/identity"
|
|
"storj.io/storj/pkg/pb"
|
|
"storj.io/storj/pkg/rpc/rpcstatus"
|
|
"storj.io/storj/pkg/storj"
|
|
)
|
|
|
|
// SatelliteIDVerifier checks if the connection is from a trusted satellite
|
|
type SatelliteIDVerifier interface {
|
|
VerifySatelliteID(ctx context.Context, id storj.NodeID) error
|
|
}
|
|
|
|
// KademliaEndpoint implements the NodesServer Interface for backwards compatibility
|
|
type KademliaEndpoint struct {
|
|
log *zap.Logger
|
|
service *Service
|
|
trust SatelliteIDVerifier
|
|
}
|
|
|
|
// NewKademliaEndpoint returns a new endpoint
|
|
func NewKademliaEndpoint(log *zap.Logger, service *Service, trust SatelliteIDVerifier) *KademliaEndpoint {
|
|
return &KademliaEndpoint{
|
|
log: log,
|
|
service: service,
|
|
trust: trust,
|
|
}
|
|
}
|
|
|
|
// Query is a node to node communication query
|
|
func (endpoint *KademliaEndpoint) Query(ctx context.Context, req *pb.QueryRequest) (_ *pb.QueryResponse, err error) {
|
|
defer mon.Task()(&ctx)(&err)
|
|
return &pb.QueryResponse{}, nil
|
|
}
|
|
|
|
// Ping provides an easy way to verify a node is online and accepting requests
|
|
func (endpoint *KademliaEndpoint) Ping(ctx context.Context, req *pb.PingRequest) (_ *pb.PingResponse, err error) {
|
|
defer mon.Task()(&ctx)(&err)
|
|
return &pb.PingResponse{}, nil
|
|
}
|
|
|
|
// RequestInfo returns the node info
|
|
func (endpoint *KademliaEndpoint) RequestInfo(ctx context.Context, req *pb.InfoRequest) (_ *pb.InfoResponse, err error) {
|
|
defer mon.Task()(&ctx)(&err)
|
|
self := endpoint.service.Local()
|
|
|
|
if endpoint.trust == nil {
|
|
return nil, rpcstatus.Error(rpcstatus.Internal, "missing trust")
|
|
}
|
|
|
|
peer, err := identity.PeerIdentityFromContext(ctx)
|
|
if err != nil {
|
|
return nil, rpcstatus.Error(rpcstatus.Unauthenticated, err.Error())
|
|
}
|
|
|
|
err = endpoint.trust.VerifySatelliteID(ctx, peer.ID)
|
|
if err != nil {
|
|
return nil, rpcstatus.Errorf(rpcstatus.PermissionDenied, "untrusted peer %v", peer.ID)
|
|
}
|
|
|
|
return &pb.InfoResponse{
|
|
Type: self.Type,
|
|
Operator: &self.Operator,
|
|
Capacity: &self.Capacity,
|
|
Version: &self.Version,
|
|
}, nil
|
|
}
|