6 namespace org { namespace ldk { namespace structs {
9 * An address which can be used to connect to a remote peer
11 public class NetAddress : CommonBase {
12 protected NetAddress(object _dummy, long ptr) : base(ptr) { }
14 if (ptr != 0) { bindings.NetAddress_free(ptr); }
17 internal static NetAddress constr_from_ptr(long ptr) {
18 long raw_ty = bindings.LDKNetAddress_ty_from_ptr(ptr);
20 case 0: return new NetAddress_IPv4(ptr);
21 case 1: return new NetAddress_IPv6(ptr);
22 case 2: return new NetAddress_OnionV2(ptr);
23 case 3: return new NetAddress_OnionV3(ptr);
24 case 4: return new NetAddress_Hostname(ptr);
26 throw new ArgumentException("Impossible enum variant");
30 /** A NetAddress of type IPv4 */
31 public class NetAddress_IPv4 : NetAddress {
33 * The 4-byte IPv4 address
37 * The port on which the node is listening
40 internal NetAddress_IPv4(long ptr) : base(null, ptr) {
41 this.addr = bindings.LDKNetAddress_IPv4_get_addr(ptr);
42 this.port = bindings.LDKNetAddress_IPv4_get_port(ptr);
45 /** A NetAddress of type IPv6 */
46 public class NetAddress_IPv6 : NetAddress {
48 * The 16-byte IPv6 address
52 * The port on which the node is listening
55 internal NetAddress_IPv6(long ptr) : base(null, ptr) {
56 this.addr = bindings.LDKNetAddress_IPv6_get_addr(ptr);
57 this.port = bindings.LDKNetAddress_IPv6_get_port(ptr);
60 /** A NetAddress of type OnionV2 */
61 public class NetAddress_OnionV2 : NetAddress {
62 public byte[] onion_v2;
63 internal NetAddress_OnionV2(long ptr) : base(null, ptr) {
64 this.onion_v2 = bindings.LDKNetAddress_OnionV2_get_onion_v2(ptr);
67 /** A NetAddress of type OnionV3 */
68 public class NetAddress_OnionV3 : NetAddress {
70 * The ed25519 long-term public key of the peer
72 public byte[] ed25519_pubkey;
74 * The checksum of the pubkey and version, as included in the onion address
76 public short checksum;
78 * The version byte, as defined by the Tor Onion v3 spec.
82 * The port on which the node is listening
85 internal NetAddress_OnionV3(long ptr) : base(null, ptr) {
86 this.ed25519_pubkey = bindings.LDKNetAddress_OnionV3_get_ed25519_pubkey(ptr);
87 this.checksum = bindings.LDKNetAddress_OnionV3_get_checksum(ptr);
88 this.version = bindings.LDKNetAddress_OnionV3_get_version(ptr);
89 this.port = bindings.LDKNetAddress_OnionV3_get_port(ptr);
92 /** A NetAddress of type Hostname */
93 public class NetAddress_Hostname : NetAddress {
95 * The hostname on which the node is listening.
97 public Hostname hostname;
99 * The port on which the node is listening.
102 internal NetAddress_Hostname(long ptr) : base(null, ptr) {
103 long hostname = bindings.LDKNetAddress_Hostname_get_hostname(ptr);
104 org.ldk.structs.Hostname hostname_hu_conv = null; if (hostname < 0 || hostname > 4096) { hostname_hu_conv = new org.ldk.structs.Hostname(null, hostname); }
105 if (hostname_hu_conv != null) { hostname_hu_conv.ptrs_to.AddLast(this); };
106 this.hostname = hostname_hu_conv;
107 this.port = bindings.LDKNetAddress_Hostname_get_port(ptr);
110 internal long clone_ptr() {
111 long ret = bindings.NetAddress_clone_ptr(this.ptr);
117 * Creates a copy of the NetAddress
119 public NetAddress clone() {
120 long ret = bindings.NetAddress_clone(this.ptr);
122 if (ret >= 0 && ret <= 4096) { return null; }
123 org.ldk.structs.NetAddress ret_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret);
124 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
129 * Utility method to constructs a new IPv4-variant NetAddress
131 public static NetAddress ipv4(byte[] addr, short port) {
132 long ret = bindings.NetAddress_ipv4(InternalUtils.check_arr_len(addr, 4), port);
135 if (ret >= 0 && ret <= 4096) { return null; }
136 org.ldk.structs.NetAddress ret_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret);
137 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
142 * Utility method to constructs a new IPv6-variant NetAddress
144 public static NetAddress ipv6(byte[] addr, short port) {
145 long ret = bindings.NetAddress_ipv6(InternalUtils.check_arr_len(addr, 16), port);
148 if (ret >= 0 && ret <= 4096) { return null; }
149 org.ldk.structs.NetAddress ret_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret);
150 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
155 * Utility method to constructs a new OnionV2-variant NetAddress
157 public static NetAddress onion_v2(byte[] a) {
158 long ret = bindings.NetAddress_onion_v2(InternalUtils.check_arr_len(a, 12));
160 if (ret >= 0 && ret <= 4096) { return null; }
161 org.ldk.structs.NetAddress ret_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret);
162 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
167 * Utility method to constructs a new OnionV3-variant NetAddress
169 public static NetAddress onion_v3(byte[] ed25519_pubkey, short checksum, byte version, short port) {
170 long ret = bindings.NetAddress_onion_v3(InternalUtils.check_arr_len(ed25519_pubkey, 32), checksum, version, port);
171 GC.KeepAlive(ed25519_pubkey);
172 GC.KeepAlive(checksum);
173 GC.KeepAlive(version);
175 if (ret >= 0 && ret <= 4096) { return null; }
176 org.ldk.structs.NetAddress ret_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret);
177 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
182 * Utility method to constructs a new Hostname-variant NetAddress
184 public static NetAddress hostname(org.ldk.structs.Hostname hostname, short port) {
185 long ret = bindings.NetAddress_hostname(hostname == null ? 0 : hostname.ptr, port);
186 GC.KeepAlive(hostname);
188 if (ret >= 0 && ret <= 4096) { return null; }
189 org.ldk.structs.NetAddress ret_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret);
190 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
191 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(hostname); };
196 * Checks if two NetAddresss contain equal inner contents.
197 * This ignores pointers and is_owned flags and looks at the values in fields.
199 public bool eq(org.ldk.structs.NetAddress b) {
200 bool ret = bindings.NetAddress_eq(this.ptr, b == null ? 0 : b.ptr);
206 public override bool Equals(object o) {
207 if (!(o is NetAddress)) return false;
208 return this.eq((NetAddress)o);
211 * Serialize the NetAddress object into a byte array which can be read by NetAddress_read
213 public byte[] write() {
214 byte[] ret = bindings.NetAddress_write(this.ptr);
220 * Read a NetAddress from a byte array, created by NetAddress_write
222 public static Result_NetAddressDecodeErrorZ read(byte[] ser) {
223 long ret = bindings.NetAddress_read(ser);
225 if (ret >= 0 && ret <= 4096) { return null; }
226 Result_NetAddressDecodeErrorZ ret_hu_conv = Result_NetAddressDecodeErrorZ.constr_from_ptr(ret);