2020-12-26 01:16:43 +00:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package multinode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
|
|
|
"storj.io/common/rpc/rpcstatus"
|
|
|
|
"storj.io/private/version"
|
|
|
|
"storj.io/storj/private/multinodepb"
|
|
|
|
"storj.io/storj/storagenode/apikeys"
|
|
|
|
"storj.io/storj/storagenode/contact"
|
2021-06-01 08:29:46 +01:00
|
|
|
"storj.io/storj/storagenode/operator"
|
2021-01-05 07:59:22 +00:00
|
|
|
"storj.io/storj/storagenode/reputation"
|
2021-01-07 23:26:31 +00:00
|
|
|
"storj.io/storj/storagenode/trust"
|
2020-12-26 01:16:43 +00:00
|
|
|
)
|
|
|
|
|
2021-06-01 08:29:46 +01:00
|
|
|
// ensures that NodeEndpoint implements multinodepb.DRPCNodeServer.
|
2020-12-26 01:16:43 +00:00
|
|
|
var _ multinodepb.DRPCNodeServer = (*NodeEndpoint)(nil)
|
|
|
|
|
|
|
|
// NodeEndpoint implements multinode node endpoint.
|
|
|
|
//
|
|
|
|
// architecture: Endpoint
|
|
|
|
type NodeEndpoint struct {
|
2021-03-29 09:58:04 +01:00
|
|
|
multinodepb.DRPCNodeUnimplementedServer
|
|
|
|
|
2021-06-01 08:29:46 +01:00
|
|
|
config operator.Config
|
|
|
|
|
2021-01-05 07:59:22 +00:00
|
|
|
log *zap.Logger
|
|
|
|
apiKeys *apikeys.Service
|
|
|
|
version version.Info
|
|
|
|
contact *contact.PingStats
|
|
|
|
reputation reputation.DB
|
2021-01-07 23:26:31 +00:00
|
|
|
trust *trust.Pool
|
2020-12-26 01:16:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewNodeEndpoint creates new multinode node endpoint.
|
2021-06-01 08:29:46 +01:00
|
|
|
func NewNodeEndpoint(log *zap.Logger, config operator.Config, apiKeys *apikeys.Service, version version.Info, contact *contact.PingStats, reputation reputation.DB, trust *trust.Pool) *NodeEndpoint {
|
2020-12-26 01:16:43 +00:00
|
|
|
return &NodeEndpoint{
|
2021-01-05 07:59:22 +00:00
|
|
|
log: log,
|
2021-06-01 08:29:46 +01:00
|
|
|
config: config,
|
2021-01-05 07:59:22 +00:00
|
|
|
apiKeys: apiKeys,
|
|
|
|
version: version,
|
|
|
|
contact: contact,
|
|
|
|
reputation: reputation,
|
2021-01-07 23:26:31 +00:00
|
|
|
trust: trust,
|
2020-12-26 01:16:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Version returns node current version.
|
|
|
|
func (node *NodeEndpoint) Version(ctx context.Context, req *multinodepb.VersionRequest) (_ *multinodepb.VersionResponse, err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
if err = authenticate(ctx, node.apiKeys, req.GetHeader()); err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Unauthenticated, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &multinodepb.VersionResponse{
|
|
|
|
Version: node.version.Version.String(),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// LastContact returns timestamp when node was last in contact with satellite.
|
|
|
|
func (node *NodeEndpoint) LastContact(ctx context.Context, req *multinodepb.LastContactRequest) (_ *multinodepb.LastContactResponse, err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
if err = authenticate(ctx, node.apiKeys, req.GetHeader()); err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Unauthenticated, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &multinodepb.LastContactResponse{
|
|
|
|
LastContact: node.contact.WhenLastPinged(),
|
|
|
|
}, nil
|
|
|
|
}
|
2021-01-05 07:59:22 +00:00
|
|
|
|
|
|
|
// Reputation returns reputation for specific satellite.
|
|
|
|
func (node *NodeEndpoint) Reputation(ctx context.Context, req *multinodepb.ReputationRequest) (_ *multinodepb.ReputationResponse, err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
if err = authenticate(ctx, node.apiKeys, req.GetHeader()); err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Unauthenticated, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
rep, err := node.reputation.Get(ctx, req.SatelliteId)
|
|
|
|
if err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Internal, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &multinodepb.ReputationResponse{
|
|
|
|
Online: &multinodepb.ReputationResponse_Online{
|
|
|
|
Score: rep.OnlineScore,
|
|
|
|
},
|
|
|
|
Audit: &multinodepb.ReputationResponse_Audit{
|
|
|
|
Score: rep.Audit.Score,
|
|
|
|
SuspensionScore: rep.Audit.UnknownScore,
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|
2021-01-07 23:26:31 +00:00
|
|
|
|
|
|
|
// TrustedSatellites returns list of trusted satellites node urls.
|
|
|
|
func (node *NodeEndpoint) TrustedSatellites(ctx context.Context, req *multinodepb.TrustedSatellitesRequest) (_ *multinodepb.TrustedSatellitesResponse, err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
if err = authenticate(ctx, node.apiKeys, req.GetHeader()); err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Unauthenticated, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
response := new(multinodepb.TrustedSatellitesResponse)
|
|
|
|
|
|
|
|
satellites := node.trust.GetSatellites(ctx)
|
|
|
|
for _, satellite := range satellites {
|
|
|
|
nodeURL, err := node.trust.GetNodeURL(ctx, satellite)
|
|
|
|
if err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Internal, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
response.TrustedSatellites = append(response.TrustedSatellites, &multinodepb.TrustedSatellitesResponse_NodeURL{
|
|
|
|
NodeId: nodeURL.ID,
|
|
|
|
Address: nodeURL.Address,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return response, nil
|
|
|
|
}
|
2021-06-01 08:29:46 +01:00
|
|
|
|
|
|
|
// Operator returns operators data.
|
|
|
|
func (node *NodeEndpoint) Operator(ctx context.Context, req *multinodepb.OperatorRequest) (_ *multinodepb.OperatorResponse, err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
if err = authenticate(ctx, node.apiKeys, req.GetHeader()); err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Unauthenticated, err)
|
|
|
|
}
|
|
|
|
return &multinodepb.OperatorResponse{
|
|
|
|
Email: node.config.Email,
|
|
|
|
Wallet: node.config.Wallet,
|
|
|
|
WalletFeatures: node.config.WalletFeatures,
|
|
|
|
}, nil
|
|
|
|
}
|