mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
p2psim: Use explicit flags rather than JSON config
Signed-off-by: Lewis Marshall <lewis@lmars.net>
This commit is contained in:
parent
8e17ee44f0
commit
9627a75ce0
2 changed files with 42 additions and 15 deletions
|
|
@ -33,7 +33,9 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
|
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||||
"github.com/ethereum/go-ethereum/p2p/simulations"
|
"github.com/ethereum/go-ethereum/p2p/simulations"
|
||||||
"github.com/ethereum/go-ethereum/p2p/simulations/adapters"
|
"github.com/ethereum/go-ethereum/p2p/simulations/adapters"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
|
|
@ -77,9 +79,14 @@ func main() {
|
||||||
Action: createNetwork,
|
Action: createNetwork,
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "config",
|
Name: "id",
|
||||||
Value: "{}",
|
Value: "",
|
||||||
Usage: "JSON encoded network config",
|
Usage: "network ID",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "default-service",
|
||||||
|
Value: "",
|
||||||
|
Usage: "default service",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -141,9 +148,19 @@ func main() {
|
||||||
Action: createNode,
|
Action: createNode,
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "config",
|
Name: "name",
|
||||||
Value: "{}",
|
Value: "",
|
||||||
Usage: "JSON encoded node config",
|
Usage: "node name",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "services",
|
||||||
|
Value: "",
|
||||||
|
Usage: "node services (comma separated)",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "key",
|
||||||
|
Value: "",
|
||||||
|
Usage: "node private key (hex encoded)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -216,9 +233,9 @@ func createNetwork(ctx *cli.Context) error {
|
||||||
if len(ctx.Args()) != 0 {
|
if len(ctx.Args()) != 0 {
|
||||||
return cli.ShowCommandHelp(ctx, ctx.Command.Name)
|
return cli.ShowCommandHelp(ctx, ctx.Command.Name)
|
||||||
}
|
}
|
||||||
config := &simulations.NetworkConfig{}
|
config := &simulations.NetworkConfig{
|
||||||
if err := json.Unmarshal([]byte(ctx.String("config")), config); err != nil {
|
ID: ctx.String("id"),
|
||||||
return err
|
DefaultService: ctx.String("default-service"),
|
||||||
}
|
}
|
||||||
network, err := client.CreateNetwork(config)
|
network, err := client.CreateNetwork(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -326,9 +343,19 @@ func createNode(ctx *cli.Context) error {
|
||||||
if len(ctx.Args()) != 0 {
|
if len(ctx.Args()) != 0 {
|
||||||
return cli.ShowCommandHelp(ctx, ctx.Command.Name)
|
return cli.ShowCommandHelp(ctx, ctx.Command.Name)
|
||||||
}
|
}
|
||||||
config := &adapters.NodeConfig{}
|
config := &adapters.NodeConfig{
|
||||||
if err := json.Unmarshal([]byte(ctx.String("config")), config); err != nil {
|
Name: ctx.String("name"),
|
||||||
return err
|
}
|
||||||
|
if key := ctx.String("key"); key != "" {
|
||||||
|
privKey, err := crypto.HexToECDSA(key)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
config.ID = discover.PubkeyID(&privKey.PublicKey)
|
||||||
|
config.PrivateKey = privKey
|
||||||
|
}
|
||||||
|
if services := ctx.String("services"); services != "" {
|
||||||
|
config.Services = strings.Split(services, ",")
|
||||||
}
|
}
|
||||||
node, err := client.CreateNode(networkID, config)
|
node, err := client.CreateNode(networkID, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,12 @@ main() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
info "creating the example network"
|
info "creating the example network"
|
||||||
p2psim network create --config '{"id": "example", "default_service": "ping-pong"}'
|
export P2PSIM_NETWORK="example"
|
||||||
|
p2psim network create --id "${P2PSIM_NETWORK}"
|
||||||
|
|
||||||
info "creating 10 nodes"
|
info "creating 10 nodes"
|
||||||
export P2PSIM_NETWORK="example"
|
|
||||||
for i in $(seq 1 10); do
|
for i in $(seq 1 10); do
|
||||||
p2psim node create
|
p2psim node create --name "$(node_name $i)" --services "ping-pong"
|
||||||
p2psim node start "$(node_name $i)"
|
p2psim node start "$(node_name $i)"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue