3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-15 03:35:52 +00:00

Tweak HS integration again to avoid performance regression.

This commit is contained in:
Mike Hearn 2015-10-08 15:56:44 +02:00
parent e104bfbb7e
commit fabbb0a9ac
3 changed files with 11 additions and 15 deletions

View File

@ -96,15 +96,17 @@ public class PeerAddress extends ChildMessage {
* InetAddress or a String hostname. If you want to connect to a .onion, set the hostname to the .onion address.
*/
public PeerAddress(InetSocketAddress addr) {
if (addr.getHostName() == null || !addr.getHostName().toLowerCase().endsWith(".onion")) {
this.addr = addr.getHostName() == null ? addr.getAddress() : new InetSocketAddress(addr.getHostName(), addr.getPort()).getAddress();
} else {
this.hostname = addr.getHostName();
}
this.port = addr.getPort();
this(addr.getAddress(), addr.getPort());
}
/**
* Constructs a peer address from a stringified hostname+port. Use this if you want to connect to a Tor .onion address.
*/
public PeerAddress(String hostname, int port) {
this.hostname = hostname;
this.port = port;
this.protocolVersion = NetworkParameters.PROTOCOL_VERSION;
this.services = BigInteger.ZERO;
length = MESSAGE_SIZE;
}
public static PeerAddress localhost(NetworkParameters params) {

View File

@ -120,7 +120,7 @@ public class HttpDiscovery implements PeerDiscovery {
InetSocketAddress[] results = new InetSocketAddress[seeds.getSeedCount()];
int i = 0;
for (PeerSeedProtos.PeerSeedData data : seeds.getSeedList())
results[i++] = InetSocketAddress.createUnresolved(data.getIpAddress(), data.getPort());
results[i++] = new InetSocketAddress(data.getIpAddress(), data.getPort());
return results;
}

View File

@ -7,14 +7,8 @@ var context = new bcj.core.Context(params);
bcj.utils.BriefLogFormatter.init();
var PeerAddress = Java.type("org.bitcoinj.core.PeerAddress");
var InetSocketAddress = Java.type("java.net.InetSocketAddress");
// 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);
pg.addAddress(new PeerAddress(OnionAddress));
pg.addAddress(new PeerAddress("nkf5e6b7pl4jfd4a.onion", params.port));
pg.start();
pg.waitForPeers(1).get();