2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-05 15:23:54 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2019-01-25 23:06:38 +00:00
|
|
|
package testbwagreement
|
2018-11-05 15:23:54 +00:00
|
|
|
|
|
|
|
import (
|
2018-11-15 19:06:09 +00:00
|
|
|
"time"
|
2018-11-05 15:23:54 +00:00
|
|
|
|
2019-01-09 15:02:03 +00:00
|
|
|
"github.com/skyrings/skyring-common/tools/uuid"
|
2018-12-07 09:59:31 +00:00
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
"storj.io/storj/pkg/auth"
|
|
|
|
"storj.io/storj/pkg/identity"
|
2018-11-05 15:23:54 +00:00
|
|
|
"storj.io/storj/pkg/pb"
|
2019-01-07 15:19:05 +00:00
|
|
|
"storj.io/storj/pkg/storj"
|
2018-11-05 15:23:54 +00:00
|
|
|
)
|
|
|
|
|
2019-01-28 19:45:25 +00:00
|
|
|
//GeneratePayerBandwidthAllocation creates a signed PayerBandwidthAllocation from a BandwidthAction
|
|
|
|
func GeneratePayerBandwidthAllocation(action pb.BandwidthAction, satID *identity.FullIdentity, upID *identity.FullIdentity, expiration time.Duration) (*pb.PayerBandwidthAllocation, error) {
|
2019-01-09 15:02:03 +00:00
|
|
|
serialNum, err := uuid.New()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-01-28 19:45:25 +00:00
|
|
|
pba := &pb.PayerBandwidthAllocation{
|
|
|
|
SatelliteId: satID.ID,
|
|
|
|
UplinkId: upID.ID,
|
|
|
|
ExpirationUnixSec: time.Now().Add(expiration).Unix(),
|
|
|
|
SerialNumber: serialNum.String(),
|
|
|
|
Action: action,
|
|
|
|
CreatedUnixSec: time.Now().Unix(),
|
2019-01-25 18:05:21 +00:00
|
|
|
}
|
2019-01-28 19:45:25 +00:00
|
|
|
return pba, auth.SignMessage(pba, *satID)
|
2018-11-15 19:06:09 +00:00
|
|
|
}
|
|
|
|
|
2018-12-05 14:03:23 +00:00
|
|
|
//GenerateRenterBandwidthAllocation creates a signed RenterBandwidthAllocation from a PayerBandwidthAllocation
|
2019-01-25 18:05:21 +00:00
|
|
|
func GenerateRenterBandwidthAllocation(pba *pb.PayerBandwidthAllocation, storageNodeID storj.NodeID, upID *identity.FullIdentity, total int64) (*pb.RenterBandwidthAllocation, error) {
|
2019-01-28 19:45:25 +00:00
|
|
|
rba := &pb.RenterBandwidthAllocation{
|
|
|
|
PayerAllocation: *pba,
|
|
|
|
StorageNodeId: storageNodeID,
|
|
|
|
Total: total,
|
2018-11-15 19:06:09 +00:00
|
|
|
}
|
|
|
|
// Combine Signature and Data for RenterBandwidthAllocation
|
2019-01-28 19:45:25 +00:00
|
|
|
return rba, auth.SignMessage(rba, *upID)
|
2018-11-15 19:06:09 +00:00
|
|
|
}
|