1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * An init message to be sent or received from a peer
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class Init extends CommonBase {
16 Init(Object _dummy, long ptr) { super(ptr); }
17 @Override @SuppressWarnings("deprecation")
18 protected void finalize() throws Throwable {
20 if (ptr != 0) { bindings.Init_free(ptr); }
24 * The relevant features which the sender supports
26 public InitFeatures get_features() {
27 long ret = bindings.Init_get_features(this.ptr);
28 Reference.reachabilityFence(this);
29 if (ret >= 0 && ret <= 4096) { return null; }
30 org.ldk.structs.InitFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InitFeatures(null, ret); }
31 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
36 * The relevant features which the sender supports
38 public void set_features(org.ldk.structs.InitFeatures val) {
39 bindings.Init_set_features(this.ptr, val == null ? 0 : val.ptr);
40 Reference.reachabilityFence(this);
41 Reference.reachabilityFence(val);
42 if (this != null) { this.ptrs_to.add(val); };
46 * The receipient's network address. This adds the option to report a remote IP address
47 * back to a connecting peer using the init message. A node can decide to use that information
48 * to discover a potential update to its public IPv4 address (NAT) and use
49 * that for a node_announcement update message containing the new address.
51 public Option_NetAddressZ get_remote_network_address() {
52 long ret = bindings.Init_get_remote_network_address(this.ptr);
53 Reference.reachabilityFence(this);
54 if (ret >= 0 && ret <= 4096) { return null; }
55 org.ldk.structs.Option_NetAddressZ ret_hu_conv = org.ldk.structs.Option_NetAddressZ.constr_from_ptr(ret);
56 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
61 * The receipient's network address. This adds the option to report a remote IP address
62 * back to a connecting peer using the init message. A node can decide to use that information
63 * to discover a potential update to its public IPv4 address (NAT) and use
64 * that for a node_announcement update message containing the new address.
66 public void set_remote_network_address(org.ldk.structs.Option_NetAddressZ val) {
67 bindings.Init_set_remote_network_address(this.ptr, val.ptr);
68 Reference.reachabilityFence(this);
69 Reference.reachabilityFence(val);
73 * Constructs a new Init given each field
75 public static Init of(org.ldk.structs.InitFeatures features_arg, org.ldk.structs.Option_NetAddressZ remote_network_address_arg) {
76 long ret = bindings.Init_new(features_arg == null ? 0 : features_arg.ptr, remote_network_address_arg.ptr);
77 Reference.reachabilityFence(features_arg);
78 Reference.reachabilityFence(remote_network_address_arg);
79 if (ret >= 0 && ret <= 4096) { return null; }
80 org.ldk.structs.Init ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Init(null, ret); }
81 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
82 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(features_arg); };
87 long ret = bindings.Init_clone_ptr(this.ptr);
88 Reference.reachabilityFence(this);
93 * Creates a copy of the Init
96 long ret = bindings.Init_clone(this.ptr);
97 Reference.reachabilityFence(this);
98 if (ret >= 0 && ret <= 4096) { return null; }
99 org.ldk.structs.Init ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Init(null, ret); }
100 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
105 * Checks if two Inits contain equal inner contents.
106 * This ignores pointers and is_owned flags and looks at the values in fields.
107 * Two objects with NULL inner values will be considered "equal" here.
109 public boolean eq(org.ldk.structs.Init b) {
110 boolean ret = bindings.Init_eq(this.ptr, b == null ? 0 : b.ptr);
111 Reference.reachabilityFence(this);
112 Reference.reachabilityFence(b);
113 if (this != null) { this.ptrs_to.add(b); };
117 @Override public boolean equals(Object o) {
118 if (!(o instanceof Init)) return false;
119 return this.eq((Init)o);
122 * Serialize the Init object into a byte array which can be read by Init_read
124 public byte[] write() {
125 byte[] ret = bindings.Init_write(this.ptr);
126 Reference.reachabilityFence(this);
131 * Read a Init from a byte array, created by Init_write
133 public static Result_InitDecodeErrorZ read(byte[] ser) {
134 long ret = bindings.Init_read(ser);
135 Reference.reachabilityFence(ser);
136 if (ret >= 0 && ret <= 4096) { return null; }
137 Result_InitDecodeErrorZ ret_hu_conv = Result_InitDecodeErrorZ.constr_from_ptr(ret);