* 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 {
/**
* 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;
KeysInterface keys_interface, FeeEstimator fee_estimator, ChainMonitor chain_monitor,
@Nullable Filter filter, @Nullable byte[] net_graph_serialized,
BroadcasterInterface tx_broadcaster, Logger logger) throws InvalidSerializedDataException {
- final IgnoringMessageHandler no_custom_messages = IgnoringMessageHandler.of();
+ final IgnoringMessageHandler ignoring_handler = IgnoringMessageHandler.of();
final ChannelMonitor[] monitors = new ChannelMonitor[channel_monitors_serialized.length];
this.channel_monitors = new TwoTuple_BlockHashChannelMonitorZ[monitors.length];
HashSet<OutPoint> monitor_funding_set = new HashSet();
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");
}
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(),
+ ignoring_handler.as_OnionMessageHandler(),
((Result_SecretKeyNoneZ.Result_SecretKeyNoneZ_OK)node_secret).res,
- random_data, logger, no_custom_messages.as_CustomMessageHandler());
+ System.currentTimeMillis() / 1000,
+ random_data, logger, ignoring_handler.as_CustomMessageHandler());
} else {
this.graph_msg_handler = null;
- this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(), no_custom_messages.as_RoutingMessageHandler(),
+ this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(),
+ ignoring_handler.as_RoutingMessageHandler(),
+ ignoring_handler.as_OnionMessageHandler(),
((Result_SecretKeyNoneZ.Result_SecretKeyNoneZ_OK)node_secret).res,
- random_data, logger, no_custom_messages.as_CustomMessageHandler());
+ System.currentTimeMillis() / 1000,
+ random_data, logger, ignoring_handler.as_CustomMessageHandler());
}
NioPeerHandler nio_peer_handler = null;
try {
KeysInterface keys_interface, FeeEstimator fee_estimator, ChainMonitor chain_monitor,
@Nullable NetworkGraph net_graph,
BroadcasterInterface tx_broadcaster, Logger logger) {
- final IgnoringMessageHandler no_custom_messages = IgnoringMessageHandler.of();
+ final IgnoringMessageHandler ignoring_handler = IgnoringMessageHandler.of();
channel_monitors = new TwoTuple_BlockHashChannelMonitorZ[0];
channel_manager_latest_block_hash = null;
this.chain_monitor = chain_monitor;
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(),
+ ignoring_handler.as_OnionMessageHandler(),
((Result_SecretKeyNoneZ.Result_SecretKeyNoneZ_OK)node_secret).res,
- random_data, logger, no_custom_messages.as_CustomMessageHandler());
+ System.currentTimeMillis() / 1000,
+ random_data, logger, ignoring_handler.as_CustomMessageHandler());
} else {
this.graph_msg_handler = null;
- this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(), no_custom_messages.as_RoutingMessageHandler(),
+ this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(),
+ ignoring_handler.as_RoutingMessageHandler(),
+ ignoring_handler.as_OnionMessageHandler(),
((Result_SecretKeyNoneZ.Result_SecretKeyNoneZ_OK)node_secret).res,
- random_data, logger, no_custom_messages.as_CustomMessageHandler());
+ System.currentTimeMillis() / 1000,
+ random_data, logger, ignoring_handler.as_CustomMessageHandler());
}
NioPeerHandler nio_peer_handler = null;
try {
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;
}
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));
-assert this.payer != null;
+ Router router = DefaultRouter.of(net_graph, logger, router_rand_bytes, scorer.as_LockableScore()).as_Router();
+ this.payer = InvoicePayer.of(this.channel_manager.as_Payer(), router, this.logger, ldk_handler, Retry.attempts(3));
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);
+
+ Option_WriteableScoreZ writeable_score;
+ if (scorer != null)
+ writeable_score = Option_WriteableScoreZ.some(scorer.as_WriteableScore());
+ else
+ writeable_score = Option_WriteableScoreZ.none();
+
background_processor = BackgroundProcessor.start(Persister.new_impl(new Persister.PersisterInterface() {
@Override
public Result_NoneErrorZ persist_manager(ChannelManager channel_manager) {
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(WriteableScore 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, writeable_score);
}
/**