55766614a70fdaa5cebea14d862b7bf7cf22559f
[ldk-java] / c_sharp / src / org / ldk / structs / ChannelMessageHandler.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  * A trait to describe an object which can receive channel messages.
10  * 
11  * Messages MAY be called in parallel when they originate from different their_node_ids, however
12  * they MUST NOT be called in parallel when the two calls have the same their_node_id.
13  */
14 public class ChannelMessageHandler : CommonBase {
15         internal readonly bindings.LDKChannelMessageHandler bindings_instance;
16         internal ChannelMessageHandler(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
17         private ChannelMessageHandler(bindings.LDKChannelMessageHandler arg, bindings.LDKMessageSendEventsProvider MessageSendEventsProvider) : base(bindings.LDKChannelMessageHandler_new(arg, MessageSendEventsProvider)) {
18                 this.ptrs_to.AddLast(arg);
19                 this.ptrs_to.AddLast(MessageSendEventsProvider);
20                 this.bindings_instance = arg;
21         }
22         ~ChannelMessageHandler() {
23                 if (ptr != 0) { bindings.ChannelMessageHandler_free(ptr); }
24         }
25
26         public interface ChannelMessageHandlerInterface {
27                 /**
28                  * Handle an incoming open_channel message from the given peer.
29                  */
30                 void handle_open_channel(byte[] _their_node_id, InitFeatures _their_features, OpenChannel _msg);
31                 /**
32                  * Handle an incoming accept_channel message from the given peer.
33                  */
34                 void handle_accept_channel(byte[] _their_node_id, InitFeatures _their_features, AcceptChannel _msg);
35                 /**
36                  * Handle an incoming funding_created message from the given peer.
37                  */
38                 void handle_funding_created(byte[] _their_node_id, FundingCreated _msg);
39                 /**
40                  * Handle an incoming funding_signed message from the given peer.
41                  */
42                 void handle_funding_signed(byte[] _their_node_id, FundingSigned _msg);
43                 /**
44                  * Handle an incoming channel_ready message from the given peer.
45                  */
46                 void handle_channel_ready(byte[] _their_node_id, ChannelReady _msg);
47                 /**
48                  * Handle an incoming shutdown message from the given peer.
49                  */
50                 void handle_shutdown(byte[] _their_node_id, InitFeatures _their_features, Shutdown _msg);
51                 /**
52                  * Handle an incoming closing_signed message from the given peer.
53                  */
54                 void handle_closing_signed(byte[] _their_node_id, ClosingSigned _msg);
55                 /**
56                  * Handle an incoming update_add_htlc message from the given peer.
57                  */
58                 void handle_update_add_htlc(byte[] _their_node_id, UpdateAddHTLC _msg);
59                 /**
60                  * Handle an incoming update_fulfill_htlc message from the given peer.
61                  */
62                 void handle_update_fulfill_htlc(byte[] _their_node_id, UpdateFulfillHTLC _msg);
63                 /**
64                  * Handle an incoming update_fail_htlc message from the given peer.
65                  */
66                 void handle_update_fail_htlc(byte[] _their_node_id, UpdateFailHTLC _msg);
67                 /**
68                  * Handle an incoming update_fail_malformed_htlc message from the given peer.
69                  */
70                 void handle_update_fail_malformed_htlc(byte[] _their_node_id, UpdateFailMalformedHTLC _msg);
71                 /**
72                  * Handle an incoming commitment_signed message from the given peer.
73                  */
74                 void handle_commitment_signed(byte[] _their_node_id, CommitmentSigned _msg);
75                 /**
76                  * Handle an incoming revoke_and_ack message from the given peer.
77                  */
78                 void handle_revoke_and_ack(byte[] _their_node_id, RevokeAndACK _msg);
79                 /**
80                  * Handle an incoming update_fee message from the given peer.
81                  */
82                 void handle_update_fee(byte[] _their_node_id, UpdateFee _msg);
83                 /**
84                  * Handle an incoming announcement_signatures message from the given peer.
85                  */
86                 void handle_announcement_signatures(byte[] _their_node_id, AnnouncementSignatures _msg);
87                 /**
88                  * Indicates a connection to the peer failed/an existing connection was lost. If no connection
89                  * is believed to be possible in the future (eg they're sending us messages we don't
90                  * understand or indicate they require unknown feature bits), no_connection_possible is set
91                  * and any outstanding channels should be failed.
92                  * 
93                  * Note that in some rare cases this may be called without a corresponding
94                  * [`Self::peer_connected`].
95                  */
96                 void peer_disconnected(byte[] _their_node_id, bool _no_connection_possible);
97                 /**
98                  * Handle a peer reconnecting, possibly generating channel_reestablish message(s).
99                  * 
100                  * May return an `Err(())` if the features the peer supports are not sufficient to communicate
101                  * with us. Implementors should be somewhat conservative about doing so, however, as other
102                  * message handlers may still wish to communicate with this peer.
103                  */
104                 Result_NoneNoneZ peer_connected(byte[] _their_node_id, Init _msg);
105                 /**
106                  * Handle an incoming channel_reestablish message from the given peer.
107                  */
108                 void handle_channel_reestablish(byte[] _their_node_id, ChannelReestablish _msg);
109                 /**
110                  * Handle an incoming channel update from the given peer.
111                  */
112                 void handle_channel_update(byte[] _their_node_id, ChannelUpdate _msg);
113                 /**
114                  * Handle an incoming error message from the given peer.
115                  */
116                 void handle_error(byte[] _their_node_id, ErrorMessage _msg);
117                 /**
118                  * Gets the node feature flags which this handler itself supports. All available handlers are
119                  * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
120                  * which are broadcasted in our [`NodeAnnouncement`] message.
121                  */
122                 NodeFeatures provided_node_features();
123                 /**
124                  * Gets the init feature flags which should be sent to the given peer. All available handlers
125                  * are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
126                  * which are sent in our [`Init`] message.
127                  * 
128                  * Note that this method is called before [`Self::peer_connected`].
129                  */
130                 InitFeatures provided_init_features(byte[] _their_node_id);
131         }
132         private class LDKChannelMessageHandlerHolder { internal ChannelMessageHandler held; }
133         private class LDKChannelMessageHandlerImpl : bindings.LDKChannelMessageHandler {
134                 internal LDKChannelMessageHandlerImpl(ChannelMessageHandlerInterface arg, LDKChannelMessageHandlerHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
135                 private ChannelMessageHandlerInterface arg;
136                 private LDKChannelMessageHandlerHolder impl_holder;
137                 public void handle_open_channel(byte[] _their_node_id, long _their_features, long _msg) {
138                         org.ldk.structs.InitFeatures _their_features_hu_conv = null; if (_their_features < 0 || _their_features > 4096) { _their_features_hu_conv = new org.ldk.structs.InitFeatures(null, _their_features); }
139                         if (_their_features_hu_conv != null) { _their_features_hu_conv.ptrs_to.AddLast(this); };
140                         org.ldk.structs.OpenChannel _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.OpenChannel(null, _msg); }
141                         arg.handle_open_channel(_their_node_id, _their_features_hu_conv, _msg_hu_conv);
142                                 GC.KeepAlive(arg);
143                 }
144                 public void handle_accept_channel(byte[] _their_node_id, long _their_features, long _msg) {
145                         org.ldk.structs.InitFeatures _their_features_hu_conv = null; if (_their_features < 0 || _their_features > 4096) { _their_features_hu_conv = new org.ldk.structs.InitFeatures(null, _their_features); }
146                         if (_their_features_hu_conv != null) { _their_features_hu_conv.ptrs_to.AddLast(this); };
147                         org.ldk.structs.AcceptChannel _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.AcceptChannel(null, _msg); }
148                         arg.handle_accept_channel(_their_node_id, _their_features_hu_conv, _msg_hu_conv);
149                                 GC.KeepAlive(arg);
150                 }
151                 public void handle_funding_created(byte[] _their_node_id, long _msg) {
152                         org.ldk.structs.FundingCreated _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.FundingCreated(null, _msg); }
153                         arg.handle_funding_created(_their_node_id, _msg_hu_conv);
154                                 GC.KeepAlive(arg);
155                 }
156                 public void handle_funding_signed(byte[] _their_node_id, long _msg) {
157                         org.ldk.structs.FundingSigned _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.FundingSigned(null, _msg); }
158                         arg.handle_funding_signed(_their_node_id, _msg_hu_conv);
159                                 GC.KeepAlive(arg);
160                 }
161                 public void handle_channel_ready(byte[] _their_node_id, long _msg) {
162                         org.ldk.structs.ChannelReady _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.ChannelReady(null, _msg); }
163                         arg.handle_channel_ready(_their_node_id, _msg_hu_conv);
164                                 GC.KeepAlive(arg);
165                 }
166                 public void handle_shutdown(byte[] _their_node_id, long _their_features, long _msg) {
167                         org.ldk.structs.InitFeatures _their_features_hu_conv = null; if (_their_features < 0 || _their_features > 4096) { _their_features_hu_conv = new org.ldk.structs.InitFeatures(null, _their_features); }
168                         org.ldk.structs.Shutdown _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.Shutdown(null, _msg); }
169                         arg.handle_shutdown(_their_node_id, _their_features_hu_conv, _msg_hu_conv);
170                                 GC.KeepAlive(arg);
171                 }
172                 public void handle_closing_signed(byte[] _their_node_id, long _msg) {
173                         org.ldk.structs.ClosingSigned _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.ClosingSigned(null, _msg); }
174                         arg.handle_closing_signed(_their_node_id, _msg_hu_conv);
175                                 GC.KeepAlive(arg);
176                 }
177                 public void handle_update_add_htlc(byte[] _their_node_id, long _msg) {
178                         org.ldk.structs.UpdateAddHTLC _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.UpdateAddHTLC(null, _msg); }
179                         arg.handle_update_add_htlc(_their_node_id, _msg_hu_conv);
180                                 GC.KeepAlive(arg);
181                 }
182                 public void handle_update_fulfill_htlc(byte[] _their_node_id, long _msg) {
183                         org.ldk.structs.UpdateFulfillHTLC _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.UpdateFulfillHTLC(null, _msg); }
184                         arg.handle_update_fulfill_htlc(_their_node_id, _msg_hu_conv);
185                                 GC.KeepAlive(arg);
186                 }
187                 public void handle_update_fail_htlc(byte[] _their_node_id, long _msg) {
188                         org.ldk.structs.UpdateFailHTLC _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.UpdateFailHTLC(null, _msg); }
189                         arg.handle_update_fail_htlc(_their_node_id, _msg_hu_conv);
190                                 GC.KeepAlive(arg);
191                 }
192                 public void handle_update_fail_malformed_htlc(byte[] _their_node_id, long _msg) {
193                         org.ldk.structs.UpdateFailMalformedHTLC _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.UpdateFailMalformedHTLC(null, _msg); }
194                         arg.handle_update_fail_malformed_htlc(_their_node_id, _msg_hu_conv);
195                                 GC.KeepAlive(arg);
196                 }
197                 public void handle_commitment_signed(byte[] _their_node_id, long _msg) {
198                         org.ldk.structs.CommitmentSigned _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.CommitmentSigned(null, _msg); }
199                         arg.handle_commitment_signed(_their_node_id, _msg_hu_conv);
200                                 GC.KeepAlive(arg);
201                 }
202                 public void handle_revoke_and_ack(byte[] _their_node_id, long _msg) {
203                         org.ldk.structs.RevokeAndACK _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.RevokeAndACK(null, _msg); }
204                         arg.handle_revoke_and_ack(_their_node_id, _msg_hu_conv);
205                                 GC.KeepAlive(arg);
206                 }
207                 public void handle_update_fee(byte[] _their_node_id, long _msg) {
208                         org.ldk.structs.UpdateFee _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.UpdateFee(null, _msg); }
209                         arg.handle_update_fee(_their_node_id, _msg_hu_conv);
210                                 GC.KeepAlive(arg);
211                 }
212                 public void handle_announcement_signatures(byte[] _their_node_id, long _msg) {
213                         org.ldk.structs.AnnouncementSignatures _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.AnnouncementSignatures(null, _msg); }
214                         arg.handle_announcement_signatures(_their_node_id, _msg_hu_conv);
215                                 GC.KeepAlive(arg);
216                 }
217                 public void peer_disconnected(byte[] _their_node_id, bool _no_connection_possible) {
218                         arg.peer_disconnected(_their_node_id, _no_connection_possible);
219                                 GC.KeepAlive(arg);
220                 }
221                 public long peer_connected(byte[] _their_node_id, long _msg) {
222                         org.ldk.structs.Init _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.Init(null, _msg); }
223                         Result_NoneNoneZ ret = arg.peer_connected(_their_node_id, _msg_hu_conv);
224                                 GC.KeepAlive(arg);
225                         long result = ret == null ? 0 : ret.clone_ptr();
226                         return result;
227                 }
228                 public void handle_channel_reestablish(byte[] _their_node_id, long _msg) {
229                         org.ldk.structs.ChannelReestablish _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.ChannelReestablish(null, _msg); }
230                         arg.handle_channel_reestablish(_their_node_id, _msg_hu_conv);
231                                 GC.KeepAlive(arg);
232                 }
233                 public void handle_channel_update(byte[] _their_node_id, long _msg) {
234                         org.ldk.structs.ChannelUpdate _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.ChannelUpdate(null, _msg); }
235                         arg.handle_channel_update(_their_node_id, _msg_hu_conv);
236                                 GC.KeepAlive(arg);
237                 }
238                 public void handle_error(byte[] _their_node_id, long _msg) {
239                         org.ldk.structs.ErrorMessage _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.ErrorMessage(null, _msg); }
240                         arg.handle_error(_their_node_id, _msg_hu_conv);
241                                 GC.KeepAlive(arg);
242                 }
243                 public long provided_node_features() {
244                         NodeFeatures ret = arg.provided_node_features();
245                                 GC.KeepAlive(arg);
246                         long result = ret == null ? 0 : ret.clone_ptr();
247                         return result;
248                 }
249                 public long provided_init_features(byte[] _their_node_id) {
250                         InitFeatures ret = arg.provided_init_features(_their_node_id);
251                                 GC.KeepAlive(arg);
252                         long result = ret == null ? 0 : ret.clone_ptr();
253                         return result;
254                 }
255         }
256         public static ChannelMessageHandler new_impl(ChannelMessageHandlerInterface arg, MessageSendEventsProvider.MessageSendEventsProviderInterface MessageSendEventsProvider_impl) {
257                 LDKChannelMessageHandlerHolder impl_holder = new LDKChannelMessageHandlerHolder();
258                 impl_holder.held = new ChannelMessageHandler(new LDKChannelMessageHandlerImpl(arg, impl_holder), MessageSendEventsProvider.new_impl(MessageSendEventsProvider_impl).bindings_instance);
259                 return impl_holder.held;
260         }
261
262         /**
263          * Gets the underlying MessageSendEventsProvider.
264          */
265         public MessageSendEventsProvider get_message_send_events_provider() {
266                 MessageSendEventsProvider res = new MessageSendEventsProvider(null, bindings.LDKChannelMessageHandler_get_MessageSendEventsProvider(this.ptr));
267                 this.ptrs_to.AddLast(res);
268                 return res;
269         }
270
271         /**
272          * Handle an incoming open_channel message from the given peer.
273          */
274         public void handle_open_channel(byte[] their_node_id, org.ldk.structs.InitFeatures their_features, org.ldk.structs.OpenChannel msg) {
275                 bindings.ChannelMessageHandler_handle_open_channel(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), their_features == null ? 0 : their_features.ptr, msg == null ? 0 : msg.ptr);
276                 GC.KeepAlive(this);
277                 GC.KeepAlive(their_node_id);
278                 GC.KeepAlive(their_features);
279                 GC.KeepAlive(msg);
280                 if (this != null) { this.ptrs_to.AddLast(their_features); };
281                 if (this != null) { this.ptrs_to.AddLast(msg); };
282         }
283
284         /**
285          * Handle an incoming accept_channel message from the given peer.
286          */
287         public void handle_accept_channel(byte[] their_node_id, org.ldk.structs.InitFeatures their_features, org.ldk.structs.AcceptChannel msg) {
288                 bindings.ChannelMessageHandler_handle_accept_channel(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), their_features == null ? 0 : their_features.ptr, msg == null ? 0 : msg.ptr);
289                 GC.KeepAlive(this);
290                 GC.KeepAlive(their_node_id);
291                 GC.KeepAlive(their_features);
292                 GC.KeepAlive(msg);
293                 if (this != null) { this.ptrs_to.AddLast(their_features); };
294                 if (this != null) { this.ptrs_to.AddLast(msg); };
295         }
296
297         /**
298          * Handle an incoming funding_created message from the given peer.
299          */
300         public void handle_funding_created(byte[] their_node_id, org.ldk.structs.FundingCreated msg) {
301                 bindings.ChannelMessageHandler_handle_funding_created(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
302                 GC.KeepAlive(this);
303                 GC.KeepAlive(their_node_id);
304                 GC.KeepAlive(msg);
305                 if (this != null) { this.ptrs_to.AddLast(msg); };
306         }
307
308         /**
309          * Handle an incoming funding_signed message from the given peer.
310          */
311         public void handle_funding_signed(byte[] their_node_id, org.ldk.structs.FundingSigned msg) {
312                 bindings.ChannelMessageHandler_handle_funding_signed(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
313                 GC.KeepAlive(this);
314                 GC.KeepAlive(their_node_id);
315                 GC.KeepAlive(msg);
316                 if (this != null) { this.ptrs_to.AddLast(msg); };
317         }
318
319         /**
320          * Handle an incoming channel_ready message from the given peer.
321          */
322         public void handle_channel_ready(byte[] their_node_id, org.ldk.structs.ChannelReady msg) {
323                 bindings.ChannelMessageHandler_handle_channel_ready(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
324                 GC.KeepAlive(this);
325                 GC.KeepAlive(their_node_id);
326                 GC.KeepAlive(msg);
327                 if (this != null) { this.ptrs_to.AddLast(msg); };
328         }
329
330         /**
331          * Handle an incoming shutdown message from the given peer.
332          */
333         public void handle_shutdown(byte[] their_node_id, org.ldk.structs.InitFeatures their_features, org.ldk.structs.Shutdown msg) {
334                 bindings.ChannelMessageHandler_handle_shutdown(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), their_features == null ? 0 : their_features.ptr, msg == null ? 0 : msg.ptr);
335                 GC.KeepAlive(this);
336                 GC.KeepAlive(their_node_id);
337                 GC.KeepAlive(their_features);
338                 GC.KeepAlive(msg);
339                 if (this != null) { this.ptrs_to.AddLast(their_features); };
340                 if (this != null) { this.ptrs_to.AddLast(msg); };
341         }
342
343         /**
344          * Handle an incoming closing_signed message from the given peer.
345          */
346         public void handle_closing_signed(byte[] their_node_id, org.ldk.structs.ClosingSigned msg) {
347                 bindings.ChannelMessageHandler_handle_closing_signed(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
348                 GC.KeepAlive(this);
349                 GC.KeepAlive(their_node_id);
350                 GC.KeepAlive(msg);
351                 if (this != null) { this.ptrs_to.AddLast(msg); };
352         }
353
354         /**
355          * Handle an incoming update_add_htlc message from the given peer.
356          */
357         public void handle_update_add_htlc(byte[] their_node_id, org.ldk.structs.UpdateAddHTLC msg) {
358                 bindings.ChannelMessageHandler_handle_update_add_htlc(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
359                 GC.KeepAlive(this);
360                 GC.KeepAlive(their_node_id);
361                 GC.KeepAlive(msg);
362                 if (this != null) { this.ptrs_to.AddLast(msg); };
363         }
364
365         /**
366          * Handle an incoming update_fulfill_htlc message from the given peer.
367          */
368         public void handle_update_fulfill_htlc(byte[] their_node_id, org.ldk.structs.UpdateFulfillHTLC msg) {
369                 bindings.ChannelMessageHandler_handle_update_fulfill_htlc(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
370                 GC.KeepAlive(this);
371                 GC.KeepAlive(their_node_id);
372                 GC.KeepAlive(msg);
373                 if (this != null) { this.ptrs_to.AddLast(msg); };
374         }
375
376         /**
377          * Handle an incoming update_fail_htlc message from the given peer.
378          */
379         public void handle_update_fail_htlc(byte[] their_node_id, org.ldk.structs.UpdateFailHTLC msg) {
380                 bindings.ChannelMessageHandler_handle_update_fail_htlc(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
381                 GC.KeepAlive(this);
382                 GC.KeepAlive(their_node_id);
383                 GC.KeepAlive(msg);
384                 if (this != null) { this.ptrs_to.AddLast(msg); };
385         }
386
387         /**
388          * Handle an incoming update_fail_malformed_htlc message from the given peer.
389          */
390         public void handle_update_fail_malformed_htlc(byte[] their_node_id, org.ldk.structs.UpdateFailMalformedHTLC msg) {
391                 bindings.ChannelMessageHandler_handle_update_fail_malformed_htlc(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
392                 GC.KeepAlive(this);
393                 GC.KeepAlive(their_node_id);
394                 GC.KeepAlive(msg);
395                 if (this != null) { this.ptrs_to.AddLast(msg); };
396         }
397
398         /**
399          * Handle an incoming commitment_signed message from the given peer.
400          */
401         public void handle_commitment_signed(byte[] their_node_id, org.ldk.structs.CommitmentSigned msg) {
402                 bindings.ChannelMessageHandler_handle_commitment_signed(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
403                 GC.KeepAlive(this);
404                 GC.KeepAlive(their_node_id);
405                 GC.KeepAlive(msg);
406                 if (this != null) { this.ptrs_to.AddLast(msg); };
407         }
408
409         /**
410          * Handle an incoming revoke_and_ack message from the given peer.
411          */
412         public void handle_revoke_and_ack(byte[] their_node_id, org.ldk.structs.RevokeAndACK msg) {
413                 bindings.ChannelMessageHandler_handle_revoke_and_ack(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
414                 GC.KeepAlive(this);
415                 GC.KeepAlive(their_node_id);
416                 GC.KeepAlive(msg);
417                 if (this != null) { this.ptrs_to.AddLast(msg); };
418         }
419
420         /**
421          * Handle an incoming update_fee message from the given peer.
422          */
423         public void handle_update_fee(byte[] their_node_id, org.ldk.structs.UpdateFee msg) {
424                 bindings.ChannelMessageHandler_handle_update_fee(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
425                 GC.KeepAlive(this);
426                 GC.KeepAlive(their_node_id);
427                 GC.KeepAlive(msg);
428                 if (this != null) { this.ptrs_to.AddLast(msg); };
429         }
430
431         /**
432          * Handle an incoming announcement_signatures message from the given peer.
433          */
434         public void handle_announcement_signatures(byte[] their_node_id, org.ldk.structs.AnnouncementSignatures msg) {
435                 bindings.ChannelMessageHandler_handle_announcement_signatures(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
436                 GC.KeepAlive(this);
437                 GC.KeepAlive(their_node_id);
438                 GC.KeepAlive(msg);
439                 if (this != null) { this.ptrs_to.AddLast(msg); };
440         }
441
442         /**
443          * Indicates a connection to the peer failed/an existing connection was lost. If no connection
444          * is believed to be possible in the future (eg they're sending us messages we don't
445          * understand or indicate they require unknown feature bits), no_connection_possible is set
446          * and any outstanding channels should be failed.
447          * 
448          * Note that in some rare cases this may be called without a corresponding
449          * [`Self::peer_connected`].
450          */
451         public void peer_disconnected(byte[] their_node_id, bool no_connection_possible) {
452                 bindings.ChannelMessageHandler_peer_disconnected(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), no_connection_possible);
453                 GC.KeepAlive(this);
454                 GC.KeepAlive(their_node_id);
455                 GC.KeepAlive(no_connection_possible);
456         }
457
458         /**
459          * Handle a peer reconnecting, possibly generating channel_reestablish message(s).
460          * 
461          * May return an `Err(())` if the features the peer supports are not sufficient to communicate
462          * with us. Implementors should be somewhat conservative about doing so, however, as other
463          * message handlers may still wish to communicate with this peer.
464          */
465         public Result_NoneNoneZ peer_connected(byte[] their_node_id, org.ldk.structs.Init msg) {
466                 long ret = bindings.ChannelMessageHandler_peer_connected(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
467                 GC.KeepAlive(this);
468                 GC.KeepAlive(their_node_id);
469                 GC.KeepAlive(msg);
470                 if (ret >= 0 && ret <= 4096) { return null; }
471                 Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
472                 if (this != null) { this.ptrs_to.AddLast(msg); };
473                 return ret_hu_conv;
474         }
475
476         /**
477          * Handle an incoming channel_reestablish message from the given peer.
478          */
479         public void handle_channel_reestablish(byte[] their_node_id, org.ldk.structs.ChannelReestablish msg) {
480                 bindings.ChannelMessageHandler_handle_channel_reestablish(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
481                 GC.KeepAlive(this);
482                 GC.KeepAlive(their_node_id);
483                 GC.KeepAlive(msg);
484                 if (this != null) { this.ptrs_to.AddLast(msg); };
485         }
486
487         /**
488          * Handle an incoming channel update from the given peer.
489          */
490         public void handle_channel_update(byte[] their_node_id, org.ldk.structs.ChannelUpdate msg) {
491                 bindings.ChannelMessageHandler_handle_channel_update(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
492                 GC.KeepAlive(this);
493                 GC.KeepAlive(their_node_id);
494                 GC.KeepAlive(msg);
495                 if (this != null) { this.ptrs_to.AddLast(msg); };
496         }
497
498         /**
499          * Handle an incoming error message from the given peer.
500          */
501         public void handle_error(byte[] their_node_id, org.ldk.structs.ErrorMessage msg) {
502                 bindings.ChannelMessageHandler_handle_error(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
503                 GC.KeepAlive(this);
504                 GC.KeepAlive(their_node_id);
505                 GC.KeepAlive(msg);
506                 if (this != null) { this.ptrs_to.AddLast(msg); };
507         }
508
509         /**
510          * Gets the node feature flags which this handler itself supports. All available handlers are
511          * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
512          * which are broadcasted in our [`NodeAnnouncement`] message.
513          */
514         public NodeFeatures provided_node_features() {
515                 long ret = bindings.ChannelMessageHandler_provided_node_features(this.ptr);
516                 GC.KeepAlive(this);
517                 if (ret >= 0 && ret <= 4096) { return null; }
518                 org.ldk.structs.NodeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeFeatures(null, ret); }
519                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
520                 return ret_hu_conv;
521         }
522
523         /**
524          * Gets the init feature flags which should be sent to the given peer. All available handlers
525          * are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
526          * which are sent in our [`Init`] message.
527          * 
528          * Note that this method is called before [`Self::peer_connected`].
529          */
530         public InitFeatures provided_init_features(byte[] their_node_id) {
531                 long ret = bindings.ChannelMessageHandler_provided_init_features(this.ptr, InternalUtils.check_arr_len(their_node_id, 33));
532                 GC.KeepAlive(this);
533                 GC.KeepAlive(their_node_id);
534                 if (ret >= 0 && ret <= 4096) { return null; }
535                 org.ldk.structs.InitFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InitFeatures(null, ret); }
536                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
537                 return ret_hu_conv;
538         }
539
540 }
541 } } }