X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fbatteries%2FChannelManagerConstructor.java;h=109acbe39f505afa9cf1c272a9ef08b4e039511b;hb=13cdf8bde340072288b39a5e29f0946d3e095ad4;hp=122fcff8b45ba9e21f07ff6a7d9f07ed7a9234f3;hpb=1ef2dc8b8a3e0e244ad82ac08e286df489eca4b7;p=ldk-java diff --git a/src/main/java/org/ldk/batteries/ChannelManagerConstructor.java b/src/main/java/org/ldk/batteries/ChannelManagerConstructor.java index 122fcff8..109acbe3 100644 --- a/src/main/java/org/ldk/batteries/ChannelManagerConstructor.java +++ b/src/main/java/org/ldk/batteries/ChannelManagerConstructor.java @@ -14,6 +14,10 @@ import java.util.HashSet; * more ChannelMonitors. * * Also constructs a PeerManager and spawns a background thread to monitor for and notify you of relevant Events. + * + * Note that you must ensure you hold a reference to any constructed ChannelManagerConstructor objects to ensure you + * continue to receive events generated by the background thread which will be stopped if this object is garbage + * collected. */ public class ChannelManagerConstructor { /** @@ -68,7 +72,7 @@ public class ChannelManagerConstructor { * given explicitly to the new-object constructor. */ @Nullable public final NetworkGraph net_graph; - @Nullable private final NetGraphMsgHandler graph_msg_handler; + @Nullable private final P2PGossipSync graph_msg_handler; private final Logger logger; private final byte[] router_rand_bytes; @@ -111,7 +115,7 @@ public class ChannelManagerConstructor { this.logger = logger; byte[] random_data = keys_interface.get_secure_random_bytes(); if (net_graph_serialized != null) { - Result_NetworkGraphDecodeErrorZ graph_res = NetworkGraph.read(net_graph_serialized); + Result_NetworkGraphDecodeErrorZ graph_res = NetworkGraph.read(net_graph_serialized, logger); if (!graph_res.is_ok()) { throw new InvalidSerializedDataException("Serialized Network Graph was corrupt"); } @@ -123,7 +127,7 @@ public class ChannelManagerConstructor { assert node_secret.is_ok(); if (net_graph != null) { //TODO: We really need to expose the Access here to let users prevent DoS issues - this.graph_msg_handler = NetGraphMsgHandler.of(net_graph, Option_AccessZ.none(), logger); + this.graph_msg_handler = P2PGossipSync.of(net_graph, Option_AccessZ.none(), logger); this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(), graph_msg_handler.as_RoutingMessageHandler(), ((Result_SecretKeyNoneZ.Result_SecretKeyNoneZ_OK)node_secret).res, @@ -170,7 +174,7 @@ public class ChannelManagerConstructor { assert node_secret.is_ok(); if (net_graph != null) { //TODO: We really need to expose the Access here to let users prevent DoS issues - this.graph_msg_handler = NetGraphMsgHandler.of(net_graph, Option_AccessZ.none(), logger); + this.graph_msg_handler = P2PGossipSync.of(net_graph, Option_AccessZ.none(), logger); this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(), graph_msg_handler.as_RoutingMessageHandler(), ((Result_SecretKeyNoneZ.Result_SecretKeyNoneZ_OK)node_secret).res, @@ -199,6 +203,7 @@ public class ChannelManagerConstructor { void handle_event(Event events); void persist_manager(byte[] channel_manager_bytes); void persist_network_graph(byte[] network_graph); + void persist_scorer(byte[] scorer_bytes); } BackgroundProcessor background_processor = null; @@ -218,11 +223,17 @@ public class ChannelManagerConstructor { org.ldk.structs.EventHandler ldk_handler = org.ldk.structs.EventHandler.new_impl(event_handler::handle_event); if (this.net_graph != null && scorer != null) { Router router = DefaultRouter.of(net_graph, logger, router_rand_bytes).as_Router(); - this.payer = InvoicePayer.of(this.channel_manager.as_Payer(), router, scorer, this.logger, ldk_handler, RetryAttempts.of(3)); + this.payer = InvoicePayer.of(this.channel_manager.as_Payer(), router, scorer, this.logger, ldk_handler, Retry.attempts(3)); assert this.payer != null; ldk_handler = this.payer.as_EventHandler(); } + GossipSync gossip_sync; + if (this.graph_msg_handler == null) + gossip_sync = GossipSync.none(); + else + gossip_sync = GossipSync.p2_p(this.graph_msg_handler); + background_processor = BackgroundProcessor.start(Persister.new_impl(new Persister.PersisterInterface() { @Override public Result_NoneErrorZ persist_manager(ChannelManager channel_manager) { @@ -235,7 +246,13 @@ assert this.payer != null; event_handler.persist_network_graph(network_graph.write()); return Result_NoneErrorZ.ok(); } - }), ldk_handler, this.chain_monitor, this.channel_manager, this.graph_msg_handler, this.peer_manager, this.logger); + + @Override + public Result_NoneErrorZ persist_scorer(MultiThreadedLockableScore scorer) { + event_handler.persist_scorer(scorer.write()); + return Result_NoneErrorZ.ok(); + } + }), ldk_handler, this.chain_monitor, this.channel_manager, gossip_sync, this.peer_manager, this.logger, scorer); } /**