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;
12 * Receives and validates network updates from peers,
13 * stores authentic and relevant data as a network graph.
14 * This network graph is then used for routing payments.
15 * Provides interface to help with initial routing sync by
16 * serving historical announcements.
18 * Serves as an [`EventHandler`] for applying updates from [`Event::PaymentPathFailed`] to the
21 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
22 public class NetGraphMsgHandler extends CommonBase {
23 NetGraphMsgHandler(Object _dummy, long ptr) { super(ptr); }
24 @Override @SuppressWarnings("deprecation")
25 protected void finalize() throws Throwable {
27 if (ptr != 0) { bindings.NetGraphMsgHandler_free(ptr); }
31 * Constructs a new EventHandler which calls the relevant methods on this_arg.
32 * This copies the `inner` pointer in this_arg and thus the returned EventHandler must be freed before this_arg is
34 public EventHandler as_EventHandler() {
35 long ret = bindings.NetGraphMsgHandler_as_EventHandler(this.ptr);
36 Reference.reachabilityFence(this);
37 if (ret >= 0 && ret <= 4096) { return null; }
38 EventHandler ret_hu_conv = new EventHandler(null, ret);
39 ret_hu_conv.ptrs_to.add(this);
44 * Creates a new tracker of the actual state of the network of channels and nodes,
45 * assuming an existing Network Graph.
46 * Chain monitor is used to make sure announced channels exist on-chain,
47 * channel data is correct, and that the announcement is signed with
48 * channel owners' keys.
50 public static NetGraphMsgHandler of(NetworkGraph network_graph, Option_AccessZ chain_access, Logger logger) {
51 long ret = bindings.NetGraphMsgHandler_new(network_graph == null ? 0 : network_graph.ptr & ~1, chain_access.ptr, logger == null ? 0 : logger.ptr);
52 Reference.reachabilityFence(network_graph);
53 Reference.reachabilityFence(chain_access);
54 Reference.reachabilityFence(logger);
55 if (ret >= 0 && ret <= 4096) { return null; }
56 NetGraphMsgHandler ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new NetGraphMsgHandler(null, ret); }
57 ret_hu_conv.ptrs_to.add(ret_hu_conv);
58 ret_hu_conv.ptrs_to.add(network_graph);
59 ret_hu_conv.ptrs_to.add(chain_access);
60 ret_hu_conv.ptrs_to.add(logger);
65 * Adds a provider used to check new announcements. Does not affect
66 * existing announcements unless they are updated.
67 * Add, update or remove the provider would replace the current one.
69 public void add_chain_access(Option_AccessZ chain_access) {
70 bindings.NetGraphMsgHandler_add_chain_access(this.ptr, chain_access.ptr);
71 Reference.reachabilityFence(this);
72 Reference.reachabilityFence(chain_access);
73 this.ptrs_to.add(chain_access);
77 * Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg.
78 * This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is
80 public RoutingMessageHandler as_RoutingMessageHandler() {
81 long ret = bindings.NetGraphMsgHandler_as_RoutingMessageHandler(this.ptr);
82 Reference.reachabilityFence(this);
83 if (ret >= 0 && ret <= 4096) { return null; }
84 RoutingMessageHandler ret_hu_conv = new RoutingMessageHandler(null, ret);
85 ret_hu_conv.ptrs_to.add(this);
90 * Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
91 * This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
93 public MessageSendEventsProvider as_MessageSendEventsProvider() {
94 long ret = bindings.NetGraphMsgHandler_as_MessageSendEventsProvider(this.ptr);
95 Reference.reachabilityFence(this);
96 if (ret >= 0 && ret <= 4096) { return null; }
97 MessageSendEventsProvider ret_hu_conv = new MessageSendEventsProvider(null, ret);
98 ret_hu_conv.ptrs_to.add(this);