X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FNetGraphMsgHandler.java;h=debc8fe4bea2b512c6fdf334d4723b7f6e39c975;hb=c6bac88847b7c09560af81f00ba8dd3c2ebe3a19;hp=2351063e62e0c262c7c52b835d8ef14b2aa32e3e;hpb=fed2245c60159f6c074c9ed5c0f3ce273ad9841b;p=ldk-java diff --git a/src/main/java/org/ldk/structs/NetGraphMsgHandler.java b/src/main/java/org/ldk/structs/NetGraphMsgHandler.java index 2351063e..debc8fe4 100644 --- a/src/main/java/org/ldk/structs/NetGraphMsgHandler.java +++ b/src/main/java/org/ldk/structs/NetGraphMsgHandler.java @@ -4,7 +4,19 @@ import org.ldk.impl.bindings; import org.ldk.enums.*; import org.ldk.util.*; import java.util.Arrays; +import javax.annotation.Nullable; + +/** + * Receives and validates network updates from peers, + * stores authentic and relevant data as a network graph. + * 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 { NetGraphMsgHandler(Object _dummy, long ptr) { super(ptr); } @@ -14,40 +26,63 @@ public class NetGraphMsgHandler extends CommonBase { if (ptr != 0) { bindings.NetGraphMsgHandler_free(ptr); } } - public static NetGraphMsgHandler constructor_new(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); + /** + * 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 EventHandler as_EventHandler() { + long ret = bindings.NetGraphMsgHandler_as_EventHandler(this.ptr); + 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; } - public static NetGraphMsgHandler constructor_from_net_graph(Access chain_access, Logger logger, byte[] network_graph_genesis_hash) { - long ret = bindings.NetGraphMsgHandler_from_net_graph(chain_access == null ? 0 : chain_access.ptr, logger == null ? 0 : logger.ptr, bindings.NetworkGraph_new(network_graph_genesis_hash)); - NetGraphMsgHandler ret_hu_conv = new NetGraphMsgHandler(null, ret); + /** + * 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 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); + 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(chain_access); + ret_hu_conv.ptrs_to.add(network_graph); ret_hu_conv.ptrs_to.add(logger); return ret_hu_conv; } - 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; + /** + * Adds a provider used to check new announcements. Does not affect + * existing announcements unless they are updated. + * Add, update or remove the provider would replace the current one. + */ + public void add_chain_access(Option_AccessZ chain_access) { + bindings.NetGraphMsgHandler_add_chain_access(this.ptr, chain_access.ptr); } + /** + * 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); + 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; } + /** + * Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg. + * This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is + */ public MessageSendEventsProvider as_MessageSendEventsProvider() { long ret = bindings.NetGraphMsgHandler_as_MessageSendEventsProvider(this.ptr); + 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;