[Java] Update auto-generated Java bindings
[ldk-java] / src / main / java / org / ldk / structs / NetAddress.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
12  * An address which can be used to connect to a remote peer
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class NetAddress extends CommonBase {
16         private NetAddress(Object _dummy, long ptr) { super(ptr); }
17         @Override @SuppressWarnings("deprecation")
18         protected void finalize() throws Throwable {
19                 super.finalize();
20                 if (ptr != 0) { bindings.NetAddress_free(ptr); }
21         }
22         static NetAddress constr_from_ptr(long ptr) {
23                 bindings.LDKNetAddress raw_val = bindings.LDKNetAddress_ref_from_ptr(ptr);
24                 if (raw_val.getClass() == bindings.LDKNetAddress.IPv4.class) {
25                         return new IPv4(ptr, (bindings.LDKNetAddress.IPv4)raw_val);
26                 }
27                 if (raw_val.getClass() == bindings.LDKNetAddress.IPv6.class) {
28                         return new IPv6(ptr, (bindings.LDKNetAddress.IPv6)raw_val);
29                 }
30                 if (raw_val.getClass() == bindings.LDKNetAddress.OnionV2.class) {
31                         return new OnionV2(ptr, (bindings.LDKNetAddress.OnionV2)raw_val);
32                 }
33                 if (raw_val.getClass() == bindings.LDKNetAddress.OnionV3.class) {
34                         return new OnionV3(ptr, (bindings.LDKNetAddress.OnionV3)raw_val);
35                 }
36                 if (raw_val.getClass() == bindings.LDKNetAddress.Hostname.class) {
37                         return new Hostname(ptr, (bindings.LDKNetAddress.Hostname)raw_val);
38                 }
39                 assert false; return null; // Unreachable without extending the (internal) bindings interface
40         }
41
42         /**
43          * An IPv4 address/port on which the peer is listening.
44          */
45         public final static class IPv4 extends NetAddress {
46                 /**
47                  * The 4-byte IPv4 address
48                 */
49                 public final byte[] addr;
50                 /**
51                  * The port on which the node is listening
52                 */
53                 public final short port;
54                 private IPv4(long ptr, bindings.LDKNetAddress.IPv4 obj) {
55                         super(null, ptr);
56                         this.addr = obj.addr;
57                         this.port = obj.port;
58                 }
59         }
60         /**
61          * An IPv6 address/port on which the peer is listening.
62          */
63         public final static class IPv6 extends NetAddress {
64                 /**
65                  * The 16-byte IPv6 address
66                 */
67                 public final byte[] addr;
68                 /**
69                  * The port on which the node is listening
70                 */
71                 public final short port;
72                 private IPv6(long ptr, bindings.LDKNetAddress.IPv6 obj) {
73                         super(null, ptr);
74                         this.addr = obj.addr;
75                         this.port = obj.port;
76                 }
77         }
78         /**
79          * An old-style Tor onion address/port on which the peer is listening.
80          * 
81          * This field is deprecated and the Tor network generally no longer supports V2 Onion
82          * addresses. Thus, the details are not parsed here.
83          */
84         public final static class OnionV2 extends NetAddress {
85                 public final byte[] onion_v2;
86                 private OnionV2(long ptr, bindings.LDKNetAddress.OnionV2 obj) {
87                         super(null, ptr);
88                         this.onion_v2 = obj.onion_v2;
89                 }
90         }
91         /**
92          * A new-style Tor onion address/port on which the peer is listening.
93          * To create the human-readable \"hostname\", concatenate ed25519_pubkey, checksum, and version,
94          * wrap as base32 and append \".onion\".
95          */
96         public final static class OnionV3 extends NetAddress {
97                 /**
98                  * The ed25519 long-term public key of the peer
99                 */
100                 public final byte[] ed25519_pubkey;
101                 /**
102                  * The checksum of the pubkey and version, as included in the onion address
103                 */
104                 public final short checksum;
105                 /**
106                  * The version byte, as defined by the Tor Onion v3 spec.
107                 */
108                 public final byte version;
109                 /**
110                  * The port on which the node is listening
111                 */
112                 public final short port;
113                 private OnionV3(long ptr, bindings.LDKNetAddress.OnionV3 obj) {
114                         super(null, ptr);
115                         this.ed25519_pubkey = obj.ed25519_pubkey;
116                         this.checksum = obj.checksum;
117                         this.version = obj.version;
118                         this.port = obj.port;
119                 }
120         }
121         /**
122          * A hostname/port on which the peer is listening.
123          */
124         public final static class Hostname extends NetAddress {
125                 /**
126                  * The hostname on which the node is listening.
127                 */
128                 public final org.ldk.structs.Hostname hostname;
129                 /**
130                  * The port on which the node is listening.
131                 */
132                 public final short port;
133                 private Hostname(long ptr, bindings.LDKNetAddress.Hostname obj) {
134                         super(null, ptr);
135                         long hostname = obj.hostname;
136                         org.ldk.structs.Hostname hostname_hu_conv = null; if (hostname < 0 || hostname > 4096) { hostname_hu_conv = new org.ldk.structs.Hostname(null, hostname); }
137                         hostname_hu_conv.ptrs_to.add(this);
138                         this.hostname = hostname_hu_conv;
139                         this.port = obj.port;
140                 }
141         }
142         long clone_ptr() {
143                 long ret = bindings.NetAddress_clone_ptr(this.ptr);
144                 Reference.reachabilityFence(this);
145                 return ret;
146         }
147
148         /**
149          * Creates a copy of the NetAddress
150          */
151         public NetAddress clone() {
152                 long ret = bindings.NetAddress_clone(this.ptr);
153                 Reference.reachabilityFence(this);
154                 if (ret >= 0 && ret <= 4096) { return null; }
155                 org.ldk.structs.NetAddress ret_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret);
156                 ret_hu_conv.ptrs_to.add(this);
157                 return ret_hu_conv;
158         }
159
160         /**
161          * Utility method to constructs a new IPv4-variant NetAddress
162          */
163         public static NetAddress ipv4(byte[] addr, short port) {
164                 long ret = bindings.NetAddress_ipv4(InternalUtils.check_arr_len(addr, 4), port);
165                 Reference.reachabilityFence(addr);
166                 Reference.reachabilityFence(port);
167                 if (ret >= 0 && ret <= 4096) { return null; }
168                 org.ldk.structs.NetAddress ret_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret);
169                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
170                 return ret_hu_conv;
171         }
172
173         /**
174          * Utility method to constructs a new IPv6-variant NetAddress
175          */
176         public static NetAddress ipv6(byte[] addr, short port) {
177                 long ret = bindings.NetAddress_ipv6(InternalUtils.check_arr_len(addr, 16), port);
178                 Reference.reachabilityFence(addr);
179                 Reference.reachabilityFence(port);
180                 if (ret >= 0 && ret <= 4096) { return null; }
181                 org.ldk.structs.NetAddress ret_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret);
182                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
183                 return ret_hu_conv;
184         }
185
186         /**
187          * Utility method to constructs a new OnionV2-variant NetAddress
188          */
189         public static NetAddress onion_v2(byte[] a) {
190                 long ret = bindings.NetAddress_onion_v2(InternalUtils.check_arr_len(a, 12));
191                 Reference.reachabilityFence(a);
192                 if (ret >= 0 && ret <= 4096) { return null; }
193                 org.ldk.structs.NetAddress ret_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret);
194                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
195                 return ret_hu_conv;
196         }
197
198         /**
199          * Utility method to constructs a new OnionV3-variant NetAddress
200          */
201         public static NetAddress onion_v3(byte[] ed25519_pubkey, short checksum, byte version, short port) {
202                 long ret = bindings.NetAddress_onion_v3(InternalUtils.check_arr_len(ed25519_pubkey, 32), checksum, version, port);
203                 Reference.reachabilityFence(ed25519_pubkey);
204                 Reference.reachabilityFence(checksum);
205                 Reference.reachabilityFence(version);
206                 Reference.reachabilityFence(port);
207                 if (ret >= 0 && ret <= 4096) { return null; }
208                 org.ldk.structs.NetAddress ret_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret);
209                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
210                 return ret_hu_conv;
211         }
212
213         /**
214          * Utility method to constructs a new Hostname-variant NetAddress
215          */
216         public static NetAddress hostname(Hostname hostname, short port) {
217                 long ret = bindings.NetAddress_hostname(hostname == null ? 0 : hostname.ptr, port);
218                 Reference.reachabilityFence(hostname);
219                 Reference.reachabilityFence(port);
220                 if (ret >= 0 && ret <= 4096) { return null; }
221                 org.ldk.structs.NetAddress ret_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret);
222                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
223                 ret_hu_conv.ptrs_to.add(hostname);
224                 return ret_hu_conv;
225         }
226
227         /**
228          * Serialize the NetAddress object into a byte array which can be read by NetAddress_read
229          */
230         public byte[] write() {
231                 byte[] ret = bindings.NetAddress_write(this.ptr);
232                 Reference.reachabilityFence(this);
233                 return ret;
234         }
235
236         /**
237          * Read a NetAddress from a byte array, created by NetAddress_write
238          */
239         public static Result_NetAddressDecodeErrorZ read(byte[] ser) {
240                 long ret = bindings.NetAddress_read(ser);
241                 Reference.reachabilityFence(ser);
242                 if (ret >= 0 && ret <= 4096) { return null; }
243                 Result_NetAddressDecodeErrorZ ret_hu_conv = Result_NetAddressDecodeErrorZ.constr_from_ptr(ret);
244                 return ret_hu_conv;
245         }
246
247 }