0e4f8ed2c6db99a415e7eef73a55e2b18889c48e
[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 Network Graph.
30          * Chain monitor is used to make sure announced channels exist on-chain,
31          * channel data is correct, and that the announcement is signed with
32          * channel owners' keys.
33          */
34         public static P2PGossipSync of(org.ldk.structs.NetworkGraph network_graph, org.ldk.structs.Option_AccessZ chain_access, org.ldk.structs.Logger logger) {
35                 long ret = bindings.P2PGossipSync_new(network_graph == null ? 0 : network_graph.ptr, chain_access.ptr, logger == null ? 0 : logger.ptr);
36                 Reference.reachabilityFence(network_graph);
37                 Reference.reachabilityFence(chain_access);
38                 Reference.reachabilityFence(logger);
39                 if (ret >= 0 && ret <= 4096) { return null; }
40                 org.ldk.structs.P2PGossipSync ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.P2PGossipSync(null, ret); }
41                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
42                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(network_graph); };
43                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(chain_access); };
44                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); };
45                 return ret_hu_conv;
46         }
47
48         /**
49          * Adds a provider used to check new announcements. Does not affect
50          * existing announcements unless they are updated.
51          * Add, update or remove the provider would replace the current one.
52          */
53         public void add_chain_access(org.ldk.structs.Option_AccessZ chain_access) {
54                 bindings.P2PGossipSync_add_chain_access(this.ptr, chain_access.ptr);
55                 Reference.reachabilityFence(this);
56                 Reference.reachabilityFence(chain_access);
57                 if (this != null) { this.ptrs_to.add(chain_access); };
58         }
59
60         /**
61          * Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg.
62          * This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is
63          */
64         public RoutingMessageHandler as_RoutingMessageHandler() {
65                 long ret = bindings.P2PGossipSync_as_RoutingMessageHandler(this.ptr);
66                 Reference.reachabilityFence(this);
67                 if (ret >= 0 && ret <= 4096) { return null; }
68                 RoutingMessageHandler ret_hu_conv = new RoutingMessageHandler(null, ret);
69                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
70                 return ret_hu_conv;
71         }
72
73         /**
74          * Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
75          * This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
76          */
77         public MessageSendEventsProvider as_MessageSendEventsProvider() {
78                 long ret = bindings.P2PGossipSync_as_MessageSendEventsProvider(this.ptr);
79                 Reference.reachabilityFence(this);
80                 if (ret >= 0 && ret <= 4096) { return null; }
81                 MessageSendEventsProvider ret_hu_conv = new MessageSendEventsProvider(null, ret);
82                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
83                 return ret_hu_conv;
84         }
85
86 }