Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions genbindings.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -31,11 +31,11 @@ javac -h src/main/jni src/main/java/org/ldk/enums/*.java src/main/java/org/ldk/i
rm src/main/java/org/ldk/enums/*.class src/main/java/org/ldk/impl/bindings*.class

echo "Building Java bindings..."
COMPILE="$COMMON_COMPILE -Isrc/main/jni -pthread -ldl -Wl,--no-undefined -o liblightningjni.so -shared -fPIC"
COMPILE="$COMMON_COMPILE -Isrc/main/jni -pthread -ldl -Wl,--no-undefined -shared -fPIC"
if [ "$3" = "true" ]; then
$COMPILE -g -fsanitize=address -shared-libasan -Wl,-wrap,calloc -Wl,-wrap,realloc -Wl,-wrap,reallocarray -Wl,-wrap,malloc -Wl,-wrap,free -rdynamic -I"$1"/lightning-c-bindings/include/ $2 src/main/jni/bindings.c "$1"/lightning-c-bindings/target/debug/libldk.a -lm
$COMPILE -o liblightningjni_debug.so -g -fsanitize=address -shared-libasan -Wl,-wrap,calloc -Wl,-wrap,realloc -Wl,-wrap,reallocarray -Wl,-wrap,malloc -Wl,-wrap,free -rdynamic -I"$1"/lightning-c-bindings/include/ $2 src/main/jni/bindings.c "$1"/lightning-c-bindings/target/debug/libldk.a -lm
else
$COMPILE -Wl,--version-script=libcode.version -flto -fuse-ld=lld -O3 -I"$1"/lightning-c-bindings/include/ $2 src/main/jni/bindings.c "$1"/lightning-c-bindings/target/release/libldk.a
$COMPILE -o liblightningjni_release.so -Wl,--version-script=libcode.version -flto -fuse-ld=lld -O3 -I"$1"/lightning-c-bindings/include/ $2 src/main/jni/bindings.c "$1"/lightning-c-bindings/target/release/libldk.a
fi

echo "Creating TS bindings..."
Expand Down
6 changes: 5 additions & 1 deletion java_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ class CommonBase {
void __attribute__((destructor)) check_leaks() {
size_t alloc_count = 0;
size_t alloc_size = 0;
fprintf(stderr, "The following LDK-allocated blocks still remain.\\n");
fprintf(stderr, "Note that this is only accurate if System.gc(); System.runFinalization()\\n");
fprintf(stderr, "was called prior to exit after all LDK objects were out of scope.\\n");
for (allocation* a = allocation_ll; a != NULL; a = a->next) {
fprintf(stderr, "%s %p (%lu bytes) remains:\\n", a->struct_name, a->ptr, a->alloc_len);
backtrace_symbols_fd(a->bt, a->bt_len, STDERR_FILENO);
Expand All @@ -205,7 +208,8 @@ class CommonBase {
alloc_size += a->alloc_len;
}
fprintf(stderr, "%lu allocations remained for %lu bytes.\\n", alloc_count, alloc_size);
DO_ASSERT(allocation_ll == NULL);
fprintf(stderr, "Note that this is only accurate if System.gc(); System.runFinalization()\\n");
fprintf(stderr, "was called prior to exit after all LDK objects were out of scope.\\n");
}
"""
self.c_file_pfx = self.c_file_pfx + """
Expand Down
Binary file removed liblightningjni.so
Binary file not shown.
1 change: 1 addition & 0 deletions liblightningjni.so
Binary file added liblightningjni_debug.so
Binary file not shown.
Binary file added liblightningjni_release.so
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public static class InvalidSerializedDataException extends Exception {}
* 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,
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/org/ldk/batteries/NioPeerHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,20 @@ public NioPeerHandler(PeerManager manager) throws IOException {
* @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) {
Expand Down
29 changes: 25 additions & 4 deletions src/main/java/org/ldk/impl/bindings.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ public final static class SendShortIdsQuery extends LDKMessageSendEvent {
public static native boolean LDKCResult_ChannelFeaturesDecodeErrorZ_result_ok(long arg);
public static native long LDKCResult_ChannelFeaturesDecodeErrorZ_get_ok(long arg);
public static native long LDKCResult_ChannelFeaturesDecodeErrorZ_get_err(long arg);
public static native boolean LDKCResult_InvoiceFeaturesDecodeErrorZ_result_ok(long arg);
public static native long LDKCResult_InvoiceFeaturesDecodeErrorZ_get_ok(long arg);
public static native long LDKCResult_InvoiceFeaturesDecodeErrorZ_get_err(long arg);
public static native boolean LDKCResult_ChannelConfigDecodeErrorZ_result_ok(long arg);
public static native long LDKCResult_ChannelConfigDecodeErrorZ_get_ok(long arg);
public static native long LDKCResult_ChannelConfigDecodeErrorZ_get_err(long arg);
Expand Down Expand Up @@ -1023,6 +1026,12 @@ public interface LDKSocketDescriptor {
public static native long CResult_ChannelFeaturesDecodeErrorZ_err(long e);
// void CResult_ChannelFeaturesDecodeErrorZ_free(struct LDKCResult_ChannelFeaturesDecodeErrorZ _res);
public static native void CResult_ChannelFeaturesDecodeErrorZ_free(long _res);
// struct LDKCResult_InvoiceFeaturesDecodeErrorZ CResult_InvoiceFeaturesDecodeErrorZ_ok(struct LDKInvoiceFeatures o);
public static native long CResult_InvoiceFeaturesDecodeErrorZ_ok(long o);
// struct LDKCResult_InvoiceFeaturesDecodeErrorZ CResult_InvoiceFeaturesDecodeErrorZ_err(struct LDKDecodeError e);
public static native long CResult_InvoiceFeaturesDecodeErrorZ_err(long e);
// void CResult_InvoiceFeaturesDecodeErrorZ_free(struct LDKCResult_InvoiceFeaturesDecodeErrorZ _res);
public static native void CResult_InvoiceFeaturesDecodeErrorZ_free(long _res);
// struct LDKCResult_ChannelConfigDecodeErrorZ CResult_ChannelConfigDecodeErrorZ_ok(struct LDKChannelConfig o);
public static native long CResult_ChannelConfigDecodeErrorZ_ok(long o);
// struct LDKCResult_ChannelConfigDecodeErrorZ CResult_ChannelConfigDecodeErrorZ_err(struct LDKDecodeError e);
Expand Down Expand Up @@ -3005,8 +3014,8 @@ public interface LDKSocketDescriptor {
public static native void PeerManager_socket_disconnected(long this_arg, long descriptor);
// void PeerManager_disconnect_by_node_id(const struct LDKPeerManager *NONNULL_PTR this_arg, struct LDKPublicKey node_id, bool no_connection_possible);
public static native void PeerManager_disconnect_by_node_id(long this_arg, byte[] node_id, boolean no_connection_possible);
// void PeerManager_timer_tick_occured(const struct LDKPeerManager *NONNULL_PTR this_arg);
public static native void PeerManager_timer_tick_occured(long this_arg);
// void PeerManager_timer_tick_occurred(const struct LDKPeerManager *NONNULL_PTR this_arg);
public static native void PeerManager_timer_tick_occurred(long this_arg);
// struct LDKThirtyTwoBytes build_commitment_secret(const uint8_t (*commitment_seed)[32], uint64_t idx);
public static native byte[] build_commitment_secret(byte[] commitment_seed, long idx);
// struct LDKCResult_SecretKeyErrorZ derive_private_key(struct LDKPublicKey per_commitment_point, const uint8_t (*base_secret)[32]);
Expand Down Expand Up @@ -3255,12 +3264,16 @@ public interface LDKSocketDescriptor {
public static native long NodeFeatures_clone(long orig);
// struct LDKChannelFeatures ChannelFeatures_clone(const struct LDKChannelFeatures *NONNULL_PTR orig);
public static native long ChannelFeatures_clone(long orig);
// struct LDKInvoiceFeatures InvoiceFeatures_clone(const struct LDKInvoiceFeatures *NONNULL_PTR orig);
public static native long InvoiceFeatures_clone(long orig);
// void InitFeatures_free(struct LDKInitFeatures this_obj);
public static native void InitFeatures_free(long this_obj);
// void NodeFeatures_free(struct LDKNodeFeatures this_obj);
public static native void NodeFeatures_free(long this_obj);
// void ChannelFeatures_free(struct LDKChannelFeatures this_obj);
public static native void ChannelFeatures_free(long this_obj);
// void InvoiceFeatures_free(struct LDKInvoiceFeatures this_obj);
public static native void InvoiceFeatures_free(long this_obj);
// MUST_USE_RES struct LDKInitFeatures InitFeatures_empty(void);
public static native long InitFeatures_empty();
// MUST_USE_RES struct LDKInitFeatures InitFeatures_known(void);
Expand All @@ -3273,18 +3286,26 @@ public interface LDKSocketDescriptor {
public static native long ChannelFeatures_empty();
// MUST_USE_RES struct LDKChannelFeatures ChannelFeatures_known(void);
public static native long ChannelFeatures_known();
// MUST_USE_RES struct LDKInvoiceFeatures InvoiceFeatures_empty(void);
public static native long InvoiceFeatures_empty();
// MUST_USE_RES struct LDKInvoiceFeatures InvoiceFeatures_known(void);
public static native long InvoiceFeatures_known();
// struct LDKCVec_u8Z InitFeatures_write(const struct LDKInitFeatures *NONNULL_PTR obj);
public static native byte[] InitFeatures_write(long obj);
// struct LDKCVec_u8Z NodeFeatures_write(const struct LDKNodeFeatures *NONNULL_PTR obj);
public static native byte[] NodeFeatures_write(long obj);
// struct LDKCVec_u8Z ChannelFeatures_write(const struct LDKChannelFeatures *NONNULL_PTR obj);
public static native byte[] ChannelFeatures_write(long obj);
// struct LDKCVec_u8Z InvoiceFeatures_write(const struct LDKInvoiceFeatures *NONNULL_PTR obj);
public static native byte[] InvoiceFeatures_write(long obj);
// struct LDKCResult_InitFeaturesDecodeErrorZ InitFeatures_read(struct LDKu8slice ser);
public static native long InitFeatures_read(byte[] ser);
// struct LDKCResult_NodeFeaturesDecodeErrorZ NodeFeatures_read(struct LDKu8slice ser);
public static native long NodeFeatures_read(byte[] ser);
// struct LDKCResult_ChannelFeaturesDecodeErrorZ ChannelFeatures_read(struct LDKu8slice ser);
public static native long ChannelFeatures_read(byte[] ser);
// struct LDKCResult_InvoiceFeaturesDecodeErrorZ InvoiceFeatures_read(struct LDKu8slice ser);
public static native long InvoiceFeatures_read(byte[] ser);
// void RouteHop_free(struct LDKRouteHop this_obj);
public static native void RouteHop_free(long this_obj);
// struct LDKPublicKey RouteHop_get_pubkey(const struct LDKRouteHop *NONNULL_PTR this_ptr);
Expand Down Expand Up @@ -3347,8 +3368,8 @@ public interface LDKSocketDescriptor {
public static native void RouteHint_set_cltv_expiry_delta(long this_ptr, short val);
// struct LDKRouteHint RouteHint_clone(const struct LDKRouteHint *NONNULL_PTR orig);
public static native long RouteHint_clone(long orig);
// struct LDKCResult_RouteLightningErrorZ get_route(struct LDKPublicKey our_node_id, const struct LDKNetworkGraph *NONNULL_PTR network, struct LDKPublicKey payee, struct LDKCVec_ChannelDetailsZ *first_hops, struct LDKCVec_RouteHintZ last_hops, uint64_t final_value_msat, uint32_t final_cltv, struct LDKLogger logger);
public static native long get_route(byte[] our_node_id, long network, byte[] payee, long[] first_hops, long[] last_hops, long final_value_msat, int final_cltv, long logger);
// struct LDKCResult_RouteLightningErrorZ get_route(struct LDKPublicKey our_node_id, const struct LDKNetworkGraph *NONNULL_PTR network, struct LDKPublicKey payee, struct LDKInvoiceFeatures payee_features, struct LDKCVec_ChannelDetailsZ *first_hops, struct LDKCVec_RouteHintZ last_hops, uint64_t final_value_msat, uint32_t final_cltv, struct LDKLogger logger);
public static native long get_route(byte[] our_node_id, long network, byte[] payee, long payee_features, long[] first_hops, long[] last_hops, long final_value_msat, int final_cltv, long logger);
// void NetworkGraph_free(struct LDKNetworkGraph this_obj);
public static native void NetworkGraph_free(long this_obj);
// struct LDKNetworkGraph NetworkGraph_clone(const struct LDKNetworkGraph *NONNULL_PTR orig);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/ldk/structs/ChannelConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public ChannelConfig clone() {
}

/**
* Creates a "default" ChannelConfig. See other documentaiton for details on what this implies.
* Creates a "default" ChannelConfig. See struct and individual field documentaiton for details on which values are used.
*/
public static ChannelConfig constructor_default() {
long ret = bindings.ChannelConfig_default();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/ldk/structs/ChannelHandshakeConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public ChannelHandshakeConfig clone() {
}

/**
* Creates a "default" ChannelHandshakeConfig. See other documentaiton for details on what this implies.
* Creates a "default" ChannelHandshakeConfig. See struct and individual field documentaiton for details on which values are used.
*/
public static ChannelHandshakeConfig constructor_default() {
long ret = bindings.ChannelHandshakeConfig_default();
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/ldk/structs/ChannelHandshakeLimits.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ public void set_force_announced_channel_preference(boolean val) {
* Not checking this value would be a security issue, as our peer would be able to set it to
* max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time.
*
* Default value: MAX_LOCAL_BREAKDOWN_TIMEOUT (1008), which we also enforce as a maximum value
* so you can tweak config to reduce the loss of having useless locked funds (if your peer accepts)
* Default value: 2016, which we also enforce as a maximum value so you can tweak config to
* reduce the loss of having useless locked funds (if your peer accepts)
*/
public short get_their_to_self_delay() {
short ret = bindings.ChannelHandshakeLimits_get_their_to_self_delay(this.ptr);
Expand All @@ -257,8 +257,8 @@ public short get_their_to_self_delay() {
* Not checking this value would be a security issue, as our peer would be able to set it to
* max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time.
*
* Default value: MAX_LOCAL_BREAKDOWN_TIMEOUT (1008), which we also enforce as a maximum value
* so you can tweak config to reduce the loss of having useless locked funds (if your peer accepts)
* Default value: 2016, which we also enforce as a maximum value so you can tweak config to
* reduce the loss of having useless locked funds (if your peer accepts)
*/
public void set_their_to_self_delay(short val) {
bindings.ChannelHandshakeLimits_set_their_to_self_delay(this.ptr, val);
Expand All @@ -285,7 +285,7 @@ public ChannelHandshakeLimits clone() {
}

/**
* Creates a "default" ChannelHandshakeLimits. See other documentaiton for details on what this implies.
* Creates a "default" ChannelHandshakeLimits. See struct and individual field documentaiton for details on which values are used.
*/
public static ChannelHandshakeLimits constructor_default() {
long ret = bindings.ChannelHandshakeLimits_default();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/ldk/structs/PeerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ public void disconnect_by_node_id(byte[] node_id, boolean no_connection_possible
* It will send pings to each peer and disconnect those which did not respond to the last round of pings.
* Will most likely call send_data on all of the registered descriptors, thus, be very careful with reentrancy issues!
*/
public void timer_tick_occured() {
bindings.PeerManager_timer_tick_occured(this.ptr);
public void timer_tick_occurred() {
bindings.PeerManager_timer_tick_occurred(this.ptr);
}

}
2 changes: 1 addition & 1 deletion src/main/java/org/ldk/structs/UserConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public UserConfig clone() {
}

/**
* Creates a "default" UserConfig. See other documentaiton for details on what this implies.
* Creates a "default" UserConfig. See struct and individual field documentaiton for details on which values are used.
*/
public static UserConfig constructor_default() {
long ret = bindings.UserConfig_default();
Expand Down
Loading