57544fdc719fac09cf70c9013c7b535c378632cf
[ldk-java] / src / main / java / org / ldk / structs / P2PGossipSync.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
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.
17  */
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 {
23                 super.finalize();
24                 if (ptr != 0) { bindings.P2PGossipSync_free(ptr); }
25         }
26
27         /**
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.
32          */
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); };
44                 return ret_hu_conv;
45         }
46
47         /**
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.
51          */
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); };
57         }
58
59         /**
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
62          */
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); };
69                 return ret_hu_conv;
70         }
71
72         /**
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
75          */
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); };
82                 return ret_hu_conv;
83         }
84
85 }