+ org.ldk.structs.EventHandler ldk_handler = org.ldk.structs.EventHandler.new_impl(event_handler::handle_event);
+
+ final IgnoringMessageHandler ignoring_handler = IgnoringMessageHandler.of();
+ P2PGossipSync graph_msg_handler = P2PGossipSync.of(net_graph, Option_UtxoLookupZ.none(), logger);
+ RoutingMessageHandler routing_msg_handler;
+ if (use_p2p_graph_sync)
+ routing_msg_handler = graph_msg_handler.as_RoutingMessageHandler();
+ else
+ routing_msg_handler = ignoring_handler.as_RoutingMessageHandler();
+ this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(),
+ routing_msg_handler, ignoring_handler.as_OnionMessageHandler(),
+ ignoring_handler.as_CustomMessageHandler(), (int)(System.currentTimeMillis() / 1000),
+ this.entropy_source.get_secure_random_bytes(), logger, this.node_signer);
+
+ try {
+ this.nio_peer_handler = new NioPeerHandler(peer_manager);
+ } catch (IOException e) {
+ throw new IllegalStateException("We should never fail to construct nio objects unless we're on a platform that cannot run LDK.");
+ }
+
+ GossipSync gossip_sync;
+ if (use_p2p_graph_sync)
+ gossip_sync = GossipSync.p2_p(graph_msg_handler);
+ else
+ gossip_sync = GossipSync.none();
+
+ Option_WriteableScoreZ writeable_score = Option_WriteableScoreZ.some(scorer.as_WriteableScore());
+
+ background_processor = BackgroundProcessor.start(Persister.new_impl(new Persister.PersisterInterface() {
+ @Override
+ public Result_NoneErrorZ persist_manager(ChannelManager channel_manager) {
+ event_handler.persist_manager(channel_manager.write());
+ return Result_NoneErrorZ.ok();
+ }
+
+ @Override
+ public Result_NoneErrorZ persist_graph(NetworkGraph network_graph) {
+ event_handler.persist_network_graph(network_graph.write());
+ return Result_NoneErrorZ.ok();
+ }
+
+ @Override
+ public Result_NoneErrorZ persist_scorer(WriteableScore scorer) {
+ event_handler.persist_scorer(scorer.write());
+ return Result_NoneErrorZ.ok();
+ }
+ }), ldk_handler, this.chain_monitor, this.channel_manager, gossip_sync, peer_manager, this.logger, writeable_score);
+ }
+
+ /**
+ * Interrupt the background thread, stopping the background handling of events.
+ */
+ public void interrupt() {
+ if (this.nio_peer_handler != null)
+ this.nio_peer_handler.interrupt();
+ this.background_processor.stop();