6 namespace org { namespace ldk { namespace structs {
9 * A trait to describe an object which can receive routing messages.
11 * # Implementor DoS Warnings
13 * For messages enabled with the `gossip_queries` feature there are potential DoS vectors when
14 * handling 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.
17 public class RoutingMessageHandler : CommonBase {
18 internal readonly bindings.LDKRoutingMessageHandler bindings_instance;
19 internal RoutingMessageHandler(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
20 private RoutingMessageHandler(bindings.LDKRoutingMessageHandler arg, bindings.LDKMessageSendEventsProvider MessageSendEventsProvider) : base(bindings.LDKRoutingMessageHandler_new(arg, MessageSendEventsProvider)) {
21 this.ptrs_to.AddLast(arg);
22 this.ptrs_to.AddLast(MessageSendEventsProvider);
23 this.bindings_instance = arg;
25 ~RoutingMessageHandler() {
26 if (ptr != 0) { bindings.RoutingMessageHandler_free(ptr); }
29 public interface RoutingMessageHandlerInterface {
31 * Handle an incoming `node_announcement` message, returning `true` if it should be forwarded on,
32 * `false` or returning an `Err` otherwise.
34 Result_boolLightningErrorZ handle_node_announcement(NodeAnnouncement _msg);
36 * Handle a `channel_announcement` message, returning `true` if it should be forwarded on, `false`
37 * or returning an `Err` otherwise.
39 Result_boolLightningErrorZ handle_channel_announcement(ChannelAnnouncement _msg);
41 * Handle an incoming `channel_update` message, returning true if it should be forwarded on,
42 * `false` or returning an `Err` otherwise.
44 Result_boolLightningErrorZ handle_channel_update(ChannelUpdate _msg);
46 * Gets channel announcements and updates required to dump our routing table to a remote node,
47 * starting at the `short_channel_id` indicated by `starting_point` and including announcements
48 * for a single channel.
50 Option_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ get_next_channel_announcement(long _starting_point);
52 * Gets a node announcement required to dump our routing table to a remote node, starting at
53 * the node *after* the provided pubkey and including up to one announcement immediately
54 * higher (as defined by `<PublicKey as Ord>::cmp`) than `starting_point`.
55 * If `None` is provided for `starting_point`, we start at the first node.
57 * Note that starting_point (or a relevant inner pointer) may be NULL or all-0s to represent None
58 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
60 NodeAnnouncement get_next_node_announcement(NodeId _starting_point);
62 * Called when a connection is established with a peer. This can be used to
63 * perform routing table synchronization using a strategy defined by the
66 * May return an `Err(())` if the features the peer supports are not sufficient to communicate
67 * with us. Implementors should be somewhat conservative about doing so, however, as other
68 * message handlers may still wish to communicate with this peer.
70 Result_NoneNoneZ peer_connected(byte[] _their_node_id, Init _init, bool _inbound);
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.
76 Result_NoneLightningErrorZ handle_reply_channel_range(byte[] _their_node_id, ReplyChannelRange _msg);
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
83 Result_NoneLightningErrorZ handle_reply_short_channel_ids_end(byte[] _their_node_id, ReplyShortChannelIdsEnd _msg);
85 * Handles when a peer asks us to send a list of `short_channel_id`s
86 * for the requested range of blocks.
88 Result_NoneLightningErrorZ handle_query_channel_range(byte[] _their_node_id, QueryChannelRange _msg);
90 * Handles when a peer asks us to send routing gossip messages for a
91 * list of `short_channel_id`s.
93 Result_NoneLightningErrorZ handle_query_short_channel_ids(byte[] _their_node_id, QueryShortChannelIds _msg);
95 * Indicates that there are a large number of [`ChannelAnnouncement`] (or other) messages
96 * pending some async action. While there is no guarantee of the rate of future messages, the
97 * caller should seek to reduce the rate of new gossip messages handled, especially
98 * [`ChannelAnnouncement`]s.
100 bool processing_queue_high();
102 * Gets the node feature flags which this handler itself supports. All available handlers are
103 * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
104 * which are broadcasted in our [`NodeAnnouncement`] message.
106 NodeFeatures provided_node_features();
108 * Gets the init feature flags which should be sent to the given peer. All available handlers
109 * are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
110 * which are sent in our [`Init`] message.
112 * Note that this method is called before [`Self::peer_connected`].
114 InitFeatures provided_init_features(byte[] _their_node_id);
116 private class LDKRoutingMessageHandlerHolder { internal RoutingMessageHandler held; }
117 private class LDKRoutingMessageHandlerImpl : bindings.LDKRoutingMessageHandler {
118 internal LDKRoutingMessageHandlerImpl(RoutingMessageHandlerInterface arg, LDKRoutingMessageHandlerHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
119 private RoutingMessageHandlerInterface arg;
120 private LDKRoutingMessageHandlerHolder impl_holder;
121 public long handle_node_announcement(long _msg) {
122 org.ldk.structs.NodeAnnouncement _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.NodeAnnouncement(null, _msg); }
123 Result_boolLightningErrorZ ret = arg.handle_node_announcement(_msg_hu_conv);
125 long result = ret == null ? 0 : ret.clone_ptr();
128 public long handle_channel_announcement(long _msg) {
129 org.ldk.structs.ChannelAnnouncement _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.ChannelAnnouncement(null, _msg); }
130 Result_boolLightningErrorZ ret = arg.handle_channel_announcement(_msg_hu_conv);
132 long result = ret == null ? 0 : ret.clone_ptr();
135 public long handle_channel_update(long _msg) {
136 org.ldk.structs.ChannelUpdate _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.ChannelUpdate(null, _msg); }
137 Result_boolLightningErrorZ ret = arg.handle_channel_update(_msg_hu_conv);
139 long result = ret == null ? 0 : ret.clone_ptr();
142 public long get_next_channel_announcement(long _starting_point) {
143 Option_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ ret = arg.get_next_channel_announcement(_starting_point);
145 long result = ret == null ? 0 : ret.clone_ptr();
146 if (impl_holder.held != null) { impl_holder.held.ptrs_to.AddLast(ret); };
149 public long get_next_node_announcement(long _starting_point) {
150 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); }
151 if (_starting_point_hu_conv != null) { _starting_point_hu_conv.ptrs_to.AddLast(this); };
152 NodeAnnouncement ret = arg.get_next_node_announcement(_starting_point_hu_conv);
154 long result = ret == null ? 0 : ret.clone_ptr();
157 public long peer_connected(byte[] _their_node_id, long _init, bool _inbound) {
158 org.ldk.structs.Init _init_hu_conv = null; if (_init < 0 || _init > 4096) { _init_hu_conv = new org.ldk.structs.Init(null, _init); }
159 Result_NoneNoneZ ret = arg.peer_connected(_their_node_id, _init_hu_conv, _inbound);
161 long result = ret == null ? 0 : ret.clone_ptr();
164 public long handle_reply_channel_range(byte[] _their_node_id, long _msg) {
165 org.ldk.structs.ReplyChannelRange _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.ReplyChannelRange(null, _msg); }
166 if (_msg_hu_conv != null) { _msg_hu_conv.ptrs_to.AddLast(this); };
167 Result_NoneLightningErrorZ ret = arg.handle_reply_channel_range(_their_node_id, _msg_hu_conv);
169 long result = ret == null ? 0 : ret.clone_ptr();
172 public long handle_reply_short_channel_ids_end(byte[] _their_node_id, long _msg) {
173 org.ldk.structs.ReplyShortChannelIdsEnd _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.ReplyShortChannelIdsEnd(null, _msg); }
174 if (_msg_hu_conv != null) { _msg_hu_conv.ptrs_to.AddLast(this); };
175 Result_NoneLightningErrorZ ret = arg.handle_reply_short_channel_ids_end(_their_node_id, _msg_hu_conv);
177 long result = ret == null ? 0 : ret.clone_ptr();
180 public long handle_query_channel_range(byte[] _their_node_id, long _msg) {
181 org.ldk.structs.QueryChannelRange _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.QueryChannelRange(null, _msg); }
182 if (_msg_hu_conv != null) { _msg_hu_conv.ptrs_to.AddLast(this); };
183 Result_NoneLightningErrorZ ret = arg.handle_query_channel_range(_their_node_id, _msg_hu_conv);
185 long result = ret == null ? 0 : ret.clone_ptr();
188 public long handle_query_short_channel_ids(byte[] _their_node_id, long _msg) {
189 org.ldk.structs.QueryShortChannelIds _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.QueryShortChannelIds(null, _msg); }
190 if (_msg_hu_conv != null) { _msg_hu_conv.ptrs_to.AddLast(this); };
191 Result_NoneLightningErrorZ ret = arg.handle_query_short_channel_ids(_their_node_id, _msg_hu_conv);
193 long result = ret == null ? 0 : ret.clone_ptr();
196 public bool processing_queue_high() {
197 bool ret = arg.processing_queue_high();
201 public long provided_node_features() {
202 NodeFeatures ret = arg.provided_node_features();
204 long result = ret == null ? 0 : ret.clone_ptr();
207 public long provided_init_features(byte[] _their_node_id) {
208 InitFeatures ret = arg.provided_init_features(_their_node_id);
210 long result = ret == null ? 0 : ret.clone_ptr();
214 public static RoutingMessageHandler new_impl(RoutingMessageHandlerInterface arg, MessageSendEventsProvider.MessageSendEventsProviderInterface MessageSendEventsProvider_impl) {
215 LDKRoutingMessageHandlerHolder impl_holder = new LDKRoutingMessageHandlerHolder();
216 impl_holder.held = new RoutingMessageHandler(new LDKRoutingMessageHandlerImpl(arg, impl_holder), MessageSendEventsProvider.new_impl(MessageSendEventsProvider_impl).bindings_instance);
217 return impl_holder.held;
221 * Gets the underlying MessageSendEventsProvider.
223 public MessageSendEventsProvider get_message_send_events_provider() {
224 MessageSendEventsProvider res = new MessageSendEventsProvider(null, bindings.LDKRoutingMessageHandler_get_MessageSendEventsProvider(this.ptr));
225 this.ptrs_to.AddLast(res);
230 * Handle an incoming `node_announcement` message, returning `true` if it should be forwarded on,
231 * `false` or returning an `Err` otherwise.
233 public Result_boolLightningErrorZ handle_node_announcement(org.ldk.structs.NodeAnnouncement msg) {
234 long ret = bindings.RoutingMessageHandler_handle_node_announcement(this.ptr, msg == null ? 0 : msg.ptr);
237 if (ret >= 0 && ret <= 4096) { return null; }
238 Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret);
239 if (this != null) { this.ptrs_to.AddLast(msg); };
244 * Handle a `channel_announcement` message, returning `true` if it should be forwarded on, `false`
245 * or returning an `Err` otherwise.
247 public Result_boolLightningErrorZ handle_channel_announcement(org.ldk.structs.ChannelAnnouncement msg) {
248 long ret = bindings.RoutingMessageHandler_handle_channel_announcement(this.ptr, msg == null ? 0 : msg.ptr);
251 if (ret >= 0 && ret <= 4096) { return null; }
252 Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret);
253 if (this != null) { this.ptrs_to.AddLast(msg); };
258 * Handle an incoming `channel_update` message, returning true if it should be forwarded on,
259 * `false` or returning an `Err` otherwise.
261 public Result_boolLightningErrorZ handle_channel_update(org.ldk.structs.ChannelUpdate msg) {
262 long ret = bindings.RoutingMessageHandler_handle_channel_update(this.ptr, msg == null ? 0 : msg.ptr);
265 if (ret >= 0 && ret <= 4096) { return null; }
266 Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret);
267 if (this != null) { this.ptrs_to.AddLast(msg); };
272 * Gets channel announcements and updates required to dump our routing table to a remote node,
273 * starting at the `short_channel_id` indicated by `starting_point` and including announcements
274 * for a single channel.
276 public Option_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ get_next_channel_announcement(long starting_point) {
277 long ret = bindings.RoutingMessageHandler_get_next_channel_announcement(this.ptr, starting_point);
279 GC.KeepAlive(starting_point);
280 if (ret >= 0 && ret <= 4096) { return null; }
281 org.ldk.structs.Option_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ ret_hu_conv = org.ldk.structs.Option_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ.constr_from_ptr(ret);
282 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
287 * Gets a node announcement required to dump our routing table to a remote node, starting at
288 * the node *after* the provided pubkey and including up to one announcement immediately
289 * higher (as defined by `<PublicKey as Ord>::cmp`) than `starting_point`.
290 * If `None` is provided for `starting_point`, we start at the first node.
292 * Note that starting_point (or a relevant inner pointer) may be NULL or all-0s to represent None
293 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
295 public NodeAnnouncement get_next_node_announcement(org.ldk.structs.NodeId starting_point) {
296 long ret = bindings.RoutingMessageHandler_get_next_node_announcement(this.ptr, starting_point == null ? 0 : starting_point.ptr);
298 GC.KeepAlive(starting_point);
299 if (ret >= 0 && ret <= 4096) { return null; }
300 org.ldk.structs.NodeAnnouncement ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeAnnouncement(null, ret); }
301 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
302 if (this != null) { this.ptrs_to.AddLast(starting_point); };
307 * Called when a connection is established with a peer. This can be used to
308 * perform routing table synchronization using a strategy defined by the
311 * May return an `Err(())` if the features the peer supports are not sufficient to communicate
312 * with us. Implementors should be somewhat conservative about doing so, however, as other
313 * message handlers may still wish to communicate with this peer.
315 public Result_NoneNoneZ peer_connected(byte[] their_node_id, org.ldk.structs.Init init, bool inbound) {
316 long ret = bindings.RoutingMessageHandler_peer_connected(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), init == null ? 0 : init.ptr, inbound);
318 GC.KeepAlive(their_node_id);
320 GC.KeepAlive(inbound);
321 if (ret >= 0 && ret <= 4096) { return null; }
322 Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
323 if (this != null) { this.ptrs_to.AddLast(init); };
328 * Handles the reply of a query we initiated to learn about channels
329 * for a given range of blocks. We can expect to receive one or more
330 * replies to a single query.
332 public Result_NoneLightningErrorZ handle_reply_channel_range(byte[] their_node_id, org.ldk.structs.ReplyChannelRange msg) {
333 long ret = bindings.RoutingMessageHandler_handle_reply_channel_range(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
335 GC.KeepAlive(their_node_id);
337 if (ret >= 0 && ret <= 4096) { return null; }
338 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
339 if (this != null) { this.ptrs_to.AddLast(msg); };
344 * Handles the reply of a query we initiated asking for routing gossip
345 * messages for a list of channels. We should receive this message when
346 * a node has completed its best effort to send us the pertaining routing
349 public Result_NoneLightningErrorZ handle_reply_short_channel_ids_end(byte[] their_node_id, org.ldk.structs.ReplyShortChannelIdsEnd msg) {
350 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);
352 GC.KeepAlive(their_node_id);
354 if (ret >= 0 && ret <= 4096) { return null; }
355 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
356 if (this != null) { this.ptrs_to.AddLast(msg); };
361 * Handles when a peer asks us to send a list of `short_channel_id`s
362 * for the requested range of blocks.
364 public Result_NoneLightningErrorZ handle_query_channel_range(byte[] their_node_id, org.ldk.structs.QueryChannelRange msg) {
365 long ret = bindings.RoutingMessageHandler_handle_query_channel_range(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
367 GC.KeepAlive(their_node_id);
369 if (ret >= 0 && ret <= 4096) { return null; }
370 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
371 if (this != null) { this.ptrs_to.AddLast(msg); };
376 * Handles when a peer asks us to send routing gossip messages for a
377 * list of `short_channel_id`s.
379 public Result_NoneLightningErrorZ handle_query_short_channel_ids(byte[] their_node_id, org.ldk.structs.QueryShortChannelIds msg) {
380 long ret = bindings.RoutingMessageHandler_handle_query_short_channel_ids(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
382 GC.KeepAlive(their_node_id);
384 if (ret >= 0 && ret <= 4096) { return null; }
385 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
386 if (this != null) { this.ptrs_to.AddLast(msg); };
391 * Indicates that there are a large number of [`ChannelAnnouncement`] (or other) messages
392 * pending some async action. While there is no guarantee of the rate of future messages, the
393 * caller should seek to reduce the rate of new gossip messages handled, especially
394 * [`ChannelAnnouncement`]s.
396 public bool processing_queue_high() {
397 bool ret = bindings.RoutingMessageHandler_processing_queue_high(this.ptr);
403 * Gets the node feature flags which this handler itself supports. All available handlers are
404 * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
405 * which are broadcasted in our [`NodeAnnouncement`] message.
407 public NodeFeatures provided_node_features() {
408 long ret = bindings.RoutingMessageHandler_provided_node_features(this.ptr);
410 if (ret >= 0 && ret <= 4096) { return null; }
411 org.ldk.structs.NodeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeFeatures(null, ret); }
412 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
417 * Gets the init feature flags which should be sent to the given peer. All available handlers
418 * are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
419 * which are sent in our [`Init`] message.
421 * Note that this method is called before [`Self::peer_connected`].
423 public InitFeatures provided_init_features(byte[] their_node_id) {
424 long ret = bindings.RoutingMessageHandler_provided_init_features(this.ptr, InternalUtils.check_arr_len(their_node_id, 33));
426 GC.KeepAlive(their_node_id);
427 if (ret >= 0 && ret <= 4096) { return null; }
428 org.ldk.structs.InitFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InitFeatures(null, ret); }
429 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };