Update auto-generated bindings to 0.0.103
[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 javax.annotation.Nullable;
8
9 /**
10  * A trait to describe an object which can receive channel messages.
11  * 
12  * Messages MAY be called in parallel when they originate from different their_node_ids, however
13  * they MUST NOT be called in parallel when the two calls have the same their_node_id.
14  */
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class ChannelMessageHandler extends CommonBase {
17         final bindings.LDKChannelMessageHandler bindings_instance;
18         ChannelMessageHandler(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
19         private ChannelMessageHandler(bindings.LDKChannelMessageHandler arg, bindings.LDKMessageSendEventsProvider MessageSendEventsProvider) {
20                 super(bindings.LDKChannelMessageHandler_new(arg, MessageSendEventsProvider));
21                 this.ptrs_to.add(arg);
22                 this.ptrs_to.add(MessageSendEventsProvider);
23                 this.bindings_instance = arg;
24         }
25         @Override @SuppressWarnings("deprecation")
26         protected void finalize() throws Throwable {
27                 if (ptr != 0) { bindings.ChannelMessageHandler_free(ptr); } super.finalize();
28         }
29
30         public static interface ChannelMessageHandlerInterface {
31                 /**
32                  * Handle an incoming open_channel message from the given peer.
33                  */
34                 void handle_open_channel(byte[] their_node_id, InitFeatures their_features, OpenChannel msg);
35                 /**
36                  * Handle an incoming accept_channel message from the given peer.
37                  */
38                 void handle_accept_channel(byte[] their_node_id, InitFeatures their_features, AcceptChannel msg);
39                 /**
40                  * Handle an incoming funding_created message from the given peer.
41                  */
42                 void handle_funding_created(byte[] their_node_id, FundingCreated msg);
43                 /**
44                  * Handle an incoming funding_signed message from the given peer.
45                  */
46                 void handle_funding_signed(byte[] their_node_id, FundingSigned msg);
47                 /**
48                  * Handle an incoming funding_locked message from the given peer.
49                  */
50                 void handle_funding_locked(byte[] their_node_id, FundingLocked msg);
51                 /**
52                  * Handle an incoming shutdown message from the given peer.
53                  */
54                 void handle_shutdown(byte[] their_node_id, InitFeatures their_features, Shutdown msg);
55                 /**
56                  * Handle an incoming closing_signed message from the given peer.
57                  */
58                 void handle_closing_signed(byte[] their_node_id, ClosingSigned msg);
59                 /**
60                  * Handle an incoming update_add_htlc message from the given peer.
61                  */
62                 void handle_update_add_htlc(byte[] their_node_id, UpdateAddHTLC msg);
63                 /**
64                  * Handle an incoming update_fulfill_htlc message from the given peer.
65                  */
66                 void handle_update_fulfill_htlc(byte[] their_node_id, UpdateFulfillHTLC msg);
67                 /**
68                  * Handle an incoming update_fail_htlc message from the given peer.
69                  */
70                 void handle_update_fail_htlc(byte[] their_node_id, UpdateFailHTLC msg);
71                 /**
72                  * Handle an incoming update_fail_malformed_htlc message from the given peer.
73                  */
74                 void handle_update_fail_malformed_htlc(byte[] their_node_id, UpdateFailMalformedHTLC msg);
75                 /**
76                  * Handle an incoming commitment_signed message from the given peer.
77                  */
78                 void handle_commitment_signed(byte[] their_node_id, CommitmentSigned msg);
79                 /**
80                  * Handle an incoming revoke_and_ack message from the given peer.
81                  */
82                 void handle_revoke_and_ack(byte[] their_node_id, RevokeAndACK msg);
83                 /**
84                  * Handle an incoming update_fee message from the given peer.
85                  */
86                 void handle_update_fee(byte[] their_node_id, UpdateFee msg);
87                 /**
88                  * Handle an incoming announcement_signatures message from the given peer.
89                  */
90                 void handle_announcement_signatures(byte[] their_node_id, AnnouncementSignatures msg);
91                 /**
92                  * Indicates a connection to the peer failed/an existing connection was lost. If no connection
93                  * is believed to be possible in the future (eg they're sending us messages we don't
94                  * understand or indicate they require unknown feature bits), no_connection_possible is set
95                  * and any outstanding channels should be failed.
96                  */
97                 void peer_disconnected(byte[] their_node_id, boolean no_connection_possible);
98                 /**
99                  * Handle a peer reconnecting, possibly generating channel_reestablish message(s).
100                  */
101                 void peer_connected(byte[] their_node_id, Init msg);
102                 /**
103                  * Handle an incoming channel_reestablish message from the given peer.
104                  */
105                 void handle_channel_reestablish(byte[] their_node_id, ChannelReestablish msg);
106                 /**
107                  * Handle an incoming channel update from the given peer.
108                  */
109                 void handle_channel_update(byte[] their_node_id, ChannelUpdate msg);
110                 /**
111                  * Handle an incoming error message from the given peer.
112                  */
113                 void handle_error(byte[] their_node_id, ErrorMessage msg);
114         }
115         private static class LDKChannelMessageHandlerHolder { ChannelMessageHandler held; }
116         public static ChannelMessageHandler new_impl(ChannelMessageHandlerInterface arg, MessageSendEventsProvider.MessageSendEventsProviderInterface MessageSendEventsProvider_impl) {
117                 final LDKChannelMessageHandlerHolder impl_holder = new LDKChannelMessageHandlerHolder();
118                 impl_holder.held = new ChannelMessageHandler(new bindings.LDKChannelMessageHandler() {
119                         @Override public void handle_open_channel(byte[] their_node_id, long their_features, long msg) {
120                                 InitFeatures their_features_hu_conv = null; if (their_features < 0 || their_features > 4096) { their_features_hu_conv = new InitFeatures(null, their_features); }
121                                 their_features_hu_conv.ptrs_to.add(this);
122                                 OpenChannel msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new OpenChannel(null, msg); }
123                                 arg.handle_open_channel(their_node_id, their_features_hu_conv, msg_hu_conv);
124                         }
125                         @Override public void handle_accept_channel(byte[] their_node_id, long their_features, long msg) {
126                                 InitFeatures their_features_hu_conv = null; if (their_features < 0 || their_features > 4096) { their_features_hu_conv = new InitFeatures(null, their_features); }
127                                 their_features_hu_conv.ptrs_to.add(this);
128                                 AcceptChannel msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new AcceptChannel(null, msg); }
129                                 arg.handle_accept_channel(their_node_id, their_features_hu_conv, msg_hu_conv);
130                         }
131                         @Override public void handle_funding_created(byte[] their_node_id, long msg) {
132                                 FundingCreated msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new FundingCreated(null, msg); }
133                                 arg.handle_funding_created(their_node_id, msg_hu_conv);
134                         }
135                         @Override public void handle_funding_signed(byte[] their_node_id, long msg) {
136                                 FundingSigned msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new FundingSigned(null, msg); }
137                                 arg.handle_funding_signed(their_node_id, msg_hu_conv);
138                         }
139                         @Override public void handle_funding_locked(byte[] their_node_id, long msg) {
140                                 FundingLocked msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new FundingLocked(null, msg); }
141                                 arg.handle_funding_locked(their_node_id, msg_hu_conv);
142                         }
143                         @Override public void handle_shutdown(byte[] their_node_id, long their_features, long msg) {
144                                 InitFeatures their_features_hu_conv = null; if (their_features < 0 || their_features > 4096) { their_features_hu_conv = new InitFeatures(null, their_features); }
145                                 Shutdown msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new Shutdown(null, msg); }
146                                 arg.handle_shutdown(their_node_id, their_features_hu_conv, msg_hu_conv);
147                         }
148                         @Override public void handle_closing_signed(byte[] their_node_id, long msg) {
149                                 ClosingSigned msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new ClosingSigned(null, msg); }
150                                 arg.handle_closing_signed(their_node_id, msg_hu_conv);
151                         }
152                         @Override public void handle_update_add_htlc(byte[] their_node_id, long msg) {
153                                 UpdateAddHTLC msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new UpdateAddHTLC(null, msg); }
154                                 arg.handle_update_add_htlc(their_node_id, msg_hu_conv);
155                         }
156                         @Override public void handle_update_fulfill_htlc(byte[] their_node_id, long msg) {
157                                 UpdateFulfillHTLC msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new UpdateFulfillHTLC(null, msg); }
158                                 arg.handle_update_fulfill_htlc(their_node_id, msg_hu_conv);
159                         }
160                         @Override public void handle_update_fail_htlc(byte[] their_node_id, long msg) {
161                                 UpdateFailHTLC msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new UpdateFailHTLC(null, msg); }
162                                 arg.handle_update_fail_htlc(their_node_id, msg_hu_conv);
163                         }
164                         @Override public void handle_update_fail_malformed_htlc(byte[] their_node_id, long msg) {
165                                 UpdateFailMalformedHTLC msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new UpdateFailMalformedHTLC(null, msg); }
166                                 arg.handle_update_fail_malformed_htlc(their_node_id, msg_hu_conv);
167                         }
168                         @Override public void handle_commitment_signed(byte[] their_node_id, long msg) {
169                                 CommitmentSigned msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new CommitmentSigned(null, msg); }
170                                 arg.handle_commitment_signed(their_node_id, msg_hu_conv);
171                         }
172                         @Override public void handle_revoke_and_ack(byte[] their_node_id, long msg) {
173                                 RevokeAndACK msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new RevokeAndACK(null, msg); }
174                                 arg.handle_revoke_and_ack(their_node_id, msg_hu_conv);
175                         }
176                         @Override public void handle_update_fee(byte[] their_node_id, long msg) {
177                                 UpdateFee msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new UpdateFee(null, msg); }
178                                 arg.handle_update_fee(their_node_id, msg_hu_conv);
179                         }
180                         @Override public void handle_announcement_signatures(byte[] their_node_id, long msg) {
181                                 AnnouncementSignatures msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new AnnouncementSignatures(null, msg); }
182                                 arg.handle_announcement_signatures(their_node_id, msg_hu_conv);
183                         }
184                         @Override public void peer_disconnected(byte[] their_node_id, boolean no_connection_possible) {
185                                 arg.peer_disconnected(their_node_id, no_connection_possible);
186                         }
187                         @Override public void peer_connected(byte[] their_node_id, long msg) {
188                                 Init msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new Init(null, msg); }
189                                 arg.peer_connected(their_node_id, msg_hu_conv);
190                         }
191                         @Override public void handle_channel_reestablish(byte[] their_node_id, long msg) {
192                                 ChannelReestablish msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new ChannelReestablish(null, msg); }
193                                 arg.handle_channel_reestablish(their_node_id, msg_hu_conv);
194                         }
195                         @Override public void handle_channel_update(byte[] their_node_id, long msg) {
196                                 ChannelUpdate msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new ChannelUpdate(null, msg); }
197                                 arg.handle_channel_update(their_node_id, msg_hu_conv);
198                         }
199                         @Override public void handle_error(byte[] their_node_id, long msg) {
200                                 ErrorMessage msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new ErrorMessage(null, msg); }
201                                 arg.handle_error(their_node_id, msg_hu_conv);
202                         }
203                 }, MessageSendEventsProvider.new_impl(MessageSendEventsProvider_impl).bindings_instance);
204                 return impl_holder.held;
205         }
206
207         /**
208          * Gets the underlying MessageSendEventsProvider.
209          */
210         public MessageSendEventsProvider get_message_send_events_provider() {
211                 MessageSendEventsProvider res = new MessageSendEventsProvider(null, bindings.LDKChannelMessageHandler_get_MessageSendEventsProvider(this.ptr));
212                 this.ptrs_to.add(res);
213                 return res;
214         }
215
216         /**
217          * Handle an incoming open_channel message from the given peer.
218          */
219         public void handle_open_channel(byte[] their_node_id, InitFeatures their_features, OpenChannel msg) {
220                 bindings.ChannelMessageHandler_handle_open_channel(this.ptr, their_node_id, their_features == null ? 0 : their_features.ptr & ~1, msg == null ? 0 : msg.ptr & ~1);
221                 this.ptrs_to.add(msg);
222         }
223
224         /**
225          * Handle an incoming accept_channel message from the given peer.
226          */
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(msg);
230         }
231
232         /**
233          * Handle an incoming funding_created message from the given peer.
234          */
235         public void handle_funding_created(byte[] their_node_id, FundingCreated msg) {
236                 bindings.ChannelMessageHandler_handle_funding_created(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
237                 this.ptrs_to.add(msg);
238         }
239
240         /**
241          * Handle an incoming funding_signed message from the given peer.
242          */
243         public void handle_funding_signed(byte[] their_node_id, FundingSigned msg) {
244                 bindings.ChannelMessageHandler_handle_funding_signed(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
245                 this.ptrs_to.add(msg);
246         }
247
248         /**
249          * Handle an incoming funding_locked message from the given peer.
250          */
251         public void handle_funding_locked(byte[] their_node_id, FundingLocked msg) {
252                 bindings.ChannelMessageHandler_handle_funding_locked(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
253                 this.ptrs_to.add(msg);
254         }
255
256         /**
257          * Handle an incoming shutdown message from the given peer.
258          */
259         public void handle_shutdown(byte[] their_node_id, InitFeatures their_features, Shutdown msg) {
260                 bindings.ChannelMessageHandler_handle_shutdown(this.ptr, their_node_id, their_features == null ? 0 : their_features.ptr & ~1, msg == null ? 0 : msg.ptr & ~1);
261                 this.ptrs_to.add(their_features);
262                 this.ptrs_to.add(msg);
263         }
264
265         /**
266          * Handle an incoming closing_signed message from the given peer.
267          */
268         public void handle_closing_signed(byte[] their_node_id, ClosingSigned msg) {
269                 bindings.ChannelMessageHandler_handle_closing_signed(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
270                 this.ptrs_to.add(msg);
271         }
272
273         /**
274          * Handle an incoming update_add_htlc message from the given peer.
275          */
276         public void handle_update_add_htlc(byte[] their_node_id, UpdateAddHTLC msg) {
277                 bindings.ChannelMessageHandler_handle_update_add_htlc(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
278                 this.ptrs_to.add(msg);
279         }
280
281         /**
282          * Handle an incoming update_fulfill_htlc message from the given peer.
283          */
284         public void handle_update_fulfill_htlc(byte[] their_node_id, UpdateFulfillHTLC msg) {
285                 bindings.ChannelMessageHandler_handle_update_fulfill_htlc(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
286                 this.ptrs_to.add(msg);
287         }
288
289         /**
290          * Handle an incoming update_fail_htlc message from the given peer.
291          */
292         public void handle_update_fail_htlc(byte[] their_node_id, UpdateFailHTLC msg) {
293                 bindings.ChannelMessageHandler_handle_update_fail_htlc(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
294                 this.ptrs_to.add(msg);
295         }
296
297         /**
298          * Handle an incoming update_fail_malformed_htlc message from the given peer.
299          */
300         public void handle_update_fail_malformed_htlc(byte[] their_node_id, UpdateFailMalformedHTLC msg) {
301                 bindings.ChannelMessageHandler_handle_update_fail_malformed_htlc(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
302                 this.ptrs_to.add(msg);
303         }
304
305         /**
306          * Handle an incoming commitment_signed message from the given peer.
307          */
308         public void handle_commitment_signed(byte[] their_node_id, CommitmentSigned msg) {
309                 bindings.ChannelMessageHandler_handle_commitment_signed(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
310                 this.ptrs_to.add(msg);
311         }
312
313         /**
314          * Handle an incoming revoke_and_ack message from the given peer.
315          */
316         public void handle_revoke_and_ack(byte[] their_node_id, RevokeAndACK msg) {
317                 bindings.ChannelMessageHandler_handle_revoke_and_ack(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
318                 this.ptrs_to.add(msg);
319         }
320
321         /**
322          * Handle an incoming update_fee message from the given peer.
323          */
324         public void handle_update_fee(byte[] their_node_id, UpdateFee msg) {
325                 bindings.ChannelMessageHandler_handle_update_fee(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
326                 this.ptrs_to.add(msg);
327         }
328
329         /**
330          * Handle an incoming announcement_signatures message from the given peer.
331          */
332         public void handle_announcement_signatures(byte[] their_node_id, AnnouncementSignatures msg) {
333                 bindings.ChannelMessageHandler_handle_announcement_signatures(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
334                 this.ptrs_to.add(msg);
335         }
336
337         /**
338          * Indicates a connection to the peer failed/an existing connection was lost. If no connection
339          * is believed to be possible in the future (eg they're sending us messages we don't
340          * understand or indicate they require unknown feature bits), no_connection_possible is set
341          * and any outstanding channels should be failed.
342          */
343         public void peer_disconnected(byte[] their_node_id, boolean no_connection_possible) {
344                 bindings.ChannelMessageHandler_peer_disconnected(this.ptr, their_node_id, no_connection_possible);
345         }
346
347         /**
348          * Handle a peer reconnecting, possibly generating channel_reestablish message(s).
349          */
350         public void peer_connected(byte[] their_node_id, Init msg) {
351                 bindings.ChannelMessageHandler_peer_connected(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
352                 this.ptrs_to.add(msg);
353         }
354
355         /**
356          * Handle an incoming channel_reestablish message from the given peer.
357          */
358         public void handle_channel_reestablish(byte[] their_node_id, ChannelReestablish msg) {
359                 bindings.ChannelMessageHandler_handle_channel_reestablish(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
360                 this.ptrs_to.add(msg);
361         }
362
363         /**
364          * Handle an incoming channel update from the given peer.
365          */
366         public void handle_channel_update(byte[] their_node_id, ChannelUpdate msg) {
367                 bindings.ChannelMessageHandler_handle_channel_update(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
368                 this.ptrs_to.add(msg);
369         }
370
371         /**
372          * Handle an incoming error message from the given peer.
373          */
374         public void handle_error(byte[] their_node_id, ErrorMessage msg) {
375                 bindings.ChannelMessageHandler_handle_error(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
376                 this.ptrs_to.add(msg);
377         }
378
379 }