[Java] Update auto-generated Java bindings to LDK 0.0.121
[ldk-java] / src / main / java / org / ldk / structs / MessageRouter.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  * A trait defining behavior for routing an [`OnionMessage`].
12  */
13 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
14 public class MessageRouter extends CommonBase {
15         final bindings.LDKMessageRouter bindings_instance;
16         MessageRouter(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
17         private MessageRouter(bindings.LDKMessageRouter arg) {
18                 super(bindings.LDKMessageRouter_new(arg));
19                 this.ptrs_to.add(arg);
20                 this.bindings_instance = arg;
21         }
22         @Override @SuppressWarnings("deprecation")
23         protected void finalize() throws Throwable {
24                 if (ptr != 0) { bindings.MessageRouter_free(ptr); } super.finalize();
25         }
26         /**
27          * Destroys the object, freeing associated resources. After this call, any access
28          * to this object may result in a SEGFAULT or worse.
29          *
30          * You should generally NEVER call this method. You should let the garbage collector
31          * do this for you when it finalizes objects. However, it may be useful for types
32          * which represent locks and should be closed immediately to avoid holding locks
33          * until the GC runs.
34          */
35         public void destroy() {
36                 if (ptr != 0) { bindings.MessageRouter_free(ptr); }
37                 ptr = 0;
38         }
39         public static interface MessageRouterInterface {
40                 /**
41                  * Returns a route for sending an [`OnionMessage`] to the given [`Destination`].
42                  */
43                 Result_OnionMessagePathNoneZ find_path(byte[] sender, byte[][] peers, Destination destination);
44                 /**
45                  * Creates [`BlindedPath`]s to the `recipient` node. The nodes in `peers` are assumed to be
46                  * direct peers with the `recipient`.
47                  */
48                 Result_CVec_BlindedPathZNoneZ create_blinded_paths(byte[] recipient, byte[][] peers);
49         }
50         private static class LDKMessageRouterHolder { MessageRouter held; }
51         public static MessageRouter new_impl(MessageRouterInterface arg) {
52                 final LDKMessageRouterHolder impl_holder = new LDKMessageRouterHolder();
53                 impl_holder.held = new MessageRouter(new bindings.LDKMessageRouter() {
54                         @Override public long find_path(byte[] sender, byte[][] peers, long destination) {
55                                 org.ldk.structs.Destination destination_hu_conv = org.ldk.structs.Destination.constr_from_ptr(destination);
56                                 if (destination_hu_conv != null) { destination_hu_conv.ptrs_to.add(this); };
57                                 Result_OnionMessagePathNoneZ ret = arg.find_path(sender, peers, destination_hu_conv);
58                                 Reference.reachabilityFence(arg);
59                                 long result = ret == null ? 0 : ret.clone_ptr();
60                                 return result;
61                         }
62                         @Override public long create_blinded_paths(byte[] recipient, byte[][] peers) {
63                                 Result_CVec_BlindedPathZNoneZ ret = arg.create_blinded_paths(recipient, peers);
64                                 Reference.reachabilityFence(arg);
65                                 long result = ret == null ? 0 : ret.clone_ptr();
66                                 return result;
67                         }
68                 });
69                 return impl_holder.held;
70         }
71         /**
72          * Returns a route for sending an [`OnionMessage`] to the given [`Destination`].
73          */
74         public Result_OnionMessagePathNoneZ find_path(byte[] sender, byte[][] peers, org.ldk.structs.Destination destination) {
75                 long ret = bindings.MessageRouter_find_path(this.ptr, InternalUtils.check_arr_len(sender, 33), peers != null ? Arrays.stream(peers).map(peers_conv_8 -> InternalUtils.check_arr_len(peers_conv_8, 33)).toArray(byte[][]::new) : null, destination.ptr);
76                 Reference.reachabilityFence(this);
77                 Reference.reachabilityFence(sender);
78                 Reference.reachabilityFence(peers);
79                 Reference.reachabilityFence(destination);
80                 if (ret >= 0 && ret <= 4096) { return null; }
81                 Result_OnionMessagePathNoneZ ret_hu_conv = Result_OnionMessagePathNoneZ.constr_from_ptr(ret);
82                 if (this != null) { this.ptrs_to.add(destination); };
83                 return ret_hu_conv;
84         }
85
86         /**
87          * Creates [`BlindedPath`]s to the `recipient` node. The nodes in `peers` are assumed to be
88          * direct peers with the `recipient`.
89          */
90         public Result_CVec_BlindedPathZNoneZ create_blinded_paths(byte[] recipient, byte[][] peers) {
91                 long ret = bindings.MessageRouter_create_blinded_paths(this.ptr, InternalUtils.check_arr_len(recipient, 33), peers != null ? Arrays.stream(peers).map(peers_conv_8 -> InternalUtils.check_arr_len(peers_conv_8, 33)).toArray(byte[][]::new) : null);
92                 Reference.reachabilityFence(this);
93                 Reference.reachabilityFence(recipient);
94                 Reference.reachabilityFence(peers);
95                 if (ret >= 0 && ret <= 4096) { return null; }
96                 Result_CVec_BlindedPathZNoneZ ret_hu_conv = Result_CVec_BlindedPathZNoneZ.constr_from_ptr(ret);
97                 return ret_hu_conv;
98         }
99
100 }