X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FNetAddress.java;h=74ccb308db826e7627c35fb2dba03d0a742e2dfd;hb=890e35a4387758c0447aab34166caa579bbf3a08;hp=55851a719da1f30dbd880d2a3029acec047abfe2;hpb=1854b5cebef22ace9e9e4dd191f609818df9ce08;p=ldk-java diff --git a/src/main/java/org/ldk/structs/NetAddress.java b/src/main/java/org/ldk/structs/NetAddress.java index 55851a71..74ccb308 100644 --- a/src/main/java/org/ldk/structs/NetAddress.java +++ b/src/main/java/org/ldk/structs/NetAddress.java @@ -33,6 +33,9 @@ public class NetAddress extends CommonBase { if (raw_val.getClass() == bindings.LDKNetAddress.OnionV3.class) { return new OnionV3(ptr, (bindings.LDKNetAddress.OnionV3)raw_val); } + if (raw_val.getClass() == bindings.LDKNetAddress.Hostname.class) { + return new Hostname(ptr, (bindings.LDKNetAddress.Hostname)raw_val); + } assert false; return null; // Unreachable without extending the (internal) bindings interface } @@ -115,6 +118,27 @@ public class NetAddress extends CommonBase { this.port = obj.port; } } + /** + * A hostname/port on which the peer is listening. + */ + public final static class Hostname extends NetAddress { + /** + * The hostname on which the node is listening. + */ + public final org.ldk.structs.Hostname hostname; + /** + * The port on which the node is listening. + */ + public final short port; + private Hostname(long ptr, bindings.LDKNetAddress.Hostname obj) { + super(null, ptr); + long hostname = obj.hostname; + org.ldk.structs.Hostname hostname_hu_conv = null; if (hostname < 0 || hostname > 4096) { hostname_hu_conv = new org.ldk.structs.Hostname(null, hostname); } + if (hostname_hu_conv != null) { hostname_hu_conv.ptrs_to.add(this); }; + this.hostname = hostname_hu_conv; + this.port = obj.port; + } + } long clone_ptr() { long ret = bindings.NetAddress_clone_ptr(this.ptr); Reference.reachabilityFence(this); @@ -128,8 +152,8 @@ public class NetAddress extends CommonBase { 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); - ret_hu_conv.ptrs_to.add(this); + org.ldk.structs.NetAddress ret_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; return ret_hu_conv; } @@ -141,8 +165,8 @@ public class NetAddress extends CommonBase { Reference.reachabilityFence(addr); Reference.reachabilityFence(port); if (ret >= 0 && ret <= 4096) { return null; } - NetAddress ret_hu_conv = NetAddress.constr_from_ptr(ret); - ret_hu_conv.ptrs_to.add(ret_hu_conv); + org.ldk.structs.NetAddress ret_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; return ret_hu_conv; } @@ -154,8 +178,8 @@ public class NetAddress extends CommonBase { Reference.reachabilityFence(addr); Reference.reachabilityFence(port); if (ret >= 0 && ret <= 4096) { return null; } - NetAddress ret_hu_conv = NetAddress.constr_from_ptr(ret); - ret_hu_conv.ptrs_to.add(ret_hu_conv); + org.ldk.structs.NetAddress ret_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; return ret_hu_conv; } @@ -166,8 +190,8 @@ public class NetAddress extends CommonBase { 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); - ret_hu_conv.ptrs_to.add(ret_hu_conv); + org.ldk.structs.NetAddress ret_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; return ret_hu_conv; } @@ -181,8 +205,22 @@ public class NetAddress extends CommonBase { Reference.reachabilityFence(version); Reference.reachabilityFence(port); if (ret >= 0 && ret <= 4096) { return null; } - NetAddress ret_hu_conv = NetAddress.constr_from_ptr(ret); - ret_hu_conv.ptrs_to.add(ret_hu_conv); + org.ldk.structs.NetAddress ret_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; + return ret_hu_conv; + } + + /** + * Utility method to constructs a new Hostname-variant NetAddress + */ + public static NetAddress hostname(Hostname hostname, short port) { + long ret = bindings.NetAddress_hostname(hostname == null ? 0 : hostname.ptr, port); + Reference.reachabilityFence(hostname); + Reference.reachabilityFence(port); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.NetAddress ret_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(hostname); }; return ret_hu_conv; }