private/testplanet: add a mock referral manager server into testplanet (#3631)

This commit is contained in:
Yingrong Zhao 2019-11-21 17:34:49 -05:00 committed by GitHub
parent 1339252cbe
commit 63e51df9a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 110 additions and 0 deletions

View File

@ -21,6 +21,7 @@ import (
"golang.org/x/sync/errgroup"
"storj.io/storj/pkg/identity"
"storj.io/storj/pkg/server"
"storj.io/storj/pkg/storj"
"storj.io/storj/private/dbutil/pgutil"
"storj.io/storj/private/testidentity"
@ -75,6 +76,8 @@ type Planet struct {
StorageNodes []*storagenode.Peer
Uplinks []*Uplink
ReferralManager *server.Server
identities *testidentity.Identities
whitelistPath string // TODO: in-memory
@ -177,6 +180,11 @@ func NewCustom(log *zap.Logger, config Config) (*Planet, error) {
return nil, errs.Combine(err, planet.Shutdown())
}
planet.ReferralManager, err = planet.newReferralManager()
if err != nil {
return nil, errs.Combine(err, planet.Shutdown())
}
planet.Satellites, err = planet.newSatellites(config.SatelliteCount)
if err != nil {
return nil, errs.Combine(err, planet.Shutdown())
@ -209,6 +217,12 @@ func (planet *Planet) Start(ctx context.Context) {
return planet.VersionControl.Run(ctx)
})
if planet.ReferralManager != nil {
planet.run.Go(func() error {
return planet.ReferralManager.Run(ctx)
})
}
for i := range planet.peers {
peer := &planet.peers[i]
peer.ctx, peer.cancel = context.WithCancel(ctx)
@ -285,6 +299,11 @@ func (planet *Planet) Shutdown() error {
for _, db := range planet.databases {
errlist.Add(db.Close())
}
if planet.ReferralManager != nil {
errlist.Add(planet.ReferralManager.Close())
}
errlist.Add(planet.VersionControl.Close())
errlist.Add(os.RemoveAll(planet.directory))

View File

@ -8,6 +8,7 @@ import (
"go.uber.org/zap"
"storj.io/storj/pkg/pb"
"storj.io/storj/satellite"
"storj.io/storj/satellite/metainfo"
"storj.io/storj/storagenode"
@ -18,6 +19,7 @@ type Reconfigure struct {
NewSatelliteDB func(log *zap.Logger, index int) (satellite.DB, error)
NewSatellitePointerDB func(log *zap.Logger, index int) (metainfo.PointerDB, error)
Satellite func(log *zap.Logger, index int, config *satellite.Config)
ReferralManagerServer func(log *zap.Logger) pb.ReferralManagerServer
NewStorageNodeDB func(index int, db storagenode.DB, log *zap.Logger) (storagenode.DB, error)
StorageNode func(index int, config *storagenode.Config)

View File

@ -0,0 +1,66 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information
package testplanet
import (
"os"
"path/filepath"
"storj.io/storj/pkg/pb"
"storj.io/storj/pkg/peertls/extensions"
"storj.io/storj/pkg/peertls/tlsopts"
"storj.io/storj/pkg/server"
)
// newReferralManager initializes a referral manager server
func (planet *Planet) newReferralManager() (*server.Server, error) {
prefix := "referralmanager"
log := planet.log.Named(prefix)
referralmanagerDir := filepath.Join(planet.directory, prefix)
if err := os.MkdirAll(referralmanagerDir, 0700); err != nil {
return nil, err
}
identity, err := planet.NewIdentity()
if err != nil {
return nil, err
}
config := server.Config{
Address: "127.0.0.1:0",
PrivateAddress: "127.0.0.1:0",
Config: tlsopts.Config{
RevocationDBURL: "bolt://" + filepath.Join(referralmanagerDir, "revocation.db"),
UsePeerCAWhitelist: true,
PeerIDVersions: "*",
Extensions: extensions.Config{
Revocation: false,
WhitelistSignedLeaf: false,
},
},
}
var endpoints pb.ReferralManagerServer
// only create a referral manager server if testplanet was reconfigured with a custom referral manager endpoint
if planet.config.Reconfigure.ReferralManagerServer != nil {
endpoints = planet.config.Reconfigure.ReferralManagerServer(log)
} else {
return nil, nil
}
tlsOptions, err := tlsopts.NewOptions(identity, config.Config, nil)
if err != nil {
return nil, err
}
referralmanager, err := server.New(log, tlsOptions, config.Address, config.PrivateAddress, nil)
if err != nil {
return nil, err
}
pb.DRPCRegisterReferralManager(referralmanager.DRPC(), endpoints)
log.Debug("id=" + identity.ID.String() + " addr=" + referralmanager.Addr().String())
return referralmanager, nil
}

View File

@ -382,6 +382,13 @@ func (planet *Planet) newSatellites(count int) ([]*SatelliteSystem, error) {
ChoreInterval: defaultInterval,
},
}
if planet.ReferralManager != nil {
config.Referrals.ReferralManagerURL = storj.NodeURL{
ID: planet.ReferralManager.Identity().ID,
Address: planet.ReferralManager.Addr().String(),
}
}
if planet.config.Reconfigure.Satellite != nil {
planet.config.Reconfigure.Satellite(log, i, &config)
}

View File

@ -29,6 +29,7 @@ import (
"storj.io/storj/satellite/overlay"
"storj.io/storj/satellite/payments/paymentsconfig"
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/referrals"
"storj.io/storj/satellite/repair/checker"
"storj.io/storj/satellite/repair/irreparable"
"storj.io/storj/satellite/repair/queue"
@ -111,6 +112,8 @@ type Config struct {
Payments paymentsconfig.Config
Referrals referrals.Config
Console consoleweb.Config
Marketing marketingweb.Config

View File

@ -0,0 +1,11 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package referrals
import "storj.io/storj/pkg/storj"
// Config for referrals service.
type Config struct {
ReferralManagerURL storj.NodeURL
}

View File

@ -370,6 +370,8 @@ identity.key-path: /root/.local/share/storj/identity/satellite/identity.key
# price in cents user should pay for storing each TB per hour
# payments.tbh-price: 0
# referrals.referral-manager-url: ""
# time limit for downloading pieces from a node for repair
# repairer.download-timeout: 5m0s