mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-01-18 13:22:42 +01:00
Update javascript Tor example to reflect simplified handling of .onion addresses
This commit is contained in:
parent
8a2e742598
commit
0f0c7baec9
@ -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();
|
Loading…
Reference in New Issue
Block a user