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 P2PGossipSync extends CommonBase {
23 P2PGossipSync(Object _dummy, long ptr) { super(ptr); }
24 @Override @SuppressWarnings("deprecation")
25 protected void finalize() throws Throwable {
27 if (ptr != 0) { bindings.P2PGossipSync_free(ptr); }
31 * Creates a new tracker of the actual state of the network of channels and nodes,
32 * assuming an existing Network Graph.
33 * Chain monitor is used to make sure announced channels exist on-chain,
34 * channel data is correct, and that the announcement is signed with
35 * channel owners' keys.
37 public static P2PGossipSync of(NetworkGraph network_graph, Option_AccessZ chain_access, Logger logger) {
38 long ret = bindings.P2PGossipSync_new(network_graph == null ? 0 : network_graph.ptr & ~1, chain_access.ptr, logger == null ? 0 : logger.ptr);
39 Reference.reachabilityFence(network_graph);
40 Reference.reachabilityFence(chain_access);
41 Reference.reachabilityFence(logger);
42 if (ret >= 0 && ret <= 4096) { return null; }
43 org.ldk.structs.P2PGossipSync ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.P2PGossipSync(null, ret); }
44 ret_hu_conv.ptrs_to.add(ret_hu_conv);
45 ret_hu_conv.ptrs_to.add(network_graph);
46 ret_hu_conv.ptrs_to.add(chain_access);
47 ret_hu_conv.ptrs_to.add(logger);
52 * Adds a provider used to check new announcements. Does not affect
53 * existing announcements unless they are updated.
54 * Add, update or remove the provider would replace the current one.
56 public void add_chain_access(Option_AccessZ chain_access) {
57 bindings.P2PGossipSync_add_chain_access(this.ptr, chain_access.ptr);
58 Reference.reachabilityFence(this);
59 Reference.reachabilityFence(chain_access);
60 this.ptrs_to.add(chain_access);
64 * Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg.
65 * This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is
67 public RoutingMessageHandler as_RoutingMessageHandler() {
68 long ret = bindings.P2PGossipSync_as_RoutingMessageHandler(this.ptr);
69 Reference.reachabilityFence(this);
70 if (ret >= 0 && ret <= 4096) { return null; }
71 RoutingMessageHandler ret_hu_conv = new RoutingMessageHandler(null, ret);
72 ret_hu_conv.ptrs_to.add(this);
77 * Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
78 * This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
80 public MessageSendEventsProvider as_MessageSendEventsProvider() {
81 long ret = bindings.P2PGossipSync_as_MessageSendEventsProvider(this.ptr);
82 Reference.reachabilityFence(this);
83 if (ret >= 0 && ret <= 4096) { return null; }
84 MessageSendEventsProvider ret_hu_conv = new MessageSendEventsProvider(null, ret);
85 ret_hu_conv.ptrs_to.add(this);