Update java bindings with new generator and new upstream code
[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 error message from the given peer.
107                  */
108                 void handle_error(byte[] their_node_id, ErrorMessage msg);
109         }
110         private static class LDKChannelMessageHandlerHolder { ChannelMessageHandler held; }
111         public static ChannelMessageHandler new_impl(ChannelMessageHandlerInterface arg, MessageSendEventsProvider.MessageSendEventsProviderInterface MessageSendEventsProvider_impl) {
112                 final LDKChannelMessageHandlerHolder impl_holder = new LDKChannelMessageHandlerHolder();
113                 impl_holder.held = new ChannelMessageHandler(new bindings.LDKChannelMessageHandler() {
114                         @Override public void handle_open_channel(byte[] their_node_id, long their_features, long msg) {
115                                 InitFeatures their_features_hu_conv = new InitFeatures(null, their_features);
116                                 their_features_hu_conv.ptrs_to.add(this);
117                                 OpenChannel msg_hu_conv = new OpenChannel(null, msg);
118                                 arg.handle_open_channel(their_node_id, their_features_hu_conv, msg_hu_conv);
119                         }
120                         @Override public void handle_accept_channel(byte[] their_node_id, long their_features, long msg) {
121                                 InitFeatures their_features_hu_conv = new InitFeatures(null, their_features);
122                                 their_features_hu_conv.ptrs_to.add(this);
123                                 AcceptChannel msg_hu_conv = new AcceptChannel(null, msg);
124                                 arg.handle_accept_channel(their_node_id, their_features_hu_conv, msg_hu_conv);
125                         }
126                         @Override public void handle_funding_created(byte[] their_node_id, long msg) {
127                                 FundingCreated msg_hu_conv = new FundingCreated(null, msg);
128                                 arg.handle_funding_created(their_node_id, msg_hu_conv);
129                         }
130                         @Override public void handle_funding_signed(byte[] their_node_id, long msg) {
131                                 FundingSigned msg_hu_conv = new FundingSigned(null, msg);
132                                 arg.handle_funding_signed(their_node_id, msg_hu_conv);
133                         }
134                         @Override public void handle_funding_locked(byte[] their_node_id, long msg) {
135                                 FundingLocked msg_hu_conv = new FundingLocked(null, msg);
136                                 arg.handle_funding_locked(their_node_id, msg_hu_conv);
137                         }
138                         @Override public void handle_shutdown(byte[] their_node_id, long their_features, long msg) {
139                                 InitFeatures their_features_hu_conv = new InitFeatures(null, their_features);
140                                 Shutdown msg_hu_conv = new Shutdown(null, msg);
141                                 arg.handle_shutdown(their_node_id, their_features_hu_conv, msg_hu_conv);
142                         }
143                         @Override public void handle_closing_signed(byte[] their_node_id, long msg) {
144                                 ClosingSigned msg_hu_conv = new ClosingSigned(null, msg);
145                                 arg.handle_closing_signed(their_node_id, msg_hu_conv);
146                         }
147                         @Override public void handle_update_add_htlc(byte[] their_node_id, long msg) {
148                                 UpdateAddHTLC msg_hu_conv = new UpdateAddHTLC(null, msg);
149                                 arg.handle_update_add_htlc(their_node_id, msg_hu_conv);
150                         }
151                         @Override public void handle_update_fulfill_htlc(byte[] their_node_id, long msg) {
152                                 UpdateFulfillHTLC msg_hu_conv = new UpdateFulfillHTLC(null, msg);
153                                 arg.handle_update_fulfill_htlc(their_node_id, msg_hu_conv);
154                         }
155                         @Override public void handle_update_fail_htlc(byte[] their_node_id, long msg) {
156                                 UpdateFailHTLC msg_hu_conv = new UpdateFailHTLC(null, msg);
157                                 arg.handle_update_fail_htlc(their_node_id, msg_hu_conv);
158                         }
159                         @Override public void handle_update_fail_malformed_htlc(byte[] their_node_id, long msg) {
160                                 UpdateFailMalformedHTLC msg_hu_conv = new UpdateFailMalformedHTLC(null, msg);
161                                 arg.handle_update_fail_malformed_htlc(their_node_id, msg_hu_conv);
162                         }
163                         @Override public void handle_commitment_signed(byte[] their_node_id, long msg) {
164                                 CommitmentSigned msg_hu_conv = new CommitmentSigned(null, msg);
165                                 arg.handle_commitment_signed(their_node_id, msg_hu_conv);
166                         }
167                         @Override public void handle_revoke_and_ack(byte[] their_node_id, long msg) {
168                                 RevokeAndACK msg_hu_conv = new RevokeAndACK(null, msg);
169                                 arg.handle_revoke_and_ack(their_node_id, msg_hu_conv);
170                         }
171                         @Override public void handle_update_fee(byte[] their_node_id, long msg) {
172                                 UpdateFee msg_hu_conv = new UpdateFee(null, msg);
173                                 arg.handle_update_fee(their_node_id, msg_hu_conv);
174                         }
175                         @Override public void handle_announcement_signatures(byte[] their_node_id, long msg) {
176                                 AnnouncementSignatures msg_hu_conv = new AnnouncementSignatures(null, msg);
177                                 arg.handle_announcement_signatures(their_node_id, msg_hu_conv);
178                         }
179                         @Override public void peer_disconnected(byte[] their_node_id, boolean no_connection_possible) {
180                                 arg.peer_disconnected(their_node_id, no_connection_possible);
181                         }
182                         @Override public void peer_connected(byte[] their_node_id, long msg) {
183                                 Init msg_hu_conv = new Init(null, msg);
184                                 arg.peer_connected(their_node_id, msg_hu_conv);
185                         }
186                         @Override public void handle_channel_reestablish(byte[] their_node_id, long msg) {
187                                 ChannelReestablish msg_hu_conv = new ChannelReestablish(null, msg);
188                                 arg.handle_channel_reestablish(their_node_id, msg_hu_conv);
189                         }
190                         @Override public void handle_error(byte[] their_node_id, long msg) {
191                                 ErrorMessage msg_hu_conv = new ErrorMessage(null, msg);
192                                 arg.handle_error(their_node_id, msg_hu_conv);
193                         }
194                 }, MessageSendEventsProvider.new_impl(MessageSendEventsProvider_impl).bindings_instance);
195                 return impl_holder.held;
196         }
197         /**
198          * Handle an incoming open_channel message from the given peer.
199          */
200         public void handle_open_channel(byte[] their_node_id, InitFeatures their_features, OpenChannel msg) {
201                 bindings.ChannelMessageHandler_handle_open_channel(this.ptr, their_node_id, their_features == null ? 0 : their_features.ptr & ~1, msg == null ? 0 : msg.ptr & ~1);
202                 this.ptrs_to.add(their_features);
203                 this.ptrs_to.add(msg);
204         }
205
206         /**
207          * Handle an incoming accept_channel message from the given peer.
208          */
209         public void handle_accept_channel(byte[] their_node_id, InitFeatures their_features, AcceptChannel msg) {
210                 bindings.ChannelMessageHandler_handle_accept_channel(this.ptr, their_node_id, their_features == null ? 0 : their_features.ptr & ~1, msg == null ? 0 : msg.ptr & ~1);
211                 this.ptrs_to.add(their_features);
212                 this.ptrs_to.add(msg);
213         }
214
215         /**
216          * Handle an incoming funding_created message from the given peer.
217          */
218         public void handle_funding_created(byte[] their_node_id, FundingCreated msg) {
219                 bindings.ChannelMessageHandler_handle_funding_created(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
220                 this.ptrs_to.add(msg);
221         }
222
223         /**
224          * Handle an incoming funding_signed message from the given peer.
225          */
226         public void handle_funding_signed(byte[] their_node_id, FundingSigned msg) {
227                 bindings.ChannelMessageHandler_handle_funding_signed(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_locked message from the given peer.
233          */
234         public void handle_funding_locked(byte[] their_node_id, FundingLocked msg) {
235                 bindings.ChannelMessageHandler_handle_funding_locked(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
236                 this.ptrs_to.add(msg);
237         }
238
239         /**
240          * Handle an incoming shutdown message from the given peer.
241          */
242         public void handle_shutdown(byte[] their_node_id, InitFeatures their_features, Shutdown msg) {
243                 bindings.ChannelMessageHandler_handle_shutdown(this.ptr, their_node_id, their_features == null ? 0 : their_features.ptr & ~1, msg == null ? 0 : msg.ptr & ~1);
244                 this.ptrs_to.add(their_features);
245                 this.ptrs_to.add(msg);
246         }
247
248         /**
249          * Handle an incoming closing_signed message from the given peer.
250          */
251         public void handle_closing_signed(byte[] their_node_id, ClosingSigned msg) {
252                 bindings.ChannelMessageHandler_handle_closing_signed(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
253                 this.ptrs_to.add(msg);
254         }
255
256         /**
257          * Handle an incoming update_add_htlc message from the given peer.
258          */
259         public void handle_update_add_htlc(byte[] their_node_id, UpdateAddHTLC msg) {
260                 bindings.ChannelMessageHandler_handle_update_add_htlc(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_fulfill_htlc message from the given peer.
266          */
267         public void handle_update_fulfill_htlc(byte[] their_node_id, UpdateFulfillHTLC msg) {
268                 bindings.ChannelMessageHandler_handle_update_fulfill_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_fail_htlc message from the given peer.
274          */
275         public void handle_update_fail_htlc(byte[] their_node_id, UpdateFailHTLC msg) {
276                 bindings.ChannelMessageHandler_handle_update_fail_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_malformed_htlc message from the given peer.
282          */
283         public void handle_update_fail_malformed_htlc(byte[] their_node_id, UpdateFailMalformedHTLC msg) {
284                 bindings.ChannelMessageHandler_handle_update_fail_malformed_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 commitment_signed message from the given peer.
290          */
291         public void handle_commitment_signed(byte[] their_node_id, CommitmentSigned msg) {
292                 bindings.ChannelMessageHandler_handle_commitment_signed(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
293                 this.ptrs_to.add(msg);
294         }
295
296         /**
297          * Handle an incoming revoke_and_ack message from the given peer.
298          */
299         public void handle_revoke_and_ack(byte[] their_node_id, RevokeAndACK msg) {
300                 bindings.ChannelMessageHandler_handle_revoke_and_ack(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
301                 this.ptrs_to.add(msg);
302         }
303
304         /**
305          * Handle an incoming update_fee message from the given peer.
306          */
307         public void handle_update_fee(byte[] their_node_id, UpdateFee msg) {
308                 bindings.ChannelMessageHandler_handle_update_fee(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
309                 this.ptrs_to.add(msg);
310         }
311
312         /**
313          * Handle an incoming announcement_signatures message from the given peer.
314          */
315         public void handle_announcement_signatures(byte[] their_node_id, AnnouncementSignatures msg) {
316                 bindings.ChannelMessageHandler_handle_announcement_signatures(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
317                 this.ptrs_to.add(msg);
318         }
319
320         /**
321          * Indicates a connection to the peer failed/an existing connection was lost. If no connection
322          * is believed to be possible in the future (eg they're sending us messages we don't
323          * understand or indicate they require unknown feature bits), no_connection_possible is set
324          * and any outstanding channels should be failed.
325          */
326         public void peer_disconnected(byte[] their_node_id, boolean no_connection_possible) {
327                 bindings.ChannelMessageHandler_peer_disconnected(this.ptr, their_node_id, no_connection_possible);
328         }
329
330         /**
331          * Handle a peer reconnecting, possibly generating channel_reestablish message(s).
332          */
333         public void peer_connected(byte[] their_node_id, Init msg) {
334                 bindings.ChannelMessageHandler_peer_connected(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
335                 this.ptrs_to.add(msg);
336         }
337
338         /**
339          * Handle an incoming channel_reestablish message from the given peer.
340          */
341         public void handle_channel_reestablish(byte[] their_node_id, ChannelReestablish msg) {
342                 bindings.ChannelMessageHandler_handle_channel_reestablish(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
343                 this.ptrs_to.add(msg);
344         }
345
346         /**
347          * Handle an incoming error message from the given peer.
348          */
349         public void handle_error(byte[] their_node_id, ErrorMessage msg) {
350                 bindings.ChannelMessageHandler_handle_error(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
351                 this.ptrs_to.add(msg);
352         }
353
354 }