Update auto-generated bindings to 0.0.101
[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<ChannelAnnouncement, ChannelUpdate, ChannelUpdate>[] 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 = new NodeAnnouncement(null, msg);
100                                 Result_boolLightningErrorZ ret = arg.handle_node_announcement(msg_hu_conv);
101                                 long result = ret != null ? ret.ptr : 0;
102                                 return result;
103                         }
104                         @Override public long handle_channel_announcement(long msg) {
105                                 ChannelAnnouncement msg_hu_conv = new ChannelAnnouncement(null, msg);
106                                 Result_boolLightningErrorZ ret = arg.handle_channel_announcement(msg_hu_conv);
107                                 long result = ret != null ? ret.ptr : 0;
108                                 return result;
109                         }
110                         @Override public long handle_channel_update(long msg) {
111                                 ChannelUpdate msg_hu_conv = new ChannelUpdate(null, msg);
112                                 Result_boolLightningErrorZ ret = arg.handle_channel_update(msg_hu_conv);
113                                 long result = ret != null ? ret.ptr : 0;
114                                 return result;
115                         }
116                         @Override public long[] get_next_channel_announcements(long starting_point, byte batch_amount) {
117                                 ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate>[] ret = arg.get_next_channel_announcements(starting_point, batch_amount);
118                                 long[] result = ret != null ? Arrays.stream(ret).mapToLong(ret_conv_63 -> bindings.C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_new(ret_conv_63.a == null ? 0 : ret_conv_63.a.ptr & ~1, ret_conv_63.b == null ? 0 : ret_conv_63.b.ptr & ~1, ret_conv_63.c == null ? 0 : ret_conv_63.c.ptr & ~1)).toArray() : null;
119                                 for (ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate> ret_conv_63: ret) { impl_holder.held.ptrs_to.add(ret_conv_63.a); impl_holder.held.ptrs_to.add(ret_conv_63.b); impl_holder.held.ptrs_to.add(ret_conv_63.c); };
120                                 return result;
121                         }
122                         @Override public long[] get_next_node_announcements(byte[] starting_point, byte batch_amount) {
123                                 NodeAnnouncement[] ret = arg.get_next_node_announcements(starting_point, batch_amount);
124                                 long[] result = ret != null ? Arrays.stream(ret).mapToLong(ret_conv_18 -> ret_conv_18 == null ? 0 : ret_conv_18.ptr & ~1).toArray() : null;
125                                 for (NodeAnnouncement ret_conv_18: ret) { impl_holder.held.ptrs_to.add(ret_conv_18); };
126                                 return result;
127                         }
128                         @Override public void sync_routing_table(byte[] their_node_id, long init) {
129                                 Init init_hu_conv = new Init(null, init);
130                                 arg.sync_routing_table(their_node_id, init_hu_conv);
131                         }
132                         @Override public long handle_reply_channel_range(byte[] their_node_id, long msg) {
133                                 ReplyChannelRange msg_hu_conv = new ReplyChannelRange(null, msg);
134                                 msg_hu_conv.ptrs_to.add(this);
135                                 Result_NoneLightningErrorZ ret = arg.handle_reply_channel_range(their_node_id, msg_hu_conv);
136                                 long result = ret != null ? ret.ptr : 0;
137                                 return result;
138                         }
139                         @Override public long handle_reply_short_channel_ids_end(byte[] their_node_id, long msg) {
140                                 ReplyShortChannelIdsEnd msg_hu_conv = new ReplyShortChannelIdsEnd(null, msg);
141                                 msg_hu_conv.ptrs_to.add(this);
142                                 Result_NoneLightningErrorZ ret = arg.handle_reply_short_channel_ids_end(their_node_id, msg_hu_conv);
143                                 long result = ret != null ? ret.ptr : 0;
144                                 return result;
145                         }
146                         @Override public long handle_query_channel_range(byte[] their_node_id, long msg) {
147                                 QueryChannelRange msg_hu_conv = new QueryChannelRange(null, msg);
148                                 msg_hu_conv.ptrs_to.add(this);
149                                 Result_NoneLightningErrorZ ret = arg.handle_query_channel_range(their_node_id, msg_hu_conv);
150                                 long result = ret != null ? ret.ptr : 0;
151                                 return result;
152                         }
153                         @Override public long handle_query_short_channel_ids(byte[] their_node_id, long msg) {
154                                 QueryShortChannelIds msg_hu_conv = new QueryShortChannelIds(null, msg);
155                                 msg_hu_conv.ptrs_to.add(this);
156                                 Result_NoneLightningErrorZ ret = arg.handle_query_short_channel_ids(their_node_id, msg_hu_conv);
157                                 long result = ret != null ? ret.ptr : 0;
158                                 return result;
159                         }
160                 }, MessageSendEventsProvider.new_impl(MessageSendEventsProvider_impl).bindings_instance);
161                 return impl_holder.held;
162         }
163
164         /**
165          * Gets the underlying MessageSendEventsProvider.
166          */
167         public MessageSendEventsProvider get_message_send_events_provider() {
168                 MessageSendEventsProvider res = new MessageSendEventsProvider(null, bindings.LDKRoutingMessageHandler_get_MessageSendEventsProvider(this.ptr));
169                 this.ptrs_to.add(res);
170                 return res;
171         }
172
173         /**
174          * Handle an incoming node_announcement message, returning true if it should be forwarded on,
175          * false or returning an Err otherwise.
176          */
177         public Result_boolLightningErrorZ handle_node_announcement(NodeAnnouncement msg) {
178                 long ret = bindings.RoutingMessageHandler_handle_node_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1);
179                 if (ret < 1024) { return null; }
180                 Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret);
181                 this.ptrs_to.add(msg);
182                 return ret_hu_conv;
183         }
184
185         /**
186          * Handle a channel_announcement message, returning true if it should be forwarded on, false
187          * or returning an Err otherwise.
188          */
189         public Result_boolLightningErrorZ handle_channel_announcement(ChannelAnnouncement msg) {
190                 long ret = bindings.RoutingMessageHandler_handle_channel_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1);
191                 if (ret < 1024) { return null; }
192                 Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret);
193                 this.ptrs_to.add(msg);
194                 return ret_hu_conv;
195         }
196
197         /**
198          * Handle an incoming channel_update message, returning true if it should be forwarded on,
199          * false or returning an Err otherwise.
200          */
201         public Result_boolLightningErrorZ handle_channel_update(ChannelUpdate msg) {
202                 long ret = bindings.RoutingMessageHandler_handle_channel_update(this.ptr, msg == null ? 0 : msg.ptr & ~1);
203                 if (ret < 1024) { return null; }
204                 Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret);
205                 this.ptrs_to.add(msg);
206                 return ret_hu_conv;
207         }
208
209         /**
210          * Gets a subset of the channel announcements and updates required to dump our routing table
211          * to a remote node, starting at the short_channel_id indicated by starting_point and
212          * including the batch_amount entries immediately higher in numerical value than starting_point.
213          */
214         public ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate>[] get_next_channel_announcements(long starting_point, byte batch_amount) {
215                 long[] ret = bindings.RoutingMessageHandler_get_next_channel_announcements(this.ptr, starting_point, batch_amount);
216                 ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate>[] ret_conv_63_arr = new ThreeTuple[ret.length];
217                 for (int l = 0; l < ret.length; l++) {
218                         long ret_conv_63 = ret[l];
219                         long ret_conv_63_a = bindings.LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_get_a(ret_conv_63);
220                         ChannelAnnouncement ret_conv_63_a_hu_conv = new ChannelAnnouncement(null, ret_conv_63_a);
221                         ret_conv_63_a_hu_conv.ptrs_to.add(this);;
222                         long ret_conv_63_b = bindings.LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_get_b(ret_conv_63);
223                         ChannelUpdate ret_conv_63_b_hu_conv = new ChannelUpdate(null, ret_conv_63_b);
224                         ret_conv_63_b_hu_conv.ptrs_to.add(this);;
225                         long ret_conv_63_c = bindings.LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_get_c(ret_conv_63);
226                         ChannelUpdate ret_conv_63_c_hu_conv = new ChannelUpdate(null, ret_conv_63_c);
227                         ret_conv_63_c_hu_conv.ptrs_to.add(this);;
228                         ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate> ret_conv_63_conv = new ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate>(ret_conv_63_a_hu_conv, ret_conv_63_b_hu_conv, ret_conv_63_c_hu_conv, () -> {
229                                 bindings.C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_free(ret_conv_63);
230                         });
231                         ret_conv_63_a_hu_conv.ptrs_to.add(ret_conv_63_conv);
232                         ret_conv_63_b_hu_conv.ptrs_to.add(ret_conv_63_conv);
233                         ret_conv_63_c_hu_conv.ptrs_to.add(ret_conv_63_conv);
234                         ret_conv_63_arr[l] = ret_conv_63_conv;
235                 }
236                 return ret_conv_63_arr;
237         }
238
239         /**
240          * Gets a subset of the node announcements required to dump our routing table to a remote node,
241          * starting at the node *after* the provided publickey and including batch_amount entries
242          * immediately higher (as defined by <PublicKey as Ord>::cmp) than starting_point.
243          * If None is provided for starting_point, we start at the first node.
244          * 
245          * Note that starting_point (or a relevant inner pointer) may be NULL or all-0s to represent None
246          */
247         public NodeAnnouncement[] get_next_node_announcements(@Nullable byte[] starting_point, byte batch_amount) {
248                 long[] ret = bindings.RoutingMessageHandler_get_next_node_announcements(this.ptr, starting_point, batch_amount);
249                 NodeAnnouncement[] ret_conv_18_arr = new NodeAnnouncement[ret.length];
250                 for (int s = 0; s < ret.length; s++) {
251                         long ret_conv_18 = ret[s];
252                         NodeAnnouncement ret_conv_18_hu_conv = new NodeAnnouncement(null, ret_conv_18);
253                         ret_conv_18_hu_conv.ptrs_to.add(this);
254                         ret_conv_18_arr[s] = ret_conv_18_hu_conv;
255                 }
256                 return ret_conv_18_arr;
257         }
258
259         /**
260          * Called when a connection is established with a peer. This can be used to
261          * perform routing table synchronization using a strategy defined by the
262          * implementor.
263          */
264         public void sync_routing_table(byte[] their_node_id, Init init) {
265                 bindings.RoutingMessageHandler_sync_routing_table(this.ptr, their_node_id, init == null ? 0 : init.ptr & ~1);
266                 this.ptrs_to.add(init);
267         }
268
269         /**
270          * Handles the reply of a query we initiated to learn about channels
271          * for a given range of blocks. We can expect to receive one or more
272          * replies to a single query.
273          */
274         public Result_NoneLightningErrorZ handle_reply_channel_range(byte[] their_node_id, ReplyChannelRange msg) {
275                 long ret = bindings.RoutingMessageHandler_handle_reply_channel_range(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
276                 if (ret < 1024) { return null; }
277                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
278                 this.ptrs_to.add(msg);
279                 return ret_hu_conv;
280         }
281
282         /**
283          * Handles the reply of a query we initiated asking for routing gossip
284          * messages for a list of channels. We should receive this message when
285          * a node has completed its best effort to send us the pertaining routing
286          * gossip messages.
287          */
288         public Result_NoneLightningErrorZ handle_reply_short_channel_ids_end(byte[] their_node_id, ReplyShortChannelIdsEnd msg) {
289                 long ret = bindings.RoutingMessageHandler_handle_reply_short_channel_ids_end(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
290                 if (ret < 1024) { return null; }
291                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
292                 this.ptrs_to.add(msg);
293                 return ret_hu_conv;
294         }
295
296         /**
297          * Handles when a peer asks us to send a list of short_channel_ids
298          * for the requested range of blocks.
299          */
300         public Result_NoneLightningErrorZ handle_query_channel_range(byte[] their_node_id, QueryChannelRange msg) {
301                 long ret = bindings.RoutingMessageHandler_handle_query_channel_range(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
302                 if (ret < 1024) { return null; }
303                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
304                 this.ptrs_to.add(msg);
305                 return ret_hu_conv;
306         }
307
308         /**
309          * Handles when a peer asks us to send routing gossip messages for a
310          * list of short_channel_ids.
311          */
312         public Result_NoneLightningErrorZ handle_query_short_channel_ids(byte[] their_node_id, QueryShortChannelIds msg) {
313                 long ret = bindings.RoutingMessageHandler_handle_query_short_channel_ids(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
314                 if (ret < 1024) { return null; }
315                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
316                 this.ptrs_to.add(msg);
317                 return ret_hu_conv;
318         }
319
320 }