1b9e1fae7ecb31bcaca744d30129db71dd450e91
[ldk-java] / src / main / java / org / ldk / structs / NodeAnnouncementInfo.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  * Information received in the latest node_announcement from this node.
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class NodeAnnouncementInfo extends CommonBase {
16         NodeAnnouncementInfo(Object _dummy, long ptr) { super(ptr); }
17         @Override @SuppressWarnings("deprecation")
18         protected void finalize() throws Throwable {
19                 super.finalize();
20                 if (ptr != 0) { bindings.NodeAnnouncementInfo_free(ptr); }
21         }
22
23         /**
24          * Protocol features the node announced support for
25          */
26         public NodeFeatures get_features() {
27                 long ret = bindings.NodeAnnouncementInfo_get_features(this.ptr);
28                 Reference.reachabilityFence(this);
29                 if (ret >= 0 && ret <= 4096) { return null; }
30                 org.ldk.structs.NodeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeFeatures(null, ret); }
31                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
32                 return ret_hu_conv;
33         }
34
35         /**
36          * Protocol features the node announced support for
37          */
38         public void set_features(org.ldk.structs.NodeFeatures val) {
39                 bindings.NodeAnnouncementInfo_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); };
43         }
44
45         /**
46          * When the last known update to the node state was issued.
47          * Value is opaque, as set in the announcement.
48          */
49         public int get_last_update() {
50                 int ret = bindings.NodeAnnouncementInfo_get_last_update(this.ptr);
51                 Reference.reachabilityFence(this);
52                 return ret;
53         }
54
55         /**
56          * When the last known update to the node state was issued.
57          * Value is opaque, as set in the announcement.
58          */
59         public void set_last_update(int val) {
60                 bindings.NodeAnnouncementInfo_set_last_update(this.ptr, val);
61                 Reference.reachabilityFence(this);
62                 Reference.reachabilityFence(val);
63         }
64
65         /**
66          * Color assigned to the node
67          */
68         public byte[] get_rgb() {
69                 byte[] ret = bindings.NodeAnnouncementInfo_get_rgb(this.ptr);
70                 Reference.reachabilityFence(this);
71                 return ret;
72         }
73
74         /**
75          * Color assigned to the node
76          */
77         public void set_rgb(byte[] val) {
78                 bindings.NodeAnnouncementInfo_set_rgb(this.ptr, InternalUtils.check_arr_len(val, 3));
79                 Reference.reachabilityFence(this);
80                 Reference.reachabilityFence(val);
81         }
82
83         /**
84          * Moniker assigned to the node.
85          * May be invalid or malicious (eg control chars),
86          * should not be exposed to the user.
87          */
88         public NodeAlias get_alias() {
89                 long ret = bindings.NodeAnnouncementInfo_get_alias(this.ptr);
90                 Reference.reachabilityFence(this);
91                 if (ret >= 0 && ret <= 4096) { return null; }
92                 org.ldk.structs.NodeAlias ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeAlias(null, ret); }
93                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
94                 return ret_hu_conv;
95         }
96
97         /**
98          * Moniker assigned to the node.
99          * May be invalid or malicious (eg control chars),
100          * should not be exposed to the user.
101          */
102         public void set_alias(org.ldk.structs.NodeAlias val) {
103                 bindings.NodeAnnouncementInfo_set_alias(this.ptr, val == null ? 0 : val.ptr);
104                 Reference.reachabilityFence(this);
105                 Reference.reachabilityFence(val);
106                 if (this != null) { this.ptrs_to.add(val); };
107         }
108
109         /**
110          * Internet-level addresses via which one can connect to the node
111          * 
112          * Returns a copy of the field.
113          */
114         public NetAddress[] get_addresses() {
115                 long[] ret = bindings.NodeAnnouncementInfo_get_addresses(this.ptr);
116                 Reference.reachabilityFence(this);
117                 int ret_conv_12_len = ret.length;
118                 NetAddress[] ret_conv_12_arr = new NetAddress[ret_conv_12_len];
119                 for (int m = 0; m < ret_conv_12_len; m++) {
120                         long ret_conv_12 = ret[m];
121                         org.ldk.structs.NetAddress ret_conv_12_hu_conv = org.ldk.structs.NetAddress.constr_from_ptr(ret_conv_12);
122                         if (ret_conv_12_hu_conv != null) { ret_conv_12_hu_conv.ptrs_to.add(this); };
123                         ret_conv_12_arr[m] = ret_conv_12_hu_conv;
124                 }
125                 return ret_conv_12_arr;
126         }
127
128         /**
129          * Internet-level addresses via which one can connect to the node
130          */
131         public void set_addresses(NetAddress[] val) {
132                 bindings.NodeAnnouncementInfo_set_addresses(this.ptr, val != null ? Arrays.stream(val).mapToLong(val_conv_12 -> val_conv_12.ptr).toArray() : null);
133                 Reference.reachabilityFence(this);
134                 Reference.reachabilityFence(val);
135                 for (NetAddress val_conv_12: val) { if (this != null) { this.ptrs_to.add(val_conv_12); }; };
136         }
137
138         /**
139          * An initial announcement of the node
140          * Mostly redundant with the data we store in fields explicitly.
141          * Everything else is useful only for sending out for initial routing sync.
142          * Not stored if contains excess data to prevent DoS.
143          * 
144          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
145          */
146         @Nullable
147         public NodeAnnouncement get_announcement_message() {
148                 long ret = bindings.NodeAnnouncementInfo_get_announcement_message(this.ptr);
149                 Reference.reachabilityFence(this);
150                 if (ret >= 0 && ret <= 4096) { return null; }
151                 org.ldk.structs.NodeAnnouncement ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeAnnouncement(null, ret); }
152                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
153                 return ret_hu_conv;
154         }
155
156         /**
157          * An initial announcement of the node
158          * Mostly redundant with the data we store in fields explicitly.
159          * Everything else is useful only for sending out for initial routing sync.
160          * Not stored if contains excess data to prevent DoS.
161          * 
162          * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
163          */
164         public void set_announcement_message(@Nullable org.ldk.structs.NodeAnnouncement val) {
165                 bindings.NodeAnnouncementInfo_set_announcement_message(this.ptr, val == null ? 0 : val.ptr);
166                 Reference.reachabilityFence(this);
167                 Reference.reachabilityFence(val);
168                 if (this != null) { this.ptrs_to.add(val); };
169         }
170
171         /**
172          * Constructs a new NodeAnnouncementInfo given each field
173          */
174         public static NodeAnnouncementInfo of(org.ldk.structs.NodeFeatures features_arg, int last_update_arg, byte[] rgb_arg, org.ldk.structs.NodeAlias alias_arg, NetAddress[] addresses_arg, org.ldk.structs.NodeAnnouncement announcement_message_arg) {
175                 long ret = bindings.NodeAnnouncementInfo_new(features_arg == null ? 0 : features_arg.ptr, last_update_arg, InternalUtils.check_arr_len(rgb_arg, 3), alias_arg == null ? 0 : alias_arg.ptr, addresses_arg != null ? Arrays.stream(addresses_arg).mapToLong(addresses_arg_conv_12 -> addresses_arg_conv_12.ptr).toArray() : null, announcement_message_arg == null ? 0 : announcement_message_arg.ptr);
176                 Reference.reachabilityFence(features_arg);
177                 Reference.reachabilityFence(last_update_arg);
178                 Reference.reachabilityFence(rgb_arg);
179                 Reference.reachabilityFence(alias_arg);
180                 Reference.reachabilityFence(addresses_arg);
181                 Reference.reachabilityFence(announcement_message_arg);
182                 if (ret >= 0 && ret <= 4096) { return null; }
183                 org.ldk.structs.NodeAnnouncementInfo ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeAnnouncementInfo(null, ret); }
184                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
185                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(features_arg); };
186                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(alias_arg); };
187                 for (NetAddress addresses_arg_conv_12: addresses_arg) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(addresses_arg_conv_12); }; };
188                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(announcement_message_arg); };
189                 return ret_hu_conv;
190         }
191
192         long clone_ptr() {
193                 long ret = bindings.NodeAnnouncementInfo_clone_ptr(this.ptr);
194                 Reference.reachabilityFence(this);
195                 return ret;
196         }
197
198         /**
199          * Creates a copy of the NodeAnnouncementInfo
200          */
201         public NodeAnnouncementInfo clone() {
202                 long ret = bindings.NodeAnnouncementInfo_clone(this.ptr);
203                 Reference.reachabilityFence(this);
204                 if (ret >= 0 && ret <= 4096) { return null; }
205                 org.ldk.structs.NodeAnnouncementInfo ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeAnnouncementInfo(null, ret); }
206                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
207                 return ret_hu_conv;
208         }
209
210         /**
211          * Checks if two NodeAnnouncementInfos contain equal inner contents.
212          * This ignores pointers and is_owned flags and looks at the values in fields.
213          * Two objects with NULL inner values will be considered "equal" here.
214          */
215         public boolean eq(org.ldk.structs.NodeAnnouncementInfo b) {
216                 boolean ret = bindings.NodeAnnouncementInfo_eq(this.ptr, b == null ? 0 : b.ptr);
217                 Reference.reachabilityFence(this);
218                 Reference.reachabilityFence(b);
219                 if (this != null) { this.ptrs_to.add(b); };
220                 return ret;
221         }
222
223         @Override public boolean equals(Object o) {
224                 if (!(o instanceof NodeAnnouncementInfo)) return false;
225                 return this.eq((NodeAnnouncementInfo)o);
226         }
227         /**
228          * Serialize the NodeAnnouncementInfo object into a byte array which can be read by NodeAnnouncementInfo_read
229          */
230         public byte[] write() {
231                 byte[] ret = bindings.NodeAnnouncementInfo_write(this.ptr);
232                 Reference.reachabilityFence(this);
233                 return ret;
234         }
235
236         /**
237          * Read a NodeAnnouncementInfo from a byte array, created by NodeAnnouncementInfo_write
238          */
239         public static Result_NodeAnnouncementInfoDecodeErrorZ read(byte[] ser) {
240                 long ret = bindings.NodeAnnouncementInfo_read(ser);
241                 Reference.reachabilityFence(ser);
242                 if (ret >= 0 && ret <= 4096) { return null; }
243                 Result_NodeAnnouncementInfoDecodeErrorZ ret_hu_conv = Result_NodeAnnouncementInfoDecodeErrorZ.constr_from_ptr(ret);
244                 return ret_hu_conv;
245         }
246
247 }