X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FNetGraphMsgHandler.java;h=2236f5bc0128d16bf803bef169e9e770df6f444a;hb=1854b5cebef22ace9e9e4dd191f609818df9ce08;hp=977e197a0e56dc545043f297288355cb5917825d;hpb=b6cc0960eaee5a5bbc7fde79a56152d6dcd649d8;p=ldk-java diff --git a/src/main/java/org/ldk/structs/NetGraphMsgHandler.java b/src/main/java/org/ldk/structs/NetGraphMsgHandler.java index 977e197a..2236f5bc 100644 --- a/src/main/java/org/ldk/structs/NetGraphMsgHandler.java +++ b/src/main/java/org/ldk/structs/NetGraphMsgHandler.java @@ -4,6 +4,8 @@ import org.ldk.impl.bindings; import org.ldk.enums.*; import org.ldk.util.*; import java.util.Arrays; +import java.lang.ref.Reference; +import javax.annotation.Nullable; /** @@ -12,6 +14,9 @@ import java.util.Arrays; * This network graph is then used for routing payments. * Provides interface to help with initial routing sync by * serving historical announcements. + * + * Serves as an [`EventHandler`] for applying updates from [`Event::PaymentPathFailed`] to the + * [`NetworkGraph`]. */ @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class NetGraphMsgHandler extends CommonBase { @@ -23,32 +28,36 @@ public class NetGraphMsgHandler extends CommonBase { } /** - * Creates a new tracker of the actual state of the network of channels and nodes, - * assuming a fresh network graph. - * Chain monitor is used to make sure announced channels exist on-chain, - * channel data is correct, and that the announcement is signed with - * channel owners' keys. + * Constructs a new EventHandler which calls the relevant methods on this_arg. + * This copies the `inner` pointer in this_arg and thus the returned EventHandler must be freed before this_arg is */ - public static NetGraphMsgHandler of(byte[] genesis_hash, Access chain_access, Logger logger) { - long ret = bindings.NetGraphMsgHandler_new(genesis_hash, chain_access == null ? 0 : chain_access.ptr, logger == null ? 0 : logger.ptr); - NetGraphMsgHandler ret_hu_conv = new NetGraphMsgHandler(null, ret); - ret_hu_conv.ptrs_to.add(ret_hu_conv); - ret_hu_conv.ptrs_to.add(chain_access); - ret_hu_conv.ptrs_to.add(logger); + public EventHandler as_EventHandler() { + long ret = bindings.NetGraphMsgHandler_as_EventHandler(this.ptr); + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } + EventHandler ret_hu_conv = new EventHandler(null, ret); + ret_hu_conv.ptrs_to.add(this); return ret_hu_conv; } /** * Creates a new tracker of the actual state of the network of channels and nodes, * assuming an existing Network Graph. + * Chain monitor is used to make sure announced channels exist on-chain, + * channel data is correct, and that the announcement is signed with + * channel owners' keys. */ - public static NetGraphMsgHandler from_net_graph(Access chain_access, Logger logger, NetworkGraph network_graph) { - 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); - NetGraphMsgHandler ret_hu_conv = new NetGraphMsgHandler(null, ret); + public static NetGraphMsgHandler of(NetworkGraph network_graph, Option_AccessZ chain_access, Logger logger) { + long ret = bindings.NetGraphMsgHandler_new(network_graph == null ? 0 : network_graph.ptr & ~1, chain_access.ptr, logger == null ? 0 : logger.ptr); + Reference.reachabilityFence(network_graph); + Reference.reachabilityFence(chain_access); + Reference.reachabilityFence(logger); + if (ret >= 0 && ret <= 4096) { return null; } + NetGraphMsgHandler ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new NetGraphMsgHandler(null, ret); } ret_hu_conv.ptrs_to.add(ret_hu_conv); + ret_hu_conv.ptrs_to.add(network_graph); ret_hu_conv.ptrs_to.add(chain_access); ret_hu_conv.ptrs_to.add(logger); - ret_hu_conv.ptrs_to.add(network_graph); return ret_hu_conv; } @@ -57,30 +66,21 @@ public class NetGraphMsgHandler extends CommonBase { * existing announcements unless they are updated. * Add, update or remove the provider would replace the current one. */ - public void add_chain_access(Access chain_access) { - bindings.NetGraphMsgHandler_add_chain_access(this.ptr, chain_access == null ? 0 : chain_access.ptr); + public void add_chain_access(Option_AccessZ chain_access) { + bindings.NetGraphMsgHandler_add_chain_access(this.ptr, chain_access.ptr); + Reference.reachabilityFence(this); + Reference.reachabilityFence(chain_access); this.ptrs_to.add(chain_access); } - /** - * Take a read lock on the network_graph and return it in the C-bindings - * newtype helper. This is likely only useful when called via the C - * bindings as you can call `self.network_graph.read().unwrap()` in Rust - * yourself. - */ - public LockedNetworkGraph read_locked_graph() { - long ret = bindings.NetGraphMsgHandler_read_locked_graph(this.ptr); - LockedNetworkGraph ret_hu_conv = new LockedNetworkGraph(null, ret); - ret_hu_conv.ptrs_to.add(this); - return ret_hu_conv; - } - /** * Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg. * This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is */ public RoutingMessageHandler as_RoutingMessageHandler() { long ret = bindings.NetGraphMsgHandler_as_RoutingMessageHandler(this.ptr); + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } RoutingMessageHandler ret_hu_conv = new RoutingMessageHandler(null, ret); ret_hu_conv.ptrs_to.add(this); return ret_hu_conv; @@ -92,6 +92,8 @@ public class NetGraphMsgHandler extends CommonBase { */ public MessageSendEventsProvider as_MessageSendEventsProvider() { long ret = bindings.NetGraphMsgHandler_as_MessageSendEventsProvider(this.ptr); + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } MessageSendEventsProvider ret_hu_conv = new MessageSendEventsProvider(null, ret); ret_hu_conv.ptrs_to.add(this); return ret_hu_conv;