storj/cmd/captplanet/run.go
Bryan White 5d20cf8829
Node Identity (#193)
* peertls: don't log errors for double close

understood that this part of the code is undergoing heavy change
right now, but just want to make sure this fix gets incorporated
somewhere

* git cleanup: node-id stuff

* cleanup

* rename identity_util.go

* wip `CertificateAuthority` refactor

* refactoring

* gitignore update

* wip

* Merge remote-tracking branch 'storj/doubleclose' into node-id3

* storj/doubleclose:
  peertls: don't log errors for double close

* add peertls tests & gomports

* wip:

+ refactor
+ style changes
+ cleanup
+ [wip] add version to CA and identity configs
+ [wip] heavy client setup

* refactor

* wip:

+ refactor
+ style changes
+ add `CAConfig.Load`
+ add `CAConfig.Save`

* wip:

+ add `LoadOrCreate` and `Create` to CA and Identity configs
+ add overwrite to CA and identity configs
+ heavy client setup
+ refactor
+ style changes
+ cleanup

* wip

* fixing things

* fixing things

* wip hc setup

* hc setup:

+ refactor
+ bugfixing

* improvements based on reveiw feedback

* goimports

* improvements:

+ responding to review feedback
+ refactor

* feedback-based improvements

* feedback-based improvements

* feedback-based improvements

* feedback-based improvements

* feedback-based improvements

* feedback-based improvements

* cleanup

* refactoring CA and Identity structs

* Merge branch 'master' into node-id3

* move version field to setup config structs for CA and identity

* fix typo

* responding to revieiw feedback

* responding to revieiw feedback

* responding to revieiw feedback

* responding to revieiw feedback

* responding to revieiw feedback

* responding to revieiw feedback

* Merge branch 'master' into node-id3

* fix gateway setup finally

* go imports

* fix `FullCertificateAuthority.GenerateIdentity`

* cleanup overlay tests

* bugfixing

* update ca/identity setup

* go imports

* fix peertls test copy/paste fail

* responding to review feedback

* setup tweaking

* update farmer setup
2018-08-13 10:39:45 +02:00

106 lines
2.3 KiB
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"fmt"
"github.com/spf13/cobra"
"storj.io/storj/pkg/cfgstruct"
"storj.io/storj/pkg/kademlia"
"storj.io/storj/pkg/miniogw"
"storj.io/storj/pkg/overlay"
"storj.io/storj/pkg/piecestore/psservice"
"storj.io/storj/pkg/pointerdb"
"storj.io/storj/pkg/process"
"storj.io/storj/pkg/provider"
proto "storj.io/storj/protos/overlay"
)
const (
farmerCount = 50
)
type HeavyClient struct {
Identity provider.IdentityConfig
Kademlia kademlia.Config
PointerDB pointerdb.Config
Overlay overlay.Config
}
type Farmer struct {
Identity provider.IdentityConfig
Kademlia kademlia.Config
Storage psservice.Config
}
var (
runCmd = &cobra.Command{
Use: "run",
Short: "Run all providers",
RunE: cmdRun,
}
runCfg struct {
HeavyClient HeavyClient
Farmers [farmerCount]Farmer
Gateway miniogw.Config
}
)
func init() {
rootCmd.AddCommand(runCmd)
cfgstruct.Bind(runCmd.Flags(), &runCfg, cfgstruct.ConfDir(defaultConfDir))
}
func cmdRun(cmd *cobra.Command, args []string) (err error) {
ctx := process.Ctx(cmd)
defer mon.Task()(&ctx)(&err)
errch := make(chan error, len(runCfg.Farmers)+2)
// start heavy client
go func() {
_, _ = fmt.Printf("starting heavy client on %s\n",
runCfg.HeavyClient.Identity.Address)
errch <- runCfg.HeavyClient.Identity.Run(ctx,
runCfg.HeavyClient.Kademlia,
runCfg.HeavyClient.PointerDB,
runCfg.HeavyClient.Overlay)
}()
// start the farmers
for i := 0; i < len(runCfg.Farmers); i++ {
go func(i int) {
_, _ = fmt.Printf("starting farmer %d grpc on %s, kad on %s\n", i,
runCfg.Farmers[i].Identity.Address,
runCfg.Farmers[i].Kademlia.TODOListenAddr)
errch <- runCfg.Farmers[i].Identity.Run(ctx,
runCfg.Farmers[i].Kademlia,
runCfg.Farmers[i].Storage)
}(i)
identity, err := runCfg.Farmers[i].Identity.Load()
if err != nil {
return err
}
miniogw.GlobalMockOverlay.Nodes[identity.ID.String()] = &proto.Node{
Id: identity.ID.String(),
Address: &proto.NodeAddress{
Transport: proto.NodeTransport_TCP,
Address: runCfg.Farmers[i].Identity.Address,
},
}
}
// start s3 gateway
go func() {
_, _ = fmt.Printf("starting minio gateway on %s\n",
runCfg.Gateway.IdentityConfig.Address)
errch <- runCfg.Gateway.Run(ctx)
}()
return <-errch
}