Update auto-generated bindings
[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
8 /**
9  * A trait to describe an object which can receive channel messages.
10  * 
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.
13  */
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;
23         }
24         @Override @SuppressWarnings("deprecation")
25         protected void finalize() throws Throwable {
26                 if (ptr != 0) { bindings.ChannelMessageHandler_free(ptr); } super.finalize();
27         }
28
29         public static interface ChannelMessageHandlerInterface {
30                 /**
31                  * Handle an incoming open_channel message from the given peer.
32                  */
33                 void handle_open_channel(byte[] their_node_id, InitFeatures their_features, OpenChannel msg);
34                 /**
35                  * Handle an incoming accept_channel message from the given peer.
36                  */
37                 void handle_accept_channel(byte[] their_node_id, InitFeatures their_features, AcceptChannel msg);
38                 /**
39                  * Handle an incoming funding_created message from the given peer.
40                  */
41                 void handle_funding_created(byte[] their_node_id, FundingCreated msg);
42                 /**
43                  * Handle an incoming funding_signed message from the given peer.
44                  */
45                 void handle_funding_signed(byte[] their_node_id, FundingSigned msg);
46                 /**
47                  * Handle an incoming funding_locked message from the given peer.
48                  */
49                 void handle_funding_locked(byte[] their_node_id, FundingLocked msg);
50                 /**
51                  * Handle an incoming shutdown message from the given peer.
52                  */
53                 void handle_shutdown(byte[] their_node_id, InitFeatures their_features, Shutdown msg);
54                 /**
55                  * Handle an incoming closing_signed message from the given peer.
56                  */
57                 void handle_closing_signed(byte[] their_node_id, ClosingSigned msg);
58                 /**
59                  * Handle an incoming update_add_htlc message from the given peer.
60                  */
61                 void handle_update_add_htlc(byte[] their_node_id, UpdateAddHTLC msg);
62                 /**
63                  * Handle an incoming update_fulfill_htlc message from the given peer.
64                  */
65                 void handle_update_fulfill_htlc(byte[] their_node_id, UpdateFulfillHTLC msg);
66                 /**
67                  * Handle an incoming update_fail_htlc message from the given peer.
68                  */
69                 void handle_update_fail_htlc(byte[] their_node_id, UpdateFailHTLC msg);
70                 /**
71                  * Handle an incoming update_fail_malformed_htlc message from the given peer.
72                  */
73                 void handle_update_fail_malformed_htlc(byte[] their_node_id, UpdateFailMalformedHTLC msg);
74                 /**
75                  * Handle an incoming commitment_signed message from the given peer.
76                  */
77                 void handle_commitment_signed(byte[] their_node_id, CommitmentSigned msg);
78                 /**
79                  * Handle an incoming revoke_and_ack message from the given peer.
80                  */
81                 void handle_revoke_and_ack(byte[] their_node_id, RevokeAndACK msg);
82                 /**
83                  * Handle an incoming update_fee message from the given peer.
84                  */
85                 void handle_update_fee(byte[] their_node_id, UpdateFee msg);
86                 /**
87                  * Handle an incoming announcement_signatures message from the given peer.
88                  */
89                 void handle_announcement_signatures(byte[] their_node_id, AnnouncementSignatures msg);
90                 /**
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.
95                  */
96                 void peer_disconnected(byte[] their_node_id, boolean no_connection_possible);
97                 /**
98                  * Handle a peer reconnecting, possibly generating channel_reestablish message(s).
99                  */
100                 void peer_connected(byte[] their_node_id, Init msg);
101                 /**
102                  * Handle an incoming channel_reestablish message from the given peer.
103                  */
104                 void handle_channel_reestablish(byte[] their_node_id, ChannelReestablish msg);
105                 /**
106                  * Handle an incoming channel update from the given peer.
107                  */
108                 void handle_channel_update(byte[] their_node_id, ChannelUpdate msg);
109                 /**
110                  * Handle an incoming error message from the given peer.
111                  */
112                 void handle_error(byte[] their_node_id, ErrorMessage msg);
113         }
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);
123                         }
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);
129                         }
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);
133                         }
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);
137                         }
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);
141                         }
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);
146                         }
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);
150                         }
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);
154                         }
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);
158                         }
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);
162                         }
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);
166                         }
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);
170                         }
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);
174                         }
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);
178                         }
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);
182                         }
183                         @Override public void peer_disconnected(byte[] their_node_id, boolean no_connection_possible) {
184                                 arg.peer_disconnected(their_node_id, no_connection_possible);
185                         }
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);
189                         }
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);
193                         }
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);
197                         }
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);
201                         }
202                 }, MessageSendEventsProvider.new_impl(MessageSendEventsProvider_impl).bindings_instance);
203                 return impl_holder.held;
204         }
205         /**
206          * Handle an incoming open_channel message from the given peer.
207          */
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);
212         }
213
214         /**
215          * Handle an incoming accept_channel message from the given peer.
216          */
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);
221         }
222
223         /**
224          * Handle an incoming funding_created message from the given peer.
225          */
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);
229         }
230
231         /**
232          * Handle an incoming funding_signed message from the given peer.
233          */
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);
237         }
238
239         /**
240          * Handle an incoming funding_locked message from the given peer.
241          */
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);
245         }
246
247         /**
248          * Handle an incoming shutdown message from the given peer.
249          */
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);
254         }
255
256         /**
257          * Handle an incoming closing_signed message from the given peer.
258          */
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);
262         }
263
264         /**
265          * Handle an incoming update_add_htlc message from the given peer.
266          */
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);
270         }
271
272         /**
273          * Handle an incoming update_fulfill_htlc message from the given peer.
274          */
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);
278         }
279
280         /**
281          * Handle an incoming update_fail_htlc message from the given peer.
282          */
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);
286         }
287
288         /**
289          * Handle an incoming update_fail_malformed_htlc message from the given peer.
290          */
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);
294         }
295
296         /**
297          * Handle an incoming commitment_signed message from the given peer.
298          */
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);
302         }
303
304         /**
305          * Handle an incoming revoke_and_ack message from the given peer.
306          */
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);
310         }
311
312         /**
313          * Handle an incoming update_fee message from the given peer.
314          */
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);
318         }
319
320         /**
321          * Handle an incoming announcement_signatures message from the given peer.
322          */
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);
326         }
327
328         /**
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.
333          */
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);
336         }
337
338         /**
339          * Handle a peer reconnecting, possibly generating channel_reestablish message(s).
340          */
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);
344         }
345
346         /**
347          * Handle an incoming channel_reestablish message from the given peer.
348          */
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);
352         }
353
354         /**
355          * Handle an incoming channel update from the given peer.
356          */
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);
360         }
361
362         /**
363          * Handle an incoming error message from the given peer.
364          */
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);
368         }
369
370 }