20173f72520bcbb735c02190a702047d6bf45628
[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          * Destroys the object, freeing associated resources. After this call, any access
32          * to this object may result in a SEGFAULT or worse.
33          *
34          * You should generally NEVER call this method. You should let the garbage collector
35          * do this for you when it finalizes objects. However, it may be useful for types
36          * which represent locks and should be closed immediately to avoid holding locks
37          * until the GC runs.
38          */
39         public void destroy() {
40                 if (ptr != 0) { bindings.ChannelMessageHandler_free(ptr); }
41                 ptr = 0;
42         }
43         public static interface ChannelMessageHandlerInterface {
44                 /**
45                  * Handle an incoming `open_channel` message from the given peer.
46                  */
47                 void handle_open_channel(byte[] their_node_id, OpenChannel msg);
48                 /**
49                  * Handle an incoming `open_channel2` message from the given peer.
50                  */
51                 void handle_open_channel_v2(byte[] their_node_id, OpenChannelV2 msg);
52                 /**
53                  * Handle an incoming `accept_channel` message from the given peer.
54                  */
55                 void handle_accept_channel(byte[] their_node_id, AcceptChannel msg);
56                 /**
57                  * Handle an incoming `accept_channel2` message from the given peer.
58                  */
59                 void handle_accept_channel_v2(byte[] their_node_id, AcceptChannelV2 msg);
60                 /**
61                  * Handle an incoming `funding_created` message from the given peer.
62                  */
63                 void handle_funding_created(byte[] their_node_id, FundingCreated msg);
64                 /**
65                  * Handle an incoming `funding_signed` message from the given peer.
66                  */
67                 void handle_funding_signed(byte[] their_node_id, FundingSigned msg);
68                 /**
69                  * Handle an incoming `channel_ready` message from the given peer.
70                  */
71                 void handle_channel_ready(byte[] their_node_id, ChannelReady msg);
72                 /**
73                  * Handle an incoming `shutdown` message from the given peer.
74                  */
75                 void handle_shutdown(byte[] their_node_id, Shutdown msg);
76                 /**
77                  * Handle an incoming `closing_signed` message from the given peer.
78                  */
79                 void handle_closing_signed(byte[] their_node_id, ClosingSigned msg);
80                 /**
81                  * Handle an incoming `tx_add_input message` from the given peer.
82                  */
83                 void handle_tx_add_input(byte[] their_node_id, TxAddInput msg);
84                 /**
85                  * Handle an incoming `tx_add_output` message from the given peer.
86                  */
87                 void handle_tx_add_output(byte[] their_node_id, TxAddOutput msg);
88                 /**
89                  * Handle an incoming `tx_remove_input` message from the given peer.
90                  */
91                 void handle_tx_remove_input(byte[] their_node_id, TxRemoveInput msg);
92                 /**
93                  * Handle an incoming `tx_remove_output` message from the given peer.
94                  */
95                 void handle_tx_remove_output(byte[] their_node_id, TxRemoveOutput msg);
96                 /**
97                  * Handle an incoming `tx_complete message` from the given peer.
98                  */
99                 void handle_tx_complete(byte[] their_node_id, TxComplete msg);
100                 /**
101                  * Handle an incoming `tx_signatures` message from the given peer.
102                  */
103                 void handle_tx_signatures(byte[] their_node_id, TxSignatures msg);
104                 /**
105                  * Handle an incoming `tx_init_rbf` message from the given peer.
106                  */
107                 void handle_tx_init_rbf(byte[] their_node_id, TxInitRbf msg);
108                 /**
109                  * Handle an incoming `tx_ack_rbf` message from the given peer.
110                  */
111                 void handle_tx_ack_rbf(byte[] their_node_id, TxAckRbf msg);
112                 /**
113                  * Handle an incoming `tx_abort message` from the given peer.
114                  */
115                 void handle_tx_abort(byte[] their_node_id, TxAbort msg);
116                 /**
117                  * Handle an incoming `update_add_htlc` message from the given peer.
118                  */
119                 void handle_update_add_htlc(byte[] their_node_id, UpdateAddHTLC msg);
120                 /**
121                  * Handle an incoming `update_fulfill_htlc` message from the given peer.
122                  */
123                 void handle_update_fulfill_htlc(byte[] their_node_id, UpdateFulfillHTLC msg);
124                 /**
125                  * Handle an incoming `update_fail_htlc` message from the given peer.
126                  */
127                 void handle_update_fail_htlc(byte[] their_node_id, UpdateFailHTLC msg);
128                 /**
129                  * Handle an incoming `update_fail_malformed_htlc` message from the given peer.
130                  */
131                 void handle_update_fail_malformed_htlc(byte[] their_node_id, UpdateFailMalformedHTLC msg);
132                 /**
133                  * Handle an incoming `commitment_signed` message from the given peer.
134                  */
135                 void handle_commitment_signed(byte[] their_node_id, CommitmentSigned msg);
136                 /**
137                  * Handle an incoming `revoke_and_ack` message from the given peer.
138                  */
139                 void handle_revoke_and_ack(byte[] their_node_id, RevokeAndACK msg);
140                 /**
141                  * Handle an incoming `update_fee` message from the given peer.
142                  */
143                 void handle_update_fee(byte[] their_node_id, UpdateFee msg);
144                 /**
145                  * Handle an incoming `announcement_signatures` message from the given peer.
146                  */
147                 void handle_announcement_signatures(byte[] their_node_id, AnnouncementSignatures msg);
148                 /**
149                  * Indicates a connection to the peer failed/an existing connection was lost.
150                  */
151                 void peer_disconnected(byte[] their_node_id);
152                 /**
153                  * Handle a peer reconnecting, possibly generating `channel_reestablish` message(s).
154                  * 
155                  * May return an `Err(())` if the features the peer supports are not sufficient to communicate
156                  * with us. Implementors should be somewhat conservative about doing so, however, as other
157                  * message handlers may still wish to communicate with this peer.
158                  */
159                 Result_NoneNoneZ peer_connected(byte[] their_node_id, Init msg, boolean inbound);
160                 /**
161                  * Handle an incoming `channel_reestablish` message from the given peer.
162                  */
163                 void handle_channel_reestablish(byte[] their_node_id, ChannelReestablish msg);
164                 /**
165                  * Handle an incoming `channel_update` message from the given peer.
166                  */
167                 void handle_channel_update(byte[] their_node_id, ChannelUpdate msg);
168                 /**
169                  * Handle an incoming `error` message from the given peer.
170                  */
171                 void handle_error(byte[] their_node_id, ErrorMessage msg);
172                 /**
173                  * Gets the node feature flags which this handler itself supports. All available handlers are
174                  * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
175                  * which are broadcasted in our [`NodeAnnouncement`] message.
176                  */
177                 NodeFeatures provided_node_features();
178                 /**
179                  * Gets the init feature flags which should be sent to the given peer. All available handlers
180                  * are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
181                  * which are sent in our [`Init`] message.
182                  * 
183                  * Note that this method is called before [`Self::peer_connected`].
184                  */
185                 InitFeatures provided_init_features(byte[] their_node_id);
186                 /**
187                  * Gets the chain hashes for this `ChannelMessageHandler` indicating which chains it supports.
188                  * 
189                  * If it's `None`, then no particular network chain hash compatibility will be enforced when
190                  * connecting to peers.
191                  */
192                 Option_CVec_ThirtyTwoBytesZZ get_chain_hashes();
193         }
194         private static class LDKChannelMessageHandlerHolder { ChannelMessageHandler held; }
195         public static ChannelMessageHandler new_impl(ChannelMessageHandlerInterface arg, MessageSendEventsProvider.MessageSendEventsProviderInterface MessageSendEventsProvider_impl) {
196                 final LDKChannelMessageHandlerHolder impl_holder = new LDKChannelMessageHandlerHolder();
197                 impl_holder.held = new ChannelMessageHandler(new bindings.LDKChannelMessageHandler() {
198                         @Override public void handle_open_channel(byte[] their_node_id, long msg) {
199                                 org.ldk.structs.OpenChannel msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.OpenChannel(null, msg); }
200                                 arg.handle_open_channel(their_node_id, msg_hu_conv);
201                                 Reference.reachabilityFence(arg);
202                         }
203                         @Override public void handle_open_channel_v2(byte[] their_node_id, long msg) {
204                                 org.ldk.structs.OpenChannelV2 msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.OpenChannelV2(null, msg); }
205                                 arg.handle_open_channel_v2(their_node_id, msg_hu_conv);
206                                 Reference.reachabilityFence(arg);
207                         }
208                         @Override public void handle_accept_channel(byte[] their_node_id, long msg) {
209                                 org.ldk.structs.AcceptChannel msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.AcceptChannel(null, msg); }
210                                 arg.handle_accept_channel(their_node_id, msg_hu_conv);
211                                 Reference.reachabilityFence(arg);
212                         }
213                         @Override public void handle_accept_channel_v2(byte[] their_node_id, long msg) {
214                                 org.ldk.structs.AcceptChannelV2 msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.AcceptChannelV2(null, msg); }
215                                 arg.handle_accept_channel_v2(their_node_id, msg_hu_conv);
216                                 Reference.reachabilityFence(arg);
217                         }
218                         @Override public void handle_funding_created(byte[] their_node_id, long msg) {
219                                 org.ldk.structs.FundingCreated msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.FundingCreated(null, msg); }
220                                 arg.handle_funding_created(their_node_id, msg_hu_conv);
221                                 Reference.reachabilityFence(arg);
222                         }
223                         @Override public void handle_funding_signed(byte[] their_node_id, long msg) {
224                                 org.ldk.structs.FundingSigned msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.FundingSigned(null, msg); }
225                                 arg.handle_funding_signed(their_node_id, msg_hu_conv);
226                                 Reference.reachabilityFence(arg);
227                         }
228                         @Override public void handle_channel_ready(byte[] their_node_id, long msg) {
229                                 org.ldk.structs.ChannelReady msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.ChannelReady(null, msg); }
230                                 arg.handle_channel_ready(their_node_id, msg_hu_conv);
231                                 Reference.reachabilityFence(arg);
232                         }
233                         @Override public void handle_shutdown(byte[] their_node_id, long msg) {
234                                 org.ldk.structs.Shutdown msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.Shutdown(null, msg); }
235                                 arg.handle_shutdown(their_node_id, msg_hu_conv);
236                                 Reference.reachabilityFence(arg);
237                         }
238                         @Override public void handle_closing_signed(byte[] their_node_id, long msg) {
239                                 org.ldk.structs.ClosingSigned msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.ClosingSigned(null, msg); }
240                                 arg.handle_closing_signed(their_node_id, msg_hu_conv);
241                                 Reference.reachabilityFence(arg);
242                         }
243                         @Override public void handle_tx_add_input(byte[] their_node_id, long msg) {
244                                 org.ldk.structs.TxAddInput msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.TxAddInput(null, msg); }
245                                 arg.handle_tx_add_input(their_node_id, msg_hu_conv);
246                                 Reference.reachabilityFence(arg);
247                         }
248                         @Override public void handle_tx_add_output(byte[] their_node_id, long msg) {
249                                 org.ldk.structs.TxAddOutput msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.TxAddOutput(null, msg); }
250                                 arg.handle_tx_add_output(their_node_id, msg_hu_conv);
251                                 Reference.reachabilityFence(arg);
252                         }
253                         @Override public void handle_tx_remove_input(byte[] their_node_id, long msg) {
254                                 org.ldk.structs.TxRemoveInput msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.TxRemoveInput(null, msg); }
255                                 arg.handle_tx_remove_input(their_node_id, msg_hu_conv);
256                                 Reference.reachabilityFence(arg);
257                         }
258                         @Override public void handle_tx_remove_output(byte[] their_node_id, long msg) {
259                                 org.ldk.structs.TxRemoveOutput msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.TxRemoveOutput(null, msg); }
260                                 arg.handle_tx_remove_output(their_node_id, msg_hu_conv);
261                                 Reference.reachabilityFence(arg);
262                         }
263                         @Override public void handle_tx_complete(byte[] their_node_id, long msg) {
264                                 org.ldk.structs.TxComplete msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.TxComplete(null, msg); }
265                                 arg.handle_tx_complete(their_node_id, msg_hu_conv);
266                                 Reference.reachabilityFence(arg);
267                         }
268                         @Override public void handle_tx_signatures(byte[] their_node_id, long msg) {
269                                 org.ldk.structs.TxSignatures msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.TxSignatures(null, msg); }
270                                 arg.handle_tx_signatures(their_node_id, msg_hu_conv);
271                                 Reference.reachabilityFence(arg);
272                         }
273                         @Override public void handle_tx_init_rbf(byte[] their_node_id, long msg) {
274                                 org.ldk.structs.TxInitRbf msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.TxInitRbf(null, msg); }
275                                 arg.handle_tx_init_rbf(their_node_id, msg_hu_conv);
276                                 Reference.reachabilityFence(arg);
277                         }
278                         @Override public void handle_tx_ack_rbf(byte[] their_node_id, long msg) {
279                                 org.ldk.structs.TxAckRbf msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.TxAckRbf(null, msg); }
280                                 arg.handle_tx_ack_rbf(their_node_id, msg_hu_conv);
281                                 Reference.reachabilityFence(arg);
282                         }
283                         @Override public void handle_tx_abort(byte[] their_node_id, long msg) {
284                                 org.ldk.structs.TxAbort msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.TxAbort(null, msg); }
285                                 arg.handle_tx_abort(their_node_id, msg_hu_conv);
286                                 Reference.reachabilityFence(arg);
287                         }
288                         @Override public void handle_update_add_htlc(byte[] their_node_id, long msg) {
289                                 org.ldk.structs.UpdateAddHTLC msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.UpdateAddHTLC(null, msg); }
290                                 arg.handle_update_add_htlc(their_node_id, msg_hu_conv);
291                                 Reference.reachabilityFence(arg);
292                         }
293                         @Override public void handle_update_fulfill_htlc(byte[] their_node_id, long msg) {
294                                 org.ldk.structs.UpdateFulfillHTLC msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.UpdateFulfillHTLC(null, msg); }
295                                 arg.handle_update_fulfill_htlc(their_node_id, msg_hu_conv);
296                                 Reference.reachabilityFence(arg);
297                         }
298                         @Override public void handle_update_fail_htlc(byte[] their_node_id, long msg) {
299                                 org.ldk.structs.UpdateFailHTLC msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.UpdateFailHTLC(null, msg); }
300                                 arg.handle_update_fail_htlc(their_node_id, msg_hu_conv);
301                                 Reference.reachabilityFence(arg);
302                         }
303                         @Override public void handle_update_fail_malformed_htlc(byte[] their_node_id, long msg) {
304                                 org.ldk.structs.UpdateFailMalformedHTLC msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.UpdateFailMalformedHTLC(null, msg); }
305                                 arg.handle_update_fail_malformed_htlc(their_node_id, msg_hu_conv);
306                                 Reference.reachabilityFence(arg);
307                         }
308                         @Override public void handle_commitment_signed(byte[] their_node_id, long msg) {
309                                 org.ldk.structs.CommitmentSigned msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.CommitmentSigned(null, msg); }
310                                 arg.handle_commitment_signed(their_node_id, msg_hu_conv);
311                                 Reference.reachabilityFence(arg);
312                         }
313                         @Override public void handle_revoke_and_ack(byte[] their_node_id, long msg) {
314                                 org.ldk.structs.RevokeAndACK msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.RevokeAndACK(null, msg); }
315                                 arg.handle_revoke_and_ack(their_node_id, msg_hu_conv);
316                                 Reference.reachabilityFence(arg);
317                         }
318                         @Override public void handle_update_fee(byte[] their_node_id, long msg) {
319                                 org.ldk.structs.UpdateFee msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.UpdateFee(null, msg); }
320                                 arg.handle_update_fee(their_node_id, msg_hu_conv);
321                                 Reference.reachabilityFence(arg);
322                         }
323                         @Override public void handle_announcement_signatures(byte[] their_node_id, long msg) {
324                                 org.ldk.structs.AnnouncementSignatures msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.AnnouncementSignatures(null, msg); }
325                                 arg.handle_announcement_signatures(their_node_id, msg_hu_conv);
326                                 Reference.reachabilityFence(arg);
327                         }
328                         @Override public void peer_disconnected(byte[] their_node_id) {
329                                 arg.peer_disconnected(their_node_id);
330                                 Reference.reachabilityFence(arg);
331                         }
332                         @Override public long peer_connected(byte[] their_node_id, long msg, boolean inbound) {
333                                 org.ldk.structs.Init msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.Init(null, msg); }
334                                 Result_NoneNoneZ ret = arg.peer_connected(their_node_id, msg_hu_conv, inbound);
335                                 Reference.reachabilityFence(arg);
336                                 long result = ret == null ? 0 : ret.clone_ptr();
337                                 return result;
338                         }
339                         @Override public void handle_channel_reestablish(byte[] their_node_id, long msg) {
340                                 org.ldk.structs.ChannelReestablish msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.ChannelReestablish(null, msg); }
341                                 arg.handle_channel_reestablish(their_node_id, msg_hu_conv);
342                                 Reference.reachabilityFence(arg);
343                         }
344                         @Override public void handle_channel_update(byte[] their_node_id, long msg) {
345                                 org.ldk.structs.ChannelUpdate msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.ChannelUpdate(null, msg); }
346                                 arg.handle_channel_update(their_node_id, msg_hu_conv);
347                                 Reference.reachabilityFence(arg);
348                         }
349                         @Override public void handle_error(byte[] their_node_id, long msg) {
350                                 org.ldk.structs.ErrorMessage msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.ErrorMessage(null, msg); }
351                                 arg.handle_error(their_node_id, msg_hu_conv);
352                                 Reference.reachabilityFence(arg);
353                         }
354                         @Override public long provided_node_features() {
355                                 NodeFeatures ret = arg.provided_node_features();
356                                 Reference.reachabilityFence(arg);
357                                 long result = ret == null ? 0 : ret.clone_ptr();
358                                 return result;
359                         }
360                         @Override public long provided_init_features(byte[] their_node_id) {
361                                 InitFeatures ret = arg.provided_init_features(their_node_id);
362                                 Reference.reachabilityFence(arg);
363                                 long result = ret == null ? 0 : ret.clone_ptr();
364                                 return result;
365                         }
366                         @Override public long get_chain_hashes() {
367                                 Option_CVec_ThirtyTwoBytesZZ ret = arg.get_chain_hashes();
368                                 Reference.reachabilityFence(arg);
369                                 long result = ret == null ? 0 : ret.clone_ptr();
370                                 if (impl_holder.held != null) { impl_holder.held.ptrs_to.add(ret); };
371                                 return result;
372                         }
373                 }, MessageSendEventsProvider.new_impl(MessageSendEventsProvider_impl).bindings_instance);
374                 return impl_holder.held;
375         }
376
377         /**
378          * Gets the underlying MessageSendEventsProvider.
379          */
380         public MessageSendEventsProvider get_message_send_events_provider() {
381                 MessageSendEventsProvider res = new MessageSendEventsProvider(null, bindings.LDKChannelMessageHandler_get_MessageSendEventsProvider(this.ptr));
382                 res.ptrs_to.add(this);
383                 return res;
384         }
385
386         /**
387          * Handle an incoming `open_channel` message from the given peer.
388          */
389         public void handle_open_channel(byte[] their_node_id, org.ldk.structs.OpenChannel msg) {
390                 bindings.ChannelMessageHandler_handle_open_channel(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
391                 Reference.reachabilityFence(this);
392                 Reference.reachabilityFence(their_node_id);
393                 Reference.reachabilityFence(msg);
394                 if (this != null) { this.ptrs_to.add(msg); };
395         }
396
397         /**
398          * Handle an incoming `open_channel2` message from the given peer.
399          */
400         public void handle_open_channel_v2(byte[] their_node_id, org.ldk.structs.OpenChannelV2 msg) {
401                 bindings.ChannelMessageHandler_handle_open_channel_v2(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
402                 Reference.reachabilityFence(this);
403                 Reference.reachabilityFence(their_node_id);
404                 Reference.reachabilityFence(msg);
405                 if (this != null) { this.ptrs_to.add(msg); };
406         }
407
408         /**
409          * Handle an incoming `accept_channel` message from the given peer.
410          */
411         public void handle_accept_channel(byte[] their_node_id, org.ldk.structs.AcceptChannel msg) {
412                 bindings.ChannelMessageHandler_handle_accept_channel(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
413                 Reference.reachabilityFence(this);
414                 Reference.reachabilityFence(their_node_id);
415                 Reference.reachabilityFence(msg);
416                 if (this != null) { this.ptrs_to.add(msg); };
417         }
418
419         /**
420          * Handle an incoming `accept_channel2` message from the given peer.
421          */
422         public void handle_accept_channel_v2(byte[] their_node_id, org.ldk.structs.AcceptChannelV2 msg) {
423                 bindings.ChannelMessageHandler_handle_accept_channel_v2(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
424                 Reference.reachabilityFence(this);
425                 Reference.reachabilityFence(their_node_id);
426                 Reference.reachabilityFence(msg);
427                 if (this != null) { this.ptrs_to.add(msg); };
428         }
429
430         /**
431          * Handle an incoming `funding_created` message from the given peer.
432          */
433         public void handle_funding_created(byte[] their_node_id, org.ldk.structs.FundingCreated msg) {
434                 bindings.ChannelMessageHandler_handle_funding_created(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
435                 Reference.reachabilityFence(this);
436                 Reference.reachabilityFence(their_node_id);
437                 Reference.reachabilityFence(msg);
438                 if (this != null) { this.ptrs_to.add(msg); };
439         }
440
441         /**
442          * Handle an incoming `funding_signed` message from the given peer.
443          */
444         public void handle_funding_signed(byte[] their_node_id, org.ldk.structs.FundingSigned msg) {
445                 bindings.ChannelMessageHandler_handle_funding_signed(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
446                 Reference.reachabilityFence(this);
447                 Reference.reachabilityFence(their_node_id);
448                 Reference.reachabilityFence(msg);
449                 if (this != null) { this.ptrs_to.add(msg); };
450         }
451
452         /**
453          * Handle an incoming `channel_ready` message from the given peer.
454          */
455         public void handle_channel_ready(byte[] their_node_id, org.ldk.structs.ChannelReady msg) {
456                 bindings.ChannelMessageHandler_handle_channel_ready(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
457                 Reference.reachabilityFence(this);
458                 Reference.reachabilityFence(their_node_id);
459                 Reference.reachabilityFence(msg);
460                 if (this != null) { this.ptrs_to.add(msg); };
461         }
462
463         /**
464          * Handle an incoming `shutdown` message from the given peer.
465          */
466         public void handle_shutdown(byte[] their_node_id, org.ldk.structs.Shutdown msg) {
467                 bindings.ChannelMessageHandler_handle_shutdown(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 (this != null) { this.ptrs_to.add(msg); };
472         }
473
474         /**
475          * Handle an incoming `closing_signed` message from the given peer.
476          */
477         public void handle_closing_signed(byte[] their_node_id, org.ldk.structs.ClosingSigned msg) {
478                 bindings.ChannelMessageHandler_handle_closing_signed(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
479                 Reference.reachabilityFence(this);
480                 Reference.reachabilityFence(their_node_id);
481                 Reference.reachabilityFence(msg);
482                 if (this != null) { this.ptrs_to.add(msg); };
483         }
484
485         /**
486          * Handle an incoming `tx_add_input message` from the given peer.
487          */
488         public void handle_tx_add_input(byte[] their_node_id, org.ldk.structs.TxAddInput msg) {
489                 bindings.ChannelMessageHandler_handle_tx_add_input(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
490                 Reference.reachabilityFence(this);
491                 Reference.reachabilityFence(their_node_id);
492                 Reference.reachabilityFence(msg);
493                 if (this != null) { this.ptrs_to.add(msg); };
494         }
495
496         /**
497          * Handle an incoming `tx_add_output` message from the given peer.
498          */
499         public void handle_tx_add_output(byte[] their_node_id, org.ldk.structs.TxAddOutput msg) {
500                 bindings.ChannelMessageHandler_handle_tx_add_output(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
501                 Reference.reachabilityFence(this);
502                 Reference.reachabilityFence(their_node_id);
503                 Reference.reachabilityFence(msg);
504                 if (this != null) { this.ptrs_to.add(msg); };
505         }
506
507         /**
508          * Handle an incoming `tx_remove_input` message from the given peer.
509          */
510         public void handle_tx_remove_input(byte[] their_node_id, org.ldk.structs.TxRemoveInput msg) {
511                 bindings.ChannelMessageHandler_handle_tx_remove_input(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
512                 Reference.reachabilityFence(this);
513                 Reference.reachabilityFence(their_node_id);
514                 Reference.reachabilityFence(msg);
515                 if (this != null) { this.ptrs_to.add(msg); };
516         }
517
518         /**
519          * Handle an incoming `tx_remove_output` message from the given peer.
520          */
521         public void handle_tx_remove_output(byte[] their_node_id, org.ldk.structs.TxRemoveOutput msg) {
522                 bindings.ChannelMessageHandler_handle_tx_remove_output(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
523                 Reference.reachabilityFence(this);
524                 Reference.reachabilityFence(their_node_id);
525                 Reference.reachabilityFence(msg);
526                 if (this != null) { this.ptrs_to.add(msg); };
527         }
528
529         /**
530          * Handle an incoming `tx_complete message` from the given peer.
531          */
532         public void handle_tx_complete(byte[] their_node_id, org.ldk.structs.TxComplete msg) {
533                 bindings.ChannelMessageHandler_handle_tx_complete(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
534                 Reference.reachabilityFence(this);
535                 Reference.reachabilityFence(their_node_id);
536                 Reference.reachabilityFence(msg);
537                 if (this != null) { this.ptrs_to.add(msg); };
538         }
539
540         /**
541          * Handle an incoming `tx_signatures` message from the given peer.
542          */
543         public void handle_tx_signatures(byte[] their_node_id, org.ldk.structs.TxSignatures msg) {
544                 bindings.ChannelMessageHandler_handle_tx_signatures(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
545                 Reference.reachabilityFence(this);
546                 Reference.reachabilityFence(their_node_id);
547                 Reference.reachabilityFence(msg);
548                 if (this != null) { this.ptrs_to.add(msg); };
549         }
550
551         /**
552          * Handle an incoming `tx_init_rbf` message from the given peer.
553          */
554         public void handle_tx_init_rbf(byte[] their_node_id, org.ldk.structs.TxInitRbf msg) {
555                 bindings.ChannelMessageHandler_handle_tx_init_rbf(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
556                 Reference.reachabilityFence(this);
557                 Reference.reachabilityFence(their_node_id);
558                 Reference.reachabilityFence(msg);
559                 if (this != null) { this.ptrs_to.add(msg); };
560         }
561
562         /**
563          * Handle an incoming `tx_ack_rbf` message from the given peer.
564          */
565         public void handle_tx_ack_rbf(byte[] their_node_id, org.ldk.structs.TxAckRbf msg) {
566                 bindings.ChannelMessageHandler_handle_tx_ack_rbf(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
567                 Reference.reachabilityFence(this);
568                 Reference.reachabilityFence(their_node_id);
569                 Reference.reachabilityFence(msg);
570                 if (this != null) { this.ptrs_to.add(msg); };
571         }
572
573         /**
574          * Handle an incoming `tx_abort message` from the given peer.
575          */
576         public void handle_tx_abort(byte[] their_node_id, org.ldk.structs.TxAbort msg) {
577                 bindings.ChannelMessageHandler_handle_tx_abort(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
578                 Reference.reachabilityFence(this);
579                 Reference.reachabilityFence(their_node_id);
580                 Reference.reachabilityFence(msg);
581                 if (this != null) { this.ptrs_to.add(msg); };
582         }
583
584         /**
585          * Handle an incoming `update_add_htlc` message from the given peer.
586          */
587         public void handle_update_add_htlc(byte[] their_node_id, org.ldk.structs.UpdateAddHTLC msg) {
588                 bindings.ChannelMessageHandler_handle_update_add_htlc(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
589                 Reference.reachabilityFence(this);
590                 Reference.reachabilityFence(their_node_id);
591                 Reference.reachabilityFence(msg);
592                 if (this != null) { this.ptrs_to.add(msg); };
593         }
594
595         /**
596          * Handle an incoming `update_fulfill_htlc` message from the given peer.
597          */
598         public void handle_update_fulfill_htlc(byte[] their_node_id, org.ldk.structs.UpdateFulfillHTLC msg) {
599                 bindings.ChannelMessageHandler_handle_update_fulfill_htlc(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
600                 Reference.reachabilityFence(this);
601                 Reference.reachabilityFence(their_node_id);
602                 Reference.reachabilityFence(msg);
603                 if (this != null) { this.ptrs_to.add(msg); };
604         }
605
606         /**
607          * Handle an incoming `update_fail_htlc` message from the given peer.
608          */
609         public void handle_update_fail_htlc(byte[] their_node_id, org.ldk.structs.UpdateFailHTLC msg) {
610                 bindings.ChannelMessageHandler_handle_update_fail_htlc(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
611                 Reference.reachabilityFence(this);
612                 Reference.reachabilityFence(their_node_id);
613                 Reference.reachabilityFence(msg);
614                 if (this != null) { this.ptrs_to.add(msg); };
615         }
616
617         /**
618          * Handle an incoming `update_fail_malformed_htlc` message from the given peer.
619          */
620         public void handle_update_fail_malformed_htlc(byte[] their_node_id, org.ldk.structs.UpdateFailMalformedHTLC msg) {
621                 bindings.ChannelMessageHandler_handle_update_fail_malformed_htlc(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
622                 Reference.reachabilityFence(this);
623                 Reference.reachabilityFence(their_node_id);
624                 Reference.reachabilityFence(msg);
625                 if (this != null) { this.ptrs_to.add(msg); };
626         }
627
628         /**
629          * Handle an incoming `commitment_signed` message from the given peer.
630          */
631         public void handle_commitment_signed(byte[] their_node_id, org.ldk.structs.CommitmentSigned msg) {
632                 bindings.ChannelMessageHandler_handle_commitment_signed(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
633                 Reference.reachabilityFence(this);
634                 Reference.reachabilityFence(their_node_id);
635                 Reference.reachabilityFence(msg);
636                 if (this != null) { this.ptrs_to.add(msg); };
637         }
638
639         /**
640          * Handle an incoming `revoke_and_ack` message from the given peer.
641          */
642         public void handle_revoke_and_ack(byte[] their_node_id, org.ldk.structs.RevokeAndACK msg) {
643                 bindings.ChannelMessageHandler_handle_revoke_and_ack(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
644                 Reference.reachabilityFence(this);
645                 Reference.reachabilityFence(their_node_id);
646                 Reference.reachabilityFence(msg);
647                 if (this != null) { this.ptrs_to.add(msg); };
648         }
649
650         /**
651          * Handle an incoming `update_fee` message from the given peer.
652          */
653         public void handle_update_fee(byte[] their_node_id, org.ldk.structs.UpdateFee msg) {
654                 bindings.ChannelMessageHandler_handle_update_fee(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
655                 Reference.reachabilityFence(this);
656                 Reference.reachabilityFence(their_node_id);
657                 Reference.reachabilityFence(msg);
658                 if (this != null) { this.ptrs_to.add(msg); };
659         }
660
661         /**
662          * Handle an incoming `announcement_signatures` message from the given peer.
663          */
664         public void handle_announcement_signatures(byte[] their_node_id, org.ldk.structs.AnnouncementSignatures msg) {
665                 bindings.ChannelMessageHandler_handle_announcement_signatures(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
666                 Reference.reachabilityFence(this);
667                 Reference.reachabilityFence(their_node_id);
668                 Reference.reachabilityFence(msg);
669                 if (this != null) { this.ptrs_to.add(msg); };
670         }
671
672         /**
673          * Indicates a connection to the peer failed/an existing connection was lost.
674          */
675         public void peer_disconnected(byte[] their_node_id) {
676                 bindings.ChannelMessageHandler_peer_disconnected(this.ptr, InternalUtils.check_arr_len(their_node_id, 33));
677                 Reference.reachabilityFence(this);
678                 Reference.reachabilityFence(their_node_id);
679         }
680
681         /**
682          * Handle a peer reconnecting, possibly generating `channel_reestablish` message(s).
683          * 
684          * May return an `Err(())` if the features the peer supports are not sufficient to communicate
685          * with us. Implementors should be somewhat conservative about doing so, however, as other
686          * message handlers may still wish to communicate with this peer.
687          */
688         public Result_NoneNoneZ peer_connected(byte[] their_node_id, org.ldk.structs.Init msg, boolean inbound) {
689                 long ret = bindings.ChannelMessageHandler_peer_connected(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr, inbound);
690                 Reference.reachabilityFence(this);
691                 Reference.reachabilityFence(their_node_id);
692                 Reference.reachabilityFence(msg);
693                 Reference.reachabilityFence(inbound);
694                 if (ret >= 0 && ret <= 4096) { return null; }
695                 Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
696                 if (this != null) { this.ptrs_to.add(msg); };
697                 return ret_hu_conv;
698         }
699
700         /**
701          * Handle an incoming `channel_reestablish` message from the given peer.
702          */
703         public void handle_channel_reestablish(byte[] their_node_id, org.ldk.structs.ChannelReestablish msg) {
704                 bindings.ChannelMessageHandler_handle_channel_reestablish(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
705                 Reference.reachabilityFence(this);
706                 Reference.reachabilityFence(their_node_id);
707                 Reference.reachabilityFence(msg);
708                 if (this != null) { this.ptrs_to.add(msg); };
709         }
710
711         /**
712          * Handle an incoming `channel_update` message from the given peer.
713          */
714         public void handle_channel_update(byte[] their_node_id, org.ldk.structs.ChannelUpdate msg) {
715                 bindings.ChannelMessageHandler_handle_channel_update(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
716                 Reference.reachabilityFence(this);
717                 Reference.reachabilityFence(their_node_id);
718                 Reference.reachabilityFence(msg);
719                 if (this != null) { this.ptrs_to.add(msg); };
720         }
721
722         /**
723          * Handle an incoming `error` message from the given peer.
724          */
725         public void handle_error(byte[] their_node_id, org.ldk.structs.ErrorMessage msg) {
726                 bindings.ChannelMessageHandler_handle_error(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
727                 Reference.reachabilityFence(this);
728                 Reference.reachabilityFence(their_node_id);
729                 Reference.reachabilityFence(msg);
730                 if (this != null) { this.ptrs_to.add(msg); };
731         }
732
733         /**
734          * Gets the node feature flags which this handler itself supports. All available handlers are
735          * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
736          * which are broadcasted in our [`NodeAnnouncement`] message.
737          */
738         public NodeFeatures provided_node_features() {
739                 long ret = bindings.ChannelMessageHandler_provided_node_features(this.ptr);
740                 Reference.reachabilityFence(this);
741                 if (ret >= 0 && ret <= 4096) { return null; }
742                 org.ldk.structs.NodeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeFeatures(null, ret); }
743                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
744                 return ret_hu_conv;
745         }
746
747         /**
748          * Gets the init feature flags which should be sent to the given peer. All available handlers
749          * are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
750          * which are sent in our [`Init`] message.
751          * 
752          * Note that this method is called before [`Self::peer_connected`].
753          */
754         public InitFeatures provided_init_features(byte[] their_node_id) {
755                 long ret = bindings.ChannelMessageHandler_provided_init_features(this.ptr, InternalUtils.check_arr_len(their_node_id, 33));
756                 Reference.reachabilityFence(this);
757                 Reference.reachabilityFence(their_node_id);
758                 if (ret >= 0 && ret <= 4096) { return null; }
759                 org.ldk.structs.InitFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InitFeatures(null, ret); }
760                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
761                 return ret_hu_conv;
762         }
763
764         /**
765          * Gets the chain hashes for this `ChannelMessageHandler` indicating which chains it supports.
766          * 
767          * If it's `None`, then no particular network chain hash compatibility will be enforced when
768          * connecting to peers.
769          */
770         public Option_CVec_ThirtyTwoBytesZZ get_chain_hashes() {
771                 long ret = bindings.ChannelMessageHandler_get_chain_hashes(this.ptr);
772                 Reference.reachabilityFence(this);
773                 if (ret >= 0 && ret <= 4096) { return null; }
774                 org.ldk.structs.Option_CVec_ThirtyTwoBytesZZ ret_hu_conv = org.ldk.structs.Option_CVec_ThirtyTwoBytesZZ.constr_from_ptr(ret);
775                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
776                 return ret_hu_conv;
777         }
778
779 }