X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FRoutingMessageHandler.java;h=2ca68de19b287532138f53a2c56d932768532953;hb=a442b8532ad57aed1fc740141189899b39a15d79;hp=a4f5353dd237799770c820f8fd44fb54b7ee6033;hpb=fed2245c60159f6c074c9ed5c0f3ce273ad9841b;p=ldk-java diff --git a/src/main/java/org/ldk/structs/RoutingMessageHandler.java b/src/main/java/org/ldk/structs/RoutingMessageHandler.java index a4f5353d..2ca68de1 100644 --- a/src/main/java/org/ldk/structs/RoutingMessageHandler.java +++ b/src/main/java/org/ldk/structs/RoutingMessageHandler.java @@ -5,6 +5,15 @@ import org.ldk.enums.*; import org.ldk.util.*; import java.util.Arrays; +/** + * A trait to describe an object which can receive routing messages. + * + * # Implementor DoS Warnings + * + * For `gossip_queries` messages there are potential DoS vectors when handling + * inbound queries. Implementors using an on-disk network graph should be aware of + * repeated disk I/O for queries accessing different parts of the network graph. + */ @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class RoutingMessageHandler extends CommonBase { final bindings.LDKRoutingMessageHandler bindings_instance; @@ -21,16 +30,66 @@ public class RoutingMessageHandler extends CommonBase { } public static interface RoutingMessageHandlerInterface { + /** + * Handle an incoming node_announcement message, returning true if it should be forwarded on, + * false or returning an Err otherwise. + */ Result_boolLightningErrorZ handle_node_announcement(NodeAnnouncement msg); + /** + * Handle a channel_announcement message, returning true if it should be forwarded on, false + * or returning an Err otherwise. + */ Result_boolLightningErrorZ handle_channel_announcement(ChannelAnnouncement msg); + /** + * Handle an incoming channel_update message, returning true if it should be forwarded on, + * false or returning an Err otherwise. + */ Result_boolLightningErrorZ handle_channel_update(ChannelUpdate msg); + /** + * Handle some updates to the route graph that we learned due to an outbound failed payment. + */ void handle_htlc_fail_channel_update(HTLCFailChannelUpdate update); + /** + * Gets a subset of the channel announcements and updates required to dump our routing table + * to a remote node, starting at the short_channel_id indicated by starting_point and + * including the batch_amount entries immediately higher in numerical value than starting_point. + */ ThreeTuple[] get_next_channel_announcements(long starting_point, byte batch_amount); + /** + * Gets a subset of the node announcements required to dump our routing table to a remote node, + * starting at the node *after* the provided publickey and including batch_amount entries + * immediately higher (as defined by ::cmp) than starting_point. + * If None is provided for starting_point, we start at the first node. + */ NodeAnnouncement[] get_next_node_announcements(byte[] starting_point, byte batch_amount); + /** + * Called when a connection is established with a peer. This can be used to + * perform routing table synchronization using a strategy defined by the + * implementor. + */ void sync_routing_table(byte[] their_node_id, Init init); + /** + * Handles the reply of a query we initiated to learn about channels + * for a given range of blocks. We can expect to receive one or more + * replies to a single query. + */ Result_NoneLightningErrorZ handle_reply_channel_range(byte[] their_node_id, ReplyChannelRange msg); + /** + * Handles the reply of a query we initiated asking for routing gossip + * messages for a list of channels. We should receive this message when + * a node has completed its best effort to send us the pertaining routing + * gossip messages. + */ Result_NoneLightningErrorZ handle_reply_short_channel_ids_end(byte[] their_node_id, ReplyShortChannelIdsEnd msg); + /** + * Handles when a peer asks us to send a list of short_channel_ids + * for the requested range of blocks. + */ Result_NoneLightningErrorZ handle_query_channel_range(byte[] their_node_id, QueryChannelRange msg); + /** + * Handles when a peer asks us to send routing gossip messages for a + * list of short_channel_ids. + */ Result_NoneLightningErrorZ handle_query_short_channel_ids(byte[] their_node_id, QueryShortChannelIds msg); } private static class LDKRoutingMessageHandlerHolder { RoutingMessageHandler held; } @@ -61,13 +120,13 @@ public class RoutingMessageHandler extends CommonBase { } @Override public long[] get_next_channel_announcements(long starting_point, byte batch_amount) { ThreeTuple[] ret = arg.get_next_channel_announcements(starting_point, batch_amount); - long[] result = Arrays.stream(ret).mapToLong(arr_conv_63 -> bindings.C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_new(arr_conv_63.a == null ? 0 : arr_conv_63.a.ptr & ~1, arr_conv_63.b == null ? 0 : arr_conv_63.b.ptr & ~1, arr_conv_63.c == null ? 0 : arr_conv_63.c.ptr & ~1)).toArray(); + 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(); /* TODO 2 ThreeTuple */; return result; } @Override public long[] get_next_node_announcements(byte[] starting_point, byte batch_amount) { NodeAnnouncement[] ret = arg.get_next_node_announcements(starting_point, batch_amount); - long[] result = Arrays.stream(ret).mapToLong(arr_conv_18 -> arr_conv_18 == null ? 0 : arr_conv_18.ptr & ~1).toArray(); + long[] result = Arrays.stream(ret).mapToLong(ret_conv_18 -> ret_conv_18 == null ? 0 : ret_conv_18.ptr & ~1).toArray(); /* TODO 2 NodeAnnouncement */; return result; } @@ -106,6 +165,10 @@ public class RoutingMessageHandler extends CommonBase { }, MessageSendEventsProvider.new_impl(MessageSendEventsProvider_impl).bindings_instance); return impl_holder.held; } + /** + * Handle an incoming node_announcement message, returning true if it should be forwarded on, + * false or returning an Err otherwise. + */ public Result_boolLightningErrorZ handle_node_announcement(NodeAnnouncement msg) { long ret = bindings.RoutingMessageHandler_handle_node_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1); Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret); @@ -113,6 +176,10 @@ public class RoutingMessageHandler extends CommonBase { return ret_hu_conv; } + /** + * Handle a channel_announcement message, returning true if it should be forwarded on, false + * or returning an Err otherwise. + */ public Result_boolLightningErrorZ handle_channel_announcement(ChannelAnnouncement msg) { long ret = bindings.RoutingMessageHandler_handle_channel_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1); Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret); @@ -120,6 +187,10 @@ public class RoutingMessageHandler extends CommonBase { return ret_hu_conv; } + /** + * Handle an incoming channel_update message, returning true if it should be forwarded on, + * false or returning an Err otherwise. + */ public Result_boolLightningErrorZ handle_channel_update(ChannelUpdate msg) { long ret = bindings.RoutingMessageHandler_handle_channel_update(this.ptr, msg == null ? 0 : msg.ptr & ~1); Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret); @@ -127,48 +198,77 @@ public class RoutingMessageHandler extends CommonBase { return ret_hu_conv; } + /** + * Handle some updates to the route graph that we learned due to an outbound failed payment. + */ public void handle_htlc_fail_channel_update(HTLCFailChannelUpdate update) { bindings.RoutingMessageHandler_handle_htlc_fail_channel_update(this.ptr, update == null ? 0 : update.ptr & ~1); this.ptrs_to.add(update); } + /** + * Gets a subset of the channel announcements and updates required to dump our routing table + * to a remote node, starting at the short_channel_id indicated by starting_point and + * including the batch_amount entries immediately higher in numerical value than starting_point. + */ public ThreeTuple[] get_next_channel_announcements(long starting_point, byte batch_amount) { long[] ret = bindings.RoutingMessageHandler_get_next_channel_announcements(this.ptr, starting_point, batch_amount); - ThreeTuple[] arr_conv_63_arr = new ThreeTuple[ret.length]; + ThreeTuple[] ret_conv_63_arr = new ThreeTuple[ret.length]; for (int l = 0; l < ret.length; l++) { - long arr_conv_63 = ret[l]; - long arr_conv_63_a = bindings.LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_get_a(arr_conv_63); - ChannelAnnouncement arr_conv_63_a_hu_conv = new ChannelAnnouncement(null, arr_conv_63_a); - arr_conv_63_a_hu_conv.ptrs_to.add(this);; - long arr_conv_63_b = bindings.LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_get_b(arr_conv_63); - ChannelUpdate arr_conv_63_b_hu_conv = new ChannelUpdate(null, arr_conv_63_b); - arr_conv_63_b_hu_conv.ptrs_to.add(this);; - long arr_conv_63_c = bindings.LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_get_c(arr_conv_63); - ChannelUpdate arr_conv_63_c_hu_conv = new ChannelUpdate(null, arr_conv_63_c); - arr_conv_63_c_hu_conv.ptrs_to.add(this);; - ThreeTuple arr_conv_63_conv = new ThreeTuple(arr_conv_63_a_hu_conv, arr_conv_63_b_hu_conv, arr_conv_63_c_hu_conv); - arr_conv_63_arr[l] = arr_conv_63_conv; + long ret_conv_63 = ret[l]; + long ret_conv_63_a = bindings.LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_get_a(ret_conv_63); + ChannelAnnouncement ret_conv_63_a_hu_conv = new ChannelAnnouncement(null, ret_conv_63_a); + ret_conv_63_a_hu_conv.ptrs_to.add(this);; + long ret_conv_63_b = bindings.LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_get_b(ret_conv_63); + ChannelUpdate ret_conv_63_b_hu_conv = new ChannelUpdate(null, ret_conv_63_b); + ret_conv_63_b_hu_conv.ptrs_to.add(this);; + long ret_conv_63_c = bindings.LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_get_c(ret_conv_63); + ChannelUpdate ret_conv_63_c_hu_conv = new ChannelUpdate(null, ret_conv_63_c); + ret_conv_63_c_hu_conv.ptrs_to.add(this);; + ThreeTuple ret_conv_63_conv = new ThreeTuple(ret_conv_63_a_hu_conv, ret_conv_63_b_hu_conv, ret_conv_63_c_hu_conv, () -> { + bindings.C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_free(ret_conv_63); + }); + ret_conv_63_a_hu_conv.ptrs_to.add(ret_conv_63_conv); + ret_conv_63_b_hu_conv.ptrs_to.add(ret_conv_63_conv); + ret_conv_63_c_hu_conv.ptrs_to.add(ret_conv_63_conv); + ret_conv_63_arr[l] = ret_conv_63_conv; } - return arr_conv_63_arr; + return ret_conv_63_arr; } + /** + * Gets a subset of the node announcements required to dump our routing table to a remote node, + * starting at the node *after* the provided publickey and including batch_amount entries + * immediately higher (as defined by ::cmp) than starting_point. + * If None is provided for starting_point, we start at the first node. + */ public NodeAnnouncement[] get_next_node_announcements(byte[] starting_point, byte batch_amount) { long[] ret = bindings.RoutingMessageHandler_get_next_node_announcements(this.ptr, starting_point, batch_amount); - NodeAnnouncement[] arr_conv_18_arr = new NodeAnnouncement[ret.length]; + NodeAnnouncement[] ret_conv_18_arr = new NodeAnnouncement[ret.length]; for (int s = 0; s < ret.length; s++) { - long arr_conv_18 = ret[s]; - NodeAnnouncement arr_conv_18_hu_conv = new NodeAnnouncement(null, arr_conv_18); - arr_conv_18_hu_conv.ptrs_to.add(this); - arr_conv_18_arr[s] = arr_conv_18_hu_conv; + long ret_conv_18 = ret[s]; + NodeAnnouncement ret_conv_18_hu_conv = new NodeAnnouncement(null, ret_conv_18); + ret_conv_18_hu_conv.ptrs_to.add(this); + ret_conv_18_arr[s] = ret_conv_18_hu_conv; } - return arr_conv_18_arr; + return ret_conv_18_arr; } + /** + * Called when a connection is established with a peer. This can be used to + * perform routing table synchronization using a strategy defined by the + * implementor. + */ public void sync_routing_table(byte[] their_node_id, Init init) { bindings.RoutingMessageHandler_sync_routing_table(this.ptr, their_node_id, init == null ? 0 : init.ptr & ~1); this.ptrs_to.add(init); } + /** + * Handles the reply of a query we initiated to learn about channels + * for a given range of blocks. We can expect to receive one or more + * replies to a single query. + */ public Result_NoneLightningErrorZ handle_reply_channel_range(byte[] their_node_id, ReplyChannelRange msg) { long ret = bindings.RoutingMessageHandler_handle_reply_channel_range(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1); Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret); @@ -176,6 +276,12 @@ public class RoutingMessageHandler extends CommonBase { return ret_hu_conv; } + /** + * Handles the reply of a query we initiated asking for routing gossip + * messages for a list of channels. We should receive this message when + * a node has completed its best effort to send us the pertaining routing + * gossip messages. + */ public Result_NoneLightningErrorZ handle_reply_short_channel_ids_end(byte[] their_node_id, ReplyShortChannelIdsEnd msg) { long ret = bindings.RoutingMessageHandler_handle_reply_short_channel_ids_end(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1); Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret); @@ -183,6 +289,10 @@ public class RoutingMessageHandler extends CommonBase { return ret_hu_conv; } + /** + * Handles when a peer asks us to send a list of short_channel_ids + * for the requested range of blocks. + */ public Result_NoneLightningErrorZ handle_query_channel_range(byte[] their_node_id, QueryChannelRange msg) { long ret = bindings.RoutingMessageHandler_handle_query_channel_range(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1); Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret); @@ -190,6 +300,10 @@ public class RoutingMessageHandler extends CommonBase { return ret_hu_conv; } + /** + * Handles when a peer asks us to send routing gossip messages for a + * list of short_channel_ids. + */ public Result_NoneLightningErrorZ handle_query_short_channel_ids(byte[] their_node_id, QueryShortChannelIds msg) { long ret = bindings.RoutingMessageHandler_handle_query_short_channel_ids(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1); Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);