6 namespace org { namespace ldk { namespace structs {
9 * A trait defining behavior for routing an [`OnionMessage`].
11 * [`OnionMessage`]: msgs::OnionMessage
13 public class MessageRouter : CommonBase {
14 internal readonly bindings.LDKMessageRouter bindings_instance;
15 internal MessageRouter(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
16 private MessageRouter(bindings.LDKMessageRouter arg) : base(bindings.LDKMessageRouter_new(arg)) {
17 this.ptrs_to.AddLast(arg);
18 this.bindings_instance = arg;
21 if (ptr != 0) { bindings.MessageRouter_free(ptr); }
24 public interface MessageRouterInterface {
26 * Returns a route for sending an [`OnionMessage`] to the given [`Destination`].
28 * [`OnionMessage`]: msgs::OnionMessage
30 Result_OnionMessagePathNoneZ find_path(byte[] _sender, byte[][] _peers, Destination _destination);
32 private class LDKMessageRouterHolder { internal MessageRouter held; }
33 private class LDKMessageRouterImpl : bindings.LDKMessageRouter {
34 internal LDKMessageRouterImpl(MessageRouterInterface arg, LDKMessageRouterHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
35 private MessageRouterInterface arg;
36 private LDKMessageRouterHolder impl_holder;
37 public long find_path(byte[] _sender, byte[][] _peers, long _destination) {
38 org.ldk.structs.Destination _destination_hu_conv = org.ldk.structs.Destination.constr_from_ptr(_destination);
39 if (_destination_hu_conv != null) { _destination_hu_conv.ptrs_to.AddLast(this); };
40 Result_OnionMessagePathNoneZ ret = arg.find_path(_sender, _peers, _destination_hu_conv);
42 long result = ret == null ? 0 : ret.clone_ptr();
46 public static MessageRouter new_impl(MessageRouterInterface arg) {
47 LDKMessageRouterHolder impl_holder = new LDKMessageRouterHolder();
48 impl_holder.held = new MessageRouter(new LDKMessageRouterImpl(arg, impl_holder));
49 return impl_holder.held;
52 * Returns a route for sending an [`OnionMessage`] to the given [`Destination`].
54 * [`OnionMessage`]: msgs::OnionMessage
56 public Result_OnionMessagePathNoneZ find_path(byte[] sender, byte[][] peers, org.ldk.structs.Destination destination) {
57 long ret = bindings.MessageRouter_find_path(this.ptr, InternalUtils.check_arr_len(sender, 33), peers != null ? InternalUtils.mapArray(peers, peers_conv_8 => InternalUtils.check_arr_len(peers_conv_8, 33)) : null, destination.ptr);
61 GC.KeepAlive(destination);
62 if (ret >= 0 && ret <= 4096) { return null; }
63 Result_OnionMessagePathNoneZ ret_hu_conv = Result_OnionMessagePathNoneZ.constr_from_ptr(ret);
64 if (this != null) { this.ptrs_to.AddLast(destination); };