From de366fdd4c20a635317d64bd2053a77186dc7d7b Mon Sep 17 00:00:00 2001 From: Mike Goelzer Date: Fri, 14 Sep 2018 11:08:26 -0700 Subject: [PATCH] Updated to use fixed ports (in PORTS file) --- PORTS | 10 ++++++++++ pubsub/js/index.js | 2 +- pubsub/pubsub-interop.go | 9 +++++---- pubsub/rust/src/main.rs | 31 +++++++++++++------------------ 4 files changed, 29 insertions(+), 23 deletions(-) create mode 100644 PORTS diff --git a/PORTS b/PORTS new file mode 100644 index 0000000..160c16e --- /dev/null +++ b/PORTS @@ -0,0 +1,10 @@ +|--------------|--------------| +|Program | Listens On | +|--------------+--------------| +|bootstrapper | :5555 | +|--------------|--------------| +|go-peer | :6000 | +|js-peer | :6001 | +|rust-peer | :6002 | +|--------------+--------------+ + diff --git a/pubsub/js/index.js b/pubsub/js/index.js index ccfe64d..e17f875 100644 --- a/pubsub/js/index.js +++ b/pubsub/js/index.js @@ -35,7 +35,7 @@ function createNode(callback) { waterfall([ (cb) => PeerInfo.create(cb), (peerInfo, cb) => { - peerInfo.multiaddrs.add('/ip4/0.0.0.0/tcp/0') + peerInfo.multiaddrs.add('/ip4/0.0.0.0/tcp/0') //TODO: 0 -> 6001 ? node = new MyBundle({ peerInfo }) diff --git a/pubsub/pubsub-interop.go b/pubsub/pubsub-interop.go index d9abde1..da9ddb0 100644 --- a/pubsub/pubsub-interop.go +++ b/pubsub/pubsub-interop.go @@ -58,9 +58,9 @@ func main() { bBootstrap, privKeyFilePath := parseArgs() fmt.Printf("Starting up in ") if bBootstrap { - fmt.Printf("bootstrapper mode") + fmt.Printf("bootstrapper mode (port 5555)") } else { - fmt.Printf("peer mode") + fmt.Printf("peer mode (port 6000)") } fmt.Printf(" with private key '%s'\n", privKeyFilePath) @@ -87,11 +87,12 @@ func main() { var host host.Host if bBootstrap { host, err = libp2p.New(ctx, - libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/9876"), + libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/5555"), libp2p.Identity(priv), ) } else { host, err = libp2p.New(ctx, + libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/6000"), libp2p.Identity(priv), ) } @@ -121,7 +122,7 @@ func main() { if !bBootstrap { var bootstrapMultiAddr ma.Multiaddr var pinfo *peerstore.PeerInfo - bootstrapMultiAddrStr := fmt.Sprintf("/ip4/%s/tcp/9876/ipfs/QmehVYruznbyDZuHBV4vEHESpDevMoAovET6aJ9oRuEzWa", bootstrapAddrIP4Str) + bootstrapMultiAddrStr := fmt.Sprintf("/ip4/%s/tcp/5555/ipfs/QmehVYruznbyDZuHBV4vEHESpDevMoAovET6aJ9oRuEzWa", bootstrapAddrIP4Str) fmt.Printf("bootstrapping to '%s'...\n", bootstrapMultiAddrStr) bootstrapMultiAddr, err := ma.NewMultiaddr(bootstrapMultiAddrStr) if err != nil { diff --git a/pubsub/rust/src/main.rs b/pubsub/rust/src/main.rs index 44cc5be..550946d 100644 --- a/pubsub/rust/src/main.rs +++ b/pubsub/rust/src/main.rs @@ -39,10 +39,8 @@ use libp2p::websocket::WsConfig; fn main() { env_logger::init(); - // Determine which address to listen to. - let listen_addr = env::args() - .nth(1) - .unwrap_or("/ip4/0.0.0.0/tcp/10050".to_owned()); + // Address to listen on + let listen_addr:String = "/ip4/0.0.0.0/tcp/6002".to_owned(); // We start by creating a `TcpConfig` that indicates that we want TCP/IP. let transport = TcpConfig::new() @@ -120,6 +118,16 @@ fn main() { Ok(()) }); + let m:String = "/ip4/127.0.0.1/tcp/5555".to_owned(); + let target: Multiaddr = m.parse().unwrap(); + println!("Dialing bootstrap peer {}", target); + swarm_controller + .dial( + target, + transport.clone().with_upgrade(floodsub_upgrade.clone()), + ) + .unwrap(); + let stdin = { let mut buffer = Vec::new(); tokio_stdin::spawn_stdin_stream_unbounded().for_each(move |msg| { @@ -129,21 +137,8 @@ fn main() { } else if buffer.is_empty() { return Ok(()); } - let msg = String::from_utf8(mem::replace(&mut buffer, Vec::new())).unwrap(); - if msg.starts_with("/dial ") { - let target: Multiaddr = msg[6..].parse().unwrap(); - println!("*Dialing {}*", target); - swarm_controller - .dial( - target, - transport.clone().with_upgrade(floodsub_upgrade.clone()), - ) - .unwrap(); - } else { - floodsub_ctl.publish(&topic, msg.into_bytes()); - } - + floodsub_ctl.publish(&topic, msg.into_bytes()); Ok(()) }) };