Skip to content

Commit

Permalink
Merge pull request #312 from zhangwm404/main
Browse files Browse the repository at this point in the history
fix makefile and refactoring cmd/options
  • Loading branch information
huo-ju authored Jul 6, 2023
2 parents 7dd400c + 22a1cb5 commit d148dc1
Show file tree
Hide file tree
Showing 8 changed files with 301 additions and 133 deletions.
50 changes: 41 additions & 9 deletions cmd/bootstrapnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"os"
"os/signal"
"strings"
"syscall"
"time"

Expand All @@ -19,18 +20,43 @@ import (
"github.com/rumsystem/quorum/pkg/chainapi/api"
localcrypto "github.com/rumsystem/quorum/pkg/crypto"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var (
bootstrapNodeFlag = cli.BootstrapNodeFlag{ProtocolID: "/quorum/1.0.0"}
bootstrapNode *p2p.Node
bootstrapSignalch chan os.Signal
bootstrapViper *viper.Viper
)

var bootstrapNodeCmd = &cobra.Command{
Use: "bootstrapnode",
Short: "Run bootstrapnode",
Run: func(cmd *cobra.Command, args []string) {
if err := bootstrapViper.Unmarshal(&bootstrapNodeFlag); err != nil {
logger.Fatalf("viper unmarshal failed: %s", err)
}

if len(bootstrapNodeFlag.ListenAddresses) == 0 {
if len(bootstrapViper.GetStringSlice("listen")) != 0 {
addrlist, err := cli.ParseAddrList(strings.Join(bootstrapViper.GetStringSlice("listen"), ","))
if err != nil {
logger.Fatalf("parse listen addr list failed: %s", err)
}
bootstrapNodeFlag.ListenAddresses = *addrlist
}
}
if len(bootstrapNodeFlag.BootstrapPeers) == 0 {
if len(bootstrapViper.GetStringSlice("peer")) != 0 {
addrlist, err := cli.ParseAddrList(strings.Join(bootstrapViper.GetStringSlice("peer"), ","))
if err != nil {
logger.Fatalf("parse bootstrap peer addr list failed: %s", err)
}
bootstrapNodeFlag.BootstrapPeers = *addrlist
}
}

if bootstrapNodeFlag.KeyStorePwd == "" {
bootstrapNodeFlag.KeyStorePwd = os.Getenv("RUM_KSPASSWD")
}
Expand All @@ -39,21 +65,27 @@ var bootstrapNodeCmd = &cobra.Command{
}

func init() {
bootstrapViper = options.NewViper()

rootCmd.AddCommand(bootstrapNodeCmd)

flags := bootstrapNodeCmd.Flags()
flags.SortFlags = false

flags.StringVar(&bootstrapNodeFlag.KeyStoreDir, "keystoredir", "./keystore/", "keystore dir")
flags.StringVar(&bootstrapNodeFlag.KeyStoreName, "keystorename", "default", "keystore name")
flags.StringVar(&bootstrapNodeFlag.KeyStorePwd, "keystorepass", "", "keystore password")
flags.StringVar(&bootstrapNodeFlag.ConfigDir, "configdir", "./config/", "config and keys dir")
flags.StringVar(&bootstrapNodeFlag.DataDir, "datadir", "./data/", "config dir")
flags.Var(&bootstrapNodeFlag.ListenAddresses, "listen", "Adds a multiaddress to the listen list, e.g.: --listen /ip4/127.0.0.1/tcp/4215 --listen /ip/127.0.0.1/tcp/5215/ws")
flags.String("keystoredir", "./keystore/", "keystore dir")
flags.String("keystorename", "default", "keystore name")
flags.String("keystorepass", "", "keystore password")
flags.String("configdir", "./config/", "config and keys dir")
flags.String("datadir", "./data/", "data dir")
flags.StringSlice("listen", nil, "Adds a multiaddress to the listen list, e.g.: --listen /ip4/127.0.0.1/tcp/4215 --listen /ip/127.0.0.1/tcp/5215/ws")

flags.StringVar(&bootstrapNodeFlag.APIHost, "apihost", "127.0.0.1", "Domain or public ip addresses for api server")
flags.UintVar(&bootstrapNodeFlag.APIPort, "apiport", 4216, "api server listen port")
flags.BoolVar(&bootstrapNodeFlag.EnableRelay, "autorelay", true, "enable relay")
flags.String("apihost", "127.0.0.1", "Domain or public ip addresses for api server")
flags.Int("apiport", 4216, "api server listen port")
flags.Bool("autorelay", true, "enable relay")

if err := bootstrapViper.BindPFlags(flags); err != nil {
logger.Fatalf("viper bind flags failed: %s", err)
}
}

func runBootstrapNode(config cli.BootstrapNodeFlag) {
Expand Down
62 changes: 46 additions & 16 deletions cmd/fullnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,43 @@ import (
appapi "github.com/rumsystem/quorum/pkg/chainapi/appapi"
localcrypto "github.com/rumsystem/quorum/pkg/crypto"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var (
fnodeFlag = cli.FullNodeFlag{ProtocolID: "/quorum/1.0.0"}
fullNode *p2p.Node
fullNodeViper *viper.Viper
fullNodeSignalch chan os.Signal
)

var fullnodeCmd = &cobra.Command{
Use: "fullnode",
Short: "Run fullnode",
Run: func(cmd *cobra.Command, args []string) {
if err := fullNodeViper.Unmarshal(&fnodeFlag); err != nil {
logger.Fatalf("viper unmarshal failed: %s", err)
}

if len(fnodeFlag.ListenAddresses) == 0 {
if len(fullNodeViper.GetStringSlice("listen")) != 0 {
addrlist, err := cli.ParseAddrList(strings.Join(fullNodeViper.GetStringSlice("listen"), ","))
if err != nil {
logger.Fatalf("parse listen addr list failed: %s", err)
}
fnodeFlag.ListenAddresses = *addrlist
}
}
if len(fnodeFlag.BootstrapPeers) == 0 {
if len(fullNodeViper.GetStringSlice("peer")) != 0 {
addrlist, err := cli.ParseAddrList(strings.Join(fullNodeViper.GetStringSlice("peer"), ","))
if err != nil {
logger.Fatalf("parse bootstrap peer addr list failed: %s", err)
}
fnodeFlag.BootstrapPeers = *addrlist
}
}

if fnodeFlag.KeyStorePwd == "" {
fnodeFlag.KeyStorePwd = os.Getenv("RUM_KSPASSWD")
}
Expand All @@ -54,22 +79,27 @@ func init() {
flags := fullnodeCmd.Flags()
flags.SortFlags = false

flags.StringVar(&fnodeFlag.PeerName, "peername", "peer", "peername")
flags.StringVar(&fnodeFlag.ConfigDir, "configdir", "./config/", "config and keys dir")
flags.StringVar(&fnodeFlag.DataDir, "datadir", "./data/", "data dir")
flags.StringVar(&fnodeFlag.KeyStoreDir, "keystoredir", "./keystore/", "keystore dir")
flags.StringVar(&fnodeFlag.KeyStoreName, "keystorename", "default", "keystore name")
flags.StringVar(&fnodeFlag.KeyStorePwd, "keystorepass", "", "keystore password")
flags.Var(&fnodeFlag.ListenAddresses, "listen", "Adds a multiaddress to the listen list, e.g.: --listen /ip4/127.0.0.1/tcp/4215 --listen /ip/127.0.0.1/tcp/5215/ws")
flags.StringVar(&fnodeFlag.APIHost, "apihost", "", "Domain or public ip addresses for api server")
flags.UintVar(&fnodeFlag.APIPort, "apiport", 5215, "api server listen port")
flags.StringVar(&fnodeFlag.CertDir, "certdir", "certs", "ssl certificate directory")
flags.StringVar(&fnodeFlag.ZeroAccessKey, "zerosslaccesskey", "", "zerossl access key, get from: https://app.zerossl.com/developer")
flags.Var(&fnodeFlag.BootstrapPeers, "peer", "bootstrap peer address")
flags.StringVar(&fnodeFlag.SkipPeers, "skippeers", "", "peer id lists, will be skipped in the pubsub connection")
flags.StringVar(&fnodeFlag.JsonTracer, "jsontracer", "", "output tracer data to a json file")
flags.BoolVar(&fnodeFlag.AutoAck, "autoack", true, "auto ack the transactions in pubqueue")
flags.BoolVar(&fnodeFlag.EnableRelay, "autorelay", true, "enable relay")
flags.String("peername", "peer", "peername")
flags.String("configdir", "./config/", "config and keys dir")
flags.String("datadir", "./data/", "data dir")
flags.String("keystoredir", "./keystore/", "keystore dir")
flags.String("keystorename", "default", "keystore name")
flags.String("keystorepass", "", "keystore password")
flags.StringSlice("listen", nil, "Adds a multiaddress to the listen list, e.g.: --listen /ip4/127.0.0.1/tcp/4215 --listen /ip4/127.0.0.1/tcp/5215/ws")
flags.String("apihost", "localhost", "Domain or public ip addresses for api server")
flags.Uint("apiport", 5215, "api server listen port")
flags.String("certdir", "certs", "ssl certificate directory")
flags.String("zerosslaccesskey", "", "zerossl access key, get from: https://app.zerossl.com/developer")
flags.StringSlice("peer", nil, "bootstrap peer address")
flags.String("skippeers", "", "peer id lists, will be skipped in the pubsub connection")
flags.String("jsontracer", "", "output tracer data to a json file")
flags.Bool("autoack", true, "auto ack the transactions in pubqueue")
flags.Bool("autorelay", true, "enable relay")

fullNodeViper = options.NewViper()
if err := fullNodeViper.BindPFlags(flags); err != nil {
logger.Fatalf("viper bind flags failed: %s", err)
}
}

func runFullnode(config cli.FullNodeFlag) {
Expand Down
30 changes: 21 additions & 9 deletions cmd/lightnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ import (
nodesdkapi "github.com/rumsystem/quorum/pkg/nodesdk/api"
nodesdkctx "github.com/rumsystem/quorum/pkg/nodesdk/nodesdkctx"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var (
lnodeFlag = cli.LightnodeFlag{}
lnodeViper *viper.Viper
lightnodeSignalch chan os.Signal
)

Expand All @@ -28,6 +30,10 @@ var lightnodeCmd = &cobra.Command{
Use: "lightnode",
Short: "Run lightnode",
Run: func(cmd *cobra.Command, args []string) {
if err := lnodeViper.Unmarshal(&lnodeFlag); err != nil {
logger.Fatalf("viper unmarshal failed: %s", err)
}

if lnodeFlag.KeyStorePwd == "" {
lnodeFlag.KeyStorePwd = os.Getenv("RUM_KSPASSWD")
}
Expand All @@ -37,20 +43,26 @@ var lightnodeCmd = &cobra.Command{
}

func init() {
lnodeViper = options.NewViper()

rootCmd.AddCommand(lightnodeCmd)

flags := lightnodeCmd.Flags()
flags.SortFlags = false

flags.StringVar(&lnodeFlag.PeerName, "peername", "peer", "peername")
flags.StringVar(&lnodeFlag.ConfigDir, "configdir", "./config/", "config and keys dir")
flags.StringVar(&lnodeFlag.DataDir, "datadir", "./data/", "config dir")
flags.StringVar(&lnodeFlag.KeyStoreDir, "keystoredir", "./keystore/", "keystore dir")
flags.StringVar(&lnodeFlag.KeyStoreName, "keystorename", "defaultkeystore", "keystore name")
flags.StringVar(&lnodeFlag.KeyStorePwd, "keystorepass", "", "keystore password")
flags.StringVar(&lnodeFlag.APIHost, "apihost", "", "Domain or public ip addresses for api server")
flags.UintVar(&lnodeFlag.APIPort, "apiport", 5215, "api server listen port")
flags.StringVar(&lnodeFlag.JsonTracer, "jsontracer", "", "output tracer data to a json file")
flags.String("peername", "peer", "peername")
flags.String("configdir", "./config/", "config and keys dir")
flags.String("datadir", "./data/", "config dir")
flags.String("keystoredir", "./keystore/", "keystore dir")
flags.String("keystorename", "defaultkeystore", "keystore name")
flags.String("keystorepass", "", "keystore password")
flags.String("apihost", "", "Domain or public ip addresses for api server")
flags.Int("apiport", 5215, "api server listen port")
flags.String("jsontracer", "", "output tracer data to a json file")

if err := lnodeViper.BindPFlags(flags); err != nil {
logger.Fatalf("viper bind flags failed: %s", err)
}
}

func runLightnode(config cli.LightnodeFlag) {
Expand Down
60 changes: 46 additions & 14 deletions cmd/producernode.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"os/signal"
"strings"
"syscall"
"time"

Expand All @@ -24,18 +25,43 @@ import (
"github.com/rumsystem/quorum/pkg/chainapi/api"
localcrypto "github.com/rumsystem/quorum/pkg/crypto"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var (
producerNodeFlag = cli.ProducerNodeFlag{ProtocolID: "/quorum/1.0.0"}
producerNode *p2p.Node
producerViper *viper.Viper
producerSignalCh chan os.Signal
)

var producerNodeCmd = &cobra.Command{
Use: "producernode",
Short: "Run producernode",
Run: func(cmd *cobra.Command, args []string) {
if err := producerViper.Unmarshal(&producerNodeFlag); err != nil {
logger.Fatalf("viper unmarshal failed: %s", err)
}

if len(producerNodeFlag.ListenAddresses) == 0 {
if len(producerViper.GetStringSlice("listen")) != 0 {
addrlist, err := cli.ParseAddrList(strings.Join(producerViper.GetStringSlice("listen"), ","))
if err != nil {
logger.Fatalf("parse listen addr list failed: %s", err)
}
producerNodeFlag.ListenAddresses = *addrlist
}
}
if len(producerNodeFlag.BootstrapPeers) == 0 {
if len(producerViper.GetStringSlice("peer")) != 0 {
addrlist, err := cli.ParseAddrList(strings.Join(producerViper.GetStringSlice("peer"), ","))
if err != nil {
logger.Fatalf("parse bootstrap peer addr list failed: %s", err)
}
producerNodeFlag.BootstrapPeers = *addrlist
}
}

if producerNodeFlag.KeyStorePwd == "" {
producerNodeFlag.KeyStorePwd = os.Getenv("RUM_KSPASSWD")
}
Expand All @@ -44,24 +70,30 @@ var producerNodeCmd = &cobra.Command{
}

func init() {
producerViper = options.NewViper()

rootCmd.AddCommand(producerNodeCmd)
flags := producerNodeCmd.Flags()
flags.SortFlags = false

flags.StringVar(&producerNodeFlag.PeerName, "peername", "peer", "peername")
flags.StringVar(&producerNodeFlag.ConfigDir, "configdir", "./config/", "config and keys dir")
flags.StringVar(&producerNodeFlag.DataDir, "datadir", "./data/", "config dir")
flags.StringVar(&producerNodeFlag.KeyStoreDir, "keystoredir", "./keystore/", "keystore dir")
flags.StringVar(&producerNodeFlag.KeyStoreName, "keystorename", "default", "keystore name")
flags.StringVar(&producerNodeFlag.KeyStorePwd, "keystorepass", "", "keystore password")
flags.Var(&producerNodeFlag.ListenAddresses, "listen", "Adds a multiaddress to the listen list, e.g.: --listen /ip4/127.0.0.1/tcp/4215 --listen /ip/127.0.0.1/tcp/5215/ws")
flags.StringVar(&producerNodeFlag.APIHost, "apihost", "", "Domain or public ip addresses for api server")
flags.UintVar(&producerNodeFlag.APIPort, "apiport", 5215, "api server listen port")
flags.StringVar(&producerNodeFlag.CertDir, "certdir", "certs", "ssl certificate directory")
flags.StringVar(&producerNodeFlag.ZeroAccessKey, "zerosslaccesskey", "", "zerossl access key, get from: https://app.zerossl.com/developer")
flags.Var(&producerNodeFlag.BootstrapPeers, "peer", "bootstrap peer address")
flags.StringVar(&producerNodeFlag.JsonTracer, "jsontracer", "", "output tracer data to a json file")
flags.BoolVar(&producerNodeFlag.IsDebug, "debug", false, "show debug log")
flags.String("peername", "peer", "peername")
flags.String("configdir", "./config/", "config and keys dir")
flags.String("datadir", "./data/", "config dir")
flags.String("keystoredir", "./keystore/", "keystore dir")
flags.String("keystorename", "default", "keystore name")
flags.String("keystorepass", "", "keystore password")
flags.StringSlice("listen", nil, "Adds a multiaddress to the listen list, e.g.: --listen /ip4/127.0.0.1/tcp/4215 --listen /ip/127.0.0.1/tcp/5215/ws")
flags.String("apihost", "localhost", "Domain or public ip addresses for api server")
flags.Int("apiport", 5215, "api server listen port")
flags.String("certdir", "certs", "ssl certificate directory")
flags.String("zerosslaccesskey", "", "zerossl access key, get from: https://app.zerossl.com/developer")
flags.StringSlice("peer", nil, "bootstrap peer address")
flags.String("jsontracer", "", "output tracer data to a json file")
flags.Bool("debug", false, "show debug log")

if err := producerViper.BindPFlags(flags); err != nil {
logger.Fatalf("viper bind flags failed: %s", err)
}
}

func runProducerNode(config cli.ProducerNodeFlag) {
Expand Down
Loading

0 comments on commit d148dc1

Please sign in to comment.