X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FCustomOnionMessageHandler.java;fp=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FCustomOnionMessageHandler.java;h=4c52481f59c839afc1fd14602b37a225b8c9d0b6;hb=2f0e19ab23f28c5c1bc11dc6bff24e156da3ec01;hp=77ea33064866f408b377732873c958efba99ecc7;hpb=ab07d4394be144b5e7eb123655031dba5349b849;p=ldk-java diff --git a/src/main/java/org/ldk/structs/CustomOnionMessageHandler.java b/src/main/java/org/ldk/structs/CustomOnionMessageHandler.java index 77ea3306..4c52481f 100644 --- a/src/main/java/org/ldk/structs/CustomOnionMessageHandler.java +++ b/src/main/java/org/ldk/structs/CustomOnionMessageHandler.java @@ -48,45 +48,62 @@ public class CustomOnionMessageHandler extends CommonBase { public static interface CustomOnionMessageHandlerInterface { /** * Called with the custom message that was received, returning a response to send, if any. + * + * The returned [`Self::CustomMessage`], if any, is enqueued to be sent by [`OnionMessenger`]. */ - Option_CustomOnionMessageContentsZ handle_custom_message(CustomOnionMessageContents msg); + Option_OnionMessageContentsZ handle_custom_message(OnionMessageContents msg); /** * Read a custom message of type `message_type` from `buffer`, returning `Ok(None)` if the * message type is unknown. */ - Result_COption_CustomOnionMessageContentsZDecodeErrorZ read_custom_message(long message_type, byte[] buffer); + Result_COption_OnionMessageContentsZDecodeErrorZ read_custom_message(long message_type, byte[] buffer); + /** + * Releases any [`Self::CustomMessage`]s that need to be sent. + * + * Typically, this is used for messages initiating a message flow rather than in response to + * another message. The latter should use the return value of [`Self::handle_custom_message`]. + */ + ThreeTuple_OnionMessageContentsDestinationBlindedPathZ[] release_pending_custom_messages(); } private static class LDKCustomOnionMessageHandlerHolder { CustomOnionMessageHandler held; } public static CustomOnionMessageHandler new_impl(CustomOnionMessageHandlerInterface arg) { final LDKCustomOnionMessageHandlerHolder impl_holder = new LDKCustomOnionMessageHandlerHolder(); impl_holder.held = new CustomOnionMessageHandler(new bindings.LDKCustomOnionMessageHandler() { @Override public long handle_custom_message(long msg) { - CustomOnionMessageContents ret_hu_conv = new CustomOnionMessageContents(null, msg); + OnionMessageContents ret_hu_conv = new OnionMessageContents(null, msg); if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; - Option_CustomOnionMessageContentsZ ret = arg.handle_custom_message(ret_hu_conv); + Option_OnionMessageContentsZ ret = arg.handle_custom_message(ret_hu_conv); Reference.reachabilityFence(arg); long result = ret == null ? 0 : ret.clone_ptr(); if (impl_holder.held != null) { impl_holder.held.ptrs_to.add(ret); }; return result; } @Override public long read_custom_message(long message_type, byte[] buffer) { - Result_COption_CustomOnionMessageContentsZDecodeErrorZ ret = arg.read_custom_message(message_type, buffer); + Result_COption_OnionMessageContentsZDecodeErrorZ ret = arg.read_custom_message(message_type, buffer); Reference.reachabilityFence(arg); long result = ret == null ? 0 : ret.clone_ptr(); return result; } + @Override public long[] release_pending_custom_messages() { + ThreeTuple_OnionMessageContentsDestinationBlindedPathZ[] ret = arg.release_pending_custom_messages(); + Reference.reachabilityFence(arg); + long[] result = ret != null ? Arrays.stream(ret).mapToLong(ret_conv_56 -> ret_conv_56 == null ? 0 : ret_conv_56.clone_ptr()).toArray() : null; + return result; + } }); return impl_holder.held; } /** * Called with the custom message that was received, returning a response to send, if any. + * + * The returned [`Self::CustomMessage`], if any, is enqueued to be sent by [`OnionMessenger`]. */ - public Option_CustomOnionMessageContentsZ handle_custom_message(org.ldk.structs.CustomOnionMessageContents msg) { + public Option_OnionMessageContentsZ handle_custom_message(org.ldk.structs.OnionMessageContents msg) { long ret = bindings.CustomOnionMessageHandler_handle_custom_message(this.ptr, msg.ptr); Reference.reachabilityFence(this); Reference.reachabilityFence(msg); if (ret >= 0 && ret <= 4096) { return null; } - org.ldk.structs.Option_CustomOnionMessageContentsZ ret_hu_conv = org.ldk.structs.Option_CustomOnionMessageContentsZ.constr_from_ptr(ret); + org.ldk.structs.Option_OnionMessageContentsZ ret_hu_conv = org.ldk.structs.Option_OnionMessageContentsZ.constr_from_ptr(ret); if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; if (this != null) { this.ptrs_to.add(msg); }; return ret_hu_conv; @@ -96,14 +113,34 @@ public class CustomOnionMessageHandler extends CommonBase { * Read a custom message of type `message_type` from `buffer`, returning `Ok(None)` if the * message type is unknown. */ - public Result_COption_CustomOnionMessageContentsZDecodeErrorZ read_custom_message(long message_type, byte[] buffer) { + public Result_COption_OnionMessageContentsZDecodeErrorZ read_custom_message(long message_type, byte[] buffer) { long ret = bindings.CustomOnionMessageHandler_read_custom_message(this.ptr, message_type, buffer); Reference.reachabilityFence(this); Reference.reachabilityFence(message_type); Reference.reachabilityFence(buffer); if (ret >= 0 && ret <= 4096) { return null; } - Result_COption_CustomOnionMessageContentsZDecodeErrorZ ret_hu_conv = Result_COption_CustomOnionMessageContentsZDecodeErrorZ.constr_from_ptr(ret); + Result_COption_OnionMessageContentsZDecodeErrorZ ret_hu_conv = Result_COption_OnionMessageContentsZDecodeErrorZ.constr_from_ptr(ret); return ret_hu_conv; } + /** + * Releases any [`Self::CustomMessage`]s that need to be sent. + * + * Typically, this is used for messages initiating a message flow rather than in response to + * another message. The latter should use the return value of [`Self::handle_custom_message`]. + */ + public ThreeTuple_OnionMessageContentsDestinationBlindedPathZ[] release_pending_custom_messages() { + long[] ret = bindings.CustomOnionMessageHandler_release_pending_custom_messages(this.ptr); + Reference.reachabilityFence(this); + int ret_conv_56_len = ret.length; + ThreeTuple_OnionMessageContentsDestinationBlindedPathZ[] ret_conv_56_arr = new ThreeTuple_OnionMessageContentsDestinationBlindedPathZ[ret_conv_56_len]; + for (int e = 0; e < ret_conv_56_len; e++) { + long ret_conv_56 = ret[e]; + ThreeTuple_OnionMessageContentsDestinationBlindedPathZ ret_conv_56_hu_conv = new ThreeTuple_OnionMessageContentsDestinationBlindedPathZ(null, ret_conv_56); + if (ret_conv_56_hu_conv != null) { ret_conv_56_hu_conv.ptrs_to.add(this); }; + ret_conv_56_arr[e] = ret_conv_56_hu_conv; + } + return ret_conv_56_arr; + } + }