Skip to content

Commit 7df17e5

Browse files
authored
Merge pull request #7 from TheBlueMatt/2021-03-tweaks
Slight tweaks
2 parents 1b870a3 + e696c6f commit 7df17e5

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

genbindings.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
usage() {
3-
echo "USAGE: path/to/rust-lightning \"JNI_CFLAGS\" debug android"
3+
echo "USAGE: path/to/ldk-c-bindings \"JNI_CFLAGS\" debug android"
44
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/"
55
echo "debug should either be true or false"
66
echo "android should either be true or false"

src/main/java/org/ldk/batteries/ChannelManagerConstructor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public static class InvalidSerializedDataException extends Exception {}
4040
* Deserializes a channel manager and a set of channel monitors from the given serialized copies and interface implementations
4141
*
4242
* @param filter If provided, the outputs which were previously registered to be monitored for will be loaded into the filter.
43+
* Note that if the provided Watch is a ChainWatch and has an associated filter, the previously registered
44+
* outputs will be loaded when chain_sync_completed is called.
4345
*/
4446
public ChannelManagerConstructor(byte[] channel_manager_serialized, byte[][] channel_monitors_serialized,
4547
KeysInterface keys_interface, FeeEstimator fee_estimator, Watch chain_watch, @Nullable Filter filter,

src/main/java/org/ldk/batteries/NioPeerHandler.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,20 @@ public NioPeerHandler(PeerManager manager) throws IOException {
189189
* @param their_node_id A valid 33-byte public key representing the peer's Lightning Node ID. If this is invalid,
190190
* undefined behavior (read: Segfault, etc) may occur.
191191
* @param remote The socket address to connect to.
192+
* @param timeout_ms The amount of time, in milliseconds, up to which we will wait for connection to complete.
192193
* @throws IOException If connecting to the remote endpoint fails or internal java.nio errors occur.
193194
*/
194-
public void connect(byte[] their_node_id, SocketAddress remote) throws IOException {
195-
SocketChannel chan = SocketChannel.open(remote);
195+
public void connect(byte[] their_node_id, SocketAddress remote, int timeout_ms) throws IOException {
196+
SocketChannel chan = SocketChannel.open();
197+
chan.configureBlocking(false);
198+
Selector open_selector = Selector.open();
199+
chan.register(open_selector, SelectionKey.OP_CONNECT);
200+
if (!chan.connect(remote)) {
201+
open_selector.select(timeout_ms);
202+
}
203+
if (!chan.finishConnect()) { // Note that this may throw its own IOException if we failed for another reason
204+
throw new IOException("Timed out");
205+
}
196206
Peer peer = setup_socket(chan);
197207
Result_CVec_u8ZPeerHandleErrorZ res = this.peer_manager.new_outbound_connection(their_node_id, peer.descriptor);
198208
if (res instanceof Result_CVec_u8ZPeerHandleErrorZ.Result_CVec_u8ZPeerHandleErrorZ_OK) {

src/test/java/org/ldk/HumanObjectPeerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ void do_read_event(PeerManager pm, SocketDescriptor descriptor, byte[] data) {
463463
void connect_peers(final Peer peer1, final Peer peer2) {
464464
if (use_nio_peer_handler) {
465465
try {
466-
peer1.nio_peer_handler.connect(peer2.chan_manager.get_our_node_id(), new InetSocketAddress("127.0.0.1", peer2.nio_port));
466+
peer1.nio_peer_handler.connect(peer2.chan_manager.get_our_node_id(), new InetSocketAddress("127.0.0.1", peer2.nio_port), 100);
467467
} catch (IOException e) { assert false; }
468468
} else {
469469
DescriptorHolder descriptor1 = new DescriptorHolder();

0 commit comments

Comments
 (0)