Update java bindings with new generator and new upstream code
[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
8 /**
9  * A trait to describe an object which can receive routing messages.
10  * 
11  * # Implementor DoS Warnings
12  * 
13  * For `gossip_queries` messages there are potential DoS vectors when handling
14  * inbound queries. Implementors using an on-disk network graph should be aware of
15  * repeated disk I/O for queries accessing different parts of the network graph.
16  */
17 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
18 public class RoutingMessageHandler extends CommonBase {
19         final bindings.LDKRoutingMessageHandler bindings_instance;
20         RoutingMessageHandler(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
21         private RoutingMessageHandler(bindings.LDKRoutingMessageHandler arg, bindings.LDKMessageSendEventsProvider MessageSendEventsProvider) {
22                 super(bindings.LDKRoutingMessageHandler_new(arg, MessageSendEventsProvider));
23                 this.ptrs_to.add(arg);
24                 this.ptrs_to.add(MessageSendEventsProvider);
25                 this.bindings_instance = arg;
26         }
27         @Override @SuppressWarnings("deprecation")
28         protected void finalize() throws Throwable {
29                 if (ptr != 0) { bindings.RoutingMessageHandler_free(ptr); } super.finalize();
30         }
31
32         public static interface RoutingMessageHandlerInterface {
33                 /**
34                  * Handle an incoming node_announcement message, returning true if it should be forwarded on,
35                  * false or returning an Err otherwise.
36                  */
37                 Result_boolLightningErrorZ handle_node_announcement(NodeAnnouncement msg);
38                 /**
39                  * Handle a channel_announcement message, returning true if it should be forwarded on, false
40                  * or returning an Err otherwise.
41                  */
42                 Result_boolLightningErrorZ handle_channel_announcement(ChannelAnnouncement msg);
43                 /**
44                  * Handle an incoming channel_update message, returning true if it should be forwarded on,
45                  * false or returning an Err otherwise.
46                  */
47                 Result_boolLightningErrorZ handle_channel_update(ChannelUpdate msg);
48                 /**
49                  * Handle some updates to the route graph that we learned due to an outbound failed payment.
50                  */
51                 void handle_htlc_fail_channel_update(HTLCFailChannelUpdate update);
52                 /**
53                  * Gets a subset of the channel announcements and updates required to dump our routing table
54                  * to a remote node, starting at the short_channel_id indicated by starting_point and
55                  * including the batch_amount entries immediately higher in numerical value than starting_point.
56                  */
57                 ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate>[] get_next_channel_announcements(long starting_point, byte batch_amount);
58                 /**
59                  * Gets a subset of the node announcements required to dump our routing table to a remote node,
60                  * starting at the node *after* the provided publickey and including batch_amount entries
61                  * immediately higher (as defined by <PublicKey as Ord>::cmp) than starting_point.
62                  * If None is provided for starting_point, we start at the first node.
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 sync_routing_table(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 = new NodeAnnouncement(null, msg);
101                                 Result_boolLightningErrorZ ret = arg.handle_node_announcement(msg_hu_conv);
102                                 long result = ret != null ? ret.ptr : 0;
103                                 return result;
104                         }
105                         @Override public long handle_channel_announcement(long msg) {
106                                 ChannelAnnouncement msg_hu_conv = new ChannelAnnouncement(null, msg);
107                                 Result_boolLightningErrorZ ret = arg.handle_channel_announcement(msg_hu_conv);
108                                 long result = ret != null ? ret.ptr : 0;
109                                 return result;
110                         }
111                         @Override public long handle_channel_update(long msg) {
112                                 ChannelUpdate msg_hu_conv = new ChannelUpdate(null, msg);
113                                 Result_boolLightningErrorZ ret = arg.handle_channel_update(msg_hu_conv);
114                                 long result = ret != null ? ret.ptr : 0;
115                                 return result;
116                         }
117                         @Override public void handle_htlc_fail_channel_update(long update) {
118                                 HTLCFailChannelUpdate update_hu_conv = HTLCFailChannelUpdate.constr_from_ptr(update);
119                                 arg.handle_htlc_fail_channel_update(update_hu_conv);
120                         }
121                         @Override public long[] get_next_channel_announcements(long starting_point, byte batch_amount) {
122                                 ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate>[] ret = arg.get_next_channel_announcements(starting_point, batch_amount);
123                                 long[] result = 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();
124                                 /* TODO 2 ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate>  */;
125                                 return result;
126                         }
127                         @Override public long[] get_next_node_announcements(byte[] starting_point, byte batch_amount) {
128                                 NodeAnnouncement[] ret = arg.get_next_node_announcements(starting_point, batch_amount);
129                                 long[] result = Arrays.stream(ret).mapToLong(ret_conv_18 -> ret_conv_18 == null ? 0 : ret_conv_18.ptr & ~1).toArray();
130                                 /* TODO 2 NodeAnnouncement  */;
131                                 return result;
132                         }
133                         @Override public void sync_routing_table(byte[] their_node_id, long init) {
134                                 Init init_hu_conv = new Init(null, init);
135                                 arg.sync_routing_table(their_node_id, init_hu_conv);
136                         }
137                         @Override public long handle_reply_channel_range(byte[] their_node_id, long msg) {
138                                 ReplyChannelRange 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                                 long result = ret != null ? ret.ptr : 0;
142                                 return result;
143                         }
144                         @Override public long handle_reply_short_channel_ids_end(byte[] their_node_id, long msg) {
145                                 ReplyShortChannelIdsEnd msg_hu_conv = new ReplyShortChannelIdsEnd(null, msg);
146                                 msg_hu_conv.ptrs_to.add(this);
147                                 Result_NoneLightningErrorZ ret = arg.handle_reply_short_channel_ids_end(their_node_id, msg_hu_conv);
148                                 long result = ret != null ? ret.ptr : 0;
149                                 return result;
150                         }
151                         @Override public long handle_query_channel_range(byte[] their_node_id, long msg) {
152                                 QueryChannelRange msg_hu_conv = new QueryChannelRange(null, msg);
153                                 msg_hu_conv.ptrs_to.add(this);
154                                 Result_NoneLightningErrorZ ret = arg.handle_query_channel_range(their_node_id, msg_hu_conv);
155                                 long result = ret != null ? ret.ptr : 0;
156                                 return result;
157                         }
158                         @Override public long handle_query_short_channel_ids(byte[] their_node_id, long msg) {
159                                 QueryShortChannelIds msg_hu_conv = new QueryShortChannelIds(null, msg);
160                                 msg_hu_conv.ptrs_to.add(this);
161                                 Result_NoneLightningErrorZ ret = arg.handle_query_short_channel_ids(their_node_id, msg_hu_conv);
162                                 long result = ret != null ? ret.ptr : 0;
163                                 return result;
164                         }
165                 }, MessageSendEventsProvider.new_impl(MessageSendEventsProvider_impl).bindings_instance);
166                 return impl_holder.held;
167         }
168         /**
169          * Handle an incoming node_announcement message, returning true if it should be forwarded on,
170          * false or returning an Err otherwise.
171          */
172         public Result_boolLightningErrorZ handle_node_announcement(NodeAnnouncement msg) {
173                 long ret = bindings.RoutingMessageHandler_handle_node_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1);
174                 Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret);
175                 this.ptrs_to.add(msg);
176                 return ret_hu_conv;
177         }
178
179         /**
180          * Handle a channel_announcement message, returning true if it should be forwarded on, false
181          * or returning an Err otherwise.
182          */
183         public Result_boolLightningErrorZ handle_channel_announcement(ChannelAnnouncement msg) {
184                 long ret = bindings.RoutingMessageHandler_handle_channel_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1);
185                 Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret);
186                 this.ptrs_to.add(msg);
187                 return ret_hu_conv;
188         }
189
190         /**
191          * Handle an incoming channel_update message, returning true if it should be forwarded on,
192          * false or returning an Err otherwise.
193          */
194         public Result_boolLightningErrorZ handle_channel_update(ChannelUpdate msg) {
195                 long ret = bindings.RoutingMessageHandler_handle_channel_update(this.ptr, msg == null ? 0 : msg.ptr & ~1);
196                 Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret);
197                 this.ptrs_to.add(msg);
198                 return ret_hu_conv;
199         }
200
201         /**
202          * Handle some updates to the route graph that we learned due to an outbound failed payment.
203          */
204         public void handle_htlc_fail_channel_update(HTLCFailChannelUpdate update) {
205                 bindings.RoutingMessageHandler_handle_htlc_fail_channel_update(this.ptr, update == null ? 0 : update.ptr & ~1);
206                 this.ptrs_to.add(update);
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         public NodeAnnouncement[] get_next_node_announcements(byte[] starting_point, byte batch_amount) {
246                 long[] ret = bindings.RoutingMessageHandler_get_next_node_announcements(this.ptr, starting_point, batch_amount);
247                 NodeAnnouncement[] ret_conv_18_arr = new NodeAnnouncement[ret.length];
248                 for (int s = 0; s < ret.length; s++) {
249                         long ret_conv_18 = ret[s];
250                         NodeAnnouncement ret_conv_18_hu_conv = new NodeAnnouncement(null, ret_conv_18);
251                         ret_conv_18_hu_conv.ptrs_to.add(this);
252                         ret_conv_18_arr[s] = ret_conv_18_hu_conv;
253                 }
254                 return ret_conv_18_arr;
255         }
256
257         /**
258          * Called when a connection is established with a peer. This can be used to
259          * perform routing table synchronization using a strategy defined by the
260          * implementor.
261          */
262         public void sync_routing_table(byte[] their_node_id, Init init) {
263                 bindings.RoutingMessageHandler_sync_routing_table(this.ptr, their_node_id, init == null ? 0 : init.ptr & ~1);
264                 this.ptrs_to.add(init);
265         }
266
267         /**
268          * Handles the reply of a query we initiated to learn about channels
269          * for a given range of blocks. We can expect to receive one or more
270          * replies to a single query.
271          */
272         public Result_NoneLightningErrorZ handle_reply_channel_range(byte[] their_node_id, ReplyChannelRange msg) {
273                 long ret = bindings.RoutingMessageHandler_handle_reply_channel_range(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
274                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
275                 this.ptrs_to.add(msg);
276                 return ret_hu_conv;
277         }
278
279         /**
280          * Handles the reply of a query we initiated asking for routing gossip
281          * messages for a list of channels. We should receive this message when
282          * a node has completed its best effort to send us the pertaining routing
283          * gossip messages.
284          */
285         public Result_NoneLightningErrorZ handle_reply_short_channel_ids_end(byte[] their_node_id, ReplyShortChannelIdsEnd msg) {
286                 long ret = bindings.RoutingMessageHandler_handle_reply_short_channel_ids_end(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
287                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
288                 this.ptrs_to.add(msg);
289                 return ret_hu_conv;
290         }
291
292         /**
293          * Handles when a peer asks us to send a list of short_channel_ids
294          * for the requested range of blocks.
295          */
296         public Result_NoneLightningErrorZ handle_query_channel_range(byte[] their_node_id, QueryChannelRange msg) {
297                 long ret = bindings.RoutingMessageHandler_handle_query_channel_range(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
298                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
299                 this.ptrs_to.add(msg);
300                 return ret_hu_conv;
301         }
302
303         /**
304          * Handles when a peer asks us to send routing gossip messages for a
305          * list of short_channel_ids.
306          */
307         public Result_NoneLightningErrorZ handle_query_short_channel_ids(byte[] their_node_id, QueryShortChannelIds msg) {
308                 long ret = bindings.RoutingMessageHandler_handle_query_short_channel_ids(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
309                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
310                 this.ptrs_to.add(msg);
311                 return ret_hu_conv;
312         }
313
314 }