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 `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.
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(byte[] _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);
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_ids
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_ids.
93 Result_NoneLightningErrorZ handle_query_short_channel_ids(byte[] _their_node_id, QueryShortChannelIds _msg);
95 * Gets the node feature flags which this handler itself supports. All available handlers are
96 * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
97 * which are broadcasted in our [`NodeAnnouncement`] message.
99 NodeFeatures provided_node_features();
101 * Gets the init feature flags which should be sent to the given peer. All available handlers
102 * are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
103 * which are sent in our [`Init`] message.
105 * Note that this method is called before [`Self::peer_connected`].
107 InitFeatures provided_init_features(byte[] _their_node_id);
109 private class LDKRoutingMessageHandlerHolder { internal RoutingMessageHandler held; }
110 private class LDKRoutingMessageHandlerImpl : bindings.LDKRoutingMessageHandler {
111 internal LDKRoutingMessageHandlerImpl(RoutingMessageHandlerInterface arg, LDKRoutingMessageHandlerHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
112 private RoutingMessageHandlerInterface arg;
113 private LDKRoutingMessageHandlerHolder impl_holder;
114 public long handle_node_announcement(long _msg) {
115 org.ldk.structs.NodeAnnouncement _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.NodeAnnouncement(null, _msg); }
116 Result_boolLightningErrorZ ret = arg.handle_node_announcement(_msg_hu_conv);
118 long result = ret == null ? 0 : ret.clone_ptr();
121 public long handle_channel_announcement(long _msg) {
122 org.ldk.structs.ChannelAnnouncement _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.ChannelAnnouncement(null, _msg); }
123 Result_boolLightningErrorZ ret = arg.handle_channel_announcement(_msg_hu_conv);
125 long result = ret == null ? 0 : ret.clone_ptr();
128 public long handle_channel_update(long _msg) {
129 org.ldk.structs.ChannelUpdate _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.ChannelUpdate(null, _msg); }
130 Result_boolLightningErrorZ ret = arg.handle_channel_update(_msg_hu_conv);
132 long result = ret == null ? 0 : ret.clone_ptr();
135 public long get_next_channel_announcement(long _starting_point) {
136 Option_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ ret = arg.get_next_channel_announcement(_starting_point);
138 long result = ret == null ? 0 : ret.clone_ptr();
141 public long get_next_node_announcement(byte[] _starting_point) {
142 NodeAnnouncement ret = arg.get_next_node_announcement(_starting_point);
144 long result = ret == null ? 0 : ret.clone_ptr();
147 public long peer_connected(byte[] _their_node_id, long _init) {
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, _init_hu_conv);
151 long result = ret == null ? 0 : ret.clone_ptr();
154 public long handle_reply_channel_range(byte[] _their_node_id, long _msg) {
155 org.ldk.structs.ReplyChannelRange _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.ReplyChannelRange(null, _msg); }
156 if (_msg_hu_conv != null) { _msg_hu_conv.ptrs_to.AddLast(this); };
157 Result_NoneLightningErrorZ ret = arg.handle_reply_channel_range(_their_node_id, _msg_hu_conv);
159 long result = ret == null ? 0 : ret.clone_ptr();
162 public long handle_reply_short_channel_ids_end(byte[] _their_node_id, long _msg) {
163 org.ldk.structs.ReplyShortChannelIdsEnd _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.ReplyShortChannelIdsEnd(null, _msg); }
164 if (_msg_hu_conv != null) { _msg_hu_conv.ptrs_to.AddLast(this); };
165 Result_NoneLightningErrorZ ret = arg.handle_reply_short_channel_ids_end(_their_node_id, _msg_hu_conv);
167 long result = ret == null ? 0 : ret.clone_ptr();
170 public long handle_query_channel_range(byte[] _their_node_id, long _msg) {
171 org.ldk.structs.QueryChannelRange _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.QueryChannelRange(null, _msg); }
172 if (_msg_hu_conv != null) { _msg_hu_conv.ptrs_to.AddLast(this); };
173 Result_NoneLightningErrorZ ret = arg.handle_query_channel_range(_their_node_id, _msg_hu_conv);
175 long result = ret == null ? 0 : ret.clone_ptr();
178 public long handle_query_short_channel_ids(byte[] _their_node_id, long _msg) {
179 org.ldk.structs.QueryShortChannelIds _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.QueryShortChannelIds(null, _msg); }
180 if (_msg_hu_conv != null) { _msg_hu_conv.ptrs_to.AddLast(this); };
181 Result_NoneLightningErrorZ ret = arg.handle_query_short_channel_ids(_their_node_id, _msg_hu_conv);
183 long result = ret == null ? 0 : ret.clone_ptr();
186 public long provided_node_features() {
187 NodeFeatures ret = arg.provided_node_features();
189 long result = ret == null ? 0 : ret.clone_ptr();
192 public long provided_init_features(byte[] _their_node_id) {
193 InitFeatures ret = arg.provided_init_features(_their_node_id);
195 long result = ret == null ? 0 : ret.clone_ptr();
199 public static RoutingMessageHandler new_impl(RoutingMessageHandlerInterface arg, MessageSendEventsProvider.MessageSendEventsProviderInterface MessageSendEventsProvider_impl) {
200 LDKRoutingMessageHandlerHolder impl_holder = new LDKRoutingMessageHandlerHolder();
201 impl_holder.held = new RoutingMessageHandler(new LDKRoutingMessageHandlerImpl(arg, impl_holder), MessageSendEventsProvider.new_impl(MessageSendEventsProvider_impl).bindings_instance);
202 return impl_holder.held;
206 * Gets the underlying MessageSendEventsProvider.
208 public MessageSendEventsProvider get_message_send_events_provider() {
209 MessageSendEventsProvider res = new MessageSendEventsProvider(null, bindings.LDKRoutingMessageHandler_get_MessageSendEventsProvider(this.ptr));
210 this.ptrs_to.AddLast(res);
215 * Handle an incoming node_announcement message, returning true if it should be forwarded on,
216 * false or returning an Err otherwise.
218 public Result_boolLightningErrorZ handle_node_announcement(org.ldk.structs.NodeAnnouncement msg) {
219 long ret = bindings.RoutingMessageHandler_handle_node_announcement(this.ptr, msg == null ? 0 : msg.ptr);
222 if (ret >= 0 && ret <= 4096) { return null; }
223 Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret);
224 if (this != null) { this.ptrs_to.AddLast(msg); };
229 * Handle a channel_announcement message, returning true if it should be forwarded on, false
230 * or returning an Err otherwise.
232 public Result_boolLightningErrorZ handle_channel_announcement(org.ldk.structs.ChannelAnnouncement msg) {
233 long ret = bindings.RoutingMessageHandler_handle_channel_announcement(this.ptr, msg == null ? 0 : msg.ptr);
236 if (ret >= 0 && ret <= 4096) { return null; }
237 Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret);
238 if (this != null) { this.ptrs_to.AddLast(msg); };
243 * Handle an incoming channel_update message, returning true if it should be forwarded on,
244 * false or returning an Err otherwise.
246 public Result_boolLightningErrorZ handle_channel_update(org.ldk.structs.ChannelUpdate msg) {
247 long ret = bindings.RoutingMessageHandler_handle_channel_update(this.ptr, msg == null ? 0 : msg.ptr);
250 if (ret >= 0 && ret <= 4096) { return null; }
251 Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret);
252 if (this != null) { this.ptrs_to.AddLast(msg); };
257 * Gets channel announcements and updates required to dump our routing table to a remote node,
258 * starting at the short_channel_id indicated by starting_point and including announcements
259 * for a single channel.
261 public Option_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ get_next_channel_announcement(long starting_point) {
262 long ret = bindings.RoutingMessageHandler_get_next_channel_announcement(this.ptr, starting_point);
264 GC.KeepAlive(starting_point);
265 if (ret >= 0 && ret <= 4096) { return null; }
266 org.ldk.structs.Option_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ ret_hu_conv = org.ldk.structs.Option_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ.constr_from_ptr(ret);
267 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
272 * Gets a node announcement required to dump our routing table to a remote node, starting at
273 * the node *after* the provided pubkey and including up to one announcement immediately
274 * higher (as defined by <PublicKey as Ord>::cmp) than starting_point.
275 * If None is provided for starting_point, we start at the first node.
277 * Note that starting_point (or a relevant inner pointer) may be NULL or all-0s to represent None
278 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
280 public NodeAnnouncement get_next_node_announcement(byte[] starting_point) {
281 long ret = bindings.RoutingMessageHandler_get_next_node_announcement(this.ptr, InternalUtils.check_arr_len(starting_point, 33));
283 GC.KeepAlive(starting_point);
284 if (ret >= 0 && ret <= 4096) { return null; }
285 org.ldk.structs.NodeAnnouncement ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeAnnouncement(null, ret); }
286 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
291 * Called when a connection is established with a peer. This can be used to
292 * perform routing table synchronization using a strategy defined by the
295 * May return an `Err(())` if the features the peer supports are not sufficient to communicate
296 * with us. Implementors should be somewhat conservative about doing so, however, as other
297 * message handlers may still wish to communicate with this peer.
299 public Result_NoneNoneZ peer_connected(byte[] their_node_id, org.ldk.structs.Init init) {
300 long ret = bindings.RoutingMessageHandler_peer_connected(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), init == null ? 0 : init.ptr);
302 GC.KeepAlive(their_node_id);
304 if (ret >= 0 && ret <= 4096) { return null; }
305 Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
306 if (this != null) { this.ptrs_to.AddLast(init); };
311 * Handles the reply of a query we initiated to learn about channels
312 * for a given range of blocks. We can expect to receive one or more
313 * replies to a single query.
315 public Result_NoneLightningErrorZ handle_reply_channel_range(byte[] their_node_id, org.ldk.structs.ReplyChannelRange msg) {
316 long ret = bindings.RoutingMessageHandler_handle_reply_channel_range(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
318 GC.KeepAlive(their_node_id);
320 if (ret >= 0 && ret <= 4096) { return null; }
321 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
322 if (this != null) { this.ptrs_to.AddLast(msg); };
327 * Handles the reply of a query we initiated asking for routing gossip
328 * messages for a list of channels. We should receive this message when
329 * a node has completed its best effort to send us the pertaining routing
332 public Result_NoneLightningErrorZ handle_reply_short_channel_ids_end(byte[] their_node_id, org.ldk.structs.ReplyShortChannelIdsEnd msg) {
333 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);
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 when a peer asks us to send a list of short_channel_ids
345 * for the requested range of blocks.
347 public Result_NoneLightningErrorZ handle_query_channel_range(byte[] their_node_id, org.ldk.structs.QueryChannelRange msg) {
348 long ret = bindings.RoutingMessageHandler_handle_query_channel_range(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
350 GC.KeepAlive(their_node_id);
352 if (ret >= 0 && ret <= 4096) { return null; }
353 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
354 if (this != null) { this.ptrs_to.AddLast(msg); };
359 * Handles when a peer asks us to send routing gossip messages for a
360 * list of short_channel_ids.
362 public Result_NoneLightningErrorZ handle_query_short_channel_ids(byte[] their_node_id, org.ldk.structs.QueryShortChannelIds msg) {
363 long ret = bindings.RoutingMessageHandler_handle_query_short_channel_ids(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
365 GC.KeepAlive(their_node_id);
367 if (ret >= 0 && ret <= 4096) { return null; }
368 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
369 if (this != null) { this.ptrs_to.AddLast(msg); };
374 * Gets the node feature flags which this handler itself supports. All available handlers are
375 * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
376 * which are broadcasted in our [`NodeAnnouncement`] message.
378 public NodeFeatures provided_node_features() {
379 long ret = bindings.RoutingMessageHandler_provided_node_features(this.ptr);
381 if (ret >= 0 && ret <= 4096) { return null; }
382 org.ldk.structs.NodeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeFeatures(null, ret); }
383 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
388 * Gets the init feature flags which should be sent to the given peer. All available handlers
389 * are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
390 * which are sent in our [`Init`] message.
392 * Note that this method is called before [`Self::peer_connected`].
394 public InitFeatures provided_init_features(byte[] their_node_id) {
395 long ret = bindings.RoutingMessageHandler_provided_init_features(this.ptr, InternalUtils.check_arr_len(their_node_id, 33));
397 GC.KeepAlive(their_node_id);
398 if (ret >= 0 && ret <= 4096) { return null; }
399 org.ldk.structs.InitFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InitFeatures(null, ret); }
400 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };