[Java] Update auto-generated bindings
[ldk-java] / src / main / java / org / ldk / structs / RoutingMessageHandler.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  * A trait to describe an object which can receive routing messages.
12  * 
13  * # Implementor DoS Warnings
14  * 
15  * For `gossip_queries` messages there are potential DoS vectors when handling
16  * inbound queries. Implementors using an on-disk network graph should be aware of
17  * repeated disk I/O for queries accessing different parts of the network graph.
18  */
19 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
20 public class RoutingMessageHandler extends CommonBase {
21         final bindings.LDKRoutingMessageHandler bindings_instance;
22         RoutingMessageHandler(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
23         private RoutingMessageHandler(bindings.LDKRoutingMessageHandler arg, bindings.LDKMessageSendEventsProvider MessageSendEventsProvider) {
24                 super(bindings.LDKRoutingMessageHandler_new(arg, MessageSendEventsProvider));
25                 this.ptrs_to.add(arg);
26                 this.ptrs_to.add(MessageSendEventsProvider);
27                 this.bindings_instance = arg;
28         }
29         @Override @SuppressWarnings("deprecation")
30         protected void finalize() throws Throwable {
31                 if (ptr != 0) { bindings.RoutingMessageHandler_free(ptr); } super.finalize();
32         }
33
34         public static interface RoutingMessageHandlerInterface {
35                 /**
36                  * Handle an incoming node_announcement message, returning true if it should be forwarded on,
37                  * false or returning an Err otherwise.
38                  */
39                 Result_boolLightningErrorZ handle_node_announcement(NodeAnnouncement msg);
40                 /**
41                  * Handle a channel_announcement message, returning true if it should be forwarded on, false
42                  * or returning an Err otherwise.
43                  */
44                 Result_boolLightningErrorZ handle_channel_announcement(ChannelAnnouncement msg);
45                 /**
46                  * Handle an incoming channel_update message, returning true if it should be forwarded on,
47                  * false or returning an Err otherwise.
48                  */
49                 Result_boolLightningErrorZ handle_channel_update(ChannelUpdate msg);
50                 /**
51                  * Gets a subset of the channel announcements and updates required to dump our routing table
52                  * to a remote node, starting at the short_channel_id indicated by starting_point and
53                  * including the batch_amount entries immediately higher in numerical value than starting_point.
54                  */
55                 ThreeTuple_ChannelAnnouncementChannelUpdateChannelUpdateZ[] get_next_channel_announcements(long starting_point, byte batch_amount);
56                 /**
57                  * Gets a subset of the node announcements required to dump our routing table to a remote node,
58                  * starting at the node *after* the provided publickey and including batch_amount entries
59                  * immediately higher (as defined by <PublicKey as Ord>::cmp) than starting_point.
60                  * If None is provided for starting_point, we start at the first node.
61                  * 
62                  * Note that starting_point (or a relevant inner pointer) may be NULL or all-0s to represent None
63                  */
64                 NodeAnnouncement[] get_next_node_announcements(byte[] starting_point, byte batch_amount);
65                 /**
66                  * Called when a connection is established with a peer. This can be used to
67                  * perform routing table synchronization using a strategy defined by the
68                  * implementor.
69                  */
70                 void peer_connected(byte[] their_node_id, Init init);
71                 /**
72                  * Handles the reply of a query we initiated to learn about channels
73                  * for a given range of blocks. We can expect to receive one or more
74                  * replies to a single query.
75                  */
76                 Result_NoneLightningErrorZ handle_reply_channel_range(byte[] their_node_id, ReplyChannelRange msg);
77                 /**
78                  * Handles the reply of a query we initiated asking for routing gossip
79                  * messages for a list of channels. We should receive this message when
80                  * a node has completed its best effort to send us the pertaining routing
81                  * gossip messages.
82                  */
83                 Result_NoneLightningErrorZ handle_reply_short_channel_ids_end(byte[] their_node_id, ReplyShortChannelIdsEnd msg);
84                 /**
85                  * Handles when a peer asks us to send a list of short_channel_ids
86                  * for the requested range of blocks.
87                  */
88                 Result_NoneLightningErrorZ handle_query_channel_range(byte[] their_node_id, QueryChannelRange msg);
89                 /**
90                  * Handles when a peer asks us to send routing gossip messages for a
91                  * list of short_channel_ids.
92                  */
93                 Result_NoneLightningErrorZ handle_query_short_channel_ids(byte[] their_node_id, QueryShortChannelIds msg);
94         }
95         private static class LDKRoutingMessageHandlerHolder { RoutingMessageHandler held; }
96         public static RoutingMessageHandler new_impl(RoutingMessageHandlerInterface arg, MessageSendEventsProvider.MessageSendEventsProviderInterface MessageSendEventsProvider_impl) {
97                 final LDKRoutingMessageHandlerHolder impl_holder = new LDKRoutingMessageHandlerHolder();
98                 impl_holder.held = new RoutingMessageHandler(new bindings.LDKRoutingMessageHandler() {
99                         @Override public long handle_node_announcement(long msg) {
100                                 NodeAnnouncement msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new NodeAnnouncement(null, msg); }
101                                 Result_boolLightningErrorZ ret = arg.handle_node_announcement(msg_hu_conv);
102                                 Reference.reachabilityFence(arg);
103                                 long result = ret == null ? 0 : ret.clone_ptr();
104                                 return result;
105                         }
106                         @Override public long handle_channel_announcement(long msg) {
107                                 ChannelAnnouncement msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new ChannelAnnouncement(null, msg); }
108                                 Result_boolLightningErrorZ ret = arg.handle_channel_announcement(msg_hu_conv);
109                                 Reference.reachabilityFence(arg);
110                                 long result = ret == null ? 0 : ret.clone_ptr();
111                                 return result;
112                         }
113                         @Override public long handle_channel_update(long msg) {
114                                 ChannelUpdate msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new ChannelUpdate(null, msg); }
115                                 Result_boolLightningErrorZ ret = arg.handle_channel_update(msg_hu_conv);
116                                 Reference.reachabilityFence(arg);
117                                 long result = ret == null ? 0 : ret.clone_ptr();
118                                 return result;
119                         }
120                         @Override public long[] get_next_channel_announcements(long starting_point, byte batch_amount) {
121                                 ThreeTuple_ChannelAnnouncementChannelUpdateChannelUpdateZ[] ret = arg.get_next_channel_announcements(starting_point, batch_amount);
122                                 Reference.reachabilityFence(arg);
123                                 long[] result = ret != null ? Arrays.stream(ret).mapToLong(ret_conv_59 -> ret_conv_59 == null ? 0 : ret_conv_59.clone_ptr()).toArray() : null;
124                                 return result;
125                         }
126                         @Override public long[] get_next_node_announcements(byte[] starting_point, byte batch_amount) {
127                                 NodeAnnouncement[] ret = arg.get_next_node_announcements(starting_point, batch_amount);
128                                 Reference.reachabilityFence(arg);
129                                 long[] result = ret != null ? Arrays.stream(ret).mapToLong(ret_conv_18 -> ret_conv_18 == null ? 0 : ret_conv_18.clone_ptr()).toArray() : null;
130                                 return result;
131                         }
132                         @Override public void peer_connected(byte[] their_node_id, long init) {
133                                 Init init_hu_conv = null; if (init < 0 || init > 4096) { init_hu_conv = new Init(null, init); }
134                                 arg.peer_connected(their_node_id, init_hu_conv);
135                                 Reference.reachabilityFence(arg);
136                         }
137                         @Override public long handle_reply_channel_range(byte[] their_node_id, long msg) {
138                                 ReplyChannelRange msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new ReplyChannelRange(null, msg); }
139                                 msg_hu_conv.ptrs_to.add(this);
140                                 Result_NoneLightningErrorZ ret = arg.handle_reply_channel_range(their_node_id, msg_hu_conv);
141                                 Reference.reachabilityFence(arg);
142                                 long result = ret == null ? 0 : ret.clone_ptr();
143                                 return result;
144                         }
145                         @Override public long handle_reply_short_channel_ids_end(byte[] their_node_id, long msg) {
146                                 ReplyShortChannelIdsEnd msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new ReplyShortChannelIdsEnd(null, msg); }
147                                 msg_hu_conv.ptrs_to.add(this);
148                                 Result_NoneLightningErrorZ ret = arg.handle_reply_short_channel_ids_end(their_node_id, msg_hu_conv);
149                                 Reference.reachabilityFence(arg);
150                                 long result = ret == null ? 0 : ret.clone_ptr();
151                                 return result;
152                         }
153                         @Override public long handle_query_channel_range(byte[] their_node_id, long msg) {
154                                 QueryChannelRange msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new QueryChannelRange(null, msg); }
155                                 msg_hu_conv.ptrs_to.add(this);
156                                 Result_NoneLightningErrorZ ret = arg.handle_query_channel_range(their_node_id, msg_hu_conv);
157                                 Reference.reachabilityFence(arg);
158                                 long result = ret == null ? 0 : ret.clone_ptr();
159                                 return result;
160                         }
161                         @Override public long handle_query_short_channel_ids(byte[] their_node_id, long msg) {
162                                 QueryShortChannelIds msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new QueryShortChannelIds(null, msg); }
163                                 msg_hu_conv.ptrs_to.add(this);
164                                 Result_NoneLightningErrorZ ret = arg.handle_query_short_channel_ids(their_node_id, msg_hu_conv);
165                                 Reference.reachabilityFence(arg);
166                                 long result = ret == null ? 0 : ret.clone_ptr();
167                                 return result;
168                         }
169                 }, MessageSendEventsProvider.new_impl(MessageSendEventsProvider_impl).bindings_instance);
170                 return impl_holder.held;
171         }
172
173         /**
174          * Gets the underlying MessageSendEventsProvider.
175          */
176         public MessageSendEventsProvider get_message_send_events_provider() {
177                 MessageSendEventsProvider res = new MessageSendEventsProvider(null, bindings.LDKRoutingMessageHandler_get_MessageSendEventsProvider(this.ptr));
178                 this.ptrs_to.add(res);
179                 return res;
180         }
181
182         /**
183          * Handle an incoming node_announcement message, returning true if it should be forwarded on,
184          * false or returning an Err otherwise.
185          */
186         public Result_boolLightningErrorZ handle_node_announcement(NodeAnnouncement msg) {
187                 long ret = bindings.RoutingMessageHandler_handle_node_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1);
188                 Reference.reachabilityFence(this);
189                 Reference.reachabilityFence(msg);
190                 if (ret >= 0 && ret <= 4096) { return null; }
191                 Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret);
192                 this.ptrs_to.add(msg);
193                 return ret_hu_conv;
194         }
195
196         /**
197          * Handle a channel_announcement message, returning true if it should be forwarded on, false
198          * or returning an Err otherwise.
199          */
200         public Result_boolLightningErrorZ handle_channel_announcement(ChannelAnnouncement msg) {
201                 long ret = bindings.RoutingMessageHandler_handle_channel_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1);
202                 Reference.reachabilityFence(this);
203                 Reference.reachabilityFence(msg);
204                 if (ret >= 0 && ret <= 4096) { return null; }
205                 Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret);
206                 this.ptrs_to.add(msg);
207                 return ret_hu_conv;
208         }
209
210         /**
211          * Handle an incoming channel_update message, returning true if it should be forwarded on,
212          * false or returning an Err otherwise.
213          */
214         public Result_boolLightningErrorZ handle_channel_update(ChannelUpdate msg) {
215                 long ret = bindings.RoutingMessageHandler_handle_channel_update(this.ptr, msg == null ? 0 : msg.ptr & ~1);
216                 Reference.reachabilityFence(this);
217                 Reference.reachabilityFence(msg);
218                 if (ret >= 0 && ret <= 4096) { return null; }
219                 Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret);
220                 this.ptrs_to.add(msg);
221                 return ret_hu_conv;
222         }
223
224         /**
225          * Gets a subset of the channel announcements and updates required to dump our routing table
226          * to a remote node, starting at the short_channel_id indicated by starting_point and
227          * including the batch_amount entries immediately higher in numerical value than starting_point.
228          */
229         public ThreeTuple_ChannelAnnouncementChannelUpdateChannelUpdateZ[] get_next_channel_announcements(long starting_point, byte batch_amount) {
230                 long[] ret = bindings.RoutingMessageHandler_get_next_channel_announcements(this.ptr, starting_point, batch_amount);
231                 Reference.reachabilityFence(this);
232                 Reference.reachabilityFence(starting_point);
233                 Reference.reachabilityFence(batch_amount);
234                 int ret_conv_59_len = ret.length;
235                 ThreeTuple_ChannelAnnouncementChannelUpdateChannelUpdateZ[] ret_conv_59_arr = new ThreeTuple_ChannelAnnouncementChannelUpdateChannelUpdateZ[ret_conv_59_len];
236                 for (int h = 0; h < ret_conv_59_len; h++) {
237                         long ret_conv_59 = ret[h];
238                         ThreeTuple_ChannelAnnouncementChannelUpdateChannelUpdateZ ret_conv_59_hu_conv = new ThreeTuple_ChannelAnnouncementChannelUpdateChannelUpdateZ(null, ret_conv_59);
239                         ret_conv_59_hu_conv.ptrs_to.add(this);
240                         ret_conv_59_arr[h] = ret_conv_59_hu_conv;
241                 }
242                 return ret_conv_59_arr;
243         }
244
245         /**
246          * Gets a subset of the node announcements required to dump our routing table to a remote node,
247          * starting at the node *after* the provided publickey and including batch_amount entries
248          * immediately higher (as defined by <PublicKey as Ord>::cmp) than starting_point.
249          * If None is provided for starting_point, we start at the first node.
250          * 
251          * Note that starting_point (or a relevant inner pointer) may be NULL or all-0s to represent None
252          */
253         public NodeAnnouncement[] get_next_node_announcements(@Nullable byte[] starting_point, byte batch_amount) {
254                 long[] ret = bindings.RoutingMessageHandler_get_next_node_announcements(this.ptr, InternalUtils.check_arr_len(starting_point, 33), batch_amount);
255                 Reference.reachabilityFence(this);
256                 Reference.reachabilityFence(starting_point);
257                 Reference.reachabilityFence(batch_amount);
258                 int ret_conv_18_len = ret.length;
259                 NodeAnnouncement[] ret_conv_18_arr = new NodeAnnouncement[ret_conv_18_len];
260                 for (int s = 0; s < ret_conv_18_len; s++) {
261                         long ret_conv_18 = ret[s];
262                         NodeAnnouncement ret_conv_18_hu_conv = null; if (ret_conv_18 < 0 || ret_conv_18 > 4096) { ret_conv_18_hu_conv = new NodeAnnouncement(null, ret_conv_18); }
263                         ret_conv_18_hu_conv.ptrs_to.add(this);
264                         ret_conv_18_arr[s] = ret_conv_18_hu_conv;
265                 }
266                 return ret_conv_18_arr;
267         }
268
269         /**
270          * Called when a connection is established with a peer. This can be used to
271          * perform routing table synchronization using a strategy defined by the
272          * implementor.
273          */
274         public void peer_connected(byte[] their_node_id, Init init) {
275                 bindings.RoutingMessageHandler_peer_connected(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), init == null ? 0 : init.ptr & ~1);
276                 Reference.reachabilityFence(this);
277                 Reference.reachabilityFence(their_node_id);
278                 Reference.reachabilityFence(init);
279                 this.ptrs_to.add(init);
280         }
281
282         /**
283          * Handles the reply of a query we initiated to learn about channels
284          * for a given range of blocks. We can expect to receive one or more
285          * replies to a single query.
286          */
287         public Result_NoneLightningErrorZ handle_reply_channel_range(byte[] their_node_id, ReplyChannelRange msg) {
288                 long ret = bindings.RoutingMessageHandler_handle_reply_channel_range(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr & ~1);
289                 Reference.reachabilityFence(this);
290                 Reference.reachabilityFence(their_node_id);
291                 Reference.reachabilityFence(msg);
292                 if (ret >= 0 && ret <= 4096) { return null; }
293                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
294                 return ret_hu_conv;
295         }
296
297         /**
298          * Handles the reply of a query we initiated asking for routing gossip
299          * messages for a list of channels. We should receive this message when
300          * a node has completed its best effort to send us the pertaining routing
301          * gossip messages.
302          */
303         public Result_NoneLightningErrorZ handle_reply_short_channel_ids_end(byte[] their_node_id, ReplyShortChannelIdsEnd msg) {
304                 long ret = bindings.RoutingMessageHandler_handle_reply_short_channel_ids_end(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr & ~1);
305                 Reference.reachabilityFence(this);
306                 Reference.reachabilityFence(their_node_id);
307                 Reference.reachabilityFence(msg);
308                 if (ret >= 0 && ret <= 4096) { return null; }
309                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
310                 return ret_hu_conv;
311         }
312
313         /**
314          * Handles when a peer asks us to send a list of short_channel_ids
315          * for the requested range of blocks.
316          */
317         public Result_NoneLightningErrorZ handle_query_channel_range(byte[] their_node_id, QueryChannelRange msg) {
318                 long ret = bindings.RoutingMessageHandler_handle_query_channel_range(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr & ~1);
319                 Reference.reachabilityFence(this);
320                 Reference.reachabilityFence(their_node_id);
321                 Reference.reachabilityFence(msg);
322                 if (ret >= 0 && ret <= 4096) { return null; }
323                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
324                 return ret_hu_conv;
325         }
326
327         /**
328          * Handles when a peer asks us to send routing gossip messages for a
329          * list of short_channel_ids.
330          */
331         public Result_NoneLightningErrorZ handle_query_short_channel_ids(byte[] their_node_id, QueryShortChannelIds msg) {
332                 long ret = bindings.RoutingMessageHandler_handle_query_short_channel_ids(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr & ~1);
333                 Reference.reachabilityFence(this);
334                 Reference.reachabilityFence(their_node_id);
335                 Reference.reachabilityFence(msg);
336                 if (ret >= 0 && ret <= 4096) { return null; }
337                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
338                 return ret_hu_conv;
339         }
340
341 }