Merge pull request #7 from TheBlueMatt/2021-03-tweaks
authorArik Sosman <arik-so@users.noreply.github.com>
Fri, 12 Mar 2021 18:59:50 +0000 (10:59 -0800)
committerGitHub <noreply@github.com>
Fri, 12 Mar 2021 18:59:50 +0000 (10:59 -0800)
Slight tweaks

genbindings.sh
src/main/java/org/ldk/batteries/ChannelManagerConstructor.java
src/main/java/org/ldk/batteries/NioPeerHandler.java
src/test/java/org/ldk/HumanObjectPeerTest.java

index 01ef62fed42893f576720ad375c5df29c764be22..2006499e83b2029680a2d7c0f9a27e797801a37c 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/bash
 usage() {
-       echo "USAGE: path/to/rust-lightning \"JNI_CFLAGS\" debug android"
+       echo "USAGE: path/to/ldk-c-bindings \"JNI_CFLAGS\" debug android"
        echo "For JNI_CFLAGS you probably want -I/usr/lib/jvm/java-11-openjdk-amd64/include/ -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux/"
        echo "debug should either be true or false"
        echo "android should either be true or false"
index 4310af1cdc314f7c038def6befabca92d5b5a5a5..0d2055b21a860c478ee4fee2f93a150aeb0bb6b7 100644 (file)
@@ -40,6 +40,8 @@ public class ChannelManagerConstructor {
      * Deserializes a channel manager and a set of channel monitors from the given serialized copies and interface implementations
      *
      * @param filter If provided, the outputs which were previously registered to be monitored for will be loaded into the filter.
+     *               Note that if the provided Watch is a ChainWatch and has an associated filter, the previously registered
+     *               outputs will be loaded when chain_sync_completed is called.
      */
     public ChannelManagerConstructor(byte[] channel_manager_serialized, byte[][] channel_monitors_serialized,
                                      KeysInterface keys_interface, FeeEstimator fee_estimator, Watch chain_watch, @Nullable Filter filter,
index 14c5611d5daa0e6dc74c9af0cd0f1144c6fcdfea..a77f1f0f49bb8cb4152d284b09f05c6b0f068116 100644 (file)
@@ -189,10 +189,20 @@ public class NioPeerHandler {
      * @param their_node_id A valid 33-byte public key representing the peer's Lightning Node ID. If this is invalid,
      *                      undefined behavior (read: Segfault, etc) may occur.
      * @param remote The socket address to connect to.
+     * @param timeout_ms The amount of time, in milliseconds, up to which we will wait for connection to complete.
      * @throws IOException If connecting to the remote endpoint fails or internal java.nio errors occur.
      */
-    public void connect(byte[] their_node_id, SocketAddress remote) throws IOException {
-        SocketChannel chan = SocketChannel.open(remote);
+    public void connect(byte[] their_node_id, SocketAddress remote, int timeout_ms) throws IOException {
+        SocketChannel chan = SocketChannel.open();
+        chan.configureBlocking(false);
+        Selector open_selector = Selector.open();
+        chan.register(open_selector, SelectionKey.OP_CONNECT);
+        if (!chan.connect(remote)) {
+            open_selector.select(timeout_ms);
+        }
+        if (!chan.finishConnect()) { // Note that this may throw its own IOException if we failed for another reason
+            throw new IOException("Timed out");
+        }
         Peer peer = setup_socket(chan);
         Result_CVec_u8ZPeerHandleErrorZ res = this.peer_manager.new_outbound_connection(their_node_id, peer.descriptor);
         if (res instanceof  Result_CVec_u8ZPeerHandleErrorZ.Result_CVec_u8ZPeerHandleErrorZ_OK) {
index 2cc67a0013afe9b16e9f08377d6b77c458a8242f..a8d439ec69c6d210901df599a686e5c635a80e40 100644 (file)
@@ -463,7 +463,7 @@ class HumanObjectPeerTestInstance {
     void connect_peers(final Peer peer1, final Peer peer2) {
         if (use_nio_peer_handler) {
             try {
-                peer1.nio_peer_handler.connect(peer2.chan_manager.get_our_node_id(), new InetSocketAddress("127.0.0.1", peer2.nio_port));
+                peer1.nio_peer_handler.connect(peer2.chan_manager.get_our_node_id(), new InetSocketAddress("127.0.0.1", peer2.nio_port), 100);
             } catch (IOException e) { assert false; }
         } else {
             DescriptorHolder descriptor1 = new DescriptorHolder();