From 0f0c7baec9d6e0a874a279c80c599b93e47ca32a Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 24 Jul 2015 11:36:54 -0400 Subject: [PATCH] Update javascript Tor example to reflect simplified handling of .onion addresses --- examples/src/main/javascript/tor.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/examples/src/main/javascript/tor.js b/examples/src/main/javascript/tor.js index dba182e09..7e906527f 100644 --- a/examples/src/main/javascript/tor.js +++ b/examples/src/main/javascript/tor.js @@ -6,19 +6,15 @@ var params = bcj.params.MainNetParams.get(); var context = new bcj.core.Context(params); bcj.utils.BriefLogFormatter.init(); -var InetAddress = Java.type("java.net.InetAddress"); +var PeerAddress = Java.type("org.bitcoinj.core.PeerAddress"); var InetSocketAddress = Java.type("java.net.InetSocketAddress"); -// Hack around the fact that PeerAddress assumes nodes have IP addresses. Simple enough for now. -var OnionAddress = Java.extend(Java.type("org.bitcoinj.core.PeerAddress"), { - toSocketAddress: function() { - return InetSocketAddress.createUnresolved("hhiv5pnxenvbf4am.onion", params.port); - } -}); +// The PeerAddress class can now handle InetSocketAddresses with hostnames if they are .onion. +var OnionAddress = InetSocketAddress.createUnresolved("hhiv5pnxenvbf4am.onion", params.port); var pg = bcj.core.PeerGroup.newWithTor(context, null, new com.subgraph.orchid.TorClient(), false); -// c'tor is bogus here: the passed in InetAddress will be ignored. -pg.addAddress(new OnionAddress(InetAddress.localHost, params.port)); + +pg.addAddress(new PeerAddress(OnionAddress)); pg.start(); pg.waitForPeers(1).get(); @@ -29,5 +25,4 @@ for each (var peer in pg.connectedPeers) { peer.ping().get() } - pg.stop(); \ No newline at end of file