diff --git a/p2p/simulations/cmd/p2psim/main.go b/p2p/simulations/cmd/p2psim/main.go index bf00aa768c..012611c5ad 100644 --- a/p2p/simulations/cmd/p2psim/main.go +++ b/p2p/simulations/cmd/p2psim/main.go @@ -33,7 +33,9 @@ import ( "strings" "text/tabwriter" + "github.com/ethereum/go-ethereum/crypto" "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/adapters" "github.com/ethereum/go-ethereum/rpc" @@ -77,9 +79,14 @@ func main() { Action: createNetwork, Flags: []cli.Flag{ cli.StringFlag{ - Name: "config", - Value: "{}", - Usage: "JSON encoded network config", + Name: "id", + Value: "", + Usage: "network ID", + }, + cli.StringFlag{ + Name: "default-service", + Value: "", + Usage: "default service", }, }, }, @@ -141,9 +148,19 @@ func main() { Action: createNode, Flags: []cli.Flag{ cli.StringFlag{ - Name: "config", - Value: "{}", - Usage: "JSON encoded node config", + Name: "name", + Value: "", + 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 { return cli.ShowCommandHelp(ctx, ctx.Command.Name) } - config := &simulations.NetworkConfig{} - if err := json.Unmarshal([]byte(ctx.String("config")), config); err != nil { - return err + config := &simulations.NetworkConfig{ + ID: ctx.String("id"), + DefaultService: ctx.String("default-service"), } network, err := client.CreateNetwork(config) if err != nil { @@ -326,9 +343,19 @@ func createNode(ctx *cli.Context) error { if len(ctx.Args()) != 0 { return cli.ShowCommandHelp(ctx, ctx.Command.Name) } - config := &adapters.NodeConfig{} - if err := json.Unmarshal([]byte(ctx.String("config")), config); err != nil { - return err + config := &adapters.NodeConfig{ + Name: ctx.String("name"), + } + 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) if err != nil { diff --git a/p2p/simulations/examples/p2psim.sh b/p2p/simulations/examples/p2psim.sh index b67a91ce0c..468d66d4e3 100755 --- a/p2p/simulations/examples/p2psim.sh +++ b/p2p/simulations/examples/p2psim.sh @@ -10,12 +10,12 @@ main() { fi 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" - export P2PSIM_NETWORK="example" 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)" done