mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-15 11:45:51 +00:00
Tweak HS integration again to avoid performance regression.
This commit is contained in:
parent
e104bfbb7e
commit
fabbb0a9ac
@ -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.
|
* InetAddress or a String hostname. If you want to connect to a .onion, set the hostname to the .onion address.
|
||||||
*/
|
*/
|
||||||
public PeerAddress(InetSocketAddress addr) {
|
public PeerAddress(InetSocketAddress addr) {
|
||||||
if (addr.getHostName() == null || !addr.getHostName().toLowerCase().endsWith(".onion")) {
|
this(addr.getAddress(), addr.getPort());
|
||||||
this.addr = addr.getHostName() == null ? addr.getAddress() : new InetSocketAddress(addr.getHostName(), addr.getPort()).getAddress();
|
}
|
||||||
} else {
|
|
||||||
this.hostname = addr.getHostName();
|
/**
|
||||||
}
|
* Constructs a peer address from a stringified hostname+port. Use this if you want to connect to a Tor .onion address.
|
||||||
this.port = addr.getPort();
|
*/
|
||||||
|
public PeerAddress(String hostname, int port) {
|
||||||
|
this.hostname = hostname;
|
||||||
|
this.port = port;
|
||||||
this.protocolVersion = NetworkParameters.PROTOCOL_VERSION;
|
this.protocolVersion = NetworkParameters.PROTOCOL_VERSION;
|
||||||
this.services = BigInteger.ZERO;
|
this.services = BigInteger.ZERO;
|
||||||
length = MESSAGE_SIZE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PeerAddress localhost(NetworkParameters params) {
|
public static PeerAddress localhost(NetworkParameters params) {
|
||||||
|
@ -120,7 +120,7 @@ public class HttpDiscovery implements PeerDiscovery {
|
|||||||
InetSocketAddress[] results = new InetSocketAddress[seeds.getSeedCount()];
|
InetSocketAddress[] results = new InetSocketAddress[seeds.getSeedCount()];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (PeerSeedProtos.PeerSeedData data : seeds.getSeedList())
|
for (PeerSeedProtos.PeerSeedData data : seeds.getSeedList())
|
||||||
results[i++] = InetSocketAddress.createUnresolved(data.getIpAddress(), data.getPort());
|
results[i++] = new InetSocketAddress(data.getIpAddress(), data.getPort());
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,14 +7,8 @@ var context = new bcj.core.Context(params);
|
|||||||
bcj.utils.BriefLogFormatter.init();
|
bcj.utils.BriefLogFormatter.init();
|
||||||
|
|
||||||
var PeerAddress = Java.type("org.bitcoinj.core.PeerAddress");
|
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);
|
var pg = bcj.core.PeerGroup.newWithTor(context, null, new com.subgraph.orchid.TorClient(), false);
|
||||||
|
pg.addAddress(new PeerAddress("nkf5e6b7pl4jfd4a.onion", params.port));
|
||||||
pg.addAddress(new PeerAddress(OnionAddress));
|
|
||||||
pg.start();
|
pg.start();
|
||||||
|
|
||||||
pg.waitForPeers(1).get();
|
pg.waitForPeers(1).get();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user