[Java] Update auto-generated bindings to LDK 0.0.118
[ldk-java] / src / main / java / org / ldk / structs / OnionMessageHandler.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 java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10 /**
11  * A handler for received [`OnionMessage`]s and for providing generated ones to send.
12  */
13 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
14 public class OnionMessageHandler extends CommonBase {
15         final bindings.LDKOnionMessageHandler bindings_instance;
16         OnionMessageHandler(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
17         private OnionMessageHandler(bindings.LDKOnionMessageHandler arg) {
18                 super(bindings.LDKOnionMessageHandler_new(arg));
19                 this.ptrs_to.add(arg);
20                 this.bindings_instance = arg;
21         }
22         @Override @SuppressWarnings("deprecation")
23         protected void finalize() throws Throwable {
24                 if (ptr != 0) { bindings.OnionMessageHandler_free(ptr); } super.finalize();
25         }
26         /**
27          * Destroys the object, freeing associated resources. After this call, any access
28          * to this object may result in a SEGFAULT or worse.
29          *
30          * You should generally NEVER call this method. You should let the garbage collector
31          * do this for you when it finalizes objects. However, it may be useful for types
32          * which represent locks and should be closed immediately to avoid holding locks
33          * until the GC runs.
34          */
35         public void destroy() {
36                 if (ptr != 0) { bindings.OnionMessageHandler_free(ptr); }
37                 ptr = 0;
38         }
39         public static interface OnionMessageHandlerInterface {
40                 /**
41                  * Handle an incoming `onion_message` message from the given peer.
42                  */
43                 void handle_onion_message(byte[] peer_node_id, OnionMessage msg);
44                 /**
45                  * Returns the next pending onion message for the peer with the given node id.
46                  * 
47                  * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
48                  */
49                 OnionMessage next_onion_message_for_peer(byte[] peer_node_id);
50                 /**
51                  * Called when a connection is established with a peer. Can be used to track which peers
52                  * advertise onion message support and are online.
53                  * 
54                  * May return an `Err(())` if the features the peer supports are not sufficient to communicate
55                  * with us. Implementors should be somewhat conservative about doing so, however, as other
56                  * message handlers may still wish to communicate with this peer.
57                  */
58                 Result_NoneNoneZ peer_connected(byte[] their_node_id, Init init, boolean inbound);
59                 /**
60                  * Indicates a connection to the peer failed/an existing connection was lost. Allows handlers to
61                  * drop and refuse to forward onion messages to this peer.
62                  */
63                 void peer_disconnected(byte[] their_node_id);
64                 /**
65                  * Gets the node feature flags which this handler itself supports. All available handlers are
66                  * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
67                  * which are broadcasted in our [`NodeAnnouncement`] message.
68                  */
69                 NodeFeatures provided_node_features();
70                 /**
71                  * Gets the init feature flags which should be sent to the given peer. All available handlers
72                  * are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
73                  * which are sent in our [`Init`] message.
74                  * 
75                  * Note that this method is called before [`Self::peer_connected`].
76                  */
77                 InitFeatures provided_init_features(byte[] their_node_id);
78         }
79         private static class LDKOnionMessageHandlerHolder { OnionMessageHandler held; }
80         public static OnionMessageHandler new_impl(OnionMessageHandlerInterface arg) {
81                 final LDKOnionMessageHandlerHolder impl_holder = new LDKOnionMessageHandlerHolder();
82                 impl_holder.held = new OnionMessageHandler(new bindings.LDKOnionMessageHandler() {
83                         @Override public void handle_onion_message(byte[] peer_node_id, long msg) {
84                                 org.ldk.structs.OnionMessage msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.OnionMessage(null, msg); }
85                                 arg.handle_onion_message(peer_node_id, msg_hu_conv);
86                                 Reference.reachabilityFence(arg);
87                         }
88                         @Override public long next_onion_message_for_peer(byte[] peer_node_id) {
89                                 OnionMessage ret = arg.next_onion_message_for_peer(peer_node_id);
90                                 Reference.reachabilityFence(arg);
91                                 long result = ret == null ? 0 : ret.clone_ptr();
92                                 return result;
93                         }
94                         @Override public long peer_connected(byte[] their_node_id, long init, boolean inbound) {
95                                 org.ldk.structs.Init init_hu_conv = null; if (init < 0 || init > 4096) { init_hu_conv = new org.ldk.structs.Init(null, init); }
96                                 Result_NoneNoneZ ret = arg.peer_connected(their_node_id, init_hu_conv, inbound);
97                                 Reference.reachabilityFence(arg);
98                                 long result = ret == null ? 0 : ret.clone_ptr();
99                                 return result;
100                         }
101                         @Override public void peer_disconnected(byte[] their_node_id) {
102                                 arg.peer_disconnected(their_node_id);
103                                 Reference.reachabilityFence(arg);
104                         }
105                         @Override public long provided_node_features() {
106                                 NodeFeatures ret = arg.provided_node_features();
107                                 Reference.reachabilityFence(arg);
108                                 long result = ret == null ? 0 : ret.clone_ptr();
109                                 return result;
110                         }
111                         @Override public long provided_init_features(byte[] their_node_id) {
112                                 InitFeatures ret = arg.provided_init_features(their_node_id);
113                                 Reference.reachabilityFence(arg);
114                                 long result = ret == null ? 0 : ret.clone_ptr();
115                                 return result;
116                         }
117                 });
118                 return impl_holder.held;
119         }
120         /**
121          * Handle an incoming `onion_message` message from the given peer.
122          */
123         public void handle_onion_message(byte[] peer_node_id, org.ldk.structs.OnionMessage msg) {
124                 bindings.OnionMessageHandler_handle_onion_message(this.ptr, InternalUtils.check_arr_len(peer_node_id, 33), msg == null ? 0 : msg.ptr);
125                 Reference.reachabilityFence(this);
126                 Reference.reachabilityFence(peer_node_id);
127                 Reference.reachabilityFence(msg);
128                 if (this != null) { this.ptrs_to.add(msg); };
129         }
130
131         /**
132          * Returns the next pending onion message for the peer with the given node id.
133          * 
134          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
135          */
136         @Nullable
137         public OnionMessage next_onion_message_for_peer(byte[] peer_node_id) {
138                 long ret = bindings.OnionMessageHandler_next_onion_message_for_peer(this.ptr, InternalUtils.check_arr_len(peer_node_id, 33));
139                 Reference.reachabilityFence(this);
140                 Reference.reachabilityFence(peer_node_id);
141                 if (ret >= 0 && ret <= 4096) { return null; }
142                 org.ldk.structs.OnionMessage ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OnionMessage(null, ret); }
143                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
144                 return ret_hu_conv;
145         }
146
147         /**
148          * Called when a connection is established with a peer. Can be used to track which peers
149          * advertise onion message support and are online.
150          * 
151          * May return an `Err(())` if the features the peer supports are not sufficient to communicate
152          * with us. Implementors should be somewhat conservative about doing so, however, as other
153          * message handlers may still wish to communicate with this peer.
154          */
155         public Result_NoneNoneZ peer_connected(byte[] their_node_id, org.ldk.structs.Init init, boolean inbound) {
156                 long ret = bindings.OnionMessageHandler_peer_connected(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), init == null ? 0 : init.ptr, inbound);
157                 Reference.reachabilityFence(this);
158                 Reference.reachabilityFence(their_node_id);
159                 Reference.reachabilityFence(init);
160                 Reference.reachabilityFence(inbound);
161                 if (ret >= 0 && ret <= 4096) { return null; }
162                 Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
163                 if (this != null) { this.ptrs_to.add(init); };
164                 return ret_hu_conv;
165         }
166
167         /**
168          * Indicates a connection to the peer failed/an existing connection was lost. Allows handlers to
169          * drop and refuse to forward onion messages to this peer.
170          */
171         public void peer_disconnected(byte[] their_node_id) {
172                 bindings.OnionMessageHandler_peer_disconnected(this.ptr, InternalUtils.check_arr_len(their_node_id, 33));
173                 Reference.reachabilityFence(this);
174                 Reference.reachabilityFence(their_node_id);
175         }
176
177         /**
178          * Gets the node feature flags which this handler itself supports. All available handlers are
179          * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
180          * which are broadcasted in our [`NodeAnnouncement`] message.
181          */
182         public NodeFeatures provided_node_features() {
183                 long ret = bindings.OnionMessageHandler_provided_node_features(this.ptr);
184                 Reference.reachabilityFence(this);
185                 if (ret >= 0 && ret <= 4096) { return null; }
186                 org.ldk.structs.NodeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeFeatures(null, ret); }
187                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
188                 return ret_hu_conv;
189         }
190
191         /**
192          * Gets the init feature flags which should be sent to the given peer. All available handlers
193          * are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
194          * which are sent in our [`Init`] message.
195          * 
196          * Note that this method is called before [`Self::peer_connected`].
197          */
198         public InitFeatures provided_init_features(byte[] their_node_id) {
199                 long ret = bindings.OnionMessageHandler_provided_init_features(this.ptr, InternalUtils.check_arr_len(their_node_id, 33));
200                 Reference.reachabilityFence(this);
201                 Reference.reachabilityFence(their_node_id);
202                 if (ret >= 0 && ret <= 4096) { return null; }
203                 org.ldk.structs.InitFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InitFeatures(null, ret); }
204                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
205                 return ret_hu_conv;
206         }
207
208 }