X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FNetAddress.java;h=73f5bc325d6491b63c0adc7853217fe9a9314afc;hb=ff3dacec3be60f870d81f6df11bd9fff92aa6047;hp=5a26a2a0f11525c62ecc5714ccbb9979f3a7a77c;hpb=99d1a3bd6dc5c7ed1499b30bfc2b4c66ffaf858a;p=ldk-java diff --git a/src/main/java/org/ldk/structs/NetAddress.java b/src/main/java/org/ldk/structs/NetAddress.java index 5a26a2a0..73f5bc32 100644 --- a/src/main/java/org/ldk/structs/NetAddress.java +++ b/src/main/java/org/ldk/structs/NetAddress.java @@ -4,6 +4,7 @@ import org.ldk.impl.bindings; import org.ldk.enums.*; import org.ldk.util.*; import java.util.Arrays; +import java.lang.ref.Reference; import javax.annotation.Nullable; @@ -35,6 +36,9 @@ public class NetAddress extends CommonBase { assert false; return null; // Unreachable without extending the (internal) bindings interface } + /** + * An IPv4 address/port on which the peer is listening. + */ public final static class IPv4 extends NetAddress { /** * The 4-byte IPv4 address @@ -50,6 +54,9 @@ public class NetAddress extends CommonBase { this.port = obj.port; } } + /** + * An IPv6 address/port on which the peer is listening. + */ public final static class IPv6 extends NetAddress { /** * The 16-byte IPv6 address @@ -65,21 +72,24 @@ public class NetAddress extends CommonBase { this.port = obj.port; } } + /** + * An old-style Tor onion address/port on which the peer is listening. + * + * This field is deprecated and the Tor network generally no longer supports V2 Onion + * addresses. Thus, the details are not parsed here. + */ public final static class OnionV2 extends NetAddress { - /** - * The bytes (usually encoded in base32 with \".onion\" appended) - */ - public final byte[] addr; - /** - * The port on which the node is listening - */ - public final short port; + public final byte[] onion_v2; private OnionV2(long ptr, bindings.LDKNetAddress.OnionV2 obj) { super(null, ptr); - this.addr = obj.addr; - this.port = obj.port; + this.onion_v2 = obj.onion_v2; } } + /** + * A new-style Tor onion address/port on which the peer is listening. + * To create the human-readable \"hostname\", concatenate ed25519_pubkey, checksum, and version, + * wrap as base32 and append \".onion\". + */ public final static class OnionV3 extends NetAddress { /** * The ed25519 long-term public key of the peer @@ -105,13 +115,20 @@ public class NetAddress extends CommonBase { this.port = obj.port; } } + long clone_ptr() { + long ret = bindings.NetAddress_clone_ptr(this.ptr); + Reference.reachabilityFence(this); + return ret; + } + /** * Creates a copy of the NetAddress */ public NetAddress clone() { long ret = bindings.NetAddress_clone(this.ptr); + Reference.reachabilityFence(this); if (ret >= 0 && ret <= 4096) { return null; } - NetAddress ret_hu_conv = NetAddress.constr_from_ptr(ret); + org.ldk.structs.NetAddress ret_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret); ret_hu_conv.ptrs_to.add(this); return ret_hu_conv; } @@ -120,9 +137,11 @@ public class NetAddress extends CommonBase { * Utility method to constructs a new IPv4-variant NetAddress */ public static NetAddress ipv4(byte[] addr, short port) { - long ret = bindings.NetAddress_ipv4(addr, port); + long ret = bindings.NetAddress_ipv4(InternalUtils.check_arr_len(addr, 4), port); + Reference.reachabilityFence(addr); + Reference.reachabilityFence(port); if (ret >= 0 && ret <= 4096) { return null; } - NetAddress ret_hu_conv = NetAddress.constr_from_ptr(ret); + org.ldk.structs.NetAddress ret_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret); ret_hu_conv.ptrs_to.add(ret_hu_conv); return ret_hu_conv; } @@ -131,9 +150,11 @@ public class NetAddress extends CommonBase { * Utility method to constructs a new IPv6-variant NetAddress */ public static NetAddress ipv6(byte[] addr, short port) { - long ret = bindings.NetAddress_ipv6(addr, port); + long ret = bindings.NetAddress_ipv6(InternalUtils.check_arr_len(addr, 16), port); + Reference.reachabilityFence(addr); + Reference.reachabilityFence(port); if (ret >= 0 && ret <= 4096) { return null; } - NetAddress ret_hu_conv = NetAddress.constr_from_ptr(ret); + org.ldk.structs.NetAddress ret_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret); ret_hu_conv.ptrs_to.add(ret_hu_conv); return ret_hu_conv; } @@ -141,10 +162,11 @@ public class NetAddress extends CommonBase { /** * Utility method to constructs a new OnionV2-variant NetAddress */ - public static NetAddress onion_v2(byte[] addr, short port) { - long ret = bindings.NetAddress_onion_v2(addr, port); + public static NetAddress onion_v2(byte[] a) { + long ret = bindings.NetAddress_onion_v2(InternalUtils.check_arr_len(a, 12)); + Reference.reachabilityFence(a); if (ret >= 0 && ret <= 4096) { return null; } - NetAddress ret_hu_conv = NetAddress.constr_from_ptr(ret); + org.ldk.structs.NetAddress ret_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret); ret_hu_conv.ptrs_to.add(ret_hu_conv); return ret_hu_conv; } @@ -153,9 +175,13 @@ public class NetAddress extends CommonBase { * Utility method to constructs a new OnionV3-variant NetAddress */ public static NetAddress onion_v3(byte[] ed25519_pubkey, short checksum, byte version, short port) { - long ret = bindings.NetAddress_onion_v3(ed25519_pubkey, checksum, version, port); + long ret = bindings.NetAddress_onion_v3(InternalUtils.check_arr_len(ed25519_pubkey, 32), checksum, version, port); + Reference.reachabilityFence(ed25519_pubkey); + Reference.reachabilityFence(checksum); + Reference.reachabilityFence(version); + Reference.reachabilityFence(port); if (ret >= 0 && ret <= 4096) { return null; } - NetAddress ret_hu_conv = NetAddress.constr_from_ptr(ret); + org.ldk.structs.NetAddress ret_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret); ret_hu_conv.ptrs_to.add(ret_hu_conv); return ret_hu_conv; } @@ -165,6 +191,7 @@ public class NetAddress extends CommonBase { */ public byte[] write() { byte[] ret = bindings.NetAddress_write(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -173,6 +200,7 @@ public class NetAddress extends CommonBase { */ public static Result_NetAddressDecodeErrorZ read(byte[] ser) { long ret = bindings.NetAddress_read(ser); + Reference.reachabilityFence(ser); if (ret >= 0 && ret <= 4096) { return null; } Result_NetAddressDecodeErrorZ ret_hu_conv = Result_NetAddressDecodeErrorZ.constr_from_ptr(ret); return ret_hu_conv;