[C#] Update auto-generated C# bindings
[ldk-java] / c_sharp / src / org / ldk / structs / CustomOnionMessageHandler.cs
1
2 using org.ldk.impl;
3 using org.ldk.enums;
4 using org.ldk.util;
5 using System;
6
7 namespace org { namespace ldk { namespace structs {
8
9
10
11 /** An implementation of CustomOnionMessageHandler */
12 public interface CustomOnionMessageHandlerInterface {
13         /**Called with the custom message that was received, returning a response to send, if any.
14          * 
15          * The returned [`Self::CustomMessage`], if any, is enqueued to be sent by [`OnionMessenger`].
16          */
17         Option_OnionMessageContentsZ handle_custom_message(OnionMessageContents msg);
18         /**Read a custom message of type `message_type` from `buffer`, returning `Ok(None)` if the
19          * message type is unknown.
20          */
21         Result_COption_OnionMessageContentsZDecodeErrorZ read_custom_message(long message_type, byte[] buffer);
22         /**Releases any [`Self::CustomMessage`]s that need to be sent.
23          * 
24          * Typically, this is used for messages initiating a message flow rather than in response to
25          * another message. The latter should use the return value of [`Self::handle_custom_message`].
26          */
27         ThreeTuple_OnionMessageContentsDestinationBlindedPathZ[] release_pending_custom_messages();
28 }
29
30 /**
31  * Handler for custom onion messages. If you are using [`SimpleArcOnionMessenger`],
32  * [`SimpleRefOnionMessenger`], or prefer to ignore inbound custom onion messages,
33  * [`IgnoringMessageHandler`] must be provided to [`OnionMessenger::new`]. Otherwise, a custom
34  * implementation of this trait must be provided, with [`CustomMessage`] specifying the supported
35  * message types.
36  * 
37  * See [`OnionMessenger`] for example usage.
38  * 
39  * [`IgnoringMessageHandler`]: crate::ln::peer_handler::IgnoringMessageHandler
40  * [`CustomMessage`]: Self::CustomMessage
41  */
42 public class CustomOnionMessageHandler : CommonBase {
43         internal bindings.LDKCustomOnionMessageHandler bindings_instance;
44         internal long instance_idx;
45
46         internal CustomOnionMessageHandler(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
47         ~CustomOnionMessageHandler() {
48                 if (ptr != 0) { bindings.CustomOnionMessageHandler_free(ptr); }
49         }
50
51         private class LDKCustomOnionMessageHandlerHolder { internal CustomOnionMessageHandler held; }
52         private class LDKCustomOnionMessageHandlerImpl : bindings.LDKCustomOnionMessageHandler {
53                 internal LDKCustomOnionMessageHandlerImpl(CustomOnionMessageHandlerInterface arg, LDKCustomOnionMessageHandlerHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
54                 private CustomOnionMessageHandlerInterface arg;
55                 private LDKCustomOnionMessageHandlerHolder impl_holder;
56                 public long handle_custom_message(long _msg) {
57                         OnionMessageContents ret_hu_conv = new OnionMessageContents(null, _msg);
58                         if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
59                         Option_OnionMessageContentsZ ret = arg.handle_custom_message(ret_hu_conv);
60                                 GC.KeepAlive(arg);
61                         long result = ret == null ? 0 : ret.clone_ptr();
62                         if (impl_holder.held != null) { impl_holder.held.ptrs_to.AddLast(ret); };
63                         return result;
64                 }
65                 public long read_custom_message(long _message_type, long _buffer) {
66                         byte[] _buffer_conv = InternalUtils.decodeUint8Array(_buffer);
67                         Result_COption_OnionMessageContentsZDecodeErrorZ ret = arg.read_custom_message(_message_type, _buffer_conv);
68                                 GC.KeepAlive(arg);
69                         long result = ret == null ? 0 : ret.clone_ptr();
70                         return result;
71                 }
72                 public long release_pending_custom_messages() {
73                         ThreeTuple_OnionMessageContentsDestinationBlindedPathZ[] ret = arg.release_pending_custom_messages();
74                                 GC.KeepAlive(arg);
75                         long result = InternalUtils.encodeUint64Array(InternalUtils.mapArray(ret, ret_conv_56 => ret_conv_56 == null ? 0 : ret_conv_56.clone_ptr()));
76                         return result;
77                 }
78         }
79
80         /** Creates a new instance of CustomOnionMessageHandler from a given implementation */
81         public static CustomOnionMessageHandler new_impl(CustomOnionMessageHandlerInterface arg) {
82                 LDKCustomOnionMessageHandlerHolder impl_holder = new LDKCustomOnionMessageHandlerHolder();
83                 LDKCustomOnionMessageHandlerImpl impl = new LDKCustomOnionMessageHandlerImpl(arg, impl_holder);
84                 long[] ptr_idx = bindings.LDKCustomOnionMessageHandler_new(impl);
85
86                 impl_holder.held = new CustomOnionMessageHandler(null, ptr_idx[0]);
87                 impl_holder.held.instance_idx = ptr_idx[1];
88                 impl_holder.held.bindings_instance = impl;
89                 return impl_holder.held;
90         }
91
92         /**
93          * Called with the custom message that was received, returning a response to send, if any.
94          * 
95          * The returned [`Self::CustomMessage`], if any, is enqueued to be sent by [`OnionMessenger`].
96          */
97         public Option_OnionMessageContentsZ handle_custom_message(org.ldk.structs.OnionMessageContents msg) {
98                 long ret = bindings.CustomOnionMessageHandler_handle_custom_message(this.ptr, msg.ptr);
99                 GC.KeepAlive(this);
100                 GC.KeepAlive(msg);
101                 if (ret >= 0 && ret <= 4096) { return null; }
102                 org.ldk.structs.Option_OnionMessageContentsZ ret_hu_conv = org.ldk.structs.Option_OnionMessageContentsZ.constr_from_ptr(ret);
103                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
104                 if (this != null) { this.ptrs_to.AddLast(msg); };
105                 return ret_hu_conv;
106         }
107
108         /**
109          * Read a custom message of type `message_type` from `buffer`, returning `Ok(None)` if the
110          * message type is unknown.
111          */
112         public Result_COption_OnionMessageContentsZDecodeErrorZ read_custom_message(long message_type, byte[] buffer) {
113                 long ret = bindings.CustomOnionMessageHandler_read_custom_message(this.ptr, message_type, InternalUtils.encodeUint8Array(buffer));
114                 GC.KeepAlive(this);
115                 GC.KeepAlive(message_type);
116                 GC.KeepAlive(buffer);
117                 if (ret >= 0 && ret <= 4096) { return null; }
118                 Result_COption_OnionMessageContentsZDecodeErrorZ ret_hu_conv = Result_COption_OnionMessageContentsZDecodeErrorZ.constr_from_ptr(ret);
119                 return ret_hu_conv;
120         }
121
122         /**
123          * Releases any [`Self::CustomMessage`]s that need to be sent.
124          * 
125          * Typically, this is used for messages initiating a message flow rather than in response to
126          * another message. The latter should use the return value of [`Self::handle_custom_message`].
127          */
128         public ThreeTuple_OnionMessageContentsDestinationBlindedPathZ[] release_pending_custom_messages() {
129                 long ret = bindings.CustomOnionMessageHandler_release_pending_custom_messages(this.ptr);
130                 GC.KeepAlive(this);
131                 if (ret >= 0 && ret <= 4096) { return null; }
132                 int ret_conv_56_len = InternalUtils.getArrayLength(ret);
133                 ThreeTuple_OnionMessageContentsDestinationBlindedPathZ[] ret_conv_56_arr = new ThreeTuple_OnionMessageContentsDestinationBlindedPathZ[ret_conv_56_len];
134                 for (int e = 0; e < ret_conv_56_len; e++) {
135                         long ret_conv_56 = InternalUtils.getU64ArrayElem(ret, e);
136                         ThreeTuple_OnionMessageContentsDestinationBlindedPathZ ret_conv_56_hu_conv = new ThreeTuple_OnionMessageContentsDestinationBlindedPathZ(null, ret_conv_56);
137                         if (ret_conv_56_hu_conv != null) { ret_conv_56_hu_conv.ptrs_to.AddLast(this); };
138                         ret_conv_56_arr[e] = ret_conv_56_hu_conv;
139                 }
140                 bindings.free_buffer(ret);
141                 return ret_conv_56_arr;
142         }
143
144 }
145 } } }