[Java] Update auto-generated bindings to LDK 0.0.118
[ldk-java] / src / main / java / org / ldk / structs / CustomOnionMessageHandler.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10 /**
11  * Handler for custom onion messages. If you are using [`SimpleArcOnionMessenger`],
12  * [`SimpleRefOnionMessenger`], or prefer to ignore inbound custom onion messages,
13  * [`IgnoringMessageHandler`] must be provided to [`OnionMessenger::new`]. Otherwise, a custom
14  * implementation of this trait must be provided, with [`CustomMessage`] specifying the supported
15  * message types.
16  * 
17  * See [`OnionMessenger`] for example usage.
18  * 
19  * [`IgnoringMessageHandler`]: crate::ln::peer_handler::IgnoringMessageHandler
20  * [`CustomMessage`]: Self::CustomMessage
21  */
22 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
23 public class CustomOnionMessageHandler extends CommonBase {
24         final bindings.LDKCustomOnionMessageHandler bindings_instance;
25         CustomOnionMessageHandler(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
26         private CustomOnionMessageHandler(bindings.LDKCustomOnionMessageHandler arg) {
27                 super(bindings.LDKCustomOnionMessageHandler_new(arg));
28                 this.ptrs_to.add(arg);
29                 this.bindings_instance = arg;
30         }
31         @Override @SuppressWarnings("deprecation")
32         protected void finalize() throws Throwable {
33                 if (ptr != 0) { bindings.CustomOnionMessageHandler_free(ptr); } super.finalize();
34         }
35         /**
36          * Destroys the object, freeing associated resources. After this call, any access
37          * to this object may result in a SEGFAULT or worse.
38          *
39          * You should generally NEVER call this method. You should let the garbage collector
40          * do this for you when it finalizes objects. However, it may be useful for types
41          * which represent locks and should be closed immediately to avoid holding locks
42          * until the GC runs.
43          */
44         public void destroy() {
45                 if (ptr != 0) { bindings.CustomOnionMessageHandler_free(ptr); }
46                 ptr = 0;
47         }
48         public static interface CustomOnionMessageHandlerInterface {
49                 /**
50                  * Called with the custom message that was received, returning a response to send, if any.
51                  * 
52                  * The returned [`Self::CustomMessage`], if any, is enqueued to be sent by [`OnionMessenger`].
53                  */
54                 Option_OnionMessageContentsZ handle_custom_message(OnionMessageContents msg);
55                 /**
56                  * Read a custom message of type `message_type` from `buffer`, returning `Ok(None)` if the
57                  * message type is unknown.
58                  */
59                 Result_COption_OnionMessageContentsZDecodeErrorZ read_custom_message(long message_type, byte[] buffer);
60                 /**
61                  * Releases any [`Self::CustomMessage`]s that need to be sent.
62                  * 
63                  * Typically, this is used for messages initiating a message flow rather than in response to
64                  * another message. The latter should use the return value of [`Self::handle_custom_message`].
65                  */
66                 ThreeTuple_OnionMessageContentsDestinationBlindedPathZ[] release_pending_custom_messages();
67         }
68         private static class LDKCustomOnionMessageHandlerHolder { CustomOnionMessageHandler held; }
69         public static CustomOnionMessageHandler new_impl(CustomOnionMessageHandlerInterface arg) {
70                 final LDKCustomOnionMessageHandlerHolder impl_holder = new LDKCustomOnionMessageHandlerHolder();
71                 impl_holder.held = new CustomOnionMessageHandler(new bindings.LDKCustomOnionMessageHandler() {
72                         @Override public long handle_custom_message(long msg) {
73                                 OnionMessageContents ret_hu_conv = new OnionMessageContents(null, msg);
74                                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
75                                 Option_OnionMessageContentsZ ret = arg.handle_custom_message(ret_hu_conv);
76                                 Reference.reachabilityFence(arg);
77                                 long result = ret == null ? 0 : ret.clone_ptr();
78                                 if (impl_holder.held != null) { impl_holder.held.ptrs_to.add(ret); };
79                                 return result;
80                         }
81                         @Override public long read_custom_message(long message_type, byte[] buffer) {
82                                 Result_COption_OnionMessageContentsZDecodeErrorZ ret = arg.read_custom_message(message_type, buffer);
83                                 Reference.reachabilityFence(arg);
84                                 long result = ret == null ? 0 : ret.clone_ptr();
85                                 return result;
86                         }
87                         @Override public long[] release_pending_custom_messages() {
88                                 ThreeTuple_OnionMessageContentsDestinationBlindedPathZ[] ret = arg.release_pending_custom_messages();
89                                 Reference.reachabilityFence(arg);
90                                 long[] result = ret != null ? Arrays.stream(ret).mapToLong(ret_conv_56 -> ret_conv_56 == null ? 0 : ret_conv_56.clone_ptr()).toArray() : null;
91                                 return result;
92                         }
93                 });
94                 return impl_holder.held;
95         }
96         /**
97          * Called with the custom message that was received, returning a response to send, if any.
98          * 
99          * The returned [`Self::CustomMessage`], if any, is enqueued to be sent by [`OnionMessenger`].
100          */
101         public Option_OnionMessageContentsZ handle_custom_message(org.ldk.structs.OnionMessageContents msg) {
102                 long ret = bindings.CustomOnionMessageHandler_handle_custom_message(this.ptr, msg.ptr);
103                 Reference.reachabilityFence(this);
104                 Reference.reachabilityFence(msg);
105                 if (ret >= 0 && ret <= 4096) { return null; }
106                 org.ldk.structs.Option_OnionMessageContentsZ ret_hu_conv = org.ldk.structs.Option_OnionMessageContentsZ.constr_from_ptr(ret);
107                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
108                 if (this != null) { this.ptrs_to.add(msg); };
109                 return ret_hu_conv;
110         }
111
112         /**
113          * Read a custom message of type `message_type` from `buffer`, returning `Ok(None)` if the
114          * message type is unknown.
115          */
116         public Result_COption_OnionMessageContentsZDecodeErrorZ read_custom_message(long message_type, byte[] buffer) {
117                 long ret = bindings.CustomOnionMessageHandler_read_custom_message(this.ptr, message_type, buffer);
118                 Reference.reachabilityFence(this);
119                 Reference.reachabilityFence(message_type);
120                 Reference.reachabilityFence(buffer);
121                 if (ret >= 0 && ret <= 4096) { return null; }
122                 Result_COption_OnionMessageContentsZDecodeErrorZ ret_hu_conv = Result_COption_OnionMessageContentsZDecodeErrorZ.constr_from_ptr(ret);
123                 return ret_hu_conv;
124         }
125
126         /**
127          * Releases any [`Self::CustomMessage`]s that need to be sent.
128          * 
129          * Typically, this is used for messages initiating a message flow rather than in response to
130          * another message. The latter should use the return value of [`Self::handle_custom_message`].
131          */
132         public ThreeTuple_OnionMessageContentsDestinationBlindedPathZ[] release_pending_custom_messages() {
133                 long[] ret = bindings.CustomOnionMessageHandler_release_pending_custom_messages(this.ptr);
134                 Reference.reachabilityFence(this);
135                 int ret_conv_56_len = ret.length;
136                 ThreeTuple_OnionMessageContentsDestinationBlindedPathZ[] ret_conv_56_arr = new ThreeTuple_OnionMessageContentsDestinationBlindedPathZ[ret_conv_56_len];
137                 for (int e = 0; e < ret_conv_56_len; e++) {
138                         long ret_conv_56 = ret[e];
139                         ThreeTuple_OnionMessageContentsDestinationBlindedPathZ ret_conv_56_hu_conv = new ThreeTuple_OnionMessageContentsDestinationBlindedPathZ(null, ret_conv_56);
140                         if (ret_conv_56_hu_conv != null) { ret_conv_56_hu_conv.ptrs_to.add(this); };
141                         ret_conv_56_arr[e] = ret_conv_56_hu_conv;
142                 }
143                 return ret_conv_56_arr;
144         }
145
146 }