[C#] Update auto-generated C# bindings
[ldk-java] / c_sharp / src / org / ldk / structs / CustomMessageHandler.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 CustomMessageHandler */
12 public interface CustomMessageHandlerInterface {
13         /**Handles the given message sent from `sender_node_id`, possibly producing messages for
14          * [`CustomMessageHandler::get_and_clear_pending_msg`] to return and thus for [`PeerManager`]
15          * to send.
16          */
17         Result_NoneLightningErrorZ handle_custom_message(Type msg, byte[] sender_node_id);
18         /**Returns the list of pending messages that were generated by the handler, clearing the list
19          * in the process. Each message is paired with the node id of the intended recipient. If no
20          * connection to the node exists, then the message is simply not sent.
21          */
22         TwoTuple_PublicKeyTypeZ[] get_and_clear_pending_msg();
23         /**Gets the node feature flags which this handler itself supports. All available handlers are
24          * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
25          * which are broadcasted in our [`NodeAnnouncement`] message.
26          * 
27          * [`NodeAnnouncement`]: crate::ln::msgs::NodeAnnouncement
28          */
29         NodeFeatures provided_node_features();
30         /**Gets the init feature flags which should be sent to the given peer. All available handlers
31          * are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
32          * which are sent in our [`Init`] message.
33          * 
34          * [`Init`]: crate::ln::msgs::Init
35          */
36         InitFeatures provided_init_features(byte[] their_node_id);
37 }
38
39 /**
40  * A handler provided to [`PeerManager`] for reading and handling custom messages.
41  * 
42  * [BOLT 1] specifies a custom message type range for use with experimental or application-specific
43  * messages. `CustomMessageHandler` allows for user-defined handling of such types. See the
44  * [`lightning_custom_message`] crate for tools useful in composing more than one custom handler.
45  * 
46  * [BOLT 1]: https://github.com/lightning/bolts/blob/master/01-messaging.md
47  * [`lightning_custom_message`]: https://docs.rs/lightning_custom_message/latest/lightning_custom_message
48  */
49 public class CustomMessageHandler : CommonBase {
50         internal bindings.LDKCustomMessageHandler bindings_instance;
51         internal long instance_idx;
52
53         internal CustomMessageHandler(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
54         ~CustomMessageHandler() {
55                 if (ptr != 0) { bindings.CustomMessageHandler_free(ptr); }
56         }
57
58         private class LDKCustomMessageHandlerHolder { internal CustomMessageHandler held; }
59         private class LDKCustomMessageHandlerImpl : bindings.LDKCustomMessageHandler {
60                 internal LDKCustomMessageHandlerImpl(CustomMessageHandlerInterface arg, LDKCustomMessageHandlerHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
61                 private CustomMessageHandlerInterface arg;
62                 private LDKCustomMessageHandlerHolder impl_holder;
63                 public long handle_custom_message(long _msg, long _sender_node_id) {
64                         Type ret_hu_conv = new Type(null, _msg);
65                         if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
66                         byte[] _sender_node_id_conv = InternalUtils.decodeUint8Array(_sender_node_id);
67                         Result_NoneLightningErrorZ ret = arg.handle_custom_message(ret_hu_conv, _sender_node_id_conv);
68                                 GC.KeepAlive(arg);
69                         long result = ret == null ? 0 : ret.clone_ptr();
70                         return result;
71                 }
72                 public long get_and_clear_pending_msg() {
73                         TwoTuple_PublicKeyTypeZ[] ret = arg.get_and_clear_pending_msg();
74                                 GC.KeepAlive(arg);
75                         long result = InternalUtils.encodeUint64Array(InternalUtils.mapArray(ret, ret_conv_25 => ret_conv_25 == null ? 0 : ret_conv_25.clone_ptr()));
76                         return result;
77                 }
78                 public long provided_node_features() {
79                         NodeFeatures ret = arg.provided_node_features();
80                                 GC.KeepAlive(arg);
81                         long result = ret == null ? 0 : ret.clone_ptr();
82                         return result;
83                 }
84                 public long provided_init_features(long _their_node_id) {
85                         byte[] _their_node_id_conv = InternalUtils.decodeUint8Array(_their_node_id);
86                         InitFeatures ret = arg.provided_init_features(_their_node_id_conv);
87                                 GC.KeepAlive(arg);
88                         long result = ret == null ? 0 : ret.clone_ptr();
89                         return result;
90                 }
91         }
92
93         /** Creates a new instance of CustomMessageHandler from a given implementation */
94         public static CustomMessageHandler new_impl(CustomMessageHandlerInterface arg, CustomMessageReaderInterface customMessageReader_impl) {
95                 LDKCustomMessageHandlerHolder impl_holder = new LDKCustomMessageHandlerHolder();
96                 LDKCustomMessageHandlerImpl impl = new LDKCustomMessageHandlerImpl(arg, impl_holder);
97                 CustomMessageReader customMessageReader = CustomMessageReader.new_impl(customMessageReader_impl);
98                 long[] ptr_idx = bindings.LDKCustomMessageHandler_new(impl, customMessageReader.instance_idx);
99
100                 impl_holder.held = new CustomMessageHandler(null, ptr_idx[0]);
101                 impl_holder.held.instance_idx = ptr_idx[1];
102                 impl_holder.held.bindings_instance = impl;
103                 impl_holder.held.ptrs_to.AddLast(customMessageReader);
104                 return impl_holder.held;
105         }
106
107         /**
108          * Handles the given message sent from `sender_node_id`, possibly producing messages for
109          * [`CustomMessageHandler::get_and_clear_pending_msg`] to return and thus for [`PeerManager`]
110          * to send.
111          */
112         public Result_NoneLightningErrorZ handle_custom_message(org.ldk.structs.Type msg, byte[] sender_node_id) {
113                 long ret = bindings.CustomMessageHandler_handle_custom_message(this.ptr, msg.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(sender_node_id, 33)));
114                 GC.KeepAlive(this);
115                 GC.KeepAlive(msg);
116                 GC.KeepAlive(sender_node_id);
117                 if (ret >= 0 && ret <= 4096) { return null; }
118                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
119                 if (this != null) { this.ptrs_to.AddLast(msg); };
120                 return ret_hu_conv;
121         }
122
123         /**
124          * Returns the list of pending messages that were generated by the handler, clearing the list
125          * in the process. Each message is paired with the node id of the intended recipient. If no
126          * connection to the node exists, then the message is simply not sent.
127          */
128         public TwoTuple_PublicKeyTypeZ[] get_and_clear_pending_msg() {
129                 long ret = bindings.CustomMessageHandler_get_and_clear_pending_msg(this.ptr);
130                 GC.KeepAlive(this);
131                 if (ret >= 0 && ret <= 4096) { return null; }
132                 int ret_conv_25_len = InternalUtils.getArrayLength(ret);
133                 TwoTuple_PublicKeyTypeZ[] ret_conv_25_arr = new TwoTuple_PublicKeyTypeZ[ret_conv_25_len];
134                 for (int z = 0; z < ret_conv_25_len; z++) {
135                         long ret_conv_25 = InternalUtils.getU64ArrayElem(ret, z);
136                         TwoTuple_PublicKeyTypeZ ret_conv_25_hu_conv = new TwoTuple_PublicKeyTypeZ(null, ret_conv_25);
137                         if (ret_conv_25_hu_conv != null) { ret_conv_25_hu_conv.ptrs_to.AddLast(this); };
138                         ret_conv_25_arr[z] = ret_conv_25_hu_conv;
139                 }
140                 bindings.free_buffer(ret);
141                 return ret_conv_25_arr;
142         }
143
144         /**
145          * Gets the node feature flags which this handler itself supports. All available handlers are
146          * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
147          * which are broadcasted in our [`NodeAnnouncement`] message.
148          * 
149          * [`NodeAnnouncement`]: crate::ln::msgs::NodeAnnouncement
150          */
151         public NodeFeatures provided_node_features() {
152                 long ret = bindings.CustomMessageHandler_provided_node_features(this.ptr);
153                 GC.KeepAlive(this);
154                 if (ret >= 0 && ret <= 4096) { return null; }
155                 org.ldk.structs.NodeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeFeatures(null, ret); }
156                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
157                 return ret_hu_conv;
158         }
159
160         /**
161          * Gets the init feature flags which should be sent to the given peer. All available handlers
162          * are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
163          * which are sent in our [`Init`] message.
164          * 
165          * [`Init`]: crate::ln::msgs::Init
166          */
167         public InitFeatures provided_init_features(byte[] their_node_id) {
168                 long ret = bindings.CustomMessageHandler_provided_init_features(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(their_node_id, 33)));
169                 GC.KeepAlive(this);
170                 GC.KeepAlive(their_node_id);
171                 if (ret >= 0 && ret <= 4096) { return null; }
172                 org.ldk.structs.InitFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InitFeatures(null, ret); }
173                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
174                 return ret_hu_conv;
175         }
176
177 }
178 } } }