1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
11 * Receives and validates network updates from peers,
12 * stores authentic and relevant data as a network graph.
13 * This network graph is then used for routing payments.
14 * Provides interface to help with initial routing sync by
15 * serving historical announcements.
17 * Serves as an [`EventHandler`] for applying updates from [`Event::PaymentPathFailed`] to the
20 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
21 public class NetGraphMsgHandler extends CommonBase {
22 NetGraphMsgHandler(Object _dummy, long ptr) { super(ptr); }
23 @Override @SuppressWarnings("deprecation")
24 protected void finalize() throws Throwable {
26 if (ptr != 0) { bindings.NetGraphMsgHandler_free(ptr); }
30 * Constructs a new EventHandler which calls the relevant methods on this_arg.
31 * This copies the `inner` pointer in this_arg and thus the returned EventHandler must be freed before this_arg is
33 public EventHandler as_EventHandler() {
34 long ret = bindings.NetGraphMsgHandler_as_EventHandler(this.ptr);
35 if (ret >= 0 && ret <= 4096) { return null; }
36 EventHandler ret_hu_conv = new EventHandler(null, ret);
37 ret_hu_conv.ptrs_to.add(this);
42 * Creates a new tracker of the actual state of the network of channels and nodes,
43 * assuming an existing Network Graph.
44 * Chain monitor is used to make sure announced channels exist on-chain,
45 * channel data is correct, and that the announcement is signed with
46 * channel owners' keys.
48 public static NetGraphMsgHandler of(NetworkGraph network_graph, Option_AccessZ chain_access, Logger logger) {
49 long ret = bindings.NetGraphMsgHandler_new(network_graph == null ? 0 : network_graph.ptr & ~1, chain_access.ptr, logger == null ? 0 : logger.ptr);
50 if (ret >= 0 && ret <= 4096) { return null; }
51 NetGraphMsgHandler ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new NetGraphMsgHandler(null, ret); }
52 ret_hu_conv.ptrs_to.add(ret_hu_conv);
53 ret_hu_conv.ptrs_to.add(network_graph);
54 ret_hu_conv.ptrs_to.add(logger);
59 * Adds a provider used to check new announcements. Does not affect
60 * existing announcements unless they are updated.
61 * Add, update or remove the provider would replace the current one.
63 public void add_chain_access(Option_AccessZ chain_access) {
64 bindings.NetGraphMsgHandler_add_chain_access(this.ptr, chain_access.ptr);
68 * Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg.
69 * This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is
71 public RoutingMessageHandler as_RoutingMessageHandler() {
72 long ret = bindings.NetGraphMsgHandler_as_RoutingMessageHandler(this.ptr);
73 if (ret >= 0 && ret <= 4096) { return null; }
74 RoutingMessageHandler ret_hu_conv = new RoutingMessageHandler(null, ret);
75 ret_hu_conv.ptrs_to.add(this);
80 * Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
81 * This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
83 public MessageSendEventsProvider as_MessageSendEventsProvider() {
84 long ret = bindings.NetGraphMsgHandler_as_MessageSendEventsProvider(this.ptr);
85 if (ret >= 0 && ret <= 4096) { return null; }
86 MessageSendEventsProvider ret_hu_conv = new MessageSendEventsProvider(null, ret);
87 ret_hu_conv.ptrs_to.add(this);