X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=c_sharp%2Fsrc%2Forg%2Fldk%2Fstructs%2FMessageRouter.cs;h=c2b1fb974eaa1474b48bd2114c4ed07905518d7b;hb=8de7213fbf663ff60322896282dad51e8ab2f001;hp=c70ec240483b91fec5f30b30eb10d1a75b43e093;hpb=afc50e5d491a11364849383b75a8f939df703bac;p=ldk-java diff --git a/c_sharp/src/org/ldk/structs/MessageRouter.cs b/c_sharp/src/org/ldk/structs/MessageRouter.cs index c70ec240..c2b1fb97 100644 --- a/c_sharp/src/org/ldk/structs/MessageRouter.cs +++ b/c_sharp/src/org/ldk/structs/MessageRouter.cs @@ -1,3 +1,4 @@ + using org.ldk.impl; using org.ldk.enums; using org.ldk.util; @@ -5,56 +6,68 @@ using System; namespace org { namespace ldk { namespace structs { + + +/** An implementation of MessageRouter */ +public interface MessageRouterInterface { + /**Returns a route for sending an [`OnionMessage`] to the given [`Destination`]. + */ + Result_OnionMessagePathNoneZ find_path(byte[] sender, byte[][] peers, Destination destination); +} + /** * A trait defining behavior for routing an [`OnionMessage`]. - * - * [`OnionMessage`]: msgs::OnionMessage */ public class MessageRouter : CommonBase { - internal readonly bindings.LDKMessageRouter bindings_instance; + internal bindings.LDKMessageRouter bindings_instance; + internal long instance_idx; + internal MessageRouter(object _dummy, long ptr) : base(ptr) { bindings_instance = null; } - private MessageRouter(bindings.LDKMessageRouter arg) : base(bindings.LDKMessageRouter_new(arg)) { - this.ptrs_to.AddLast(arg); - this.bindings_instance = arg; - } ~MessageRouter() { if (ptr != 0) { bindings.MessageRouter_free(ptr); } } - public interface MessageRouterInterface { - /** - * Returns a route for sending an [`OnionMessage`] to the given [`Destination`]. - * - * [`OnionMessage`]: msgs::OnionMessage - */ - Result_OnionMessagePathNoneZ find_path(byte[] _sender, byte[][] _peers, Destination _destination); - } private class LDKMessageRouterHolder { internal MessageRouter held; } private class LDKMessageRouterImpl : bindings.LDKMessageRouter { internal LDKMessageRouterImpl(MessageRouterInterface arg, LDKMessageRouterHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; } private MessageRouterInterface arg; private LDKMessageRouterHolder impl_holder; - public long find_path(byte[] _sender, byte[][] _peers, long _destination) { + public long find_path(long _sender, long _peers, long _destination) { + byte[] _sender_conv = InternalUtils.decodeUint8Array(_sender); + int _peers_conv_8_len = InternalUtils.getArrayLength(_peers); + byte[][] _peers_conv_8_arr = new byte[_peers_conv_8_len][]; + for (int i = 0; i < _peers_conv_8_len; i++) { + long _peers_conv_8 = InternalUtils.getU64ArrayElem(_peers, i); + byte[] _peers_conv_8_conv = InternalUtils.decodeUint8Array(_peers_conv_8); + _peers_conv_8_arr[i] = _peers_conv_8_conv; + } + bindings.free_buffer(_peers); org.ldk.structs.Destination _destination_hu_conv = org.ldk.structs.Destination.constr_from_ptr(_destination); if (_destination_hu_conv != null) { _destination_hu_conv.ptrs_to.AddLast(this); }; - Result_OnionMessagePathNoneZ ret = arg.find_path(_sender, _peers, _destination_hu_conv); + Result_OnionMessagePathNoneZ ret = arg.find_path(_sender_conv, _peers_conv_8_arr, _destination_hu_conv); GC.KeepAlive(arg); long result = ret == null ? 0 : ret.clone_ptr(); return result; } } + + /** Creates a new instance of MessageRouter from a given implementation */ public static MessageRouter new_impl(MessageRouterInterface arg) { LDKMessageRouterHolder impl_holder = new LDKMessageRouterHolder(); - impl_holder.held = new MessageRouter(new LDKMessageRouterImpl(arg, impl_holder)); + LDKMessageRouterImpl impl = new LDKMessageRouterImpl(arg, impl_holder); + long[] ptr_idx = bindings.LDKMessageRouter_new(impl); + + impl_holder.held = new MessageRouter(null, ptr_idx[0]); + impl_holder.held.instance_idx = ptr_idx[1]; + impl_holder.held.bindings_instance = impl; return impl_holder.held; } + /** * Returns a route for sending an [`OnionMessage`] to the given [`Destination`]. - * - * [`OnionMessage`]: msgs::OnionMessage */ public Result_OnionMessagePathNoneZ find_path(byte[] sender, byte[][] peers, org.ldk.structs.Destination destination) { - 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); + long ret = bindings.MessageRouter_find_path(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(sender, 33)), InternalUtils.encodeUint64Array(InternalUtils.mapArray(peers, peers_conv_8 => InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(peers_conv_8, 33)))), destination.ptr); GC.KeepAlive(this); GC.KeepAlive(sender); GC.KeepAlive(peers);