add --bootstrapper and cleanup readme

master
Mike Goelzer 6 years ago
parent 6d66498993
commit e2a5b30305
No known key found for this signature in database
GPG Key ID: EDAC46A37751AD6D

@ -13,7 +13,7 @@ make
./dht-interop -b ../util/private_key.bin.bootstrapper.Wa ./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. 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. **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 **First terminal**: Create the bootstrapper node
``` ```
cd pubsub 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. 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 **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. 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: **Fourth terminal**: Creates a Rust peer to connect to the bootstrap node and then subscribe and publish on the topic:

@ -27,7 +27,7 @@ var ho host.Host
var TopicName string = "RDEpsjSPrAZF9JCK5REt3tao" var TopicName string = "RDEpsjSPrAZF9JCK5REt3tao"
func parseArgs() (bool, string) { 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 bBootstrap bool = false
var privKeyFilePath string var privKeyFilePath string
var args []string = os.Args[1:] 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) fmt.Printf("Error: wrong number of arguments\n\n%s", usage)
os.Exit(1) os.Exit(1)
} }
if args[0] == "-b" { privKeyFilePath = args[0]
if (len(args) == 2) && (args[1] == "--bootstrapper") {
bBootstrap = true bBootstrap = true
args = args[1:]
} }
privKeyFilePath = args[0]
return bBootstrap, privKeyFilePath return bBootstrap, privKeyFilePath
} }

Loading…
Cancel
Save