satellite/orders: calculate order expiration inside signer
Change-Id: I07f79eeb1ab41b061a1f3146f684bd21291cffb0
This commit is contained in:
parent
189ab07846
commit
b4c8e219c7
@ -126,9 +126,6 @@ func (service *Service) CreateGetOrderLimits(ctx context.Context, bucketID []byt
|
|||||||
}
|
}
|
||||||
pieceSize := eestream.CalcPieceSize(pointer.GetSegmentSize(), redundancy)
|
pieceSize := eestream.CalcPieceSize(pointer.GetSegmentSize(), redundancy)
|
||||||
|
|
||||||
orderCreation := time.Now()
|
|
||||||
orderExpiration := orderCreation.Add(service.orderExpiration)
|
|
||||||
|
|
||||||
nodeIDs := make([]storj.NodeID, len(pointer.GetRemote().GetRemotePieces()))
|
nodeIDs := make([]storj.NodeID, len(pointer.GetRemote().GetRemotePieces()))
|
||||||
for i, piece := range pointer.GetRemote().GetRemotePieces() {
|
for i, piece := range pointer.GetRemote().GetRemotePieces() {
|
||||||
nodeIDs[i] = piece.NodeId
|
nodeIDs[i] = piece.NodeId
|
||||||
@ -140,7 +137,7 @@ func (service *Service) CreateGetOrderLimits(ctx context.Context, bucketID []byt
|
|||||||
return nil, storj.PiecePrivateKey{}, Error.Wrap(err)
|
return nil, storj.PiecePrivateKey{}, Error.Wrap(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
signer, err := NewSignerGet(service, pointer.GetRemote().RootPieceId, orderCreation, orderExpiration, pieceSize)
|
signer, err := NewSignerGet(service, pointer.GetRemote().RootPieceId, time.Now(), pieceSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, storj.PiecePrivateKey{}, Error.Wrap(err)
|
return nil, storj.PiecePrivateKey{}, Error.Wrap(err)
|
||||||
}
|
}
|
||||||
@ -203,10 +200,7 @@ func (service *Service) perm(n int) []int {
|
|||||||
func (service *Service) CreatePutOrderLimits(ctx context.Context, bucketID []byte, nodes []*overlay.SelectedNode, pieceExpiration time.Time, maxPieceSize int64) (_ storj.PieceID, _ []*pb.AddressedOrderLimit, privateKey storj.PiecePrivateKey, err error) {
|
func (service *Service) CreatePutOrderLimits(ctx context.Context, bucketID []byte, nodes []*overlay.SelectedNode, pieceExpiration time.Time, maxPieceSize int64) (_ storj.PieceID, _ []*pb.AddressedOrderLimit, privateKey storj.PiecePrivateKey, err error) {
|
||||||
defer mon.Task()(&ctx)(&err)
|
defer mon.Task()(&ctx)(&err)
|
||||||
|
|
||||||
orderCreation := time.Now()
|
signer, err := NewSignerPut(service, pieceExpiration, time.Now(), maxPieceSize)
|
||||||
orderExpiration := orderCreation.Add(service.orderExpiration)
|
|
||||||
|
|
||||||
signer, err := NewSignerPut(service, pieceExpiration, orderCreation, orderExpiration, maxPieceSize)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return storj.PieceID{}, nil, storj.PiecePrivateKey{}, Error.Wrap(err)
|
return storj.PieceID{}, nil, storj.PiecePrivateKey{}, Error.Wrap(err)
|
||||||
}
|
}
|
||||||
@ -253,10 +247,7 @@ func (service *Service) CreateDeleteOrderLimits(ctx context.Context, bucketID []
|
|||||||
return nil, storj.PiecePrivateKey{}, Error.Wrap(err)
|
return nil, storj.PiecePrivateKey{}, Error.Wrap(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
orderCreation := time.Now()
|
signer, err := NewSignerDelete(service, pointer.GetRemote().RootPieceId, time.Now())
|
||||||
orderExpiration := orderCreation.Add(service.orderExpiration)
|
|
||||||
|
|
||||||
signer, err := NewSignerDelete(service, pointer.GetRemote().RootPieceId, orderCreation, orderExpiration)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, storj.PiecePrivateKey{}, Error.Wrap(err)
|
return nil, storj.PiecePrivateKey{}, Error.Wrap(err)
|
||||||
}
|
}
|
||||||
@ -299,9 +290,6 @@ func (service *Service) CreateAuditOrderLimits(ctx context.Context, bucketID []b
|
|||||||
shareSize := redundancy.GetErasureShareSize()
|
shareSize := redundancy.GetErasureShareSize()
|
||||||
totalPieces := redundancy.GetTotal()
|
totalPieces := redundancy.GetTotal()
|
||||||
|
|
||||||
orderCreation := time.Now()
|
|
||||||
orderExpiration := orderCreation.Add(service.orderExpiration)
|
|
||||||
|
|
||||||
nodeIDs := make([]storj.NodeID, len(pointer.GetRemote().GetRemotePieces()))
|
nodeIDs := make([]storj.NodeID, len(pointer.GetRemote().GetRemotePieces()))
|
||||||
for i, piece := range pointer.GetRemote().GetRemotePieces() {
|
for i, piece := range pointer.GetRemote().GetRemotePieces() {
|
||||||
nodeIDs[i] = piece.NodeId
|
nodeIDs[i] = piece.NodeId
|
||||||
@ -313,7 +301,7 @@ func (service *Service) CreateAuditOrderLimits(ctx context.Context, bucketID []b
|
|||||||
return nil, storj.PiecePrivateKey{}, Error.Wrap(err)
|
return nil, storj.PiecePrivateKey{}, Error.Wrap(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
signer, err := NewSignerAudit(service, pointer.GetRemote().RootPieceId, orderCreation, orderExpiration, int64(shareSize))
|
signer, err := NewSignerAudit(service, pointer.GetRemote().RootPieceId, time.Now(), int64(shareSize))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, storj.PiecePrivateKey{}, Error.Wrap(err)
|
return nil, storj.PiecePrivateKey{}, Error.Wrap(err)
|
||||||
}
|
}
|
||||||
@ -369,9 +357,6 @@ func (service *Service) CreateAuditOrderLimit(ctx context.Context, bucketID []by
|
|||||||
// TODO reduce number of params ?
|
// TODO reduce number of params ?
|
||||||
defer mon.Task()(&ctx)(&err)
|
defer mon.Task()(&ctx)(&err)
|
||||||
|
|
||||||
orderCreation := time.Now()
|
|
||||||
orderExpiration := orderCreation.Add(service.orderExpiration)
|
|
||||||
|
|
||||||
node, err := service.overlay.Get(ctx, nodeID)
|
node, err := service.overlay.Get(ctx, nodeID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, storj.PiecePrivateKey{}, Error.Wrap(err)
|
return nil, storj.PiecePrivateKey{}, Error.Wrap(err)
|
||||||
@ -386,7 +371,7 @@ func (service *Service) CreateAuditOrderLimit(ctx context.Context, bucketID []by
|
|||||||
return nil, storj.PiecePrivateKey{}, overlay.ErrNodeOffline.New("%v", nodeID)
|
return nil, storj.PiecePrivateKey{}, overlay.ErrNodeOffline.New("%v", nodeID)
|
||||||
}
|
}
|
||||||
|
|
||||||
signer, err := NewSignerAudit(service, rootPieceID, orderCreation, orderExpiration, int64(shareSize))
|
signer, err := NewSignerAudit(service, rootPieceID, time.Now(), int64(shareSize))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, storj.PiecePrivateKey{}, Error.Wrap(err)
|
return nil, storj.PiecePrivateKey{}, Error.Wrap(err)
|
||||||
}
|
}
|
||||||
@ -431,8 +416,6 @@ func (service *Service) CreateGetRepairOrderLimits(ctx context.Context, bucketID
|
|||||||
|
|
||||||
pieceSize := eestream.CalcPieceSize(pointer.GetSegmentSize(), redundancy)
|
pieceSize := eestream.CalcPieceSize(pointer.GetSegmentSize(), redundancy)
|
||||||
totalPieces := redundancy.TotalCount()
|
totalPieces := redundancy.TotalCount()
|
||||||
orderCreation := time.Now()
|
|
||||||
orderExpiration := orderCreation.Add(service.orderExpiration)
|
|
||||||
|
|
||||||
nodeIDs := make([]storj.NodeID, len(pointer.GetRemote().GetRemotePieces()))
|
nodeIDs := make([]storj.NodeID, len(pointer.GetRemote().GetRemotePieces()))
|
||||||
for i, piece := range pointer.GetRemote().GetRemotePieces() {
|
for i, piece := range pointer.GetRemote().GetRemotePieces() {
|
||||||
@ -445,7 +428,7 @@ func (service *Service) CreateGetRepairOrderLimits(ctx context.Context, bucketID
|
|||||||
return nil, storj.PiecePrivateKey{}, Error.Wrap(err)
|
return nil, storj.PiecePrivateKey{}, Error.Wrap(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
signer, err := NewSignerRepairGet(service, pointer.GetRemote().RootPieceId, orderCreation, orderExpiration, pieceSize)
|
signer, err := NewSignerRepairGet(service, pointer.GetRemote().RootPieceId, time.Now(), pieceSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, storj.PiecePrivateKey{}, Error.Wrap(err)
|
return nil, storj.PiecePrivateKey{}, Error.Wrap(err)
|
||||||
}
|
}
|
||||||
@ -497,9 +480,6 @@ func (service *Service) CreateGetRepairOrderLimits(ctx context.Context, bucketID
|
|||||||
func (service *Service) CreatePutRepairOrderLimits(ctx context.Context, bucketID []byte, pointer *pb.Pointer, getOrderLimits []*pb.AddressedOrderLimit, newNodes []*overlay.SelectedNode, optimalThresholdMultiplier float64) (_ []*pb.AddressedOrderLimit, _ storj.PiecePrivateKey, err error) {
|
func (service *Service) CreatePutRepairOrderLimits(ctx context.Context, bucketID []byte, pointer *pb.Pointer, getOrderLimits []*pb.AddressedOrderLimit, newNodes []*overlay.SelectedNode, optimalThresholdMultiplier float64) (_ []*pb.AddressedOrderLimit, _ storj.PiecePrivateKey, err error) {
|
||||||
defer mon.Task()(&ctx)(&err)
|
defer mon.Task()(&ctx)(&err)
|
||||||
|
|
||||||
orderCreation := time.Now()
|
|
||||||
orderExpiration := orderCreation.Add(service.orderExpiration)
|
|
||||||
|
|
||||||
// Create the order limits for being used to upload the repaired pieces
|
// Create the order limits for being used to upload the repaired pieces
|
||||||
redundancy, err := eestream.NewRedundancyStrategyFromProto(pointer.GetRemote().GetRedundancy())
|
redundancy, err := eestream.NewRedundancyStrategyFromProto(pointer.GetRemote().GetRedundancy())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -523,7 +503,7 @@ func (service *Service) CreatePutRepairOrderLimits(ctx context.Context, bucketID
|
|||||||
totalPiecesToRepair := totalPiecesAfterRepair - numCurrentPieces
|
totalPiecesToRepair := totalPiecesAfterRepair - numCurrentPieces
|
||||||
|
|
||||||
limits := make([]*pb.AddressedOrderLimit, totalPieces)
|
limits := make([]*pb.AddressedOrderLimit, totalPieces)
|
||||||
signer, err := NewSignerRepairPut(service, pointer.GetRemote().RootPieceId, pointer.ExpirationDate, orderCreation, orderExpiration, pieceSize)
|
signer, err := NewSignerRepairPut(service, pointer.GetRemote().RootPieceId, pointer.ExpirationDate, time.Now(), pieceSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, storj.PiecePrivateKey{}, Error.Wrap(err)
|
return nil, storj.PiecePrivateKey{}, Error.Wrap(err)
|
||||||
}
|
}
|
||||||
@ -575,9 +555,6 @@ func (service *Service) CreatePutRepairOrderLimits(ctx context.Context, bucketID
|
|||||||
func (service *Service) CreateGracefulExitPutOrderLimit(ctx context.Context, bucketID []byte, nodeID storj.NodeID, pieceNum int32, rootPieceID storj.PieceID, shareSize int32) (limit *pb.AddressedOrderLimit, _ storj.PiecePrivateKey, err error) {
|
func (service *Service) CreateGracefulExitPutOrderLimit(ctx context.Context, bucketID []byte, nodeID storj.NodeID, pieceNum int32, rootPieceID storj.PieceID, shareSize int32) (limit *pb.AddressedOrderLimit, _ storj.PiecePrivateKey, err error) {
|
||||||
defer mon.Task()(&ctx)(&err)
|
defer mon.Task()(&ctx)(&err)
|
||||||
|
|
||||||
orderCreation := time.Now().UTC()
|
|
||||||
orderExpiration := orderCreation.Add(service.orderExpiration)
|
|
||||||
|
|
||||||
// should this use KnownReliable or similar?
|
// should this use KnownReliable or similar?
|
||||||
node, err := service.overlay.Get(ctx, nodeID)
|
node, err := service.overlay.Get(ctx, nodeID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -590,7 +567,7 @@ func (service *Service) CreateGracefulExitPutOrderLimit(ctx context.Context, buc
|
|||||||
return nil, storj.PiecePrivateKey{}, overlay.ErrNodeOffline.New("%v", nodeID)
|
return nil, storj.PiecePrivateKey{}, overlay.ErrNodeOffline.New("%v", nodeID)
|
||||||
}
|
}
|
||||||
|
|
||||||
signer, err := NewSignerGracefulExit(service, rootPieceID, orderCreation, orderExpiration, shareSize)
|
signer, err := NewSignerGracefulExit(service, rootPieceID, time.Now(), shareSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, storj.PiecePrivateKey{}, Error.Wrap(err)
|
return nil, storj.PiecePrivateKey{}, Error.Wrap(err)
|
||||||
}
|
}
|
||||||
|
@ -55,10 +55,8 @@ func createSerial(orderExpiration time.Time) (_ storj.SerialNumber, err error) {
|
|||||||
return serial, nil
|
return serial, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: do we need to pass both orderCreation and orderExpiration as arguments?
|
|
||||||
|
|
||||||
// NewSigner creates an order limit signer.
|
// NewSigner creates an order limit signer.
|
||||||
func NewSigner(service *Service, rootPieceID storj.PieceID, pieceExpiration time.Time, orderCreation time.Time, orderExpiration time.Time, limit int64, action pb.PieceAction) (*Signer, error) {
|
func NewSigner(service *Service, rootPieceID storj.PieceID, pieceExpiration time.Time, orderCreation time.Time, limit int64, action pb.PieceAction) (*Signer, error) {
|
||||||
signer := &Signer{}
|
signer := &Signer{}
|
||||||
signer.Service = service
|
signer.Service = service
|
||||||
|
|
||||||
@ -66,7 +64,7 @@ func NewSigner(service *Service, rootPieceID storj.PieceID, pieceExpiration time
|
|||||||
|
|
||||||
signer.PieceExpiration = pieceExpiration
|
signer.PieceExpiration = pieceExpiration
|
||||||
signer.OrderCreation = orderCreation
|
signer.OrderCreation = orderCreation
|
||||||
signer.OrderExpiration = orderExpiration
|
signer.OrderExpiration = orderCreation.Add(service.orderExpiration)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
signer.PublicKey, signer.PrivateKey, err = storj.NewPieceKey()
|
signer.PublicKey, signer.PrivateKey, err = storj.NewPieceKey()
|
||||||
@ -74,7 +72,7 @@ func NewSigner(service *Service, rootPieceID storj.PieceID, pieceExpiration time
|
|||||||
return nil, ErrSigner.Wrap(err)
|
return nil, ErrSigner.Wrap(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
signer.Serial, err = createSerial(orderExpiration)
|
signer.Serial, err = createSerial(signer.OrderExpiration)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ErrSigner.Wrap(err)
|
return nil, ErrSigner.Wrap(err)
|
||||||
}
|
}
|
||||||
@ -86,38 +84,38 @@ func NewSigner(service *Service, rootPieceID storj.PieceID, pieceExpiration time
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewSignerGet creates a new signer for get orders.
|
// NewSignerGet creates a new signer for get orders.
|
||||||
func NewSignerGet(service *Service, rootPieceID storj.PieceID, orderCreation time.Time, orderExpiration time.Time, limit int64) (*Signer, error) {
|
func NewSignerGet(service *Service, rootPieceID storj.PieceID, orderCreation time.Time, limit int64) (*Signer, error) {
|
||||||
return NewSigner(service, rootPieceID, time.Time{}, orderCreation, orderExpiration, limit, pb.PieceAction_GET)
|
return NewSigner(service, rootPieceID, time.Time{}, orderCreation, limit, pb.PieceAction_GET)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSignerPut creates a new signer for put orders.
|
// NewSignerPut creates a new signer for put orders.
|
||||||
func NewSignerPut(service *Service, pieceExpiration time.Time, orderCreation time.Time, orderExpiration time.Time, limit int64) (*Signer, error) {
|
func NewSignerPut(service *Service, pieceExpiration time.Time, orderCreation time.Time, limit int64) (*Signer, error) {
|
||||||
rootPieceID := storj.NewPieceID()
|
rootPieceID := storj.NewPieceID()
|
||||||
return NewSigner(service, rootPieceID, pieceExpiration, orderCreation, orderExpiration, limit, pb.PieceAction_PUT)
|
return NewSigner(service, rootPieceID, pieceExpiration, orderCreation, limit, pb.PieceAction_PUT)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSignerDelete creates a new signer for delete orders.
|
// NewSignerDelete creates a new signer for delete orders.
|
||||||
func NewSignerDelete(service *Service, rootPieceID storj.PieceID, orderCreation time.Time, orderExpiration time.Time) (*Signer, error) {
|
func NewSignerDelete(service *Service, rootPieceID storj.PieceID, orderCreation time.Time) (*Signer, error) {
|
||||||
return NewSigner(service, rootPieceID, time.Time{}, orderCreation, orderExpiration, 0, pb.PieceAction_DELETE)
|
return NewSigner(service, rootPieceID, time.Time{}, orderCreation, 0, pb.PieceAction_DELETE)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSignerRepairGet creates a new signer for get repair orders.
|
// NewSignerRepairGet creates a new signer for get repair orders.
|
||||||
func NewSignerRepairGet(service *Service, rootPieceID storj.PieceID, orderCreation time.Time, orderExpiration time.Time, pieceSize int64) (*Signer, error) {
|
func NewSignerRepairGet(service *Service, rootPieceID storj.PieceID, orderCreation time.Time, pieceSize int64) (*Signer, error) {
|
||||||
return NewSigner(service, rootPieceID, time.Time{}, orderCreation, orderExpiration, pieceSize, pb.PieceAction_GET_REPAIR)
|
return NewSigner(service, rootPieceID, time.Time{}, orderCreation, pieceSize, pb.PieceAction_GET_REPAIR)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSignerRepairPut creates a new signer for put repair orders.
|
// NewSignerRepairPut creates a new signer for put repair orders.
|
||||||
func NewSignerRepairPut(service *Service, rootPieceID storj.PieceID, pieceExpiration time.Time, orderCreation time.Time, orderExpiration time.Time, pieceSize int64) (*Signer, error) {
|
func NewSignerRepairPut(service *Service, rootPieceID storj.PieceID, pieceExpiration time.Time, orderCreation time.Time, pieceSize int64) (*Signer, error) {
|
||||||
return NewSigner(service, rootPieceID, pieceExpiration, orderCreation, orderExpiration, pieceSize, pb.PieceAction_PUT_REPAIR)
|
return NewSigner(service, rootPieceID, pieceExpiration, orderCreation, pieceSize, pb.PieceAction_PUT_REPAIR)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSignerAudit creates a new signer for audit orders.
|
// NewSignerAudit creates a new signer for audit orders.
|
||||||
func NewSignerAudit(service *Service, rootPieceID storj.PieceID, orderCreation time.Time, orderExpiration time.Time, pieceSize int64) (*Signer, error) {
|
func NewSignerAudit(service *Service, rootPieceID storj.PieceID, orderCreation time.Time, pieceSize int64) (*Signer, error) {
|
||||||
return NewSigner(service, rootPieceID, time.Time{}, orderCreation, orderExpiration, pieceSize, pb.PieceAction_GET_AUDIT)
|
return NewSigner(service, rootPieceID, time.Time{}, orderCreation, pieceSize, pb.PieceAction_GET_AUDIT)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSignerGracefulExit creates a new signer for graceful exit orders.
|
// NewSignerGracefulExit creates a new signer for graceful exit orders.
|
||||||
func NewSignerGracefulExit(service *Service, rootPieceID storj.PieceID, orderCreation time.Time, orderExpiration time.Time, shareSize int32) (*Signer, error) {
|
func NewSignerGracefulExit(service *Service, rootPieceID storj.PieceID, orderCreation time.Time, shareSize int32) (*Signer, error) {
|
||||||
// TODO: we're using zero time.Time for piece expiration for some reason.
|
// TODO: we're using zero time.Time for piece expiration for some reason.
|
||||||
|
|
||||||
// TODO: we're using `PUT_REPAIR` here even though we should be using `PUT`, such
|
// TODO: we're using `PUT_REPAIR` here even though we should be using `PUT`, such
|
||||||
@ -128,7 +126,7 @@ func NewSignerGracefulExit(service *Service, rootPieceID storj.PieceID, orderCre
|
|||||||
// supporting code/tables to aggregate `PUT_GRACEFUL_EXIT` bandwidth into our rollups
|
// supporting code/tables to aggregate `PUT_GRACEFUL_EXIT` bandwidth into our rollups
|
||||||
// and stuff. so, for now, we just use `PUT_REPAIR` because it's the least bad of
|
// and stuff. so, for now, we just use `PUT_REPAIR` because it's the least bad of
|
||||||
// our options. this should be fixed.
|
// our options. this should be fixed.
|
||||||
return NewSigner(service, rootPieceID, time.Time{}, orderCreation, orderExpiration, int64(shareSize), pb.PieceAction_PUT_REPAIR)
|
return NewSigner(service, rootPieceID, time.Time{}, orderCreation, int64(shareSize), pb.PieceAction_PUT_REPAIR)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sign signs an order limit for the specified node.
|
// Sign signs an order limit for the specified node.
|
||||||
|
Loading…
Reference in New Issue
Block a user