6 namespace org { namespace ldk { namespace structs {
9 * An address which can be used to connect to a remote peer.
11 public class SocketAddress : CommonBase {
12 protected SocketAddress(object _dummy, long ptr) : base(ptr) { }
14 if (ptr != 0) { bindings.SocketAddress_free(ptr); }
17 internal static SocketAddress constr_from_ptr(long ptr) {
18 long raw_ty = bindings.LDKSocketAddress_ty_from_ptr(ptr);
20 case 0: return new SocketAddress_TcpIpV4(ptr);
21 case 1: return new SocketAddress_TcpIpV6(ptr);
22 case 2: return new SocketAddress_OnionV2(ptr);
23 case 3: return new SocketAddress_OnionV3(ptr);
24 case 4: return new SocketAddress_Hostname(ptr);
26 throw new ArgumentException("Impossible enum variant");
30 /** A SocketAddress of type TcpIpV4 */
31 public class SocketAddress_TcpIpV4 : SocketAddress {
33 * The 4-byte IPv4 address
37 * The port on which the node is listening
40 internal SocketAddress_TcpIpV4(long ptr) : base(null, ptr) {
41 long addr = bindings.LDKSocketAddress_TcpIpV4_get_addr(ptr);
42 byte[] addr_conv = InternalUtils.decodeUint8Array(addr);
43 this.addr = addr_conv;
44 this.port = bindings.LDKSocketAddress_TcpIpV4_get_port(ptr);
47 /** A SocketAddress of type TcpIpV6 */
48 public class SocketAddress_TcpIpV6 : SocketAddress {
50 * The 16-byte IPv6 address
54 * The port on which the node is listening
57 internal SocketAddress_TcpIpV6(long ptr) : base(null, ptr) {
58 long addr = bindings.LDKSocketAddress_TcpIpV6_get_addr(ptr);
59 byte[] addr_conv = InternalUtils.decodeUint8Array(addr);
60 this.addr = addr_conv;
61 this.port = bindings.LDKSocketAddress_TcpIpV6_get_port(ptr);
64 /** A SocketAddress of type OnionV2 */
65 public class SocketAddress_OnionV2 : SocketAddress {
66 public byte[] onion_v2;
67 internal SocketAddress_OnionV2(long ptr) : base(null, ptr) {
68 long onion_v2 = bindings.LDKSocketAddress_OnionV2_get_onion_v2(ptr);
69 byte[] onion_v2_conv = InternalUtils.decodeUint8Array(onion_v2);
70 this.onion_v2 = onion_v2_conv;
73 /** A SocketAddress of type OnionV3 */
74 public class SocketAddress_OnionV3 : SocketAddress {
76 * The ed25519 long-term public key of the peer
78 public byte[] ed25519_pubkey;
80 * The checksum of the pubkey and version, as included in the onion address
82 public short checksum;
84 * The version byte, as defined by the Tor Onion v3 spec.
88 * The port on which the node is listening
91 internal SocketAddress_OnionV3(long ptr) : base(null, ptr) {
92 long ed25519_pubkey = bindings.LDKSocketAddress_OnionV3_get_ed25519_pubkey(ptr);
93 byte[] ed25519_pubkey_conv = InternalUtils.decodeUint8Array(ed25519_pubkey);
94 this.ed25519_pubkey = ed25519_pubkey_conv;
95 this.checksum = bindings.LDKSocketAddress_OnionV3_get_checksum(ptr);
96 this.version = bindings.LDKSocketAddress_OnionV3_get_version(ptr);
97 this.port = bindings.LDKSocketAddress_OnionV3_get_port(ptr);
100 /** A SocketAddress of type Hostname */
101 public class SocketAddress_Hostname : SocketAddress {
103 * The hostname on which the node is listening.
105 public Hostname hostname;
107 * The port on which the node is listening.
110 internal SocketAddress_Hostname(long ptr) : base(null, ptr) {
111 long hostname = bindings.LDKSocketAddress_Hostname_get_hostname(ptr);
112 org.ldk.structs.Hostname hostname_hu_conv = null; if (hostname < 0 || hostname > 4096) { hostname_hu_conv = new org.ldk.structs.Hostname(null, hostname); }
113 if (hostname_hu_conv != null) { hostname_hu_conv.ptrs_to.AddLast(this); };
114 this.hostname = hostname_hu_conv;
115 this.port = bindings.LDKSocketAddress_Hostname_get_port(ptr);
118 internal long clone_ptr() {
119 long ret = bindings.SocketAddress_clone_ptr(this.ptr);
125 * Creates a copy of the SocketAddress
127 public SocketAddress clone() {
128 long ret = bindings.SocketAddress_clone(this.ptr);
130 if (ret >= 0 && ret <= 4096) { return null; }
131 org.ldk.structs.SocketAddress ret_hu_conv = org.ldk.structs.SocketAddress.constr_from_ptr(ret);
132 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
137 * Utility method to constructs a new TcpIpV4-variant SocketAddress
139 public static SocketAddress tcp_ip_v4(byte[] addr, short port) {
140 long ret = bindings.SocketAddress_tcp_ip_v4(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(addr, 4)), port);
143 if (ret >= 0 && ret <= 4096) { return null; }
144 org.ldk.structs.SocketAddress ret_hu_conv = org.ldk.structs.SocketAddress.constr_from_ptr(ret);
145 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
150 * Utility method to constructs a new TcpIpV6-variant SocketAddress
152 public static SocketAddress tcp_ip_v6(byte[] addr, short port) {
153 long ret = bindings.SocketAddress_tcp_ip_v6(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(addr, 16)), port);
156 if (ret >= 0 && ret <= 4096) { return null; }
157 org.ldk.structs.SocketAddress ret_hu_conv = org.ldk.structs.SocketAddress.constr_from_ptr(ret);
158 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
163 * Utility method to constructs a new OnionV2-variant SocketAddress
165 public static SocketAddress onion_v2(byte[] a) {
166 long ret = bindings.SocketAddress_onion_v2(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(a, 12)));
168 if (ret >= 0 && ret <= 4096) { return null; }
169 org.ldk.structs.SocketAddress ret_hu_conv = org.ldk.structs.SocketAddress.constr_from_ptr(ret);
170 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
175 * Utility method to constructs a new OnionV3-variant SocketAddress
177 public static SocketAddress onion_v3(byte[] ed25519_pubkey, short checksum, byte version, short port) {
178 long ret = bindings.SocketAddress_onion_v3(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(ed25519_pubkey, 32)), checksum, version, port);
179 GC.KeepAlive(ed25519_pubkey);
180 GC.KeepAlive(checksum);
181 GC.KeepAlive(version);
183 if (ret >= 0 && ret <= 4096) { return null; }
184 org.ldk.structs.SocketAddress ret_hu_conv = org.ldk.structs.SocketAddress.constr_from_ptr(ret);
185 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
190 * Utility method to constructs a new Hostname-variant SocketAddress
192 public static SocketAddress hostname(org.ldk.structs.Hostname hostname, short port) {
193 long ret = bindings.SocketAddress_hostname(hostname == null ? 0 : hostname.ptr, port);
194 GC.KeepAlive(hostname);
196 if (ret >= 0 && ret <= 4096) { return null; }
197 org.ldk.structs.SocketAddress ret_hu_conv = org.ldk.structs.SocketAddress.constr_from_ptr(ret);
198 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
199 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(hostname); };
204 * Checks if two SocketAddresss contain equal inner contents.
205 * This ignores pointers and is_owned flags and looks at the values in fields.
207 public bool eq(org.ldk.structs.SocketAddress b) {
208 bool ret = bindings.SocketAddress_eq(this.ptr, b == null ? 0 : b.ptr);
214 public override bool Equals(object o) {
215 if (!(o is SocketAddress)) return false;
216 return this.eq((SocketAddress)o);
219 * Serialize the SocketAddress object into a byte array which can be read by SocketAddress_read
221 public byte[] write() {
222 long ret = bindings.SocketAddress_write(this.ptr);
224 if (ret >= 0 && ret <= 4096) { return null; }
225 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
230 * Read a SocketAddress from a byte array, created by SocketAddress_write
232 public static Result_SocketAddressDecodeErrorZ read(byte[] ser) {
233 long ret = bindings.SocketAddress_read(InternalUtils.encodeUint8Array(ser));
235 if (ret >= 0 && ret <= 4096) { return null; }
236 Result_SocketAddressDecodeErrorZ ret_hu_conv = Result_SocketAddressDecodeErrorZ.constr_from_ptr(ret);
241 * Get the string representation of a SocketAddress object
243 public string to_str() {
244 long ret = bindings.SocketAddress_to_str(this.ptr);
246 if (ret >= 0 && ret <= 4096) { return null; }
247 string ret_conv = InternalUtils.decodeString(ret);
252 * Read a SocketAddress object from a string
254 public static Result_SocketAddressSocketAddressParseErrorZ from_str(string s) {
255 long ret = bindings.SocketAddress_from_str(InternalUtils.encodeString(s));
257 if (ret >= 0 && ret <= 4096) { return null; }
258 Result_SocketAddressSocketAddressParseErrorZ ret_hu_conv = Result_SocketAddressSocketAddressParseErrorZ.constr_from_ptr(ret);