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