2018-05-15 01:31:26 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2018-07-06 20:43:53 +01:00
|
|
|
package pointerdb
|
2018-05-15 01:31:26 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2019-01-04 16:26:26 +00:00
|
|
|
"crypto/ecdsa"
|
|
|
|
"crypto/x509"
|
2018-11-08 16:04:52 +00:00
|
|
|
"time"
|
2018-05-15 01:31:26 +01:00
|
|
|
|
2018-11-20 18:29:07 +00:00
|
|
|
"github.com/gogo/protobuf/proto"
|
2018-07-27 07:02:59 +01:00
|
|
|
"github.com/golang/protobuf/ptypes"
|
2019-01-09 15:02:03 +00:00
|
|
|
"github.com/skyrings/skyring-common/tools/uuid"
|
2018-08-27 18:28:16 +01:00
|
|
|
"github.com/zeebo/errs"
|
2018-05-15 01:31:26 +01:00
|
|
|
"go.uber.org/zap"
|
2018-05-30 03:47:40 +01:00
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
2018-08-22 16:07:00 +01:00
|
|
|
monkit "gopkg.in/spacemonkeygo/monkit.v2"
|
2018-05-15 01:31:26 +01:00
|
|
|
|
2018-10-09 15:39:14 +01:00
|
|
|
"storj.io/storj/pkg/auth"
|
2018-10-04 22:00:19 +01:00
|
|
|
"storj.io/storj/pkg/overlay"
|
2018-09-18 05:39:06 +01:00
|
|
|
"storj.io/storj/pkg/pb"
|
2019-01-04 16:26:26 +00:00
|
|
|
"storj.io/storj/pkg/peertls"
|
2018-10-09 15:39:14 +01:00
|
|
|
pointerdbAuth "storj.io/storj/pkg/pointerdb/auth"
|
2018-10-11 15:35:55 +01:00
|
|
|
"storj.io/storj/pkg/provider"
|
2018-07-30 19:57:50 +01:00
|
|
|
"storj.io/storj/pkg/storage/meta"
|
2018-06-13 19:22:32 +01:00
|
|
|
"storj.io/storj/storage"
|
2018-05-15 01:31:26 +01:00
|
|
|
)
|
|
|
|
|
2018-08-22 16:07:00 +01:00
|
|
|
var (
|
2018-08-27 18:28:16 +01:00
|
|
|
mon = monkit.Package()
|
2018-08-27 15:04:46 +01:00
|
|
|
segmentError = errs.Class("segment error")
|
2018-08-22 16:07:00 +01:00
|
|
|
)
|
|
|
|
|
2018-05-15 01:31:26 +01:00
|
|
|
// Server implements the network state RPC service
|
|
|
|
type Server struct {
|
2018-10-11 15:35:55 +01:00
|
|
|
DB storage.KeyValueStore
|
|
|
|
logger *zap.Logger
|
|
|
|
config Config
|
|
|
|
cache *overlay.Cache
|
|
|
|
identity *provider.FullIdentity
|
2018-05-15 01:31:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewServer creates instance of Server
|
2018-10-11 15:35:55 +01:00
|
|
|
func NewServer(db storage.KeyValueStore, cache *overlay.Cache, logger *zap.Logger, c Config, identity *provider.FullIdentity) *Server {
|
2018-05-15 01:31:26 +01:00
|
|
|
return &Server{
|
2018-10-11 15:35:55 +01:00
|
|
|
DB: db,
|
|
|
|
logger: logger,
|
|
|
|
config: c,
|
|
|
|
cache: cache,
|
|
|
|
identity: identity,
|
2018-05-15 01:31:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-09 15:39:14 +01:00
|
|
|
func (s *Server) validateAuth(ctx context.Context) error {
|
|
|
|
APIKey, ok := auth.GetAPIKey(ctx)
|
|
|
|
if !ok || !pointerdbAuth.ValidateAPIKey(string(APIKey)) {
|
2018-08-27 18:28:16 +01:00
|
|
|
s.logger.Error("unauthorized request: ", zap.Error(status.Errorf(codes.Unauthenticated, "Invalid API credential")))
|
|
|
|
return status.Errorf(codes.Unauthenticated, "Invalid API credential")
|
2018-06-04 17:45:07 +01:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-08-27 15:04:46 +01:00
|
|
|
func (s *Server) validateSegment(req *pb.PutRequest) error {
|
2018-10-08 21:09:28 +01:00
|
|
|
min := s.config.MinRemoteSegmentSize
|
2018-08-27 15:04:46 +01:00
|
|
|
remote := req.GetPointer().Remote
|
2018-11-20 17:09:35 +00:00
|
|
|
remoteSize := req.GetPointer().GetSegmentSize()
|
2018-08-27 15:04:46 +01:00
|
|
|
|
2018-10-08 21:09:28 +01:00
|
|
|
if remote != nil && remoteSize < int64(min) {
|
|
|
|
return segmentError.New("remote segment size %d less than minimum allowed %d", remoteSize, min)
|
2018-08-27 15:04:46 +01:00
|
|
|
}
|
|
|
|
|
2019-01-14 21:19:15 +00:00
|
|
|
max := s.config.MaxInlineSegmentSize.Int()
|
2018-10-08 21:09:28 +01:00
|
|
|
inlineSize := len(req.GetPointer().InlineSegment)
|
|
|
|
|
2018-08-27 15:04:46 +01:00
|
|
|
if inlineSize > max {
|
|
|
|
return segmentError.New("inline segment size %d greater than maximum allowed %d", inlineSize, max)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-06-29 21:06:25 +01:00
|
|
|
// Put formats and hands off a key/value (path/pointer) to be saved to boltdb
|
2018-07-27 07:02:59 +01:00
|
|
|
func (s *Server) Put(ctx context.Context, req *pb.PutRequest) (resp *pb.PutResponse, err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
2018-05-15 01:31:26 +01:00
|
|
|
|
2018-08-27 15:04:46 +01:00
|
|
|
err = s.validateSegment(req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Errorf(codes.InvalidArgument, err.Error())
|
|
|
|
}
|
2018-08-27 18:28:16 +01:00
|
|
|
|
2018-10-09 15:39:14 +01:00
|
|
|
if err = s.validateAuth(ctx); err != nil {
|
2018-06-04 17:45:07 +01:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-07-27 07:02:59 +01:00
|
|
|
// Update the pointer with the creation date
|
|
|
|
req.GetPointer().CreationDate = ptypes.TimestampNow()
|
|
|
|
|
|
|
|
pointerBytes, err := proto.Marshal(req.GetPointer())
|
2018-05-30 03:47:40 +01:00
|
|
|
if err != nil {
|
|
|
|
s.logger.Error("err marshaling pointer", zap.Error(err))
|
|
|
|
return nil, status.Errorf(codes.Internal, err.Error())
|
2018-05-15 01:31:26 +01:00
|
|
|
}
|
|
|
|
|
2018-07-27 07:02:59 +01:00
|
|
|
// TODO(kaloyan): make sure that we know we are overwriting the pointer!
|
|
|
|
// In such case we should delete the pieces of the old segment if it was
|
|
|
|
// a remote one.
|
|
|
|
if err = s.DB.Put([]byte(req.GetPath()), pointerBytes); err != nil {
|
2018-05-30 03:47:40 +01:00
|
|
|
s.logger.Error("err putting pointer", zap.Error(err))
|
|
|
|
return nil, status.Errorf(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
return &pb.PutResponse{}, nil
|
2018-05-15 01:31:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get formats and hands off a file path to get from boltdb
|
2018-07-27 07:02:59 +01:00
|
|
|
func (s *Server) Get(ctx context.Context, req *pb.GetRequest) (resp *pb.GetResponse, err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
2018-05-15 01:31:26 +01:00
|
|
|
|
2018-10-09 15:39:14 +01:00
|
|
|
if err = s.validateAuth(ctx); err != nil {
|
2018-06-04 17:45:07 +01:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-07-27 07:02:59 +01:00
|
|
|
pointerBytes, err := s.DB.Get([]byte(req.GetPath()))
|
2018-05-15 01:31:26 +01:00
|
|
|
if err != nil {
|
2018-08-14 16:22:29 +01:00
|
|
|
if storage.ErrKeyNotFound.Has(err) {
|
|
|
|
return nil, status.Errorf(codes.NotFound, err.Error())
|
|
|
|
}
|
2018-07-27 07:02:59 +01:00
|
|
|
s.logger.Error("err getting pointer", zap.Error(err))
|
2018-05-30 03:47:40 +01:00
|
|
|
return nil, status.Errorf(codes.Internal, err.Error())
|
2018-05-15 01:31:26 +01:00
|
|
|
}
|
|
|
|
|
2018-10-04 22:00:19 +01:00
|
|
|
pointer := &pb.Pointer{}
|
|
|
|
err = proto.Unmarshal(pointerBytes, pointer)
|
|
|
|
if err != nil {
|
|
|
|
s.logger.Error("Error unmarshaling pointer")
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-10-30 16:24:46 +00:00
|
|
|
|
2018-11-26 18:21:44 +00:00
|
|
|
pba, err := s.PayerBandwidthAllocation(ctx, &pb.PayerBandwidthAllocationRequest{Action: pb.PayerBandwidthAllocation_GET})
|
2018-10-30 16:24:46 +00:00
|
|
|
if err != nil {
|
|
|
|
s.logger.Error("err getting payer bandwidth allocation", zap.Error(err))
|
|
|
|
return nil, status.Errorf(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
|
2018-11-05 15:12:19 +00:00
|
|
|
authorization, err := s.getSignedMessage()
|
|
|
|
if err != nil {
|
|
|
|
s.logger.Error("err getting signed message", zap.Error(err))
|
|
|
|
return nil, status.Errorf(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
|
2018-10-04 22:00:19 +01:00
|
|
|
nodes := []*pb.Node{}
|
|
|
|
|
|
|
|
var r = &pb.GetResponse{
|
2018-11-05 15:12:19 +00:00
|
|
|
Pointer: pointer,
|
|
|
|
Nodes: nil,
|
2018-11-26 18:21:44 +00:00
|
|
|
Pba: pba.GetPba(),
|
2018-11-05 15:12:19 +00:00
|
|
|
Authorization: authorization,
|
2018-10-04 22:00:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if !s.config.Overlay || pointer.Remote == nil {
|
|
|
|
return r, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, piece := range pointer.Remote.RemotePieces {
|
|
|
|
node, err := s.cache.Get(ctx, piece.NodeId)
|
|
|
|
if err != nil {
|
|
|
|
s.logger.Error("Error getting node from cache")
|
|
|
|
}
|
|
|
|
nodes = append(nodes, node)
|
|
|
|
}
|
|
|
|
|
2019-01-02 18:47:34 +00:00
|
|
|
for _, v := range nodes {
|
|
|
|
v.Type.DPanicOnInvalid("pdb server Get")
|
|
|
|
}
|
2018-10-04 22:00:19 +01:00
|
|
|
r = &pb.GetResponse{
|
2018-11-05 15:12:19 +00:00
|
|
|
Pointer: pointer,
|
|
|
|
Nodes: nodes,
|
2018-11-26 18:21:44 +00:00
|
|
|
Pba: pba.GetPba(),
|
2018-11-05 15:12:19 +00:00
|
|
|
Authorization: authorization,
|
2018-10-04 22:00:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return r, nil
|
2018-05-15 01:31:26 +01:00
|
|
|
}
|
|
|
|
|
2018-09-07 15:20:15 +01:00
|
|
|
// List returns all Path keys in the Pointers bucket
|
2018-07-27 07:02:59 +01:00
|
|
|
func (s *Server) List(ctx context.Context, req *pb.ListRequest) (resp *pb.ListResponse, err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
2018-05-15 01:31:26 +01:00
|
|
|
|
2018-10-09 15:39:14 +01:00
|
|
|
if err = s.validateAuth(ctx); err != nil {
|
2018-06-04 17:45:07 +01:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-09-07 15:20:15 +01:00
|
|
|
var prefix storage.Key
|
|
|
|
if req.Prefix != "" {
|
|
|
|
prefix = storage.Key(req.Prefix)
|
|
|
|
if prefix[len(prefix)-1] != storage.Delimiter {
|
|
|
|
prefix = append(prefix, storage.Delimiter)
|
|
|
|
}
|
|
|
|
}
|
2018-07-27 07:02:59 +01:00
|
|
|
|
2018-09-07 15:20:15 +01:00
|
|
|
rawItems, more, err := storage.ListV2(s.DB, storage.ListOptions{
|
|
|
|
Prefix: prefix, //storage.Key(req.Prefix),
|
|
|
|
StartAfter: storage.Key(req.StartAfter),
|
|
|
|
EndBefore: storage.Key(req.EndBefore),
|
|
|
|
Recursive: req.Recursive,
|
|
|
|
Limit: int(req.Limit),
|
|
|
|
IncludeValue: req.MetaFlags != meta.None,
|
|
|
|
})
|
2018-07-27 07:02:59 +01:00
|
|
|
if err != nil {
|
2018-09-07 15:20:15 +01:00
|
|
|
return nil, status.Errorf(codes.Internal, "ListV2: %v", err)
|
2018-07-27 07:02:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var items []*pb.ListResponse_Item
|
2018-09-07 15:20:15 +01:00
|
|
|
for _, rawItem := range rawItems {
|
2018-09-09 07:34:23 +01:00
|
|
|
items = append(items, s.createListItem(rawItem, req.MetaFlags))
|
2018-07-27 07:02:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return &pb.ListResponse{Items: items, More: more}, nil
|
|
|
|
}
|
|
|
|
|
2018-09-07 15:20:15 +01:00
|
|
|
// createListItem creates a new list item with the given path. It also adds
|
|
|
|
// the metadata according to the given metaFlags.
|
2018-09-09 07:34:23 +01:00
|
|
|
func (s *Server) createListItem(rawItem storage.ListItem, metaFlags uint32) *pb.ListResponse_Item {
|
2018-09-07 15:20:15 +01:00
|
|
|
item := &pb.ListResponse_Item{
|
2018-09-09 07:34:23 +01:00
|
|
|
Path: rawItem.Key.String(),
|
2018-09-07 15:20:15 +01:00
|
|
|
IsPrefix: rawItem.IsPrefix,
|
2018-05-15 01:31:26 +01:00
|
|
|
}
|
2018-09-07 15:20:15 +01:00
|
|
|
if item.IsPrefix {
|
|
|
|
return item
|
2018-07-27 07:02:59 +01:00
|
|
|
}
|
|
|
|
|
2018-09-07 15:20:15 +01:00
|
|
|
err := s.setMetadata(item, rawItem.Value, metaFlags)
|
2018-07-27 07:02:59 +01:00
|
|
|
if err != nil {
|
|
|
|
s.logger.Warn("err retrieving metadata", zap.Error(err))
|
|
|
|
}
|
|
|
|
return item
|
2018-05-15 01:31:26 +01:00
|
|
|
}
|
|
|
|
|
2018-07-27 07:02:59 +01:00
|
|
|
// getMetadata adds the metadata to the given item pointer according to the
|
|
|
|
// given metaFlags
|
2018-09-07 15:20:15 +01:00
|
|
|
func (s *Server) setMetadata(item *pb.ListResponse_Item, data []byte, metaFlags uint32) (err error) {
|
|
|
|
if metaFlags == meta.None || len(data) == 0 {
|
2018-07-27 07:02:59 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
pr := &pb.Pointer{}
|
2018-09-07 15:20:15 +01:00
|
|
|
err = proto.Unmarshal(data, pr)
|
2018-07-27 07:02:59 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-29 21:06:25 +01:00
|
|
|
}
|
2018-07-27 07:02:59 +01:00
|
|
|
|
2018-07-30 19:57:50 +01:00
|
|
|
// Start with an empty pointer to and add only what's requested in
|
|
|
|
// metaFlags to safe to transfer payload
|
|
|
|
item.Pointer = &pb.Pointer{}
|
|
|
|
if metaFlags&meta.Modified != 0 {
|
|
|
|
item.Pointer.CreationDate = pr.GetCreationDate()
|
2018-07-27 07:02:59 +01:00
|
|
|
}
|
2018-07-30 19:57:50 +01:00
|
|
|
if metaFlags&meta.Expiration != 0 {
|
|
|
|
item.Pointer.ExpirationDate = pr.GetExpirationDate()
|
2018-07-27 07:02:59 +01:00
|
|
|
}
|
2018-07-30 19:57:50 +01:00
|
|
|
if metaFlags&meta.Size != 0 {
|
2018-11-20 17:09:35 +00:00
|
|
|
item.Pointer.SegmentSize = pr.GetSegmentSize()
|
2018-07-30 19:57:50 +01:00
|
|
|
}
|
|
|
|
if metaFlags&meta.UserDefined != 0 {
|
|
|
|
item.Pointer.Metadata = pr.GetMetadata()
|
2018-07-27 07:02:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2018-06-29 21:06:25 +01:00
|
|
|
}
|
|
|
|
|
2018-05-15 01:31:26 +01:00
|
|
|
// Delete formats and hands off a file path to delete from boltdb
|
2018-07-27 07:02:59 +01:00
|
|
|
func (s *Server) Delete(ctx context.Context, req *pb.DeleteRequest) (resp *pb.DeleteResponse, err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
2018-05-15 01:31:26 +01:00
|
|
|
|
2018-10-09 15:39:14 +01:00
|
|
|
if err = s.validateAuth(ctx); err != nil {
|
2018-06-04 17:45:07 +01:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-07-27 07:02:59 +01:00
|
|
|
err = s.DB.Delete([]byte(req.GetPath()))
|
2018-05-15 01:31:26 +01:00
|
|
|
if err != nil {
|
2018-06-29 21:06:25 +01:00
|
|
|
s.logger.Error("err deleting path and pointer", zap.Error(err))
|
2018-05-30 03:47:40 +01:00
|
|
|
return nil, status.Errorf(codes.Internal, err.Error())
|
2018-05-15 01:31:26 +01:00
|
|
|
}
|
2018-11-29 20:59:26 +00:00
|
|
|
|
2018-05-30 03:47:40 +01:00
|
|
|
return &pb.DeleteResponse{}, nil
|
2018-08-13 09:39:45 +01:00
|
|
|
}
|
2018-10-09 17:09:33 +01:00
|
|
|
|
|
|
|
// Iterate iterates over items based on IterateRequest
|
2019-01-10 12:07:08 +00:00
|
|
|
func (s *Server) Iterate(ctx context.Context, req *pb.IterateRequest, f func(it storage.Iterator) error) (err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
if err = s.validateAuth(ctx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-10-09 17:09:33 +01:00
|
|
|
opts := storage.IterateOptions{
|
2018-10-11 15:35:55 +01:00
|
|
|
Prefix: storage.Key(req.Prefix),
|
|
|
|
First: storage.Key(req.First),
|
2018-10-09 17:09:33 +01:00
|
|
|
Recurse: req.Recurse,
|
|
|
|
Reverse: req.Reverse,
|
|
|
|
}
|
|
|
|
return s.DB.Iterate(opts, f)
|
2018-10-11 15:35:55 +01:00
|
|
|
}
|
2018-10-30 16:24:46 +00:00
|
|
|
|
2018-11-26 18:21:44 +00:00
|
|
|
// PayerBandwidthAllocation returns PayerBandwidthAllocation struct, signed and with given action type
|
2019-01-10 12:07:08 +00:00
|
|
|
func (s *Server) PayerBandwidthAllocation(ctx context.Context, req *pb.PayerBandwidthAllocationRequest) (pba *pb.PayerBandwidthAllocationResponse, err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
if err = s.validateAuth(ctx); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-11-29 18:39:27 +00:00
|
|
|
payer := s.identity.ID
|
2018-10-30 16:24:46 +00:00
|
|
|
|
|
|
|
// TODO(michal) should be replaced with renter id when available
|
2019-01-04 16:26:26 +00:00
|
|
|
// retrieve the public key
|
|
|
|
pi, err := provider.PeerIdentityFromContext(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
pk, ok := pi.Leaf.PublicKey.(*ecdsa.PublicKey)
|
|
|
|
if !ok {
|
|
|
|
return nil, peertls.ErrUnsupportedKey.New("%T", pi.Leaf.PublicKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
pubbytes, err := x509.MarshalPKIXPublicKey(pk)
|
|
|
|
if err != nil {
|
|
|
|
s.logger.Error("Can't Marshal Public Key for PayerBandwidthAllocation: %+v", zap.Error(err))
|
|
|
|
return nil, status.Errorf(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
|
2019-01-09 15:02:03 +00:00
|
|
|
serialNum, err := uuid.New()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-01-10 18:30:55 +00:00
|
|
|
created := time.Now().Unix()
|
|
|
|
|
|
|
|
// convert ttl from days to seconds
|
|
|
|
ttl := s.config.BwExpiration
|
|
|
|
ttl *= 86400
|
|
|
|
|
2018-10-30 19:03:41 +00:00
|
|
|
pbad := &pb.PayerBandwidthAllocation_Data{
|
2019-01-10 18:30:55 +00:00
|
|
|
SatelliteId: payer,
|
|
|
|
UplinkId: pi.ID,
|
|
|
|
CreatedUnixSec: created,
|
|
|
|
ExpirationUnixSec: created + int64(ttl),
|
|
|
|
Action: req.GetAction(),
|
|
|
|
SerialNumber: serialNum.String(),
|
|
|
|
PubKey: pubbytes,
|
2018-10-30 19:03:41 +00:00
|
|
|
}
|
2018-10-30 16:24:46 +00:00
|
|
|
|
|
|
|
data, err := proto.Marshal(pbad)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
signature, err := auth.GenerateSignature(data, s.identity)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-11-26 18:21:44 +00:00
|
|
|
return &pb.PayerBandwidthAllocationResponse{Pba: &pb.PayerBandwidthAllocation{Signature: signature, Data: data}}, nil
|
2018-10-30 16:24:46 +00:00
|
|
|
}
|
2018-11-05 15:12:19 +00:00
|
|
|
|
|
|
|
func (s *Server) getSignedMessage() (*pb.SignedMessage, error) {
|
|
|
|
signature, err := auth.GenerateSignature(s.identity.ID.Bytes(), s.identity)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return auth.NewSignedMessage(signature, s.identity)
|
|
|
|
}
|