6 namespace org { namespace ldk { namespace structs {
9 * Handler for custom onion messages. If you are using [`SimpleArcOnionMessenger`],
10 * [`SimpleRefOnionMessenger`], or prefer to ignore inbound custom onion messages,
11 * [`IgnoringMessageHandler`] must be provided to [`OnionMessenger::new`]. Otherwise, a custom
12 * implementation of this trait must be provided, with [`CustomMessage`] specifying the supported
15 * See [`OnionMessenger`] for example usage.
17 * [`IgnoringMessageHandler`]: crate::ln::peer_handler::IgnoringMessageHandler
18 * [`CustomMessage`]: Self::CustomMessage
20 public class CustomOnionMessageHandler : CommonBase {
21 internal readonly bindings.LDKCustomOnionMessageHandler bindings_instance;
22 internal CustomOnionMessageHandler(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
23 private CustomOnionMessageHandler(bindings.LDKCustomOnionMessageHandler arg) : base(bindings.LDKCustomOnionMessageHandler_new(arg)) {
24 this.ptrs_to.AddLast(arg);
25 this.bindings_instance = arg;
27 ~CustomOnionMessageHandler() {
28 if (ptr != 0) { bindings.CustomOnionMessageHandler_free(ptr); }
31 public interface CustomOnionMessageHandlerInterface {
33 * Called with the custom message that was received.
35 void handle_custom_message(CustomOnionMessageContents _msg);
37 * Read a custom message of type `message_type` from `buffer`, returning `Ok(None)` if the
38 * message type is unknown.
40 Result_COption_CustomOnionMessageContentsZDecodeErrorZ read_custom_message(long _message_type, byte[] _buffer);
42 private class LDKCustomOnionMessageHandlerHolder { internal CustomOnionMessageHandler held; }
43 private class LDKCustomOnionMessageHandlerImpl : bindings.LDKCustomOnionMessageHandler {
44 internal LDKCustomOnionMessageHandlerImpl(CustomOnionMessageHandlerInterface arg, LDKCustomOnionMessageHandlerHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
45 private CustomOnionMessageHandlerInterface arg;
46 private LDKCustomOnionMessageHandlerHolder impl_holder;
47 public void handle_custom_message(long _msg) {
48 CustomOnionMessageContents ret_hu_conv = new CustomOnionMessageContents(null, _msg);
49 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
50 arg.handle_custom_message(ret_hu_conv);
53 public long read_custom_message(long _message_type, byte[] _buffer) {
54 Result_COption_CustomOnionMessageContentsZDecodeErrorZ ret = arg.read_custom_message(_message_type, _buffer);
56 long result = ret == null ? 0 : ret.clone_ptr();
60 public static CustomOnionMessageHandler new_impl(CustomOnionMessageHandlerInterface arg) {
61 LDKCustomOnionMessageHandlerHolder impl_holder = new LDKCustomOnionMessageHandlerHolder();
62 impl_holder.held = new CustomOnionMessageHandler(new LDKCustomOnionMessageHandlerImpl(arg, impl_holder));
63 return impl_holder.held;
66 * Called with the custom message that was received.
68 public void handle_custom_message(org.ldk.structs.CustomOnionMessageContents msg) {
69 bindings.CustomOnionMessageHandler_handle_custom_message(this.ptr, msg == null ? 0 : msg.ptr);
72 if (this != null) { this.ptrs_to.AddLast(msg); };
76 * Read a custom message of type `message_type` from `buffer`, returning `Ok(None)` if the
77 * message type is unknown.
79 public Result_COption_CustomOnionMessageContentsZDecodeErrorZ read_custom_message(long message_type, byte[] buffer) {
80 long ret = bindings.CustomOnionMessageHandler_read_custom_message(this.ptr, message_type, buffer);
82 GC.KeepAlive(message_type);
84 if (ret >= 0 && ret <= 4096) { return null; }
85 Result_COption_CustomOnionMessageContentsZDecodeErrorZ ret_hu_conv = Result_COption_CustomOnionMessageContentsZDecodeErrorZ.constr_from_ptr(ret);