7 namespace org { namespace ldk { namespace structs {
11 /** An implementation of RoutingMessageHandler */
12 public interface RoutingMessageHandlerInterface {
13 /**Handle an incoming `node_announcement` message, returning `true` if it should be forwarded on,
14 * `false` or returning an `Err` otherwise.
16 Result_boolLightningErrorZ handle_node_announcement(NodeAnnouncement msg);
17 /**Handle a `channel_announcement` message, returning `true` if it should be forwarded on, `false`
18 * or returning an `Err` otherwise.
20 Result_boolLightningErrorZ handle_channel_announcement(ChannelAnnouncement msg);
21 /**Handle an incoming `channel_update` message, returning true if it should be forwarded on,
22 * `false` or returning an `Err` otherwise.
24 Result_boolLightningErrorZ handle_channel_update(ChannelUpdate msg);
25 /**Gets channel announcements and updates required to dump our routing table to a remote node,
26 * starting at the `short_channel_id` indicated by `starting_point` and including announcements
27 * for a single channel.
29 Option_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ get_next_channel_announcement(long starting_point);
30 /**Gets a node announcement required to dump our routing table to a remote node, starting at
31 * the node *after* the provided pubkey and including up to one announcement immediately
32 * higher (as defined by `<PublicKey as Ord>::cmp`) than `starting_point`.
33 * If `None` is provided for `starting_point`, we start at the first node.
35 * Note that starting_point (or a relevant inner pointer) may be NULL or all-0s to represent None
36 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
38 NodeAnnouncement get_next_node_announcement(NodeId starting_point);
39 /**Called when a connection is established with a peer. This can be used to
40 * perform routing table synchronization using a strategy defined by the
43 * May return an `Err(())` if the features the peer supports are not sufficient to communicate
44 * with us. Implementors should be somewhat conservative about doing so, however, as other
45 * message handlers may still wish to communicate with this peer.
47 Result_NoneNoneZ peer_connected(byte[] their_node_id, Init init, bool inbound);
48 /**Handles the reply of a query we initiated to learn about channels
49 * for a given range of blocks. We can expect to receive one or more
50 * replies to a single query.
52 Result_NoneLightningErrorZ handle_reply_channel_range(byte[] their_node_id, ReplyChannelRange msg);
53 /**Handles the reply of a query we initiated asking for routing gossip
54 * messages for a list of channels. We should receive this message when
55 * a node has completed its best effort to send us the pertaining routing
58 Result_NoneLightningErrorZ handle_reply_short_channel_ids_end(byte[] their_node_id, ReplyShortChannelIdsEnd msg);
59 /**Handles when a peer asks us to send a list of `short_channel_id`s
60 * for the requested range of blocks.
62 Result_NoneLightningErrorZ handle_query_channel_range(byte[] their_node_id, QueryChannelRange msg);
63 /**Handles when a peer asks us to send routing gossip messages for a
64 * list of `short_channel_id`s.
66 Result_NoneLightningErrorZ handle_query_short_channel_ids(byte[] their_node_id, QueryShortChannelIds msg);
67 /**Indicates that there are a large number of [`ChannelAnnouncement`] (or other) messages
68 * pending some async action. While there is no guarantee of the rate of future messages, the
69 * caller should seek to reduce the rate of new gossip messages handled, especially
70 * [`ChannelAnnouncement`]s.
72 bool processing_queue_high();
73 /**Gets the node feature flags which this handler itself supports. All available handlers are
74 * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
75 * which are broadcasted in our [`NodeAnnouncement`] message.
77 NodeFeatures provided_node_features();
78 /**Gets the init feature flags which should be sent to the given peer. All available handlers
79 * are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
80 * which are sent in our [`Init`] message.
82 * Note that this method is called before [`Self::peer_connected`].
84 InitFeatures provided_init_features(byte[] their_node_id);
88 * A trait to describe an object which can receive routing messages.
90 * # Implementor DoS Warnings
92 * For messages enabled with the `gossip_queries` feature there are potential DoS vectors when
93 * handling inbound queries. Implementors using an on-disk network graph should be aware of
94 * repeated disk I/O for queries accessing different parts of the network graph.
96 public class RoutingMessageHandler : CommonBase {
97 internal bindings.LDKRoutingMessageHandler bindings_instance;
98 internal long instance_idx;
100 internal RoutingMessageHandler(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
101 ~RoutingMessageHandler() {
102 if (ptr != 0) { bindings.RoutingMessageHandler_free(ptr); }
105 private class LDKRoutingMessageHandlerHolder { internal RoutingMessageHandler held; }
106 private class LDKRoutingMessageHandlerImpl : bindings.LDKRoutingMessageHandler {
107 internal LDKRoutingMessageHandlerImpl(RoutingMessageHandlerInterface arg, LDKRoutingMessageHandlerHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
108 private RoutingMessageHandlerInterface arg;
109 private LDKRoutingMessageHandlerHolder impl_holder;
110 public long handle_node_announcement(long _msg) {
111 org.ldk.structs.NodeAnnouncement _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.NodeAnnouncement(null, _msg); }
112 Result_boolLightningErrorZ ret = arg.handle_node_announcement(_msg_hu_conv);
114 long result = ret.clone_ptr();
117 public long handle_channel_announcement(long _msg) {
118 org.ldk.structs.ChannelAnnouncement _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.ChannelAnnouncement(null, _msg); }
119 Result_boolLightningErrorZ ret = arg.handle_channel_announcement(_msg_hu_conv);
121 long result = ret.clone_ptr();
124 public long handle_channel_update(long _msg) {
125 org.ldk.structs.ChannelUpdate _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.ChannelUpdate(null, _msg); }
126 Result_boolLightningErrorZ ret = arg.handle_channel_update(_msg_hu_conv);
128 long result = ret.clone_ptr();
131 public long get_next_channel_announcement(long _starting_point) {
132 Option_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ ret = arg.get_next_channel_announcement(_starting_point);
134 long result = ret.clone_ptr();
135 if (impl_holder.held != null) { impl_holder.held.ptrs_to.AddLast(ret); };
138 public long get_next_node_announcement(long _starting_point) {
139 org.ldk.structs.NodeId _starting_point_hu_conv = null; if (_starting_point < 0 || _starting_point > 4096) { _starting_point_hu_conv = new org.ldk.structs.NodeId(null, _starting_point); }
140 if (_starting_point_hu_conv != null) { _starting_point_hu_conv.ptrs_to.AddLast(this); };
141 NodeAnnouncement ret = arg.get_next_node_announcement(_starting_point_hu_conv);
143 long result = ret == null ? 0 : ret.clone_ptr();
146 public long peer_connected(long _their_node_id, long _init, bool _inbound) {
147 byte[] _their_node_id_conv = InternalUtils.decodeUint8Array(_their_node_id);
148 org.ldk.structs.Init _init_hu_conv = null; if (_init < 0 || _init > 4096) { _init_hu_conv = new org.ldk.structs.Init(null, _init); }
149 Result_NoneNoneZ ret = arg.peer_connected(_their_node_id_conv, _init_hu_conv, _inbound);
151 long result = ret.clone_ptr();
154 public long handle_reply_channel_range(long _their_node_id, long _msg) {
155 byte[] _their_node_id_conv = InternalUtils.decodeUint8Array(_their_node_id);
156 org.ldk.structs.ReplyChannelRange _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.ReplyChannelRange(null, _msg); }
157 if (_msg_hu_conv != null) { _msg_hu_conv.ptrs_to.AddLast(this); };
158 Result_NoneLightningErrorZ ret = arg.handle_reply_channel_range(_their_node_id_conv, _msg_hu_conv);
160 long result = ret.clone_ptr();
163 public long handle_reply_short_channel_ids_end(long _their_node_id, long _msg) {
164 byte[] _their_node_id_conv = InternalUtils.decodeUint8Array(_their_node_id);
165 org.ldk.structs.ReplyShortChannelIdsEnd _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.ReplyShortChannelIdsEnd(null, _msg); }
166 if (_msg_hu_conv != null) { _msg_hu_conv.ptrs_to.AddLast(this); };
167 Result_NoneLightningErrorZ ret = arg.handle_reply_short_channel_ids_end(_their_node_id_conv, _msg_hu_conv);
169 long result = ret.clone_ptr();
172 public long handle_query_channel_range(long _their_node_id, long _msg) {
173 byte[] _their_node_id_conv = InternalUtils.decodeUint8Array(_their_node_id);
174 org.ldk.structs.QueryChannelRange _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.QueryChannelRange(null, _msg); }
175 if (_msg_hu_conv != null) { _msg_hu_conv.ptrs_to.AddLast(this); };
176 Result_NoneLightningErrorZ ret = arg.handle_query_channel_range(_their_node_id_conv, _msg_hu_conv);
178 long result = ret.clone_ptr();
181 public long handle_query_short_channel_ids(long _their_node_id, long _msg) {
182 byte[] _their_node_id_conv = InternalUtils.decodeUint8Array(_their_node_id);
183 org.ldk.structs.QueryShortChannelIds _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.QueryShortChannelIds(null, _msg); }
184 if (_msg_hu_conv != null) { _msg_hu_conv.ptrs_to.AddLast(this); };
185 Result_NoneLightningErrorZ ret = arg.handle_query_short_channel_ids(_their_node_id_conv, _msg_hu_conv);
187 long result = ret.clone_ptr();
190 public bool processing_queue_high() {
191 bool ret = arg.processing_queue_high();
195 public long provided_node_features() {
196 NodeFeatures ret = arg.provided_node_features();
198 long result = ret.clone_ptr();
201 public long provided_init_features(long _their_node_id) {
202 byte[] _their_node_id_conv = InternalUtils.decodeUint8Array(_their_node_id);
203 InitFeatures ret = arg.provided_init_features(_their_node_id_conv);
205 long result = ret.clone_ptr();
210 /** Creates a new instance of RoutingMessageHandler from a given implementation */
211 public static RoutingMessageHandler new_impl(RoutingMessageHandlerInterface arg, MessageSendEventsProviderInterface messageSendEventsProvider_impl) {
212 LDKRoutingMessageHandlerHolder impl_holder = new LDKRoutingMessageHandlerHolder();
213 LDKRoutingMessageHandlerImpl impl = new LDKRoutingMessageHandlerImpl(arg, impl_holder);
214 MessageSendEventsProvider messageSendEventsProvider = MessageSendEventsProvider.new_impl(messageSendEventsProvider_impl);
215 long[] ptr_idx = bindings.LDKRoutingMessageHandler_new(impl, messageSendEventsProvider.instance_idx);
217 impl_holder.held = new RoutingMessageHandler(null, ptr_idx[0]);
218 impl_holder.held.instance_idx = ptr_idx[1];
219 impl_holder.held.bindings_instance = impl;
220 impl_holder.held.ptrs_to.AddLast(messageSendEventsProvider);
221 return impl_holder.held;
225 * Handle an incoming `node_announcement` message, returning `true` if it should be forwarded on,
226 * `false` or returning an `Err` otherwise.
228 public Result_boolLightningErrorZ handle_node_announcement(org.ldk.structs.NodeAnnouncement msg) {
229 long ret = bindings.RoutingMessageHandler_handle_node_announcement(this.ptr, msg.ptr);
232 if (ret >= 0 && ret <= 4096) { return null; }
233 Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret);
234 if (this != null) { this.ptrs_to.AddLast(msg); };
239 * Handle a `channel_announcement` message, returning `true` if it should be forwarded on, `false`
240 * or returning an `Err` otherwise.
242 public Result_boolLightningErrorZ handle_channel_announcement(org.ldk.structs.ChannelAnnouncement msg) {
243 long ret = bindings.RoutingMessageHandler_handle_channel_announcement(this.ptr, msg.ptr);
246 if (ret >= 0 && ret <= 4096) { return null; }
247 Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret);
248 if (this != null) { this.ptrs_to.AddLast(msg); };
253 * Handle an incoming `channel_update` message, returning true if it should be forwarded on,
254 * `false` or returning an `Err` otherwise.
256 public Result_boolLightningErrorZ handle_channel_update(org.ldk.structs.ChannelUpdate msg) {
257 long ret = bindings.RoutingMessageHandler_handle_channel_update(this.ptr, msg.ptr);
260 if (ret >= 0 && ret <= 4096) { return null; }
261 Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret);
262 if (this != null) { this.ptrs_to.AddLast(msg); };
267 * Gets channel announcements and updates required to dump our routing table to a remote node,
268 * starting at the `short_channel_id` indicated by `starting_point` and including announcements
269 * for a single channel.
271 public Option_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ get_next_channel_announcement(long starting_point) {
272 long ret = bindings.RoutingMessageHandler_get_next_channel_announcement(this.ptr, starting_point);
274 GC.KeepAlive(starting_point);
275 if (ret >= 0 && ret <= 4096) { return null; }
276 org.ldk.structs.Option_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ ret_hu_conv = org.ldk.structs.Option_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ.constr_from_ptr(ret);
277 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
282 * Gets a node announcement required to dump our routing table to a remote node, starting at
283 * the node *after* the provided pubkey and including up to one announcement immediately
284 * higher (as defined by `<PublicKey as Ord>::cmp`) than `starting_point`.
285 * If `None` is provided for `starting_point`, we start at the first node.
287 * Note that starting_point (or a relevant inner pointer) may be NULL or all-0s to represent None
288 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
290 public NodeAnnouncement get_next_node_announcement(org.ldk.structs.NodeId starting_point) {
291 long ret = bindings.RoutingMessageHandler_get_next_node_announcement(this.ptr, starting_point == null ? 0 : starting_point.ptr);
293 GC.KeepAlive(starting_point);
294 if (ret >= 0 && ret <= 4096) { return null; }
295 org.ldk.structs.NodeAnnouncement ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeAnnouncement(null, ret); }
296 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
297 if (this != null) { this.ptrs_to.AddLast(starting_point); };
302 * Called when a connection is established with a peer. This can be used to
303 * perform routing table synchronization using a strategy defined by the
306 * May return an `Err(())` if the features the peer supports are not sufficient to communicate
307 * with us. Implementors should be somewhat conservative about doing so, however, as other
308 * message handlers may still wish to communicate with this peer.
310 public Result_NoneNoneZ peer_connected(byte[] their_node_id, org.ldk.structs.Init init, bool inbound) {
311 long ret = bindings.RoutingMessageHandler_peer_connected(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(their_node_id, 33)), init.ptr, inbound);
313 GC.KeepAlive(their_node_id);
315 GC.KeepAlive(inbound);
316 if (ret >= 0 && ret <= 4096) { return null; }
317 Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
318 if (this != null) { this.ptrs_to.AddLast(init); };
323 * Handles the reply of a query we initiated to learn about channels
324 * for a given range of blocks. We can expect to receive one or more
325 * replies to a single query.
327 public Result_NoneLightningErrorZ handle_reply_channel_range(byte[] their_node_id, org.ldk.structs.ReplyChannelRange msg) {
328 long ret = bindings.RoutingMessageHandler_handle_reply_channel_range(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(their_node_id, 33)), msg.ptr);
330 GC.KeepAlive(their_node_id);
332 if (ret >= 0 && ret <= 4096) { return null; }
333 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
334 if (this != null) { this.ptrs_to.AddLast(msg); };
339 * Handles the reply of a query we initiated asking for routing gossip
340 * messages for a list of channels. We should receive this message when
341 * a node has completed its best effort to send us the pertaining routing
344 public Result_NoneLightningErrorZ handle_reply_short_channel_ids_end(byte[] their_node_id, org.ldk.structs.ReplyShortChannelIdsEnd msg) {
345 long ret = bindings.RoutingMessageHandler_handle_reply_short_channel_ids_end(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(their_node_id, 33)), msg.ptr);
347 GC.KeepAlive(their_node_id);
349 if (ret >= 0 && ret <= 4096) { return null; }
350 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
351 if (this != null) { this.ptrs_to.AddLast(msg); };
356 * Handles when a peer asks us to send a list of `short_channel_id`s
357 * for the requested range of blocks.
359 public Result_NoneLightningErrorZ handle_query_channel_range(byte[] their_node_id, org.ldk.structs.QueryChannelRange msg) {
360 long ret = bindings.RoutingMessageHandler_handle_query_channel_range(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(their_node_id, 33)), msg.ptr);
362 GC.KeepAlive(their_node_id);
364 if (ret >= 0 && ret <= 4096) { return null; }
365 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
366 if (this != null) { this.ptrs_to.AddLast(msg); };
371 * Handles when a peer asks us to send routing gossip messages for a
372 * list of `short_channel_id`s.
374 public Result_NoneLightningErrorZ handle_query_short_channel_ids(byte[] their_node_id, org.ldk.structs.QueryShortChannelIds msg) {
375 long ret = bindings.RoutingMessageHandler_handle_query_short_channel_ids(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(their_node_id, 33)), msg.ptr);
377 GC.KeepAlive(their_node_id);
379 if (ret >= 0 && ret <= 4096) { return null; }
380 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
381 if (this != null) { this.ptrs_to.AddLast(msg); };
386 * Indicates that there are a large number of [`ChannelAnnouncement`] (or other) messages
387 * pending some async action. While there is no guarantee of the rate of future messages, the
388 * caller should seek to reduce the rate of new gossip messages handled, especially
389 * [`ChannelAnnouncement`]s.
391 public bool processing_queue_high() {
392 bool ret = bindings.RoutingMessageHandler_processing_queue_high(this.ptr);
398 * Gets the node feature flags which this handler itself supports. All available handlers are
399 * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
400 * which are broadcasted in our [`NodeAnnouncement`] message.
402 public NodeFeatures provided_node_features() {
403 long ret = bindings.RoutingMessageHandler_provided_node_features(this.ptr);
405 if (ret >= 0 && ret <= 4096) { return null; }
406 org.ldk.structs.NodeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeFeatures(null, ret); }
407 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
412 * Gets the init feature flags which should be sent to the given peer. All available handlers
413 * are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
414 * which are sent in our [`Init`] message.
416 * Note that this method is called before [`Self::peer_connected`].
418 public InitFeatures provided_init_features(byte[] their_node_id) {
419 long ret = bindings.RoutingMessageHandler_provided_init_features(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(their_node_id, 33)));
421 GC.KeepAlive(their_node_id);
422 if (ret >= 0 && ret <= 4096) { return null; }
423 org.ldk.structs.InitFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InitFeatures(null, ret); }
424 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };