1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
11 * A trait to describe an object which can receive channel messages.
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.
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;
26 @Override @SuppressWarnings("deprecation")
27 protected void finalize() throws Throwable {
28 if (ptr != 0) { bindings.ChannelMessageHandler_free(ptr); } super.finalize();
31 public static interface ChannelMessageHandlerInterface {
33 * Handle an incoming open_channel message from the given peer.
35 void handle_open_channel(byte[] their_node_id, InitFeatures their_features, OpenChannel msg);
37 * Handle an incoming accept_channel message from the given peer.
39 void handle_accept_channel(byte[] their_node_id, InitFeatures their_features, AcceptChannel msg);
41 * Handle an incoming funding_created message from the given peer.
43 void handle_funding_created(byte[] their_node_id, FundingCreated msg);
45 * Handle an incoming funding_signed message from the given peer.
47 void handle_funding_signed(byte[] their_node_id, FundingSigned msg);
49 * Handle an incoming channel_ready message from the given peer.
51 void handle_channel_ready(byte[] their_node_id, ChannelReady msg);
53 * Handle an incoming shutdown message from the given peer.
55 void handle_shutdown(byte[] their_node_id, InitFeatures their_features, Shutdown msg);
57 * Handle an incoming closing_signed message from the given peer.
59 void handle_closing_signed(byte[] their_node_id, ClosingSigned msg);
61 * Handle an incoming update_add_htlc message from the given peer.
63 void handle_update_add_htlc(byte[] their_node_id, UpdateAddHTLC msg);
65 * Handle an incoming update_fulfill_htlc message from the given peer.
67 void handle_update_fulfill_htlc(byte[] their_node_id, UpdateFulfillHTLC msg);
69 * Handle an incoming update_fail_htlc message from the given peer.
71 void handle_update_fail_htlc(byte[] their_node_id, UpdateFailHTLC msg);
73 * Handle an incoming update_fail_malformed_htlc message from the given peer.
75 void handle_update_fail_malformed_htlc(byte[] their_node_id, UpdateFailMalformedHTLC msg);
77 * Handle an incoming commitment_signed message from the given peer.
79 void handle_commitment_signed(byte[] their_node_id, CommitmentSigned msg);
81 * Handle an incoming revoke_and_ack message from the given peer.
83 void handle_revoke_and_ack(byte[] their_node_id, RevokeAndACK msg);
85 * Handle an incoming update_fee message from the given peer.
87 void handle_update_fee(byte[] their_node_id, UpdateFee msg);
89 * Handle an incoming announcement_signatures message from the given peer.
91 void handle_announcement_signatures(byte[] their_node_id, AnnouncementSignatures msg);
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.
98 void peer_disconnected(byte[] their_node_id, boolean no_connection_possible);
100 * Handle a peer reconnecting, possibly generating channel_reestablish message(s).
102 void peer_connected(byte[] their_node_id, Init msg);
104 * Handle an incoming channel_reestablish message from the given peer.
106 void handle_channel_reestablish(byte[] their_node_id, ChannelReestablish msg);
108 * Handle an incoming channel update from the given peer.
110 void handle_channel_update(byte[] their_node_id, ChannelUpdate msg);
112 * Handle an incoming error message from the given peer.
114 void handle_error(byte[] their_node_id, ErrorMessage msg);
116 private static class LDKChannelMessageHandlerHolder { ChannelMessageHandler held; }
117 public static ChannelMessageHandler new_impl(ChannelMessageHandlerInterface arg, MessageSendEventsProvider.MessageSendEventsProviderInterface MessageSendEventsProvider_impl) {
118 final LDKChannelMessageHandlerHolder impl_holder = new LDKChannelMessageHandlerHolder();
119 impl_holder.held = new ChannelMessageHandler(new bindings.LDKChannelMessageHandler() {
120 @Override public void handle_open_channel(byte[] their_node_id, long their_features, long msg) {
121 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); }
122 their_features_hu_conv.ptrs_to.add(this);
123 org.ldk.structs.OpenChannel msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.OpenChannel(null, msg); }
124 arg.handle_open_channel(their_node_id, their_features_hu_conv, msg_hu_conv);
125 Reference.reachabilityFence(arg);
127 @Override public void handle_accept_channel(byte[] their_node_id, long their_features, long msg) {
128 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); }
129 their_features_hu_conv.ptrs_to.add(this);
130 org.ldk.structs.AcceptChannel msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.AcceptChannel(null, msg); }
131 arg.handle_accept_channel(their_node_id, their_features_hu_conv, msg_hu_conv);
132 Reference.reachabilityFence(arg);
134 @Override public void handle_funding_created(byte[] their_node_id, long msg) {
135 org.ldk.structs.FundingCreated msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.FundingCreated(null, msg); }
136 arg.handle_funding_created(their_node_id, msg_hu_conv);
137 Reference.reachabilityFence(arg);
139 @Override public void handle_funding_signed(byte[] their_node_id, long msg) {
140 org.ldk.structs.FundingSigned msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.FundingSigned(null, msg); }
141 arg.handle_funding_signed(their_node_id, msg_hu_conv);
142 Reference.reachabilityFence(arg);
144 @Override public void handle_channel_ready(byte[] their_node_id, long msg) {
145 org.ldk.structs.ChannelReady msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.ChannelReady(null, msg); }
146 arg.handle_channel_ready(their_node_id, msg_hu_conv);
147 Reference.reachabilityFence(arg);
149 @Override public void handle_shutdown(byte[] their_node_id, long their_features, long msg) {
150 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); }
151 org.ldk.structs.Shutdown msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.Shutdown(null, msg); }
152 arg.handle_shutdown(their_node_id, their_features_hu_conv, msg_hu_conv);
153 Reference.reachabilityFence(arg);
155 @Override public void handle_closing_signed(byte[] their_node_id, long msg) {
156 org.ldk.structs.ClosingSigned msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.ClosingSigned(null, msg); }
157 arg.handle_closing_signed(their_node_id, msg_hu_conv);
158 Reference.reachabilityFence(arg);
160 @Override public void handle_update_add_htlc(byte[] their_node_id, long msg) {
161 org.ldk.structs.UpdateAddHTLC msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.UpdateAddHTLC(null, msg); }
162 arg.handle_update_add_htlc(their_node_id, msg_hu_conv);
163 Reference.reachabilityFence(arg);
165 @Override public void handle_update_fulfill_htlc(byte[] their_node_id, long msg) {
166 org.ldk.structs.UpdateFulfillHTLC msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.UpdateFulfillHTLC(null, msg); }
167 arg.handle_update_fulfill_htlc(their_node_id, msg_hu_conv);
168 Reference.reachabilityFence(arg);
170 @Override public void handle_update_fail_htlc(byte[] their_node_id, long msg) {
171 org.ldk.structs.UpdateFailHTLC msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.UpdateFailHTLC(null, msg); }
172 arg.handle_update_fail_htlc(their_node_id, msg_hu_conv);
173 Reference.reachabilityFence(arg);
175 @Override public void handle_update_fail_malformed_htlc(byte[] their_node_id, long msg) {
176 org.ldk.structs.UpdateFailMalformedHTLC msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.UpdateFailMalformedHTLC(null, msg); }
177 arg.handle_update_fail_malformed_htlc(their_node_id, msg_hu_conv);
178 Reference.reachabilityFence(arg);
180 @Override public void handle_commitment_signed(byte[] their_node_id, long msg) {
181 org.ldk.structs.CommitmentSigned msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.CommitmentSigned(null, msg); }
182 arg.handle_commitment_signed(their_node_id, msg_hu_conv);
183 Reference.reachabilityFence(arg);
185 @Override public void handle_revoke_and_ack(byte[] their_node_id, long msg) {
186 org.ldk.structs.RevokeAndACK msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.RevokeAndACK(null, msg); }
187 arg.handle_revoke_and_ack(their_node_id, msg_hu_conv);
188 Reference.reachabilityFence(arg);
190 @Override public void handle_update_fee(byte[] their_node_id, long msg) {
191 org.ldk.structs.UpdateFee msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.UpdateFee(null, msg); }
192 arg.handle_update_fee(their_node_id, msg_hu_conv);
193 Reference.reachabilityFence(arg);
195 @Override public void handle_announcement_signatures(byte[] their_node_id, long msg) {
196 org.ldk.structs.AnnouncementSignatures msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.AnnouncementSignatures(null, msg); }
197 arg.handle_announcement_signatures(their_node_id, msg_hu_conv);
198 Reference.reachabilityFence(arg);
200 @Override public void peer_disconnected(byte[] their_node_id, boolean no_connection_possible) {
201 arg.peer_disconnected(their_node_id, no_connection_possible);
202 Reference.reachabilityFence(arg);
204 @Override public void peer_connected(byte[] their_node_id, long msg) {
205 org.ldk.structs.Init msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.Init(null, msg); }
206 arg.peer_connected(their_node_id, msg_hu_conv);
207 Reference.reachabilityFence(arg);
209 @Override public void handle_channel_reestablish(byte[] their_node_id, long msg) {
210 org.ldk.structs.ChannelReestablish msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.ChannelReestablish(null, msg); }
211 arg.handle_channel_reestablish(their_node_id, msg_hu_conv);
212 Reference.reachabilityFence(arg);
214 @Override public void handle_channel_update(byte[] their_node_id, long msg) {
215 org.ldk.structs.ChannelUpdate msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.ChannelUpdate(null, msg); }
216 arg.handle_channel_update(their_node_id, msg_hu_conv);
217 Reference.reachabilityFence(arg);
219 @Override public void handle_error(byte[] their_node_id, long msg) {
220 org.ldk.structs.ErrorMessage msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.ErrorMessage(null, msg); }
221 arg.handle_error(their_node_id, msg_hu_conv);
222 Reference.reachabilityFence(arg);
224 }, MessageSendEventsProvider.new_impl(MessageSendEventsProvider_impl).bindings_instance);
225 return impl_holder.held;
229 * Gets the underlying MessageSendEventsProvider.
231 public MessageSendEventsProvider get_message_send_events_provider() {
232 MessageSendEventsProvider res = new MessageSendEventsProvider(null, bindings.LDKChannelMessageHandler_get_MessageSendEventsProvider(this.ptr));
233 this.ptrs_to.add(res);
238 * Handle an incoming open_channel message from the given peer.
240 public void handle_open_channel(byte[] their_node_id, InitFeatures their_features, OpenChannel msg) {
241 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);
242 Reference.reachabilityFence(this);
243 Reference.reachabilityFence(their_node_id);
244 Reference.reachabilityFence(their_features);
245 Reference.reachabilityFence(msg);
246 this.ptrs_to.add(their_features);
247 this.ptrs_to.add(msg);
251 * Handle an incoming accept_channel message from the given peer.
253 public void handle_accept_channel(byte[] their_node_id, InitFeatures their_features, AcceptChannel msg) {
254 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);
255 Reference.reachabilityFence(this);
256 Reference.reachabilityFence(their_node_id);
257 Reference.reachabilityFence(their_features);
258 Reference.reachabilityFence(msg);
259 this.ptrs_to.add(their_features);
260 this.ptrs_to.add(msg);
264 * Handle an incoming funding_created message from the given peer.
266 public void handle_funding_created(byte[] their_node_id, FundingCreated msg) {
267 bindings.ChannelMessageHandler_handle_funding_created(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
268 Reference.reachabilityFence(this);
269 Reference.reachabilityFence(their_node_id);
270 Reference.reachabilityFence(msg);
271 this.ptrs_to.add(msg);
275 * Handle an incoming funding_signed message from the given peer.
277 public void handle_funding_signed(byte[] their_node_id, FundingSigned msg) {
278 bindings.ChannelMessageHandler_handle_funding_signed(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
279 Reference.reachabilityFence(this);
280 Reference.reachabilityFence(their_node_id);
281 Reference.reachabilityFence(msg);
282 this.ptrs_to.add(msg);
286 * Handle an incoming channel_ready message from the given peer.
288 public void handle_channel_ready(byte[] their_node_id, ChannelReady msg) {
289 bindings.ChannelMessageHandler_handle_channel_ready(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
290 Reference.reachabilityFence(this);
291 Reference.reachabilityFence(their_node_id);
292 Reference.reachabilityFence(msg);
293 this.ptrs_to.add(msg);
297 * Handle an incoming shutdown message from the given peer.
299 public void handle_shutdown(byte[] their_node_id, InitFeatures their_features, Shutdown msg) {
300 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);
301 Reference.reachabilityFence(this);
302 Reference.reachabilityFence(their_node_id);
303 Reference.reachabilityFence(their_features);
304 Reference.reachabilityFence(msg);
305 this.ptrs_to.add(their_features);
306 this.ptrs_to.add(msg);
310 * Handle an incoming closing_signed message from the given peer.
312 public void handle_closing_signed(byte[] their_node_id, ClosingSigned msg) {
313 bindings.ChannelMessageHandler_handle_closing_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 this.ptrs_to.add(msg);
321 * Handle an incoming update_add_htlc message from the given peer.
323 public void handle_update_add_htlc(byte[] their_node_id, UpdateAddHTLC msg) {
324 bindings.ChannelMessageHandler_handle_update_add_htlc(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 this.ptrs_to.add(msg);
332 * Handle an incoming update_fulfill_htlc message from the given peer.
334 public void handle_update_fulfill_htlc(byte[] their_node_id, UpdateFulfillHTLC msg) {
335 bindings.ChannelMessageHandler_handle_update_fulfill_htlc(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
336 Reference.reachabilityFence(this);
337 Reference.reachabilityFence(their_node_id);
338 Reference.reachabilityFence(msg);
339 this.ptrs_to.add(msg);
343 * Handle an incoming update_fail_htlc message from the given peer.
345 public void handle_update_fail_htlc(byte[] their_node_id, UpdateFailHTLC msg) {
346 bindings.ChannelMessageHandler_handle_update_fail_htlc(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
347 Reference.reachabilityFence(this);
348 Reference.reachabilityFence(their_node_id);
349 Reference.reachabilityFence(msg);
350 this.ptrs_to.add(msg);
354 * Handle an incoming update_fail_malformed_htlc message from the given peer.
356 public void handle_update_fail_malformed_htlc(byte[] their_node_id, UpdateFailMalformedHTLC msg) {
357 bindings.ChannelMessageHandler_handle_update_fail_malformed_htlc(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
358 Reference.reachabilityFence(this);
359 Reference.reachabilityFence(their_node_id);
360 Reference.reachabilityFence(msg);
361 this.ptrs_to.add(msg);
365 * Handle an incoming commitment_signed message from the given peer.
367 public void handle_commitment_signed(byte[] their_node_id, CommitmentSigned msg) {
368 bindings.ChannelMessageHandler_handle_commitment_signed(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
369 Reference.reachabilityFence(this);
370 Reference.reachabilityFence(their_node_id);
371 Reference.reachabilityFence(msg);
372 this.ptrs_to.add(msg);
376 * Handle an incoming revoke_and_ack message from the given peer.
378 public void handle_revoke_and_ack(byte[] their_node_id, RevokeAndACK msg) {
379 bindings.ChannelMessageHandler_handle_revoke_and_ack(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
380 Reference.reachabilityFence(this);
381 Reference.reachabilityFence(their_node_id);
382 Reference.reachabilityFence(msg);
383 this.ptrs_to.add(msg);
387 * Handle an incoming update_fee message from the given peer.
389 public void handle_update_fee(byte[] their_node_id, UpdateFee msg) {
390 bindings.ChannelMessageHandler_handle_update_fee(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 this.ptrs_to.add(msg);
398 * Handle an incoming announcement_signatures message from the given peer.
400 public void handle_announcement_signatures(byte[] their_node_id, AnnouncementSignatures msg) {
401 bindings.ChannelMessageHandler_handle_announcement_signatures(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 this.ptrs_to.add(msg);
409 * Indicates a connection to the peer failed/an existing connection was lost. If no connection
410 * is believed to be possible in the future (eg they're sending us messages we don't
411 * understand or indicate they require unknown feature bits), no_connection_possible is set
412 * and any outstanding channels should be failed.
414 public void peer_disconnected(byte[] their_node_id, boolean no_connection_possible) {
415 bindings.ChannelMessageHandler_peer_disconnected(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), no_connection_possible);
416 Reference.reachabilityFence(this);
417 Reference.reachabilityFence(their_node_id);
418 Reference.reachabilityFence(no_connection_possible);
422 * Handle a peer reconnecting, possibly generating channel_reestablish message(s).
424 public void peer_connected(byte[] their_node_id, Init msg) {
425 bindings.ChannelMessageHandler_peer_connected(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 this.ptrs_to.add(msg);
433 * Handle an incoming channel_reestablish message from the given peer.
435 public void handle_channel_reestablish(byte[] their_node_id, ChannelReestablish msg) {
436 bindings.ChannelMessageHandler_handle_channel_reestablish(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 this.ptrs_to.add(msg);
444 * Handle an incoming channel update from the given peer.
446 public void handle_channel_update(byte[] their_node_id, ChannelUpdate msg) {
447 bindings.ChannelMessageHandler_handle_channel_update(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
448 Reference.reachabilityFence(this);
449 Reference.reachabilityFence(their_node_id);
450 Reference.reachabilityFence(msg);
451 this.ptrs_to.add(msg);
455 * Handle an incoming error message from the given peer.
457 public void handle_error(byte[] their_node_id, ErrorMessage msg) {
458 bindings.ChannelMessageHandler_handle_error(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
459 Reference.reachabilityFence(this);
460 Reference.reachabilityFence(their_node_id);
461 Reference.reachabilityFence(msg);
462 this.ptrs_to.add(msg);