[C#] Update auto-generated files
[ldk-java] / c_sharp / src / org / ldk / structs / CustomOnionMessageHandler.cs
1 using org.ldk.impl;
2 using org.ldk.enums;
3 using org.ldk.util;
4 using System;
5
6 namespace org { namespace ldk { namespace structs {
7
8 /**
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
13  * message types.
14  * 
15  * See [`OnionMessenger`] for example usage.
16  * 
17  * [`IgnoringMessageHandler`]: crate::ln::peer_handler::IgnoringMessageHandler
18  * [`CustomMessage`]: Self::CustomMessage
19  */
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;
26         }
27         ~CustomOnionMessageHandler() {
28                 if (ptr != 0) { bindings.CustomOnionMessageHandler_free(ptr); }
29         }
30
31         public interface CustomOnionMessageHandlerInterface {
32                 /**
33                  * Called with the custom message that was received, returning a response to send, if any.
34                  */
35                 Option_CustomOnionMessageContentsZ handle_custom_message(CustomOnionMessageContents _msg);
36                 /**
37                  * Read a custom message of type `message_type` from `buffer`, returning `Ok(None)` if the
38                  * message type is unknown.
39                  */
40                 Result_COption_CustomOnionMessageContentsZDecodeErrorZ read_custom_message(long _message_type, byte[] _buffer);
41         }
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 long 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                         Option_CustomOnionMessageContentsZ ret = arg.handle_custom_message(ret_hu_conv);
51                                 GC.KeepAlive(arg);
52                         long result = ret == null ? 0 : ret.clone_ptr();
53                         if (impl_holder.held != null) { impl_holder.held.ptrs_to.AddLast(ret); };
54                         return result;
55                 }
56                 public long read_custom_message(long _message_type, byte[] _buffer) {
57                         Result_COption_CustomOnionMessageContentsZDecodeErrorZ ret = arg.read_custom_message(_message_type, _buffer);
58                                 GC.KeepAlive(arg);
59                         long result = ret == null ? 0 : ret.clone_ptr();
60                         return result;
61                 }
62         }
63         public static CustomOnionMessageHandler new_impl(CustomOnionMessageHandlerInterface arg) {
64                 LDKCustomOnionMessageHandlerHolder impl_holder = new LDKCustomOnionMessageHandlerHolder();
65                 impl_holder.held = new CustomOnionMessageHandler(new LDKCustomOnionMessageHandlerImpl(arg, impl_holder));
66                 return impl_holder.held;
67         }
68         /**
69          * Called with the custom message that was received, returning a response to send, if any.
70          */
71         public Option_CustomOnionMessageContentsZ handle_custom_message(org.ldk.structs.CustomOnionMessageContents msg) {
72                 long ret = bindings.CustomOnionMessageHandler_handle_custom_message(this.ptr, msg.ptr);
73                 GC.KeepAlive(this);
74                 GC.KeepAlive(msg);
75                 if (ret >= 0 && ret <= 4096) { return null; }
76                 org.ldk.structs.Option_CustomOnionMessageContentsZ ret_hu_conv = org.ldk.structs.Option_CustomOnionMessageContentsZ.constr_from_ptr(ret);
77                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
78                 if (this != null) { this.ptrs_to.AddLast(msg); };
79                 return ret_hu_conv;
80         }
81
82         /**
83          * Read a custom message of type `message_type` from `buffer`, returning `Ok(None)` if the
84          * message type is unknown.
85          */
86         public Result_COption_CustomOnionMessageContentsZDecodeErrorZ read_custom_message(long message_type, byte[] buffer) {
87                 long ret = bindings.CustomOnionMessageHandler_read_custom_message(this.ptr, message_type, buffer);
88                 GC.KeepAlive(this);
89                 GC.KeepAlive(message_type);
90                 GC.KeepAlive(buffer);
91                 if (ret >= 0 && ret <= 4096) { return null; }
92                 Result_COption_CustomOnionMessageContentsZDecodeErrorZ ret_hu_conv = Result_COption_CustomOnionMessageContentsZDecodeErrorZ.constr_from_ptr(ret);
93                 return ret_hu_conv;
94         }
95
96 }
97 } } }