[C#] Update auto-generated C# bindings
[ldk-java] / c_sharp / src / org / ldk / structs / OnionMessageHandler.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 OnionMessageHandler */
12 public interface OnionMessageHandlerInterface {
13         /**Because much of the lightning network does not yet support forwarding onion messages, we
14          * may need to directly connect to a node which will forward a message for us. In such a case,
15          * this method will return the set of nodes which need connection by node_id and the
16          * corresponding socket addresses where they may accept incoming connections.
17          * 
18          * Thus, this method should be polled regularly to detect messages await such a direct
19          * connection.
20          */
21         TwoTuple_PublicKeyCVec_SocketAddressZZ[] get_and_clear_connections_needed();
22         /**Handle an incoming `onion_message` message from the given peer.
23          */
24         void handle_onion_message(byte[] peer_node_id, OnionMessage msg);
25         /**Returns the next pending onion message for the peer with the given node id.
26          * 
27          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
28          */
29         OnionMessage next_onion_message_for_peer(byte[] peer_node_id);
30         /**Called when a connection is established with a peer. Can be used to track which peers
31          * advertise onion message support and are online.
32          * 
33          * May return an `Err(())` if the features the peer supports are not sufficient to communicate
34          * with us. Implementors should be somewhat conservative about doing so, however, as other
35          * message handlers may still wish to communicate with this peer.
36          */
37         Result_NoneNoneZ peer_connected(byte[] their_node_id, Init init, bool inbound);
38         /**Indicates a connection to the peer failed/an existing connection was lost. Allows handlers to
39          * drop and refuse to forward onion messages to this peer.
40          */
41         void peer_disconnected(byte[] their_node_id);
42         /**Performs actions that should happen roughly every ten seconds after startup. Allows handlers
43          * to drop any buffered onion messages intended for prospective peers.
44          */
45         void timer_tick_occurred();
46         /**Gets the node feature flags which this handler itself supports. All available handlers are
47          * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
48          * which are broadcasted in our [`NodeAnnouncement`] message.
49          */
50         NodeFeatures provided_node_features();
51         /**Gets the init feature flags which should be sent to the given peer. All available handlers
52          * are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
53          * which are sent in our [`Init`] message.
54          * 
55          * Note that this method is called before [`Self::peer_connected`].
56          */
57         InitFeatures provided_init_features(byte[] their_node_id);
58 }
59
60 /**
61  * A handler for received [`OnionMessage`]s and for providing generated ones to send.
62  */
63 public class OnionMessageHandler : CommonBase {
64         internal bindings.LDKOnionMessageHandler bindings_instance;
65         internal long instance_idx;
66
67         internal OnionMessageHandler(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
68         ~OnionMessageHandler() {
69                 if (ptr != 0) { bindings.OnionMessageHandler_free(ptr); }
70         }
71
72         private class LDKOnionMessageHandlerHolder { internal OnionMessageHandler held; }
73         private class LDKOnionMessageHandlerImpl : bindings.LDKOnionMessageHandler {
74                 internal LDKOnionMessageHandlerImpl(OnionMessageHandlerInterface arg, LDKOnionMessageHandlerHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
75                 private OnionMessageHandlerInterface arg;
76                 private LDKOnionMessageHandlerHolder impl_holder;
77                 public long get_and_clear_connections_needed() {
78                         TwoTuple_PublicKeyCVec_SocketAddressZZ[] ret = arg.get_and_clear_connections_needed();
79                                 GC.KeepAlive(arg);
80                         long result = InternalUtils.encodeUint64Array(InternalUtils.mapArray(ret, ret_conv_40 => ret_conv_40 == null ? 0 : ret_conv_40.clone_ptr()));
81                         return result;
82                 }
83                 public void handle_onion_message(long _peer_node_id, long _msg) {
84                         byte[] _peer_node_id_conv = InternalUtils.decodeUint8Array(_peer_node_id);
85                         org.ldk.structs.OnionMessage _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.OnionMessage(null, _msg); }
86                         arg.handle_onion_message(_peer_node_id_conv, _msg_hu_conv);
87                                 GC.KeepAlive(arg);
88                 }
89                 public long next_onion_message_for_peer(long _peer_node_id) {
90                         byte[] _peer_node_id_conv = InternalUtils.decodeUint8Array(_peer_node_id);
91                         OnionMessage ret = arg.next_onion_message_for_peer(_peer_node_id_conv);
92                                 GC.KeepAlive(arg);
93                         long result = ret == null ? 0 : ret.clone_ptr();
94                         return result;
95                 }
96                 public long peer_connected(long _their_node_id, long _init, bool _inbound) {
97                         byte[] _their_node_id_conv = InternalUtils.decodeUint8Array(_their_node_id);
98                         org.ldk.structs.Init _init_hu_conv = null; if (_init < 0 || _init > 4096) { _init_hu_conv = new org.ldk.structs.Init(null, _init); }
99                         Result_NoneNoneZ ret = arg.peer_connected(_their_node_id_conv, _init_hu_conv, _inbound);
100                                 GC.KeepAlive(arg);
101                         long result = ret == null ? 0 : ret.clone_ptr();
102                         return result;
103                 }
104                 public void peer_disconnected(long _their_node_id) {
105                         byte[] _their_node_id_conv = InternalUtils.decodeUint8Array(_their_node_id);
106                         arg.peer_disconnected(_their_node_id_conv);
107                                 GC.KeepAlive(arg);
108                 }
109                 public void timer_tick_occurred() {
110                         arg.timer_tick_occurred();
111                                 GC.KeepAlive(arg);
112                 }
113                 public long provided_node_features() {
114                         NodeFeatures ret = arg.provided_node_features();
115                                 GC.KeepAlive(arg);
116                         long result = ret == null ? 0 : ret.clone_ptr();
117                         return result;
118                 }
119                 public long provided_init_features(long _their_node_id) {
120                         byte[] _their_node_id_conv = InternalUtils.decodeUint8Array(_their_node_id);
121                         InitFeatures ret = arg.provided_init_features(_their_node_id_conv);
122                                 GC.KeepAlive(arg);
123                         long result = ret == null ? 0 : ret.clone_ptr();
124                         return result;
125                 }
126         }
127
128         /** Creates a new instance of OnionMessageHandler from a given implementation */
129         public static OnionMessageHandler new_impl(OnionMessageHandlerInterface arg) {
130                 LDKOnionMessageHandlerHolder impl_holder = new LDKOnionMessageHandlerHolder();
131                 LDKOnionMessageHandlerImpl impl = new LDKOnionMessageHandlerImpl(arg, impl_holder);
132                 long[] ptr_idx = bindings.LDKOnionMessageHandler_new(impl);
133
134                 impl_holder.held = new OnionMessageHandler(null, ptr_idx[0]);
135                 impl_holder.held.instance_idx = ptr_idx[1];
136                 impl_holder.held.bindings_instance = impl;
137                 return impl_holder.held;
138         }
139
140         /**
141          * Because much of the lightning network does not yet support forwarding onion messages, we
142          * may need to directly connect to a node which will forward a message for us. In such a case,
143          * this method will return the set of nodes which need connection by node_id and the
144          * corresponding socket addresses where they may accept incoming connections.
145          * 
146          * Thus, this method should be polled regularly to detect messages await such a direct
147          * connection.
148          */
149         public TwoTuple_PublicKeyCVec_SocketAddressZZ[] get_and_clear_connections_needed() {
150                 long ret = bindings.OnionMessageHandler_get_and_clear_connections_needed(this.ptr);
151                 GC.KeepAlive(this);
152                 if (ret >= 0 && ret <= 4096) { return null; }
153                 int ret_conv_40_len = InternalUtils.getArrayLength(ret);
154                 TwoTuple_PublicKeyCVec_SocketAddressZZ[] ret_conv_40_arr = new TwoTuple_PublicKeyCVec_SocketAddressZZ[ret_conv_40_len];
155                 for (int o = 0; o < ret_conv_40_len; o++) {
156                         long ret_conv_40 = InternalUtils.getU64ArrayElem(ret, o);
157                         TwoTuple_PublicKeyCVec_SocketAddressZZ ret_conv_40_hu_conv = new TwoTuple_PublicKeyCVec_SocketAddressZZ(null, ret_conv_40);
158                         if (ret_conv_40_hu_conv != null) { ret_conv_40_hu_conv.ptrs_to.AddLast(this); };
159                         ret_conv_40_arr[o] = ret_conv_40_hu_conv;
160                 }
161                 bindings.free_buffer(ret);
162                 return ret_conv_40_arr;
163         }
164
165         /**
166          * Handle an incoming `onion_message` message from the given peer.
167          */
168         public void handle_onion_message(byte[] peer_node_id, org.ldk.structs.OnionMessage msg) {
169                 bindings.OnionMessageHandler_handle_onion_message(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(peer_node_id, 33)), msg == null ? 0 : msg.ptr);
170                 GC.KeepAlive(this);
171                 GC.KeepAlive(peer_node_id);
172                 GC.KeepAlive(msg);
173                 if (this != null) { this.ptrs_to.AddLast(msg); };
174         }
175
176         /**
177          * Returns the next pending onion message for the peer with the given node id.
178          * 
179          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
180          */
181         public OnionMessage next_onion_message_for_peer(byte[] peer_node_id) {
182                 long ret = bindings.OnionMessageHandler_next_onion_message_for_peer(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(peer_node_id, 33)));
183                 GC.KeepAlive(this);
184                 GC.KeepAlive(peer_node_id);
185                 if (ret >= 0 && ret <= 4096) { return null; }
186                 org.ldk.structs.OnionMessage ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OnionMessage(null, ret); }
187                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
188                 return ret_hu_conv;
189         }
190
191         /**
192          * Called when a connection is established with a peer. Can be used to track which peers
193          * advertise onion message support and are online.
194          * 
195          * May return an `Err(())` if the features the peer supports are not sufficient to communicate
196          * with us. Implementors should be somewhat conservative about doing so, however, as other
197          * message handlers may still wish to communicate with this peer.
198          */
199         public Result_NoneNoneZ peer_connected(byte[] their_node_id, org.ldk.structs.Init init, bool inbound) {
200                 long ret = bindings.OnionMessageHandler_peer_connected(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(their_node_id, 33)), init == null ? 0 : init.ptr, inbound);
201                 GC.KeepAlive(this);
202                 GC.KeepAlive(their_node_id);
203                 GC.KeepAlive(init);
204                 GC.KeepAlive(inbound);
205                 if (ret >= 0 && ret <= 4096) { return null; }
206                 Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
207                 if (this != null) { this.ptrs_to.AddLast(init); };
208                 return ret_hu_conv;
209         }
210
211         /**
212          * Indicates a connection to the peer failed/an existing connection was lost. Allows handlers to
213          * drop and refuse to forward onion messages to this peer.
214          */
215         public void peer_disconnected(byte[] their_node_id) {
216                 bindings.OnionMessageHandler_peer_disconnected(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(their_node_id, 33)));
217                 GC.KeepAlive(this);
218                 GC.KeepAlive(their_node_id);
219         }
220
221         /**
222          * Performs actions that should happen roughly every ten seconds after startup. Allows handlers
223          * to drop any buffered onion messages intended for prospective peers.
224          */
225         public void timer_tick_occurred() {
226                 bindings.OnionMessageHandler_timer_tick_occurred(this.ptr);
227                 GC.KeepAlive(this);
228         }
229
230         /**
231          * Gets the node feature flags which this handler itself supports. All available handlers are
232          * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
233          * which are broadcasted in our [`NodeAnnouncement`] message.
234          */
235         public NodeFeatures provided_node_features() {
236                 long ret = bindings.OnionMessageHandler_provided_node_features(this.ptr);
237                 GC.KeepAlive(this);
238                 if (ret >= 0 && ret <= 4096) { return null; }
239                 org.ldk.structs.NodeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeFeatures(null, ret); }
240                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
241                 return ret_hu_conv;
242         }
243
244         /**
245          * Gets the init feature flags which should be sent to the given peer. All available handlers
246          * are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
247          * which are sent in our [`Init`] message.
248          * 
249          * Note that this method is called before [`Self::peer_connected`].
250          */
251         public InitFeatures provided_init_features(byte[] their_node_id) {
252                 long ret = bindings.OnionMessageHandler_provided_init_features(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(their_node_id, 33)));
253                 GC.KeepAlive(this);
254                 GC.KeepAlive(their_node_id);
255                 if (ret >= 0 && ret <= 4096) { return null; }
256                 org.ldk.structs.InitFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InitFeatures(null, ret); }
257                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
258                 return ret_hu_conv;
259         }
260
261 }
262 } } }