1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
11 * A trait indicating an object may generate onion messages to send
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;
22 @Override @SuppressWarnings("deprecation")
23 protected void finalize() throws Throwable {
24 if (ptr != 0) { bindings.OnionMessageProvider_free(ptr); } super.finalize();
27 * Destroys the object, freeing associated resources. After this call, any access
28 * to this object may result in a SEGFAULT or worse.
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
35 public void destroy() {
36 if (ptr != 0) { bindings.OnionMessageProvider_free(ptr); }
39 public static interface OnionMessageProviderInterface {
41 * Gets the next pending onion message for the peer with the given node id.
43 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
45 OnionMessage next_onion_message_for_peer(byte[] peer_node_id);
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();
58 return impl_holder.held;
61 * Gets the next pending onion message for the peer with the given node id.
63 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
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); };