6c87b44ba4fe6e8ffd9e3b5a1b1b89038b4e112d
[ldk-java] / src / main / java / org / ldk / structs / OnionMessageProvider.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 indicating an object may generate onion messages to send
12  */
13 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
14 public class OnionMessageProvider extends CommonBase {
15         final bindings.LDKOnionMessageProvider bindings_instance;
16         OnionMessageProvider(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
17         private OnionMessageProvider(bindings.LDKOnionMessageProvider arg) {
18                 super(bindings.LDKOnionMessageProvider_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.OnionMessageProvider_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.OnionMessageProvider_free(ptr); }
37                 ptr = 0;
38         }
39         public static interface OnionMessageProviderInterface {
40                 /**
41                  * Gets the next pending onion message for the peer with the given node id.
42                  * 
43                  * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
44                  */
45                 OnionMessage next_onion_message_for_peer(byte[] peer_node_id);
46         }
47         private static class LDKOnionMessageProviderHolder { OnionMessageProvider held; }
48         public static OnionMessageProvider new_impl(OnionMessageProviderInterface arg) {
49                 final LDKOnionMessageProviderHolder impl_holder = new LDKOnionMessageProviderHolder();
50                 impl_holder.held = new OnionMessageProvider(new bindings.LDKOnionMessageProvider() {
51                         @Override public long next_onion_message_for_peer(byte[] peer_node_id) {
52                                 OnionMessage ret = arg.next_onion_message_for_peer(peer_node_id);
53                                 Reference.reachabilityFence(arg);
54                                 long result = ret == null ? 0 : ret.clone_ptr();
55                                 return result;
56                         }
57                 });
58                 return impl_holder.held;
59         }
60         /**
61          * Gets the next pending onion message for the peer with the given node id.
62          * 
63          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
64          */
65         @Nullable
66         public OnionMessage next_onion_message_for_peer(byte[] peer_node_id) {
67                 long ret = bindings.OnionMessageProvider_next_onion_message_for_peer(this.ptr, InternalUtils.check_arr_len(peer_node_id, 33));
68                 Reference.reachabilityFence(this);
69                 Reference.reachabilityFence(peer_node_id);
70                 if (ret >= 0 && ret <= 4096) { return null; }
71                 org.ldk.structs.OnionMessage ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OnionMessage(null, ret); }
72                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
73                 return ret_hu_conv;
74         }
75
76 }