[Java] Update auto-generated Java bindings to LDK 0.0.121
[ldk-java] / src / main / java / org / ldk / structs / OnionMessageHandler.java
index 418f2a6730534ffe0abe760b3b44606a912df52c..4b8abe04b148c4205a6c95caf2680ecbc7a8da4e 100644 (file)
@@ -8,38 +8,74 @@ import java.lang.ref.Reference;
 import javax.annotation.Nullable;
 
 /**
- * A trait to describe an object that can receive onion messages.
+ * A handler for received [`OnionMessage`]s and for providing generated ones to send.
  */
 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
 public class OnionMessageHandler extends CommonBase {
        final bindings.LDKOnionMessageHandler bindings_instance;
        OnionMessageHandler(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
-       private OnionMessageHandler(bindings.LDKOnionMessageHandler arg, bindings.LDKOnionMessageProvider OnionMessageProvider) {
-               super(bindings.LDKOnionMessageHandler_new(arg, OnionMessageProvider));
+       private OnionMessageHandler(bindings.LDKOnionMessageHandler arg) {
+               super(bindings.LDKOnionMessageHandler_new(arg));
                this.ptrs_to.add(arg);
-               this.ptrs_to.add(OnionMessageProvider);
                this.bindings_instance = arg;
        }
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                if (ptr != 0) { bindings.OnionMessageHandler_free(ptr); } super.finalize();
        }
-
+       /**
+        * Destroys the object, freeing associated resources. After this call, any access
+        * to this object may result in a SEGFAULT or worse.
+        *
+        * You should generally NEVER call this method. You should let the garbage collector
+        * do this for you when it finalizes objects. However, it may be useful for types
+        * which represent locks and should be closed immediately to avoid holding locks
+        * until the GC runs.
+        */
+       public void destroy() {
+               if (ptr != 0) { bindings.OnionMessageHandler_free(ptr); }
+               ptr = 0;
+       }
        public static interface OnionMessageHandlerInterface {
                /**
-                * Handle an incoming onion_message message from the given peer.
+                * Because much of the lightning network does not yet support forwarding onion messages, we
+                * may need to directly connect to a node which will forward a message for us. In such a case,
+                * this method will return the set of nodes which need connection by node_id and the
+                * corresponding socket addresses where they may accept incoming connections.
+                * 
+                * Thus, this method should be polled regularly to detect messages await such a direct
+                * connection.
+                */
+               TwoTuple_PublicKeyCVec_SocketAddressZZ[] get_and_clear_connections_needed();
+               /**
+                * Handle an incoming `onion_message` message from the given peer.
                 */
                void handle_onion_message(byte[] peer_node_id, OnionMessage msg);
+               /**
+                * Returns the next pending onion message for the peer with the given node id.
+                * 
+                * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
+                */
+               OnionMessage next_onion_message_for_peer(byte[] peer_node_id);
                /**
                 * Called when a connection is established with a peer. Can be used to track which peers
                 * advertise onion message support and are online.
+                * 
+                * May return an `Err(())` if the features the peer supports are not sufficient to communicate
+                * with us. Implementors should be somewhat conservative about doing so, however, as other
+                * message handlers may still wish to communicate with this peer.
                 */
-               void peer_connected(byte[] their_node_id, Init init);
+               Result_NoneNoneZ peer_connected(byte[] their_node_id, Init init, boolean inbound);
                /**
                 * Indicates a connection to the peer failed/an existing connection was lost. Allows handlers to
                 * drop and refuse to forward onion messages to this peer.
                 */
-               void peer_disconnected(byte[] their_node_id, boolean no_connection_possible);
+               void peer_disconnected(byte[] their_node_id);
+               /**
+                * Performs actions that should happen roughly every ten seconds after startup. Allows handlers
+                * to drop any buffered onion messages intended for prospective peers.
+                */
+               void timer_tick_occurred();
                /**
                 * Gets the node feature flags which this handler itself supports. All available handlers are
                 * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
@@ -56,21 +92,39 @@ public class OnionMessageHandler extends CommonBase {
                InitFeatures provided_init_features(byte[] their_node_id);
        }
        private static class LDKOnionMessageHandlerHolder { OnionMessageHandler held; }
-       public static OnionMessageHandler new_impl(OnionMessageHandlerInterface arg, OnionMessageProvider.OnionMessageProviderInterface OnionMessageProvider_impl) {
+       public static OnionMessageHandler new_impl(OnionMessageHandlerInterface arg) {
                final LDKOnionMessageHandlerHolder impl_holder = new LDKOnionMessageHandlerHolder();
                impl_holder.held = new OnionMessageHandler(new bindings.LDKOnionMessageHandler() {
+                       @Override public long[] get_and_clear_connections_needed() {
+                               TwoTuple_PublicKeyCVec_SocketAddressZZ[] ret = arg.get_and_clear_connections_needed();
+                               Reference.reachabilityFence(arg);
+                               long[] result = ret != null ? Arrays.stream(ret).mapToLong(ret_conv_40 -> ret_conv_40 == null ? 0 : ret_conv_40.clone_ptr()).toArray() : null;
+                               return result;
+                       }
                        @Override public void handle_onion_message(byte[] peer_node_id, long msg) {
                                org.ldk.structs.OnionMessage msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.OnionMessage(null, msg); }
                                arg.handle_onion_message(peer_node_id, msg_hu_conv);
                                Reference.reachabilityFence(arg);
                        }
-                       @Override public void peer_connected(byte[] their_node_id, long init) {
+                       @Override public long next_onion_message_for_peer(byte[] peer_node_id) {
+                               OnionMessage ret = arg.next_onion_message_for_peer(peer_node_id);
+                               Reference.reachabilityFence(arg);
+                               long result = ret == null ? 0 : ret.clone_ptr();
+                               return result;
+                       }
+                       @Override public long peer_connected(byte[] their_node_id, long init, boolean inbound) {
                                org.ldk.structs.Init init_hu_conv = null; if (init < 0 || init > 4096) { init_hu_conv = new org.ldk.structs.Init(null, init); }
-                               arg.peer_connected(their_node_id, init_hu_conv);
+                               Result_NoneNoneZ ret = arg.peer_connected(their_node_id, init_hu_conv, inbound);
                                Reference.reachabilityFence(arg);
+                               long result = ret == null ? 0 : ret.clone_ptr();
+                               return result;
                        }
-                       @Override public void peer_disconnected(byte[] their_node_id, boolean no_connection_possible) {
-                               arg.peer_disconnected(their_node_id, no_connection_possible);
+                       @Override public void peer_disconnected(byte[] their_node_id) {
+                               arg.peer_disconnected(their_node_id);
+                               Reference.reachabilityFence(arg);
+                       }
+                       @Override public void timer_tick_occurred() {
+                               arg.timer_tick_occurred();
                                Reference.reachabilityFence(arg);
                        }
                        @Override public long provided_node_features() {
@@ -85,23 +139,36 @@ public class OnionMessageHandler extends CommonBase {
                                long result = ret == null ? 0 : ret.clone_ptr();
                                return result;
                        }
-               }, OnionMessageProvider.new_impl(OnionMessageProvider_impl).bindings_instance);
+               });
                return impl_holder.held;
        }
-
        /**
-        * Gets the underlying OnionMessageProvider.
+        * Because much of the lightning network does not yet support forwarding onion messages, we
+        * may need to directly connect to a node which will forward a message for us. In such a case,
+        * this method will return the set of nodes which need connection by node_id and the
+        * corresponding socket addresses where they may accept incoming connections.
+        * 
+        * Thus, this method should be polled regularly to detect messages await such a direct
+        * connection.
         */
-       public OnionMessageProvider get_onion_message_provider() {
-               OnionMessageProvider res = new OnionMessageProvider(null, bindings.LDKOnionMessageHandler_get_OnionMessageProvider(this.ptr));
-               this.ptrs_to.add(res);
-               return res;
+       public TwoTuple_PublicKeyCVec_SocketAddressZZ[] get_and_clear_connections_needed() {
+               long[] ret = bindings.OnionMessageHandler_get_and_clear_connections_needed(this.ptr);
+               Reference.reachabilityFence(this);
+               int ret_conv_40_len = ret.length;
+               TwoTuple_PublicKeyCVec_SocketAddressZZ[] ret_conv_40_arr = new TwoTuple_PublicKeyCVec_SocketAddressZZ[ret_conv_40_len];
+               for (int o = 0; o < ret_conv_40_len; o++) {
+                       long ret_conv_40 = ret[o];
+                       TwoTuple_PublicKeyCVec_SocketAddressZZ ret_conv_40_hu_conv = new TwoTuple_PublicKeyCVec_SocketAddressZZ(null, ret_conv_40);
+                       if (ret_conv_40_hu_conv != null) { ret_conv_40_hu_conv.ptrs_to.add(this); };
+                       ret_conv_40_arr[o] = ret_conv_40_hu_conv;
+               }
+               return ret_conv_40_arr;
        }
 
        /**
-        * Handle an incoming onion_message message from the given peer.
+        * Handle an incoming `onion_message` message from the given peer.
         */
-       public void handle_onion_message(byte[] peer_node_id, OnionMessage msg) {
+       public void handle_onion_message(byte[] peer_node_id, org.ldk.structs.OnionMessage msg) {
                bindings.OnionMessageHandler_handle_onion_message(this.ptr, InternalUtils.check_arr_len(peer_node_id, 33), msg == null ? 0 : msg.ptr);
                Reference.reachabilityFence(this);
                Reference.reachabilityFence(peer_node_id);
@@ -109,27 +176,59 @@ public class OnionMessageHandler extends CommonBase {
                if (this != null) { this.ptrs_to.add(msg); };
        }
 
+       /**
+        * Returns the next pending onion message for the peer with the given node id.
+        * 
+        * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
+        */
+       @Nullable
+       public OnionMessage next_onion_message_for_peer(byte[] peer_node_id) {
+               long ret = bindings.OnionMessageHandler_next_onion_message_for_peer(this.ptr, InternalUtils.check_arr_len(peer_node_id, 33));
+               Reference.reachabilityFence(this);
+               Reference.reachabilityFence(peer_node_id);
+               if (ret >= 0 && ret <= 4096) { return null; }
+               org.ldk.structs.OnionMessage ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OnionMessage(null, ret); }
+               if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
+               return ret_hu_conv;
+       }
+
        /**
         * Called when a connection is established with a peer. Can be used to track which peers
         * advertise onion message support and are online.
+        * 
+        * May return an `Err(())` if the features the peer supports are not sufficient to communicate
+        * with us. Implementors should be somewhat conservative about doing so, however, as other
+        * message handlers may still wish to communicate with this peer.
         */
-       public void peer_connected(byte[] their_node_id, Init init) {
-               bindings.OnionMessageHandler_peer_connected(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), init == null ? 0 : init.ptr);
+       public Result_NoneNoneZ peer_connected(byte[] their_node_id, org.ldk.structs.Init init, boolean inbound) {
+               long ret = bindings.OnionMessageHandler_peer_connected(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), init == null ? 0 : init.ptr, inbound);
                Reference.reachabilityFence(this);
                Reference.reachabilityFence(their_node_id);
                Reference.reachabilityFence(init);
+               Reference.reachabilityFence(inbound);
+               if (ret >= 0 && ret <= 4096) { return null; }
+               Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
                if (this != null) { this.ptrs_to.add(init); };
+               return ret_hu_conv;
        }
 
        /**
         * Indicates a connection to the peer failed/an existing connection was lost. Allows handlers to
         * drop and refuse to forward onion messages to this peer.
         */
-       public void peer_disconnected(byte[] their_node_id, boolean no_connection_possible) {
-               bindings.OnionMessageHandler_peer_disconnected(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), no_connection_possible);
+       public void peer_disconnected(byte[] their_node_id) {
+               bindings.OnionMessageHandler_peer_disconnected(this.ptr, InternalUtils.check_arr_len(their_node_id, 33));
                Reference.reachabilityFence(this);
                Reference.reachabilityFence(their_node_id);
-               Reference.reachabilityFence(no_connection_possible);
+       }
+
+       /**
+        * Performs actions that should happen roughly every ten seconds after startup. Allows handlers
+        * to drop any buffered onion messages intended for prospective peers.
+        */
+       public void timer_tick_occurred() {
+               bindings.OnionMessageHandler_timer_tick_occurred(this.ptr);
+               Reference.reachabilityFence(this);
        }
 
        /**