1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
10 * Receives and validates network updates from peers,
11 * stores authentic and relevant data as a network graph.
12 * This network graph is then used for routing payments.
13 * Provides interface to help with initial routing sync by
14 * serving historical announcements.
16 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
17 public class NetGraphMsgHandler extends CommonBase {
18 NetGraphMsgHandler(Object _dummy, long ptr) { super(ptr); }
19 @Override @SuppressWarnings("deprecation")
20 protected void finalize() throws Throwable {
22 if (ptr != 0) { bindings.NetGraphMsgHandler_free(ptr); }
26 * Creates a new tracker of the actual state of the network of channels and nodes,
27 * assuming a fresh network graph.
28 * Chain monitor is used to make sure announced channels exist on-chain,
29 * channel data is correct, and that the announcement is signed with
30 * channel owners' keys.
32 public static NetGraphMsgHandler constructor_new(byte[] genesis_hash, Access chain_access, Logger logger) {
33 long ret = bindings.NetGraphMsgHandler_new(genesis_hash, chain_access == null ? 0 : chain_access.ptr, logger == null ? 0 : logger.ptr);
34 NetGraphMsgHandler ret_hu_conv = new NetGraphMsgHandler(null, ret);
35 ret_hu_conv.ptrs_to.add(ret_hu_conv);
36 ret_hu_conv.ptrs_to.add(chain_access);
37 ret_hu_conv.ptrs_to.add(logger);
42 * Creates a new tracker of the actual state of the network of channels and nodes,
43 * assuming an existing Network Graph.
45 public static NetGraphMsgHandler constructor_from_net_graph(Access chain_access, Logger logger, NetworkGraph network_graph) {
46 long ret = bindings.NetGraphMsgHandler_from_net_graph(chain_access == null ? 0 : chain_access.ptr, logger == null ? 0 : logger.ptr, network_graph == null ? 0 : network_graph.ptr & ~1);
47 NetGraphMsgHandler ret_hu_conv = new NetGraphMsgHandler(null, ret);
48 ret_hu_conv.ptrs_to.add(ret_hu_conv);
49 ret_hu_conv.ptrs_to.add(chain_access);
50 ret_hu_conv.ptrs_to.add(logger);
51 ret_hu_conv.ptrs_to.add(network_graph);
56 * Adds a provider used to check new announcements. Does not affect
57 * existing announcements unless they are updated.
58 * Add, update or remove the provider would replace the current one.
60 public void add_chain_access(Access chain_access) {
61 bindings.NetGraphMsgHandler_add_chain_access(this.ptr, chain_access == null ? 0 : chain_access.ptr);
62 this.ptrs_to.add(chain_access);
66 * Take a read lock on the network_graph and return it in the C-bindings
67 * newtype helper. This is likely only useful when called via the C
68 * bindings as you can call `self.network_graph.read().unwrap()` in Rust
71 public LockedNetworkGraph read_locked_graph() {
72 long ret = bindings.NetGraphMsgHandler_read_locked_graph(this.ptr);
73 LockedNetworkGraph ret_hu_conv = new LockedNetworkGraph(null, ret);
74 ret_hu_conv.ptrs_to.add(this);
79 * Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg.
80 * This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is
82 public RoutingMessageHandler as_RoutingMessageHandler() {
83 long ret = bindings.NetGraphMsgHandler_as_RoutingMessageHandler(this.ptr);
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 MessageSendEventsProvider ret_hu_conv = new MessageSendEventsProvider(null, ret);
96 ret_hu_conv.ptrs_to.add(this);