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;
206 * Handle an incoming open_channel message from the given peer.
208 public void handle_open_channel(byte[] their_node_id, InitFeatures their_features, OpenChannel msg) {
209 bindings.ChannelMessageHandler_handle_open_channel(this.ptr, their_node_id, their_features == null ? 0 : their_features.ptr & ~1, msg == null ? 0 : msg.ptr & ~1);
210 this.ptrs_to.add(their_features);
211 this.ptrs_to.add(msg);
215 * Handle an incoming accept_channel message from the given peer.
217 public void handle_accept_channel(byte[] their_node_id, InitFeatures their_features, AcceptChannel msg) {
218 bindings.ChannelMessageHandler_handle_accept_channel(this.ptr, their_node_id, their_features == null ? 0 : their_features.ptr & ~1, msg == null ? 0 : msg.ptr & ~1);
219 this.ptrs_to.add(their_features);
220 this.ptrs_to.add(msg);
224 * Handle an incoming funding_created message from the given peer.
226 public void handle_funding_created(byte[] their_node_id, FundingCreated msg) {
227 bindings.ChannelMessageHandler_handle_funding_created(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
228 this.ptrs_to.add(msg);
232 * Handle an incoming funding_signed message from the given peer.
234 public void handle_funding_signed(byte[] their_node_id, FundingSigned msg) {
235 bindings.ChannelMessageHandler_handle_funding_signed(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
236 this.ptrs_to.add(msg);
240 * Handle an incoming funding_locked message from the given peer.
242 public void handle_funding_locked(byte[] their_node_id, FundingLocked msg) {
243 bindings.ChannelMessageHandler_handle_funding_locked(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
244 this.ptrs_to.add(msg);
248 * Handle an incoming shutdown message from the given peer.
250 public void handle_shutdown(byte[] their_node_id, InitFeatures their_features, Shutdown msg) {
251 bindings.ChannelMessageHandler_handle_shutdown(this.ptr, their_node_id, their_features == null ? 0 : their_features.ptr & ~1, msg == null ? 0 : msg.ptr & ~1);
252 this.ptrs_to.add(their_features);
253 this.ptrs_to.add(msg);
257 * Handle an incoming closing_signed message from the given peer.
259 public void handle_closing_signed(byte[] their_node_id, ClosingSigned msg) {
260 bindings.ChannelMessageHandler_handle_closing_signed(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
261 this.ptrs_to.add(msg);
265 * Handle an incoming update_add_htlc message from the given peer.
267 public void handle_update_add_htlc(byte[] their_node_id, UpdateAddHTLC msg) {
268 bindings.ChannelMessageHandler_handle_update_add_htlc(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
269 this.ptrs_to.add(msg);
273 * Handle an incoming update_fulfill_htlc message from the given peer.
275 public void handle_update_fulfill_htlc(byte[] their_node_id, UpdateFulfillHTLC msg) {
276 bindings.ChannelMessageHandler_handle_update_fulfill_htlc(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
277 this.ptrs_to.add(msg);
281 * Handle an incoming update_fail_htlc message from the given peer.
283 public void handle_update_fail_htlc(byte[] their_node_id, UpdateFailHTLC msg) {
284 bindings.ChannelMessageHandler_handle_update_fail_htlc(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
285 this.ptrs_to.add(msg);
289 * Handle an incoming update_fail_malformed_htlc message from the given peer.
291 public void handle_update_fail_malformed_htlc(byte[] their_node_id, UpdateFailMalformedHTLC msg) {
292 bindings.ChannelMessageHandler_handle_update_fail_malformed_htlc(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
293 this.ptrs_to.add(msg);
297 * Handle an incoming commitment_signed message from the given peer.
299 public void handle_commitment_signed(byte[] their_node_id, CommitmentSigned msg) {
300 bindings.ChannelMessageHandler_handle_commitment_signed(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
301 this.ptrs_to.add(msg);
305 * Handle an incoming revoke_and_ack message from the given peer.
307 public void handle_revoke_and_ack(byte[] their_node_id, RevokeAndACK msg) {
308 bindings.ChannelMessageHandler_handle_revoke_and_ack(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
309 this.ptrs_to.add(msg);
313 * Handle an incoming update_fee message from the given peer.
315 public void handle_update_fee(byte[] their_node_id, UpdateFee msg) {
316 bindings.ChannelMessageHandler_handle_update_fee(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
317 this.ptrs_to.add(msg);
321 * Handle an incoming announcement_signatures message from the given peer.
323 public void handle_announcement_signatures(byte[] their_node_id, AnnouncementSignatures msg) {
324 bindings.ChannelMessageHandler_handle_announcement_signatures(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
325 this.ptrs_to.add(msg);
329 * Indicates a connection to the peer failed/an existing connection was lost. If no connection
330 * is believed to be possible in the future (eg they're sending us messages we don't
331 * understand or indicate they require unknown feature bits), no_connection_possible is set
332 * and any outstanding channels should be failed.
334 public void peer_disconnected(byte[] their_node_id, boolean no_connection_possible) {
335 bindings.ChannelMessageHandler_peer_disconnected(this.ptr, their_node_id, no_connection_possible);
339 * Handle a peer reconnecting, possibly generating channel_reestablish message(s).
341 public void peer_connected(byte[] their_node_id, Init msg) {
342 bindings.ChannelMessageHandler_peer_connected(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
343 this.ptrs_to.add(msg);
347 * Handle an incoming channel_reestablish message from the given peer.
349 public void handle_channel_reestablish(byte[] their_node_id, ChannelReestablish msg) {
350 bindings.ChannelMessageHandler_handle_channel_reestablish(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
351 this.ptrs_to.add(msg);
355 * Handle an incoming channel update from the given peer.
357 public void handle_channel_update(byte[] their_node_id, ChannelUpdate msg) {
358 bindings.ChannelMessageHandler_handle_channel_update(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
359 this.ptrs_to.add(msg);
363 * Handle an incoming error message from the given peer.
365 public void handle_error(byte[] their_node_id, ErrorMessage msg) {
366 bindings.ChannelMessageHandler_handle_error(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
367 this.ptrs_to.add(msg);