X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FCustomMessageHandler.java;h=d502104919845ad948f654e0275bbdd250f170b0;hb=1854b5cebef22ace9e9e4dd191f609818df9ce08;hp=fe1a2bb1e752ca85d473e411ea26c59e83006041;hpb=a7653cf8717b1f9df4d3f4c4bd0b1f50f3bbc230;p=ldk-java diff --git a/src/main/java/org/ldk/structs/CustomMessageHandler.java b/src/main/java/org/ldk/structs/CustomMessageHandler.java index fe1a2bb1..d5021049 100644 --- a/src/main/java/org/ldk/structs/CustomMessageHandler.java +++ b/src/main/java/org/ldk/structs/CustomMessageHandler.java @@ -4,6 +4,7 @@ import org.ldk.impl.bindings; import org.ldk.enums.*; import org.ldk.util.*; import java.util.Arrays; +import java.lang.ref.Reference; import javax.annotation.Nullable; /** @@ -36,7 +37,7 @@ public class CustomMessageHandler extends CommonBase { * correspond to the intended recipients node ids. If no connection to one of the * specified node does not exist, the message is simply not sent to it. */ - TwoTuple[] get_and_clear_pending_msg(); + TwoTuple_PublicKeyTypeZ[] get_and_clear_pending_msg(); } private static class LDKCustomMessageHandlerHolder { CustomMessageHandler held; } public static CustomMessageHandler new_impl(CustomMessageHandlerInterface arg, CustomMessageReader.CustomMessageReaderInterface CustomMessageReader_impl) { @@ -46,13 +47,12 @@ public class CustomMessageHandler extends CommonBase { Type ret_hu_conv = new Type(null, msg); ret_hu_conv.ptrs_to.add(this); Result_NoneLightningErrorZ ret = arg.handle_custom_message(ret_hu_conv, sender_node_id); - long result = ret != null ? ret.ptr : 0; + long result = ret == null ? 0 : ret.clone_ptr(); return result; } @Override public long[] get_and_clear_pending_msg() { - TwoTuple[] ret = arg.get_and_clear_pending_msg(); - long[] result = ret != null ? Arrays.stream(ret).mapToLong(ret_conv_24 -> bindings.C2Tuple_PublicKeyTypeZ_new(ret_conv_24.a, ret_conv_24.b == null ? 0 : ret_conv_24.b.ptr)).toArray() : null; - for (TwoTuple ret_conv_24: ret) { impl_holder.held.ptrs_to.add(ret_conv_24.b); }; + TwoTuple_PublicKeyTypeZ[] ret = arg.get_and_clear_pending_msg(); + long[] result = ret != null ? Arrays.stream(ret).mapToLong(ret_conv_25 -> ret_conv_25 == null ? 0 : ret_conv_25.clone_ptr()).toArray() : null; return result; } }, CustomMessageReader.new_impl(CustomMessageReader_impl).bindings_instance); @@ -73,8 +73,11 @@ public class CustomMessageHandler extends CommonBase { * Can return a `MessageHandlingError` if the message could not be handled. */ public Result_NoneLightningErrorZ handle_custom_message(Type msg, byte[] sender_node_id) { - long ret = bindings.CustomMessageHandler_handle_custom_message(this.ptr, msg == null ? 0 : msg.ptr, sender_node_id); - if (ret < 1024) { return null; } + long ret = bindings.CustomMessageHandler_handle_custom_message(this.ptr, msg == null ? 0 : msg.ptr, InternalUtils.check_arr_len(sender_node_id, 33)); + Reference.reachabilityFence(this); + Reference.reachabilityFence(msg); + Reference.reachabilityFence(sender_node_id); + if (ret >= 0 && ret <= 4096) { return null; } Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret); this.ptrs_to.add(msg); return ret_hu_conv; @@ -86,22 +89,17 @@ public class CustomMessageHandler extends CommonBase { * correspond to the intended recipients node ids. If no connection to one of the * specified node does not exist, the message is simply not sent to it. */ - public TwoTuple[] get_and_clear_pending_msg() { + public TwoTuple_PublicKeyTypeZ[] get_and_clear_pending_msg() { long[] ret = bindings.CustomMessageHandler_get_and_clear_pending_msg(this.ptr); - TwoTuple[] ret_conv_24_arr = new TwoTuple[ret.length]; - for (int y = 0; y < ret.length; y++) { - long ret_conv_24 = ret[y]; - byte[] ret_conv_24_a = bindings.LDKC2Tuple_PublicKeyTypeZ_get_a(ret_conv_24); - long ret_conv_24_b = bindings.LDKC2Tuple_PublicKeyTypeZ_get_b(ret_conv_24); - Type ret_hu_conv = new Type(null, ret_conv_24_b); - ret_hu_conv.ptrs_to.add(this);; - TwoTuple ret_conv_24_conv = new TwoTuple(ret_conv_24_a, ret_hu_conv, () -> { - bindings.C2Tuple_PublicKeyTypeZ_free(ret_conv_24); - }); - ret_hu_conv.ptrs_to.add(ret_conv_24_conv); - ret_conv_24_arr[y] = ret_conv_24_conv; + Reference.reachabilityFence(this); + TwoTuple_PublicKeyTypeZ[] ret_conv_25_arr = new TwoTuple_PublicKeyTypeZ[ret.length]; + for (int z = 0; z < ret.length; z++) { + long ret_conv_25 = ret[z]; + TwoTuple_PublicKeyTypeZ ret_conv_25_hu_conv = new TwoTuple_PublicKeyTypeZ(null, ret_conv_25); + ret_conv_25_hu_conv.ptrs_to.add(this); + ret_conv_25_arr[z] = ret_conv_25_hu_conv; } - return ret_conv_24_arr; + return ret_conv_25_arr; } }