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 * An interface for looking up the node id of a channel counterparty for the purpose of forwarding
12 * an [`OnionMessage`].
14 * [`OnionMessage`]: crate::ln::msgs::OnionMessage
16 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
17 public class NodeIdLookUp extends CommonBase {
18 final bindings.LDKNodeIdLookUp bindings_instance;
19 NodeIdLookUp(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
20 private NodeIdLookUp(bindings.LDKNodeIdLookUp arg) {
21 super(bindings.LDKNodeIdLookUp_new(arg));
22 this.ptrs_to.add(arg);
23 this.bindings_instance = arg;
25 @Override @SuppressWarnings("deprecation")
26 protected void finalize() throws Throwable {
27 if (ptr != 0) { bindings.NodeIdLookUp_free(ptr); } super.finalize();
30 * Destroys the object, freeing associated resources. After this call, any access
31 * to this object may result in a SEGFAULT or worse.
33 * You should generally NEVER call this method. You should let the garbage collector
34 * do this for you when it finalizes objects. However, it may be useful for types
35 * which represent locks and should be closed immediately to avoid holding locks
38 public void destroy() {
39 if (ptr != 0) { bindings.NodeIdLookUp_free(ptr); }
42 public static interface NodeIdLookUpInterface {
44 * Returns the node id of the forwarding node's channel counterparty with `short_channel_id`.
46 * Here, the forwarding node is referring to the node of the [`OnionMessenger`] parameterized
47 * by the [`NodeIdLookUp`] and the counterparty to one of that node's peers.
49 * [`OnionMessenger`]: crate::onion_message::messenger::OnionMessenger
51 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
53 byte[] next_node_id(long short_channel_id);
55 private static class LDKNodeIdLookUpHolder { NodeIdLookUp held; }
56 public static NodeIdLookUp new_impl(NodeIdLookUpInterface arg) {
57 final LDKNodeIdLookUpHolder impl_holder = new LDKNodeIdLookUpHolder();
58 impl_holder.held = new NodeIdLookUp(new bindings.LDKNodeIdLookUp() {
59 @Override public byte[] next_node_id(long short_channel_id) {
60 byte[] ret = arg.next_node_id(short_channel_id);
61 Reference.reachabilityFence(arg);
62 byte[] result = InternalUtils.check_arr_len(ret, 33);
66 return impl_holder.held;
69 * Returns the node id of the forwarding node's channel counterparty with `short_channel_id`.
71 * Here, the forwarding node is referring to the node of the [`OnionMessenger`] parameterized
72 * by the [`NodeIdLookUp`] and the counterparty to one of that node's peers.
74 * [`OnionMessenger`]: crate::onion_message::messenger::OnionMessenger
76 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
79 public byte[] next_node_id(long short_channel_id) {
80 byte[] ret = bindings.NodeIdLookUp_next_node_id(this.ptr, short_channel_id);
81 Reference.reachabilityFence(this);
82 Reference.reachabilityFence(short_channel_id);