storj/pkg/bwagreement/server_test.go

217 lines
5.5 KiB
Go
Raw Normal View History

Satellite bw usage v3 121 (#547) * protobuf for sending bandwidth agreements to satellite from storage nodes * Setup process for sending agreements * Add payer_id to db with bandwidth agreements for better sorting * Linter errors * Read agreements from PSDB * Try writing message to server * Cleanup * Basic functionality * Better error handelling * Fix test * setup config and server structure for receiving bandwidth agreements * Resolve linter issues * Optional commit for if we want to handle deletes all at once * add identity to Server, add logic for receiving bandwidth messsages * Bandwidth agreement DBX creation and integration with bw agreement endpoint Co-authored-by: Kishore <kishore@storj.io> Co-authored-by: Cam <cameron@storj.io> * protobuf for sending bandwidth agreements to satellite from storage nodes * Setup process for sending agreements * Add payer_id to db with bandwidth agreements for better sorting * Linter errors * Read agreements from PSDB * Try writing message to server * Cleanup * Basic functionality * Better error handelling * Fix test * setup config and server structure for receiving bandwidth agreements * Resolve linter issues * Optional commit for if we want to handle deletes all at once * add identity to Server, add logic for receiving bandwidth messsages * Bandwidth agreement DBX creation and integration with bw agreement endpoint Co-authored-by: Kishore <kishore@storj.io> Co-authored-by: Cam <cameron@storj.io> * added postgres create/read/delete test function Co-authored-by: kishore <kishore@storj.io Co-authored-by: cam <cameron@storj.io> * edit comment * removed sqlite3 driver from dbx * remove generated sqlite code, add dbx read limitoffset * remove getServerAndDB function, rename getDBPath to getPSQLInfo * WIP writing server endpoint test * code review changes
2018-11-05 15:23:54 +00:00
// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package bwagreement
import (
"context"
"crypto"
"crypto/ecdsa"
"crypto/x509"
"flag"
Satellite bw usage v3 121 (#547) * protobuf for sending bandwidth agreements to satellite from storage nodes * Setup process for sending agreements * Add payer_id to db with bandwidth agreements for better sorting * Linter errors * Read agreements from PSDB * Try writing message to server * Cleanup * Basic functionality * Better error handelling * Fix test * setup config and server structure for receiving bandwidth agreements * Resolve linter issues * Optional commit for if we want to handle deletes all at once * add identity to Server, add logic for receiving bandwidth messsages * Bandwidth agreement DBX creation and integration with bw agreement endpoint Co-authored-by: Kishore <kishore@storj.io> Co-authored-by: Cam <cameron@storj.io> * protobuf for sending bandwidth agreements to satellite from storage nodes * Setup process for sending agreements * Add payer_id to db with bandwidth agreements for better sorting * Linter errors * Read agreements from PSDB * Try writing message to server * Cleanup * Basic functionality * Better error handelling * Fix test * setup config and server structure for receiving bandwidth agreements * Resolve linter issues * Optional commit for if we want to handle deletes all at once * add identity to Server, add logic for receiving bandwidth messsages * Bandwidth agreement DBX creation and integration with bw agreement endpoint Co-authored-by: Kishore <kishore@storj.io> Co-authored-by: Cam <cameron@storj.io> * added postgres create/read/delete test function Co-authored-by: kishore <kishore@storj.io Co-authored-by: cam <cameron@storj.io> * edit comment * removed sqlite3 driver from dbx * remove generated sqlite code, add dbx read limitoffset * remove getServerAndDB function, rename getDBPath to getPSQLInfo * WIP writing server endpoint test * code review changes
2018-11-05 15:23:54 +00:00
"log"
"net"
"os"
Satellite bw usage v3 121 (#547) * protobuf for sending bandwidth agreements to satellite from storage nodes * Setup process for sending agreements * Add payer_id to db with bandwidth agreements for better sorting * Linter errors * Read agreements from PSDB * Try writing message to server * Cleanup * Basic functionality * Better error handelling * Fix test * setup config and server structure for receiving bandwidth agreements * Resolve linter issues * Optional commit for if we want to handle deletes all at once * add identity to Server, add logic for receiving bandwidth messsages * Bandwidth agreement DBX creation and integration with bw agreement endpoint Co-authored-by: Kishore <kishore@storj.io> Co-authored-by: Cam <cameron@storj.io> * protobuf for sending bandwidth agreements to satellite from storage nodes * Setup process for sending agreements * Add payer_id to db with bandwidth agreements for better sorting * Linter errors * Read agreements from PSDB * Try writing message to server * Cleanup * Basic functionality * Better error handelling * Fix test * setup config and server structure for receiving bandwidth agreements * Resolve linter issues * Optional commit for if we want to handle deletes all at once * add identity to Server, add logic for receiving bandwidth messsages * Bandwidth agreement DBX creation and integration with bw agreement endpoint Co-authored-by: Kishore <kishore@storj.io> Co-authored-by: Cam <cameron@storj.io> * added postgres create/read/delete test function Co-authored-by: kishore <kishore@storj.io Co-authored-by: cam <cameron@storj.io> * edit comment * removed sqlite3 driver from dbx * remove generated sqlite code, add dbx read limitoffset * remove getServerAndDB function, rename getDBPath to getPSQLInfo * WIP writing server endpoint test * code review changes
2018-11-05 15:23:54 +00:00
"testing"
"time"
Satellite bw usage v3 121 (#547) * protobuf for sending bandwidth agreements to satellite from storage nodes * Setup process for sending agreements * Add payer_id to db with bandwidth agreements for better sorting * Linter errors * Read agreements from PSDB * Try writing message to server * Cleanup * Basic functionality * Better error handelling * Fix test * setup config and server structure for receiving bandwidth agreements * Resolve linter issues * Optional commit for if we want to handle deletes all at once * add identity to Server, add logic for receiving bandwidth messsages * Bandwidth agreement DBX creation and integration with bw agreement endpoint Co-authored-by: Kishore <kishore@storj.io> Co-authored-by: Cam <cameron@storj.io> * protobuf for sending bandwidth agreements to satellite from storage nodes * Setup process for sending agreements * Add payer_id to db with bandwidth agreements for better sorting * Linter errors * Read agreements from PSDB * Try writing message to server * Cleanup * Basic functionality * Better error handelling * Fix test * setup config and server structure for receiving bandwidth agreements * Resolve linter issues * Optional commit for if we want to handle deletes all at once * add identity to Server, add logic for receiving bandwidth messsages * Bandwidth agreement DBX creation and integration with bw agreement endpoint Co-authored-by: Kishore <kishore@storj.io> Co-authored-by: Cam <cameron@storj.io> * added postgres create/read/delete test function Co-authored-by: kishore <kishore@storj.io Co-authored-by: cam <cameron@storj.io> * edit comment * removed sqlite3 driver from dbx * remove generated sqlite code, add dbx read limitoffset * remove getServerAndDB function, rename getDBPath to getPSQLInfo * WIP writing server endpoint test * code review changes
2018-11-05 15:23:54 +00:00
"github.com/gogo/protobuf/proto"
"github.com/gtank/cryptopasta"
"github.com/stretchr/testify/assert"
"github.com/zeebo/errs"
Satellite bw usage v3 121 (#547) * protobuf for sending bandwidth agreements to satellite from storage nodes * Setup process for sending agreements * Add payer_id to db with bandwidth agreements for better sorting * Linter errors * Read agreements from PSDB * Try writing message to server * Cleanup * Basic functionality * Better error handelling * Fix test * setup config and server structure for receiving bandwidth agreements * Resolve linter issues * Optional commit for if we want to handle deletes all at once * add identity to Server, add logic for receiving bandwidth messsages * Bandwidth agreement DBX creation and integration with bw agreement endpoint Co-authored-by: Kishore <kishore@storj.io> Co-authored-by: Cam <cameron@storj.io> * protobuf for sending bandwidth agreements to satellite from storage nodes * Setup process for sending agreements * Add payer_id to db with bandwidth agreements for better sorting * Linter errors * Read agreements from PSDB * Try writing message to server * Cleanup * Basic functionality * Better error handelling * Fix test * setup config and server structure for receiving bandwidth agreements * Resolve linter issues * Optional commit for if we want to handle deletes all at once * add identity to Server, add logic for receiving bandwidth messsages * Bandwidth agreement DBX creation and integration with bw agreement endpoint Co-authored-by: Kishore <kishore@storj.io> Co-authored-by: Cam <cameron@storj.io> * added postgres create/read/delete test function Co-authored-by: kishore <kishore@storj.io Co-authored-by: cam <cameron@storj.io> * edit comment * removed sqlite3 driver from dbx * remove generated sqlite code, add dbx read limitoffset * remove getServerAndDB function, rename getDBPath to getPSQLInfo * WIP writing server endpoint test * code review changes
2018-11-05 15:23:54 +00:00
"go.uber.org/zap"
"google.golang.org/grpc"
"storj.io/storj/pkg/bwagreement/database-manager"
Satellite bw usage v3 121 (#547) * protobuf for sending bandwidth agreements to satellite from storage nodes * Setup process for sending agreements * Add payer_id to db with bandwidth agreements for better sorting * Linter errors * Read agreements from PSDB * Try writing message to server * Cleanup * Basic functionality * Better error handelling * Fix test * setup config and server structure for receiving bandwidth agreements * Resolve linter issues * Optional commit for if we want to handle deletes all at once * add identity to Server, add logic for receiving bandwidth messsages * Bandwidth agreement DBX creation and integration with bw agreement endpoint Co-authored-by: Kishore <kishore@storj.io> Co-authored-by: Cam <cameron@storj.io> * protobuf for sending bandwidth agreements to satellite from storage nodes * Setup process for sending agreements * Add payer_id to db with bandwidth agreements for better sorting * Linter errors * Read agreements from PSDB * Try writing message to server * Cleanup * Basic functionality * Better error handelling * Fix test * setup config and server structure for receiving bandwidth agreements * Resolve linter issues * Optional commit for if we want to handle deletes all at once * add identity to Server, add logic for receiving bandwidth messsages * Bandwidth agreement DBX creation and integration with bw agreement endpoint Co-authored-by: Kishore <kishore@storj.io> Co-authored-by: Cam <cameron@storj.io> * added postgres create/read/delete test function Co-authored-by: kishore <kishore@storj.io Co-authored-by: cam <cameron@storj.io> * edit comment * removed sqlite3 driver from dbx * remove generated sqlite code, add dbx read limitoffset * remove getServerAndDB function, rename getDBPath to getPSQLInfo * WIP writing server endpoint test * code review changes
2018-11-05 15:23:54 +00:00
"storj.io/storj/pkg/pb"
"storj.io/storj/pkg/provider"
)
var (
ctx = context.Background()
)
func TestBandwidthAgreements(t *testing.T) {
TS := NewTestServer(t)
defer TS.Stop()
pba, err := generatePayerBandwidthAllocation(pb.PayerBandwidthAllocation_GET, TS.k)
assert.NoError(t, err)
Satellite bw usage v3 121 (#547) * protobuf for sending bandwidth agreements to satellite from storage nodes * Setup process for sending agreements * Add payer_id to db with bandwidth agreements for better sorting * Linter errors * Read agreements from PSDB * Try writing message to server * Cleanup * Basic functionality * Better error handelling * Fix test * setup config and server structure for receiving bandwidth agreements * Resolve linter issues * Optional commit for if we want to handle deletes all at once * add identity to Server, add logic for receiving bandwidth messsages * Bandwidth agreement DBX creation and integration with bw agreement endpoint Co-authored-by: Kishore <kishore@storj.io> Co-authored-by: Cam <cameron@storj.io> * protobuf for sending bandwidth agreements to satellite from storage nodes * Setup process for sending agreements * Add payer_id to db with bandwidth agreements for better sorting * Linter errors * Read agreements from PSDB * Try writing message to server * Cleanup * Basic functionality * Better error handelling * Fix test * setup config and server structure for receiving bandwidth agreements * Resolve linter issues * Optional commit for if we want to handle deletes all at once * add identity to Server, add logic for receiving bandwidth messsages * Bandwidth agreement DBX creation and integration with bw agreement endpoint Co-authored-by: Kishore <kishore@storj.io> Co-authored-by: Cam <cameron@storj.io> * added postgres create/read/delete test function Co-authored-by: kishore <kishore@storj.io Co-authored-by: cam <cameron@storj.io> * edit comment * removed sqlite3 driver from dbx * remove generated sqlite code, add dbx read limitoffset * remove getServerAndDB function, rename getDBPath to getPSQLInfo * WIP writing server endpoint test * code review changes
2018-11-05 15:23:54 +00:00
rba, err := generateRenterBandwidthAllocation(pba, TS.k)
assert.NoError(t, err)
Satellite bw usage v3 121 (#547) * protobuf for sending bandwidth agreements to satellite from storage nodes * Setup process for sending agreements * Add payer_id to db with bandwidth agreements for better sorting * Linter errors * Read agreements from PSDB * Try writing message to server * Cleanup * Basic functionality * Better error handelling * Fix test * setup config and server structure for receiving bandwidth agreements * Resolve linter issues * Optional commit for if we want to handle deletes all at once * add identity to Server, add logic for receiving bandwidth messsages * Bandwidth agreement DBX creation and integration with bw agreement endpoint Co-authored-by: Kishore <kishore@storj.io> Co-authored-by: Cam <cameron@storj.io> * protobuf for sending bandwidth agreements to satellite from storage nodes * Setup process for sending agreements * Add payer_id to db with bandwidth agreements for better sorting * Linter errors * Read agreements from PSDB * Try writing message to server * Cleanup * Basic functionality * Better error handelling * Fix test * setup config and server structure for receiving bandwidth agreements * Resolve linter issues * Optional commit for if we want to handle deletes all at once * add identity to Server, add logic for receiving bandwidth messsages * Bandwidth agreement DBX creation and integration with bw agreement endpoint Co-authored-by: Kishore <kishore@storj.io> Co-authored-by: Cam <cameron@storj.io> * added postgres create/read/delete test function Co-authored-by: kishore <kishore@storj.io Co-authored-by: cam <cameron@storj.io> * edit comment * removed sqlite3 driver from dbx * remove generated sqlite code, add dbx read limitoffset * remove getServerAndDB function, rename getDBPath to getPSQLInfo * WIP writing server endpoint test * code review changes
2018-11-05 15:23:54 +00:00
/* emulate sending the bwagreement stream from piecestore node */
_, err = TS.c.BandwidthAgreements(ctx, rba)
Satellite bw usage v3 121 (#547) * protobuf for sending bandwidth agreements to satellite from storage nodes * Setup process for sending agreements * Add payer_id to db with bandwidth agreements for better sorting * Linter errors * Read agreements from PSDB * Try writing message to server * Cleanup * Basic functionality * Better error handelling * Fix test * setup config and server structure for receiving bandwidth agreements * Resolve linter issues * Optional commit for if we want to handle deletes all at once * add identity to Server, add logic for receiving bandwidth messsages * Bandwidth agreement DBX creation and integration with bw agreement endpoint Co-authored-by: Kishore <kishore@storj.io> Co-authored-by: Cam <cameron@storj.io> * protobuf for sending bandwidth agreements to satellite from storage nodes * Setup process for sending agreements * Add payer_id to db with bandwidth agreements for better sorting * Linter errors * Read agreements from PSDB * Try writing message to server * Cleanup * Basic functionality * Better error handelling * Fix test * setup config and server structure for receiving bandwidth agreements * Resolve linter issues * Optional commit for if we want to handle deletes all at once * add identity to Server, add logic for receiving bandwidth messsages * Bandwidth agreement DBX creation and integration with bw agreement endpoint Co-authored-by: Kishore <kishore@storj.io> Co-authored-by: Cam <cameron@storj.io> * added postgres create/read/delete test function Co-authored-by: kishore <kishore@storj.io Co-authored-by: cam <cameron@storj.io> * edit comment * removed sqlite3 driver from dbx * remove generated sqlite code, add dbx read limitoffset * remove getServerAndDB function, rename getDBPath to getPSQLInfo * WIP writing server endpoint test * code review changes
2018-11-05 15:23:54 +00:00
assert.NoError(t, err)
}
type TestServer struct {
s *Server
grpcs *grpc.Server
conn *grpc.ClientConn
c pb.BandwidthClient
k crypto.PrivateKey
}
func NewTestServer(t *testing.T) *TestServer {
check := func(e error) {
if !assert.NoError(t, e) {
t.Fail()
}
}
caS, err := provider.NewTestCA(context.Background())
check(err)
fiS, err := caS.NewIdentity()
check(err)
so, err := fiS.ServerOption()
check(err)
caC, err := provider.NewTestCA(context.Background())
check(err)
fiC, err := caC.NewIdentity()
check(err)
co, err := fiC.DialOption("")
Satellite bw usage v3 121 (#547) * protobuf for sending bandwidth agreements to satellite from storage nodes * Setup process for sending agreements * Add payer_id to db with bandwidth agreements for better sorting * Linter errors * Read agreements from PSDB * Try writing message to server * Cleanup * Basic functionality * Better error handelling * Fix test * setup config and server structure for receiving bandwidth agreements * Resolve linter issues * Optional commit for if we want to handle deletes all at once * add identity to Server, add logic for receiving bandwidth messsages * Bandwidth agreement DBX creation and integration with bw agreement endpoint Co-authored-by: Kishore <kishore@storj.io> Co-authored-by: Cam <cameron@storj.io> * protobuf for sending bandwidth agreements to satellite from storage nodes * Setup process for sending agreements * Add payer_id to db with bandwidth agreements for better sorting * Linter errors * Read agreements from PSDB * Try writing message to server * Cleanup * Basic functionality * Better error handelling * Fix test * setup config and server structure for receiving bandwidth agreements * Resolve linter issues * Optional commit for if we want to handle deletes all at once * add identity to Server, add logic for receiving bandwidth messsages * Bandwidth agreement DBX creation and integration with bw agreement endpoint Co-authored-by: Kishore <kishore@storj.io> Co-authored-by: Cam <cameron@storj.io> * added postgres create/read/delete test function Co-authored-by: kishore <kishore@storj.io Co-authored-by: cam <cameron@storj.io> * edit comment * removed sqlite3 driver from dbx * remove generated sqlite code, add dbx read limitoffset * remove getServerAndDB function, rename getDBPath to getPSQLInfo * WIP writing server endpoint test * code review changes
2018-11-05 15:23:54 +00:00
check(err)
s := newTestServerStruct(t, fiC.Key)
Satellite bw usage v3 121 (#547) * protobuf for sending bandwidth agreements to satellite from storage nodes * Setup process for sending agreements * Add payer_id to db with bandwidth agreements for better sorting * Linter errors * Read agreements from PSDB * Try writing message to server * Cleanup * Basic functionality * Better error handelling * Fix test * setup config and server structure for receiving bandwidth agreements * Resolve linter issues * Optional commit for if we want to handle deletes all at once * add identity to Server, add logic for receiving bandwidth messsages * Bandwidth agreement DBX creation and integration with bw agreement endpoint Co-authored-by: Kishore <kishore@storj.io> Co-authored-by: Cam <cameron@storj.io> * protobuf for sending bandwidth agreements to satellite from storage nodes * Setup process for sending agreements * Add payer_id to db with bandwidth agreements for better sorting * Linter errors * Read agreements from PSDB * Try writing message to server * Cleanup * Basic functionality * Better error handelling * Fix test * setup config and server structure for receiving bandwidth agreements * Resolve linter issues * Optional commit for if we want to handle deletes all at once * add identity to Server, add logic for receiving bandwidth messsages * Bandwidth agreement DBX creation and integration with bw agreement endpoint Co-authored-by: Kishore <kishore@storj.io> Co-authored-by: Cam <cameron@storj.io> * added postgres create/read/delete test function Co-authored-by: kishore <kishore@storj.io Co-authored-by: cam <cameron@storj.io> * edit comment * removed sqlite3 driver from dbx * remove generated sqlite code, add dbx read limitoffset * remove getServerAndDB function, rename getDBPath to getPSQLInfo * WIP writing server endpoint test * code review changes
2018-11-05 15:23:54 +00:00
grpcs := grpc.NewServer(so)
k, ok := fiC.Key.(*ecdsa.PrivateKey)
assert.True(t, ok)
ts := &TestServer{s: s, grpcs: grpcs, k: k}
addr := ts.start()
ts.c, ts.conn = connect(addr, co)
return ts
}
const (
// this connstring is expected to work under the storj-test docker-compose instance
defaultPostgresConn = "postgres://storj:storj-pass@test-postgres/teststorj?sslmode=disable"
)
var (
// for travis build support
testPostgres = flag.String("postgres-test-db", os.Getenv("STORJ_POSTGRES_TEST"), "PostgreSQL test database connection string")
)
func newTestServerStruct(t *testing.T, k crypto.PrivateKey) *Server {
if *testPostgres == "" {
t.Skipf("postgres flag missing, example:\n-postgres-test-db=%s", defaultPostgresConn)
}
dbm, err := dbmanager.NewDBManager("postgres", *testPostgres)
if err != nil {
t.Fatalf("Failed to initialize dbmanager when creating test server: %+v", err)
}
p, _ := k.(*ecdsa.PrivateKey)
server, err := NewServer(dbm, zap.NewNop(), &p.PublicKey)
if err != nil {
t.Fatal(err)
}
return server
Satellite bw usage v3 121 (#547) * protobuf for sending bandwidth agreements to satellite from storage nodes * Setup process for sending agreements * Add payer_id to db with bandwidth agreements for better sorting * Linter errors * Read agreements from PSDB * Try writing message to server * Cleanup * Basic functionality * Better error handelling * Fix test * setup config and server structure for receiving bandwidth agreements * Resolve linter issues * Optional commit for if we want to handle deletes all at once * add identity to Server, add logic for receiving bandwidth messsages * Bandwidth agreement DBX creation and integration with bw agreement endpoint Co-authored-by: Kishore <kishore@storj.io> Co-authored-by: Cam <cameron@storj.io> * protobuf for sending bandwidth agreements to satellite from storage nodes * Setup process for sending agreements * Add payer_id to db with bandwidth agreements for better sorting * Linter errors * Read agreements from PSDB * Try writing message to server * Cleanup * Basic functionality * Better error handelling * Fix test * setup config and server structure for receiving bandwidth agreements * Resolve linter issues * Optional commit for if we want to handle deletes all at once * add identity to Server, add logic for receiving bandwidth messsages * Bandwidth agreement DBX creation and integration with bw agreement endpoint Co-authored-by: Kishore <kishore@storj.io> Co-authored-by: Cam <cameron@storj.io> * added postgres create/read/delete test function Co-authored-by: kishore <kishore@storj.io Co-authored-by: cam <cameron@storj.io> * edit comment * removed sqlite3 driver from dbx * remove generated sqlite code, add dbx read limitoffset * remove getServerAndDB function, rename getDBPath to getPSQLInfo * WIP writing server endpoint test * code review changes
2018-11-05 15:23:54 +00:00
}
func (TS *TestServer) start() (addr string) {
lis, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
pb.RegisterBandwidthServer(TS.grpcs, TS.s)
go func() {
if err := TS.grpcs.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err)
}
}()
return lis.Addr().String()
}
func connect(addr string, o ...grpc.DialOption) (pb.BandwidthClient, *grpc.ClientConn) {
conn, err := grpc.Dial(addr, o...)
if err != nil {
log.Fatalf("did not connect: %v", err)
}
c := pb.NewBandwidthClient(conn)
return c, conn
}
func generatePayerBandwidthAllocation(action pb.PayerBandwidthAllocation_Action, satelliteKey crypto.PrivateKey) (*pb.PayerBandwidthAllocation, error) {
satelliteKeyEcdsa, ok := satelliteKey.(*ecdsa.PrivateKey)
if !ok {
return nil, errs.New("Satellite Private Key is not a valid *ecdsa.PrivateKey")
}
// Generate PayerBandwidthAllocation_Data
data, _ := proto.Marshal(
&pb.PayerBandwidthAllocation_Data{
SatelliteId: []byte("SatelliteID"),
UplinkId: []byte("UplinkID"),
ExpirationUnixSec: time.Now().Add(time.Hour * 24 * 10).Unix(),
SerialNumber: "SerialNumber",
Action: action,
CreatedUnixSec: time.Now().Unix(),
},
)
// Sign the PayerBandwidthAllocation_Data with the "Satellite" Private Key
s, err := cryptopasta.Sign(data, satelliteKeyEcdsa)
if err != nil {
return nil, errs.New("Failed to sign PayerBandwidthAllocation_Data with satellite Private Key: %+v", err)
}
// Combine Signature and Data for PayerBandwidthAllocation
return &pb.PayerBandwidthAllocation{
Data: data,
Signature: s,
}, nil
}
func generateRenterBandwidthAllocation(pba *pb.PayerBandwidthAllocation, uplinkKey crypto.PrivateKey) (*pb.RenterBandwidthAllocation, error) {
// get "Uplink" Public Key
uplinkKeyEcdsa, ok := uplinkKey.(*ecdsa.PrivateKey)
if !ok {
return nil, errs.New("Uplink Private Key is not a valid *ecdsa.PrivateKey")
}
pubbytes, err := x509.MarshalPKIXPublicKey(&uplinkKeyEcdsa.PublicKey)
if err != nil {
return nil, errs.New("Could not generate byte array from Uplink Public key: %+v", err)
}
// Generate RenterBandwidthAllocation_Data
data, _ := proto.Marshal(
&pb.RenterBandwidthAllocation_Data{
PayerAllocation: pba,
PubKey: pubbytes, // TODO: Take this out. It will be kept in a database on the satellite
StorageNodeId: []byte("StorageNodeID"),
Total: int64(666),
},
)
// Sign the PayerBandwidthAllocation_Data with the "Uplink" Private Key
s, err := cryptopasta.Sign(data, uplinkKeyEcdsa)
if err != nil {
return nil, errs.New("Failed to sign RenterBandwidthAllocation_Data with uplink Private Key: %+v", err)
}
// Combine Signature and Data for RenterBandwidthAllocation
return &pb.RenterBandwidthAllocation{
Signature: s,
Data: data,
}, nil
}
Satellite bw usage v3 121 (#547) * protobuf for sending bandwidth agreements to satellite from storage nodes * Setup process for sending agreements * Add payer_id to db with bandwidth agreements for better sorting * Linter errors * Read agreements from PSDB * Try writing message to server * Cleanup * Basic functionality * Better error handelling * Fix test * setup config and server structure for receiving bandwidth agreements * Resolve linter issues * Optional commit for if we want to handle deletes all at once * add identity to Server, add logic for receiving bandwidth messsages * Bandwidth agreement DBX creation and integration with bw agreement endpoint Co-authored-by: Kishore <kishore@storj.io> Co-authored-by: Cam <cameron@storj.io> * protobuf for sending bandwidth agreements to satellite from storage nodes * Setup process for sending agreements * Add payer_id to db with bandwidth agreements for better sorting * Linter errors * Read agreements from PSDB * Try writing message to server * Cleanup * Basic functionality * Better error handelling * Fix test * setup config and server structure for receiving bandwidth agreements * Resolve linter issues * Optional commit for if we want to handle deletes all at once * add identity to Server, add logic for receiving bandwidth messsages * Bandwidth agreement DBX creation and integration with bw agreement endpoint Co-authored-by: Kishore <kishore@storj.io> Co-authored-by: Cam <cameron@storj.io> * added postgres create/read/delete test function Co-authored-by: kishore <kishore@storj.io Co-authored-by: cam <cameron@storj.io> * edit comment * removed sqlite3 driver from dbx * remove generated sqlite code, add dbx read limitoffset * remove getServerAndDB function, rename getDBPath to getPSQLInfo * WIP writing server endpoint test * code review changes
2018-11-05 15:23:54 +00:00
func (TS *TestServer) Stop() {
if err := TS.conn.Close(); err != nil {
panic(err)
}
TS.grpcs.Stop()
}