From e2a5b303059ce6a79843d9901f40ee48ecabe2fd Mon Sep 17 00:00:00 2001 From: Mike Goelzer Date: Thu, 18 Oct 2018 11:35:14 -0700 Subject: [PATCH] add --bootstrapper and cleanup readme --- README.md | 10 ++++++---- pubsub/pubsub-interop.go | 9 ++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 8e06b3a..f7a8c70 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ make ./dht-interop -b ../util/private_key.bin.bootstrapper.Wa ``` -`-b` means bootstrap mode. In this example, the go program is always the bootstrap node, so `-b` is always required. +`-b` means bootstrap mode. In this example, the go program is always the bootstrap node, so `-b` is always required. (***TODO***: eliminate this superfluous option) Note that the node ID of `dht-interop` is always `Qm...6aJ9oRuEzWa` because it is being read in from `../util/private_key.bin.bootstrapper.Wa` (a private key marshalled to X.509 generated by the program `util/private-key-gen`). This is to keep the peer id of the bootstrap server stable across invocations. @@ -36,17 +36,19 @@ node js-dht-test/index.js /ip4/127.0.0.1/tcp/5555/ipfs/QmehVYruznbyDZuHBV4vEHESp **Quick test**: `cd pubsub` and then run `./test/test.sh`. Requires Terminator (eg, `sudo apt-get install terminator`). The rest of this section describes how to test manually. -(**TODO**: eliminate centralized bootstrapper; any peer should be able to bootstrap from any other peer and peers should be able to start in any order) +(**TODO**: maybe eliminate centralized bootstrapper; any peer could then bootstrap from any other peer and peers could start in any order; downside is the code will be more complex in all peers) **First terminal**: Create the bootstrapper node ``` cd pubsub -./pubsub-interop -b ../util/private_key.bin.bootstrapper.Wa +./pubsub-interop ../util/private_key.bin.bootstrapper.Wa --bootstrapper ``` The bootstrapper creates a new libp2p node, subscribes to the shared topic string, spawns a go routine to emit any publishes to that topic, and then waits forever. +(Note that the node ID of `pubsub-interop` is going to be `Qm...6aJ9oRuEzWa`. Node IDs in libp2p are just public keys, and the public key `Qm...6aJ9oRuEzWa` is derived from the private key file `../util/private_key.bin.bootstrapper.Wa`. That file is just an X.509 keypair generated by the included program `util/private-key-gen`). We use fixed public/private keypairs for each node in this example to keep things simple.) + **Second terminal**: Create a go peer to connect to bootstrapper and publish on the topic ``` @@ -65,7 +67,7 @@ node index.js /ip4/127.0.0.1/tcp/5555/ipfs/QmehVYruznbyDZuHBV4vEHESpDevMoAovET6a This JS peer will accept lines of text typed on stdin, and publish them on the PubSub topic. -(**TODO**: JS peer should listen for connections on 6001 from new peers) +(Note that the JS peer generates a new identity (public/private keypair) each time, and prints its public key to stdout. This is a deficiency in the demo; to be consistent with the Go code it should accept a private key on the CLI.) **Fourth terminal**: Creates a Rust peer to connect to the bootstrap node and then subscribe and publish on the topic: diff --git a/pubsub/pubsub-interop.go b/pubsub/pubsub-interop.go index 2a060ec..eb5013a 100644 --- a/pubsub/pubsub-interop.go +++ b/pubsub/pubsub-interop.go @@ -27,7 +27,7 @@ var ho host.Host var TopicName string = "RDEpsjSPrAZF9JCK5REt3tao" func parseArgs() (bool, string) { - usage := fmt.Sprintf("Usage: %s [-b] [PRIVATE_KEY]\n\n-b is bootstrap mode (creates DHT)\nPRIVATE_KEY is the path to a private key like '../util/private_key.bin'\n", os.Args[0]) + usage := fmt.Sprintf("Usage: %s PRIVATE_KEY [--bootstrapper]\n\nPRIVATE_KEY is the path to a private key like '../util/private_key.bin'\n--bootstrapper to run in bootstrap mode (creates a DHT and listens for peers)\n", os.Args[0]) var bBootstrap bool = false var privKeyFilePath string var args []string = os.Args[1:] @@ -35,11 +35,10 @@ func parseArgs() (bool, string) { fmt.Printf("Error: wrong number of arguments\n\n%s", usage) os.Exit(1) } - if args[0] == "-b" { - bBootstrap = true - args = args[1:] - } privKeyFilePath = args[0] + if (len(args) == 2) && (args[1] == "--bootstrapper") { + bBootstrap = true + } return bBootstrap, privKeyFilePath }