Skip to content

Commit

Permalink
Add deprecated constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
ripcurlx committed Sep 7, 2021
1 parent 25eab99 commit 8755d3b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions core/src/main/java/org/bitcoinj/core/PeerAddress.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class PeerAddress extends ChildMessage {

private static final BaseEncoding BASE32 = BaseEncoding.base32().lowerCase();
private static final byte[] ONIONCAT_PREFIX = Utils.HEX.decode("fd87d87eeb43");
static final int MESSAGE_SIZE = 30;

/**
* Construct a peer address from a serialized payload.
Expand Down Expand Up @@ -111,6 +112,33 @@ public PeerAddress(NetworkParameters params, InetSocketAddress addr) {
this(params, addr.getAddress(), addr.getPort());
}

/**
* Constructs a peer address from an {@link InetSocketAddress}. An InetSocketAddress can take in as parameters an
* InetAddress or a String hostname. If you want to connect to a .onion, set the hostname to the .onion address.
* Protocol version is the default for Bitcoin.
*/
public PeerAddress(InetSocketAddress addr) {
InetAddress inetAddress = addr.getAddress();
if(inetAddress != null) {
this.addr = inetAddress;
} else {
this.hostname = checkNotNull(addr.getHostString());
}
this.port = addr.getPort();
this.services = BigInteger.ZERO;
length = NetworkParameters.ProtocolVersion.CURRENT.getBitcoinProtocolVersion() > 31402 ? MESSAGE_SIZE : MESSAGE_SIZE - 4;
}

/**
* Constructs a peer address from a stringified hostname+port.
* Protocol version is the default for Bitcoin.
*/
public PeerAddress(String hostname, int port) {
this.hostname = hostname;
this.port = port;
this.services = BigInteger.ZERO;
}

/**
* Constructs a peer address from a stringified hostname+port+services.
*/
Expand Down

0 comments on commit 8755d3b

Please sign in to comment.