[Java] Update auto-generated 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                 assert false; return null; // Unreachable without extending the (internal) bindings interface
37         }
38
39         /**
40          * An IPv4 address/port on which the peer is listening.
41          */
42         public final static class IPv4 extends NetAddress {
43                 /**
44                  * The 4-byte IPv4 address
45                 */
46                 public final byte[] addr;
47                 /**
48                  * The port on which the node is listening
49                 */
50                 public final short port;
51                 private IPv4(long ptr, bindings.LDKNetAddress.IPv4 obj) {
52                         super(null, ptr);
53                         this.addr = obj.addr;
54                         this.port = obj.port;
55                 }
56         }
57         /**
58          * An IPv6 address/port on which the peer is listening.
59          */
60         public final static class IPv6 extends NetAddress {
61                 /**
62                  * The 16-byte IPv6 address
63                 */
64                 public final byte[] addr;
65                 /**
66                  * The port on which the node is listening
67                 */
68                 public final short port;
69                 private IPv6(long ptr, bindings.LDKNetAddress.IPv6 obj) {
70                         super(null, ptr);
71                         this.addr = obj.addr;
72                         this.port = obj.port;
73                 }
74         }
75         /**
76          * An old-style Tor onion address/port on which the peer is listening.
77          * 
78          * This field is deprecated and the Tor network generally no longer supports V2 Onion
79          * addresses. Thus, the details are not parsed here.
80          */
81         public final static class OnionV2 extends NetAddress {
82                 public final byte[] onion_v2;
83                 private OnionV2(long ptr, bindings.LDKNetAddress.OnionV2 obj) {
84                         super(null, ptr);
85                         this.onion_v2 = obj.onion_v2;
86                 }
87         }
88         /**
89          * A new-style Tor onion address/port on which the peer is listening.
90          * To create the human-readable \"hostname\", concatenate ed25519_pubkey, checksum, and version,
91          * wrap as base32 and append \".onion\".
92          */
93         public final static class OnionV3 extends NetAddress {
94                 /**
95                  * The ed25519 long-term public key of the peer
96                 */
97                 public final byte[] ed25519_pubkey;
98                 /**
99                  * The checksum of the pubkey and version, as included in the onion address
100                 */
101                 public final short checksum;
102                 /**
103                  * The version byte, as defined by the Tor Onion v3 spec.
104                 */
105                 public final byte version;
106                 /**
107                  * The port on which the node is listening
108                 */
109                 public final short port;
110                 private OnionV3(long ptr, bindings.LDKNetAddress.OnionV3 obj) {
111                         super(null, ptr);
112                         this.ed25519_pubkey = obj.ed25519_pubkey;
113                         this.checksum = obj.checksum;
114                         this.version = obj.version;
115                         this.port = obj.port;
116                 }
117         }
118         long clone_ptr() {
119                 long ret = bindings.NetAddress_clone_ptr(this.ptr);
120                 Reference.reachabilityFence(this);
121                 return ret;
122         }
123
124         /**
125          * Creates a copy of the NetAddress
126          */
127         public NetAddress clone() {
128                 long ret = bindings.NetAddress_clone(this.ptr);
129                 Reference.reachabilityFence(this);
130                 if (ret >= 0 && ret <= 4096) { return null; }
131                 org.ldk.structs.NetAddress ret_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret);
132                 ret_hu_conv.ptrs_to.add(this);
133                 return ret_hu_conv;
134         }
135
136         /**
137          * Utility method to constructs a new IPv4-variant NetAddress
138          */
139         public static NetAddress ipv4(byte[] addr, short port) {
140                 long ret = bindings.NetAddress_ipv4(InternalUtils.check_arr_len(addr, 4), port);
141                 Reference.reachabilityFence(addr);
142                 Reference.reachabilityFence(port);
143                 if (ret >= 0 && ret <= 4096) { return null; }
144                 org.ldk.structs.NetAddress ret_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret);
145                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
146                 return ret_hu_conv;
147         }
148
149         /**
150          * Utility method to constructs a new IPv6-variant NetAddress
151          */
152         public static NetAddress ipv6(byte[] addr, short port) {
153                 long ret = bindings.NetAddress_ipv6(InternalUtils.check_arr_len(addr, 16), port);
154                 Reference.reachabilityFence(addr);
155                 Reference.reachabilityFence(port);
156                 if (ret >= 0 && ret <= 4096) { return null; }
157                 org.ldk.structs.NetAddress ret_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret);
158                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
159                 return ret_hu_conv;
160         }
161
162         /**
163          * Utility method to constructs a new OnionV2-variant NetAddress
164          */
165         public static NetAddress onion_v2(byte[] a) {
166                 long ret = bindings.NetAddress_onion_v2(InternalUtils.check_arr_len(a, 12));
167                 Reference.reachabilityFence(a);
168                 if (ret >= 0 && ret <= 4096) { return null; }
169                 org.ldk.structs.NetAddress ret_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret);
170                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
171                 return ret_hu_conv;
172         }
173
174         /**
175          * Utility method to constructs a new OnionV3-variant NetAddress
176          */
177         public static NetAddress onion_v3(byte[] ed25519_pubkey, short checksum, byte version, short port) {
178                 long ret = bindings.NetAddress_onion_v3(InternalUtils.check_arr_len(ed25519_pubkey, 32), checksum, version, port);
179                 Reference.reachabilityFence(ed25519_pubkey);
180                 Reference.reachabilityFence(checksum);
181                 Reference.reachabilityFence(version);
182                 Reference.reachabilityFence(port);
183                 if (ret >= 0 && ret <= 4096) { return null; }
184                 org.ldk.structs.NetAddress ret_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret);
185                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
186                 return ret_hu_conv;
187         }
188
189         /**
190          * Serialize the NetAddress object into a byte array which can be read by NetAddress_read
191          */
192         public byte[] write() {
193                 byte[] ret = bindings.NetAddress_write(this.ptr);
194                 Reference.reachabilityFence(this);
195                 return ret;
196         }
197
198         /**
199          * Read a NetAddress from a byte array, created by NetAddress_write
200          */
201         public static Result_NetAddressDecodeErrorZ read(byte[] ser) {
202                 long ret = bindings.NetAddress_read(ser);
203                 Reference.reachabilityFence(ser);
204                 if (ret >= 0 && ret <= 4096) { return null; }
205                 Result_NetAddressDecodeErrorZ ret_hu_conv = Result_NetAddressDecodeErrorZ.constr_from_ptr(ret);
206                 return ret_hu_conv;
207         }
208
209 }