Rename voucher service to endpoint (#2467)
This commit is contained in:
parent
3f4662598e
commit
963e1b9710
@ -200,7 +200,7 @@ type Peer struct {
|
||||
}
|
||||
|
||||
Vouchers struct {
|
||||
Service *vouchers.Service
|
||||
Endpoint *vouchers.Endpoint
|
||||
}
|
||||
|
||||
Console struct {
|
||||
@ -341,13 +341,13 @@ func New(log *zap.Logger, full *identity.FullIdentity, db DB, config *Config, ve
|
||||
|
||||
{ // setup vouchers
|
||||
log.Debug("Setting up vouchers")
|
||||
peer.Vouchers.Service = vouchers.NewService(
|
||||
peer.Vouchers.Endpoint = vouchers.NewEndpoint(
|
||||
peer.Log.Named("vouchers"),
|
||||
signing.SignerFromFullIdentity(peer.Identity),
|
||||
peer.Overlay.Service,
|
||||
config.Vouchers.Expiration,
|
||||
)
|
||||
pb.RegisterVouchersServer(peer.Server.GRPC(), peer.Vouchers.Service)
|
||||
pb.RegisterVouchersServer(peer.Server.GRPC(), peer.Vouchers.Endpoint)
|
||||
}
|
||||
|
||||
{ // setup live accounting
|
||||
|
@ -18,13 +18,13 @@ import (
|
||||
"storj.io/storj/pkg/pb"
|
||||
)
|
||||
|
||||
// Config contains voucher service configuration parameters
|
||||
// Config contains voucher endpoint configuration parameters
|
||||
type Config struct {
|
||||
Expiration time.Duration `help:"length of time before a voucher expires" default:"720h0m0s"`
|
||||
}
|
||||
|
||||
// Service for issuing signed vouchers
|
||||
type Service struct {
|
||||
// Endpoint for issuing signed vouchers
|
||||
type Endpoint struct {
|
||||
log *zap.Logger
|
||||
satellite signing.Signer
|
||||
cache *overlay.Cache
|
||||
@ -38,9 +38,9 @@ var (
|
||||
mon = monkit.Package()
|
||||
)
|
||||
|
||||
// NewService creates a new service for issuing signed vouchers
|
||||
func NewService(log *zap.Logger, satellite signing.Signer, cache *overlay.Cache, expiration time.Duration) *Service {
|
||||
return &Service{
|
||||
// NewEndpoint creates a new endpoint for issuing signed vouchers
|
||||
func NewEndpoint(log *zap.Logger, satellite signing.Signer, cache *overlay.Cache, expiration time.Duration) *Endpoint {
|
||||
return &Endpoint{
|
||||
log: log,
|
||||
satellite: satellite,
|
||||
cache: cache,
|
||||
@ -49,7 +49,7 @@ func NewService(log *zap.Logger, satellite signing.Signer, cache *overlay.Cache,
|
||||
}
|
||||
|
||||
// Request receives a voucher request and returns a voucher and an error
|
||||
func (service *Service) Request(ctx context.Context, req *pb.VoucherRequest) (_ *pb.VoucherResponse, err error) {
|
||||
func (endpoint *Endpoint) Request(ctx context.Context, req *pb.VoucherRequest) (_ *pb.VoucherResponse, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
peer, err := identity.PeerIdentityFromContext(ctx)
|
||||
@ -57,30 +57,30 @@ func (service *Service) Request(ctx context.Context, req *pb.VoucherRequest) (_
|
||||
return nil, Error.Wrap(err)
|
||||
}
|
||||
|
||||
reputable, err := service.cache.IsVetted(ctx, peer.ID)
|
||||
reputable, err := endpoint.cache.IsVetted(ctx, peer.ID)
|
||||
if err != nil {
|
||||
return nil, Error.Wrap(err)
|
||||
}
|
||||
|
||||
service.log.Debug("Node reputation", zap.Bool("reputable", reputable))
|
||||
endpoint.log.Debug("Node reputation", zap.Bool("reputable", reputable))
|
||||
|
||||
if !reputable {
|
||||
return &pb.VoucherResponse{Status: pb.VoucherResponse_REJECTED}, nil
|
||||
}
|
||||
|
||||
expirationTime := time.Now().UTC().Add(service.expiration)
|
||||
expirationTime := time.Now().UTC().Add(endpoint.expiration)
|
||||
expiration, err := ptypes.TimestampProto(expirationTime)
|
||||
if err != nil {
|
||||
return nil, Error.Wrap(err)
|
||||
}
|
||||
|
||||
unsigned := &pb.Voucher{
|
||||
SatelliteId: service.satellite.ID(),
|
||||
SatelliteId: endpoint.satellite.ID(),
|
||||
StorageNodeId: peer.ID,
|
||||
Expiration: expiration,
|
||||
}
|
||||
|
||||
voucher, err := signing.SignVoucher(ctx, service.satellite, unsigned)
|
||||
voucher, err := signing.SignVoucher(ctx, endpoint.satellite, unsigned)
|
||||
if err != nil {
|
||||
return nil, Error.Wrap(err)
|
||||
}
|
Loading…
Reference in New Issue
Block a user