1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
9 * A trait to describe an object which can receive channel messages.
11 * Messages MAY be called in parallel when they originate from different their_node_ids, however
12 * they MUST NOT be called in parallel when the two calls have the same their_node_id.
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class ChannelMessageHandler extends CommonBase {
16 final bindings.LDKChannelMessageHandler bindings_instance;
17 ChannelMessageHandler(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
18 private ChannelMessageHandler(bindings.LDKChannelMessageHandler arg, bindings.LDKMessageSendEventsProvider MessageSendEventsProvider) {
19 super(bindings.LDKChannelMessageHandler_new(arg, MessageSendEventsProvider));
20 this.ptrs_to.add(arg);
21 this.ptrs_to.add(MessageSendEventsProvider);
22 this.bindings_instance = arg;
24 @Override @SuppressWarnings("deprecation")
25 protected void finalize() throws Throwable {
26 if (ptr != 0) { bindings.ChannelMessageHandler_free(ptr); } super.finalize();
29 public static interface ChannelMessageHandlerInterface {
31 * Handle an incoming open_channel message from the given peer.
33 void handle_open_channel(byte[] their_node_id, InitFeatures their_features, OpenChannel msg);
35 * Handle an incoming accept_channel message from the given peer.
37 void handle_accept_channel(byte[] their_node_id, InitFeatures their_features, AcceptChannel msg);
39 * Handle an incoming funding_created message from the given peer.
41 void handle_funding_created(byte[] their_node_id, FundingCreated msg);
43 * Handle an incoming funding_signed message from the given peer.
45 void handle_funding_signed(byte[] their_node_id, FundingSigned msg);
47 * Handle an incoming funding_locked message from the given peer.
49 void handle_funding_locked(byte[] their_node_id, FundingLocked msg);
51 * Handle an incoming shutdown message from the given peer.
53 void handle_shutdown(byte[] their_node_id, InitFeatures their_features, Shutdown msg);
55 * Handle an incoming closing_signed message from the given peer.
57 void handle_closing_signed(byte[] their_node_id, ClosingSigned msg);
59 * Handle an incoming update_add_htlc message from the given peer.
61 void handle_update_add_htlc(byte[] their_node_id, UpdateAddHTLC msg);
63 * Handle an incoming update_fulfill_htlc message from the given peer.
65 void handle_update_fulfill_htlc(byte[] their_node_id, UpdateFulfillHTLC msg);
67 * Handle an incoming update_fail_htlc message from the given peer.
69 void handle_update_fail_htlc(byte[] their_node_id, UpdateFailHTLC msg);
71 * Handle an incoming update_fail_malformed_htlc message from the given peer.
73 void handle_update_fail_malformed_htlc(byte[] their_node_id, UpdateFailMalformedHTLC msg);
75 * Handle an incoming commitment_signed message from the given peer.
77 void handle_commitment_signed(byte[] their_node_id, CommitmentSigned msg);
79 * Handle an incoming revoke_and_ack message from the given peer.
81 void handle_revoke_and_ack(byte[] their_node_id, RevokeAndACK msg);
83 * Handle an incoming update_fee message from the given peer.
85 void handle_update_fee(byte[] their_node_id, UpdateFee msg);
87 * Handle an incoming announcement_signatures message from the given peer.
89 void handle_announcement_signatures(byte[] their_node_id, AnnouncementSignatures msg);
91 * Indicates a connection to the peer failed/an existing connection was lost. If no connection
92 * is believed to be possible in the future (eg they're sending us messages we don't
93 * understand or indicate they require unknown feature bits), no_connection_possible is set
94 * and any outstanding channels should be failed.
96 void peer_disconnected(byte[] their_node_id, boolean no_connection_possible);
98 * Handle a peer reconnecting, possibly generating channel_reestablish message(s).
100 void peer_connected(byte[] their_node_id, Init msg);
102 * Handle an incoming channel_reestablish message from the given peer.
104 void handle_channel_reestablish(byte[] their_node_id, ChannelReestablish msg);
106 * Handle an incoming channel update from the given peer.
108 void handle_channel_update(byte[] their_node_id, ChannelUpdate msg);
110 * Handle an incoming error message from the given peer.
112 void handle_error(byte[] their_node_id, ErrorMessage msg);
114 private static class LDKChannelMessageHandlerHolder { ChannelMessageHandler held; }
115 public static ChannelMessageHandler new_impl(ChannelMessageHandlerInterface arg, MessageSendEventsProvider.MessageSendEventsProviderInterface MessageSendEventsProvider_impl) {
116 final LDKChannelMessageHandlerHolder impl_holder = new LDKChannelMessageHandlerHolder();
117 impl_holder.held = new ChannelMessageHandler(new bindings.LDKChannelMessageHandler() {
118 @Override public void handle_open_channel(byte[] their_node_id, long their_features, long msg) {
119 InitFeatures their_features_hu_conv = new InitFeatures(null, their_features);
120 their_features_hu_conv.ptrs_to.add(this);
121 OpenChannel msg_hu_conv = new OpenChannel(null, msg);
122 arg.handle_open_channel(their_node_id, their_features_hu_conv, msg_hu_conv);
124 @Override public void handle_accept_channel(byte[] their_node_id, long their_features, long msg) {
125 InitFeatures their_features_hu_conv = new InitFeatures(null, their_features);
126 their_features_hu_conv.ptrs_to.add(this);
127 AcceptChannel msg_hu_conv = new AcceptChannel(null, msg);
128 arg.handle_accept_channel(their_node_id, their_features_hu_conv, msg_hu_conv);
130 @Override public void handle_funding_created(byte[] their_node_id, long msg) {
131 FundingCreated msg_hu_conv = new FundingCreated(null, msg);
132 arg.handle_funding_created(their_node_id, msg_hu_conv);
134 @Override public void handle_funding_signed(byte[] their_node_id, long msg) {
135 FundingSigned msg_hu_conv = new FundingSigned(null, msg);
136 arg.handle_funding_signed(their_node_id, msg_hu_conv);
138 @Override public void handle_funding_locked(byte[] their_node_id, long msg) {
139 FundingLocked msg_hu_conv = new FundingLocked(null, msg);
140 arg.handle_funding_locked(their_node_id, msg_hu_conv);
142 @Override public void handle_shutdown(byte[] their_node_id, long their_features, long msg) {
143 InitFeatures their_features_hu_conv = new InitFeatures(null, their_features);
144 Shutdown msg_hu_conv = new Shutdown(null, msg);
145 arg.handle_shutdown(their_node_id, their_features_hu_conv, msg_hu_conv);
147 @Override public void handle_closing_signed(byte[] their_node_id, long msg) {
148 ClosingSigned msg_hu_conv = new ClosingSigned(null, msg);
149 arg.handle_closing_signed(their_node_id, msg_hu_conv);
151 @Override public void handle_update_add_htlc(byte[] their_node_id, long msg) {
152 UpdateAddHTLC msg_hu_conv = new UpdateAddHTLC(null, msg);
153 arg.handle_update_add_htlc(their_node_id, msg_hu_conv);
155 @Override public void handle_update_fulfill_htlc(byte[] their_node_id, long msg) {
156 UpdateFulfillHTLC msg_hu_conv = new UpdateFulfillHTLC(null, msg);
157 arg.handle_update_fulfill_htlc(their_node_id, msg_hu_conv);
159 @Override public void handle_update_fail_htlc(byte[] their_node_id, long msg) {
160 UpdateFailHTLC msg_hu_conv = new UpdateFailHTLC(null, msg);
161 arg.handle_update_fail_htlc(their_node_id, msg_hu_conv);
163 @Override public void handle_update_fail_malformed_htlc(byte[] their_node_id, long msg) {
164 UpdateFailMalformedHTLC msg_hu_conv = new UpdateFailMalformedHTLC(null, msg);
165 arg.handle_update_fail_malformed_htlc(their_node_id, msg_hu_conv);
167 @Override public void handle_commitment_signed(byte[] their_node_id, long msg) {
168 CommitmentSigned msg_hu_conv = new CommitmentSigned(null, msg);
169 arg.handle_commitment_signed(their_node_id, msg_hu_conv);
171 @Override public void handle_revoke_and_ack(byte[] their_node_id, long msg) {
172 RevokeAndACK msg_hu_conv = new RevokeAndACK(null, msg);
173 arg.handle_revoke_and_ack(their_node_id, msg_hu_conv);
175 @Override public void handle_update_fee(byte[] their_node_id, long msg) {
176 UpdateFee msg_hu_conv = new UpdateFee(null, msg);
177 arg.handle_update_fee(their_node_id, msg_hu_conv);
179 @Override public void handle_announcement_signatures(byte[] their_node_id, long msg) {
180 AnnouncementSignatures msg_hu_conv = new AnnouncementSignatures(null, msg);
181 arg.handle_announcement_signatures(their_node_id, msg_hu_conv);
183 @Override public void peer_disconnected(byte[] their_node_id, boolean no_connection_possible) {
184 arg.peer_disconnected(their_node_id, no_connection_possible);
186 @Override public void peer_connected(byte[] their_node_id, long msg) {
187 Init msg_hu_conv = new Init(null, msg);
188 arg.peer_connected(their_node_id, msg_hu_conv);
190 @Override public void handle_channel_reestablish(byte[] their_node_id, long msg) {
191 ChannelReestablish msg_hu_conv = new ChannelReestablish(null, msg);
192 arg.handle_channel_reestablish(their_node_id, msg_hu_conv);
194 @Override public void handle_channel_update(byte[] their_node_id, long msg) {
195 ChannelUpdate msg_hu_conv = new ChannelUpdate(null, msg);
196 arg.handle_channel_update(their_node_id, msg_hu_conv);
198 @Override public void handle_error(byte[] their_node_id, long msg) {
199 ErrorMessage msg_hu_conv = new ErrorMessage(null, msg);
200 arg.handle_error(their_node_id, msg_hu_conv);
202 }, MessageSendEventsProvider.new_impl(MessageSendEventsProvider_impl).bindings_instance);
203 return impl_holder.held;
207 * Gets the underlying MessageSendEventsProvider.
209 public MessageSendEventsProvider get_message_send_events_provider() {
210 MessageSendEventsProvider res = new MessageSendEventsProvider(null, bindings.LDKChannelMessageHandler_get_MessageSendEventsProvider(this.ptr));
211 this.ptrs_to.add(res);
216 * Handle an incoming open_channel message from the given peer.
218 public void handle_open_channel(byte[] their_node_id, InitFeatures their_features, OpenChannel msg) {
219 bindings.ChannelMessageHandler_handle_open_channel(this.ptr, their_node_id, their_features == null ? 0 : their_features.ptr & ~1, msg == null ? 0 : msg.ptr & ~1);
220 this.ptrs_to.add(their_features);
221 this.ptrs_to.add(msg);
225 * Handle an incoming accept_channel message from the given peer.
227 public void handle_accept_channel(byte[] their_node_id, InitFeatures their_features, AcceptChannel msg) {
228 bindings.ChannelMessageHandler_handle_accept_channel(this.ptr, their_node_id, their_features == null ? 0 : their_features.ptr & ~1, msg == null ? 0 : msg.ptr & ~1);
229 this.ptrs_to.add(their_features);
230 this.ptrs_to.add(msg);
234 * Handle an incoming funding_created message from the given peer.
236 public void handle_funding_created(byte[] their_node_id, FundingCreated msg) {
237 bindings.ChannelMessageHandler_handle_funding_created(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
238 this.ptrs_to.add(msg);
242 * Handle an incoming funding_signed message from the given peer.
244 public void handle_funding_signed(byte[] their_node_id, FundingSigned msg) {
245 bindings.ChannelMessageHandler_handle_funding_signed(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
246 this.ptrs_to.add(msg);
250 * Handle an incoming funding_locked message from the given peer.
252 public void handle_funding_locked(byte[] their_node_id, FundingLocked msg) {
253 bindings.ChannelMessageHandler_handle_funding_locked(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
254 this.ptrs_to.add(msg);
258 * Handle an incoming shutdown message from the given peer.
260 public void handle_shutdown(byte[] their_node_id, InitFeatures their_features, Shutdown msg) {
261 bindings.ChannelMessageHandler_handle_shutdown(this.ptr, their_node_id, their_features == null ? 0 : their_features.ptr & ~1, msg == null ? 0 : msg.ptr & ~1);
262 this.ptrs_to.add(their_features);
263 this.ptrs_to.add(msg);
267 * Handle an incoming closing_signed message from the given peer.
269 public void handle_closing_signed(byte[] their_node_id, ClosingSigned msg) {
270 bindings.ChannelMessageHandler_handle_closing_signed(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
271 this.ptrs_to.add(msg);
275 * Handle an incoming update_add_htlc message from the given peer.
277 public void handle_update_add_htlc(byte[] their_node_id, UpdateAddHTLC msg) {
278 bindings.ChannelMessageHandler_handle_update_add_htlc(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
279 this.ptrs_to.add(msg);
283 * Handle an incoming update_fulfill_htlc message from the given peer.
285 public void handle_update_fulfill_htlc(byte[] their_node_id, UpdateFulfillHTLC msg) {
286 bindings.ChannelMessageHandler_handle_update_fulfill_htlc(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
287 this.ptrs_to.add(msg);
291 * Handle an incoming update_fail_htlc message from the given peer.
293 public void handle_update_fail_htlc(byte[] their_node_id, UpdateFailHTLC msg) {
294 bindings.ChannelMessageHandler_handle_update_fail_htlc(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
295 this.ptrs_to.add(msg);
299 * Handle an incoming update_fail_malformed_htlc message from the given peer.
301 public void handle_update_fail_malformed_htlc(byte[] their_node_id, UpdateFailMalformedHTLC msg) {
302 bindings.ChannelMessageHandler_handle_update_fail_malformed_htlc(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
303 this.ptrs_to.add(msg);
307 * Handle an incoming commitment_signed message from the given peer.
309 public void handle_commitment_signed(byte[] their_node_id, CommitmentSigned msg) {
310 bindings.ChannelMessageHandler_handle_commitment_signed(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
311 this.ptrs_to.add(msg);
315 * Handle an incoming revoke_and_ack message from the given peer.
317 public void handle_revoke_and_ack(byte[] their_node_id, RevokeAndACK msg) {
318 bindings.ChannelMessageHandler_handle_revoke_and_ack(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
319 this.ptrs_to.add(msg);
323 * Handle an incoming update_fee message from the given peer.
325 public void handle_update_fee(byte[] their_node_id, UpdateFee msg) {
326 bindings.ChannelMessageHandler_handle_update_fee(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
327 this.ptrs_to.add(msg);
331 * Handle an incoming announcement_signatures message from the given peer.
333 public void handle_announcement_signatures(byte[] their_node_id, AnnouncementSignatures msg) {
334 bindings.ChannelMessageHandler_handle_announcement_signatures(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
335 this.ptrs_to.add(msg);
339 * Indicates a connection to the peer failed/an existing connection was lost. If no connection
340 * is believed to be possible in the future (eg they're sending us messages we don't
341 * understand or indicate they require unknown feature bits), no_connection_possible is set
342 * and any outstanding channels should be failed.
344 public void peer_disconnected(byte[] their_node_id, boolean no_connection_possible) {
345 bindings.ChannelMessageHandler_peer_disconnected(this.ptr, their_node_id, no_connection_possible);
349 * Handle a peer reconnecting, possibly generating channel_reestablish message(s).
351 public void peer_connected(byte[] their_node_id, Init msg) {
352 bindings.ChannelMessageHandler_peer_connected(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
353 this.ptrs_to.add(msg);
357 * Handle an incoming channel_reestablish message from the given peer.
359 public void handle_channel_reestablish(byte[] their_node_id, ChannelReestablish msg) {
360 bindings.ChannelMessageHandler_handle_channel_reestablish(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
361 this.ptrs_to.add(msg);
365 * Handle an incoming channel update from the given peer.
367 public void handle_channel_update(byte[] their_node_id, ChannelUpdate msg) {
368 bindings.ChannelMessageHandler_handle_channel_update(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
369 this.ptrs_to.add(msg);
373 * Handle an incoming error message from the given peer.
375 public void handle_error(byte[] their_node_id, ErrorMessage msg) {
376 bindings.ChannelMessageHandler_handle_error(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
377 this.ptrs_to.add(msg);