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