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 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
19 public class P2PGossipSync extends CommonBase {
20 P2PGossipSync(Object _dummy, long ptr) { super(ptr); }
21 @Override @SuppressWarnings("deprecation")
22 protected void finalize() throws Throwable {
24 if (ptr != 0) { bindings.P2PGossipSync_free(ptr); }
28 * Creates a new tracker of the actual state of the network of channels and nodes,
29 * assuming an existing [`NetworkGraph`].
30 * UTXO lookup is used to make sure announced channels exist on-chain, channel data is
31 * correct, and the announcement is signed with channel owners' keys.
33 public static P2PGossipSync of(org.ldk.structs.NetworkGraph network_graph, org.ldk.structs.Option_UtxoLookupZ utxo_lookup, org.ldk.structs.Logger logger) {
34 long ret = bindings.P2PGossipSync_new(network_graph == null ? 0 : network_graph.ptr, utxo_lookup.ptr, logger.ptr);
35 Reference.reachabilityFence(network_graph);
36 Reference.reachabilityFence(utxo_lookup);
37 Reference.reachabilityFence(logger);
38 if (ret >= 0 && ret <= 4096) { return null; }
39 org.ldk.structs.P2PGossipSync ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.P2PGossipSync(null, ret); }
40 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
41 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(network_graph); };
42 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(utxo_lookup); };
43 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); };
48 * Adds a provider used to check new announcements. Does not affect
49 * existing announcements unless they are updated.
50 * Add, update or remove the provider would replace the current one.
52 public void add_utxo_lookup(org.ldk.structs.Option_UtxoLookupZ utxo_lookup) {
53 bindings.P2PGossipSync_add_utxo_lookup(this.ptr, utxo_lookup.ptr);
54 Reference.reachabilityFence(this);
55 Reference.reachabilityFence(utxo_lookup);
56 if (this != null) { this.ptrs_to.add(utxo_lookup); };
60 * Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg.
61 * This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is
63 public RoutingMessageHandler as_RoutingMessageHandler() {
64 long ret = bindings.P2PGossipSync_as_RoutingMessageHandler(this.ptr);
65 Reference.reachabilityFence(this);
66 if (ret >= 0 && ret <= 4096) { return null; }
67 RoutingMessageHandler ret_hu_conv = new RoutingMessageHandler(null, ret);
68 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
73 * Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
74 * This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
76 public MessageSendEventsProvider as_MessageSendEventsProvider() {
77 long ret = bindings.P2PGossipSync_as_MessageSendEventsProvider(this.ptr);
78 Reference.reachabilityFence(this);
79 if (ret >= 0 && ret <= 4096) { return null; }
80 MessageSendEventsProvider ret_hu_conv = new MessageSendEventsProvider(null, ret);
81 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };