private final Logger logger;
+ public final @Nullable NetGraphMsgHandler router;
+
/**
* Deserializes a channel manager and a set of channel monitors from the given serialized copies and interface implementations
*
KeysInterface keys_interface, FeeEstimator fee_estimator, ChainMonitor chain_monitor, @Nullable Filter filter,
@Nullable NetGraphMsgHandler router,
BroadcasterInterface tx_broadcaster, Logger logger) throws InvalidSerializedDataException {
+ final IgnoringMessageHandler no_custom_messages = IgnoringMessageHandler.of();
final ChannelMonitor[] monitors = new ChannelMonitor[channel_monitors_serialized.length];
this.channel_monitors = new TwoTuple[monitors.length];
for (int i = 0; i < monitors.length; i++) {
this.channel_manager = ((Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK)res).res.b;
this.channel_manager_latest_block_hash = ((Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK)res).res.a;
this.chain_monitor = chain_monitor;
+ this.router = router;
this.logger = logger;
byte[] random_data = keys_interface.get_secure_random_bytes();
if (router != null) {
- this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(), router.as_RoutingMessageHandler(), keys_interface.get_node_secret(), random_data, logger);
+ this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(), router.as_RoutingMessageHandler(),
+ keys_interface.get_node_secret(), random_data, logger, no_custom_messages.as_CustomMessageHandler());
} else {
- this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(), (IgnoringMessageHandler.of()).as_RoutingMessageHandler(), keys_interface.get_node_secret(), random_data, logger);
+ this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(), (IgnoringMessageHandler.of()).as_RoutingMessageHandler(),
+ keys_interface.get_node_secret(), random_data, logger, no_custom_messages.as_CustomMessageHandler());
}
NioPeerHandler nio_peer_handler = null;
try {
KeysInterface keys_interface, FeeEstimator fee_estimator, ChainMonitor chain_monitor,
@Nullable NetGraphMsgHandler router,
BroadcasterInterface tx_broadcaster, Logger logger) {
+ final IgnoringMessageHandler no_custom_messages = IgnoringMessageHandler.of();
channel_monitors = new TwoTuple[0];
channel_manager_latest_block_hash = null;
this.chain_monitor = chain_monitor;
+ this.router = router;
BestBlock block = BestBlock.of(current_blockchain_tip_hash, current_blockchain_tip_height);
ChainParameters params = ChainParameters.of(network, block);
channel_manager = ChannelManager.of(fee_estimator, chain_monitor.as_Watch(), tx_broadcaster, logger, keys_interface, config, params);
this.logger = logger;
byte[] random_data = keys_interface.get_secure_random_bytes();
if (router != null) {
- this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(), router.as_RoutingMessageHandler(), keys_interface.get_node_secret(), random_data, logger);
+ this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(), router.as_RoutingMessageHandler(),
+ keys_interface.get_node_secret(), random_data, logger, no_custom_messages.as_CustomMessageHandler());
} else {
- this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(), (IgnoringMessageHandler.of()).as_RoutingMessageHandler(), keys_interface.get_node_secret(), random_data, logger);
+ this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(), (IgnoringMessageHandler.of()).as_RoutingMessageHandler(),
+ keys_interface.get_node_secret(), random_data, logger, no_custom_messages.as_CustomMessageHandler());
}
NioPeerHandler nio_peer_handler = null;
try {
event_handler.persist_manager(channel_manager.write());
return Result_NoneErrorZ.ok();
}), org.ldk.structs.EventHandler.new_impl(event_handler::handle_event),
- this.chain_monitor, this.channel_manager, this.peer_manager, this.logger);
+ this.chain_monitor, this.channel_manager, this.router, this.peer_manager, this.logger);
}
/**
import org.junit.jupiter.api.Test;
import org.ldk.batteries.ChannelManagerConstructor;
import org.ldk.batteries.NioPeerHandler;
+import org.ldk.enums.AccessError;
import org.ldk.enums.Currency;
import org.ldk.enums.Network;
import org.ldk.structs.*;
Sign underlying_ck = underlying_if.get_channel_signer(inbound, channel_value_satoshis);
BaseSign underlying_base = underlying_ck.get_base_sign();
BaseSign.BaseSignInterface bsi = new BaseSign.BaseSignInterface() {
- @Override
- public byte[] get_per_commitment_point(long idx) {
+ @Override public byte[] get_per_commitment_point(long idx) {
return underlying_base.get_per_commitment_point(idx);
}
-
- @Override
- public byte[] release_commitment_secret(long idx) {
+ @Override public byte[] release_commitment_secret(long idx) {
return underlying_base.release_commitment_secret(idx);
}
-
- @Override
- public byte[] channel_keys_id() {
+ @Override public Result_NoneNoneZ validate_holder_commitment(HolderCommitmentTransaction holder_tx) {
+ return underlying_base.validate_holder_commitment(holder_tx);
+ }
+ @Override public byte[] channel_keys_id() {
return new byte[32];
}
-
- @Override
- public Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment(CommitmentTransaction commitment_tx) {
+ @Override public Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment(CommitmentTransaction commitment_tx) {
return underlying_base.sign_counterparty_commitment(commitment_tx);
}
-
- @Override
- public Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_holder_commitment_and_htlcs(HolderCommitmentTransaction holder_commitment_tx) {
+ @Override public Result_NoneNoneZ validate_counterparty_revocation(long idx, byte[] secret) {
+ return underlying_base.validate_counterparty_revocation(idx, secret);
+ }
+ @Override public Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_holder_commitment_and_htlcs(HolderCommitmentTransaction holder_commitment_tx) {
return underlying_base.sign_holder_commitment_and_htlcs(holder_commitment_tx);
}
-
- @Override
- public Result_SignatureNoneZ sign_justice_revoked_output(byte[] justice_tx, long input, long amount, byte[] per_commitment_key) {
+ @Override public Result_SignatureNoneZ sign_justice_revoked_output(byte[] justice_tx, long input, long amount, byte[] per_commitment_key) {
return underlying_base.sign_justice_revoked_output(justice_tx, input, amount, per_commitment_key);
}
-
- @Override
- public Result_SignatureNoneZ sign_justice_revoked_htlc(byte[] justice_tx, long input, long amount, byte[] per_commitment_key, HTLCOutputInCommitment htlc) {
+ @Override public Result_SignatureNoneZ sign_justice_revoked_htlc(byte[] justice_tx, long input, long amount, byte[] per_commitment_key, HTLCOutputInCommitment htlc) {
return underlying_base.sign_justice_revoked_htlc(justice_tx, input, amount, per_commitment_key, htlc);
}
-
- @Override
- public Result_SignatureNoneZ sign_counterparty_htlc_transaction(byte[] htlc_tx, long input, long amount, byte[] per_commitment_point, HTLCOutputInCommitment htlc) {
+ @Override public Result_SignatureNoneZ sign_counterparty_htlc_transaction(byte[] htlc_tx, long input, long amount, byte[] per_commitment_point, HTLCOutputInCommitment htlc) {
return underlying_base.sign_counterparty_htlc_transaction(htlc_tx, input, amount, per_commitment_point, htlc);
}
-
- @Override
- public Result_SignatureNoneZ sign_closing_transaction(byte[] closing_tx) {
+ @Override public Result_SignatureNoneZ sign_closing_transaction(ClosingTransaction closing_tx) {
return underlying_base.sign_closing_transaction(closing_tx);
}
-
- @Override
- public Result_SignatureNoneZ sign_channel_announcement(UnsignedChannelAnnouncement msg) {
+ @Override public Result_SignatureNoneZ sign_channel_announcement(UnsignedChannelAnnouncement msg) {
return underlying_base.sign_channel_announcement(msg);
}
-
- @Override
- public void ready_channel(ChannelTransactionParameters params) {
+ @Override public void ready_channel(ChannelTransactionParameters params) {
underlying_base.ready_channel(params);
}
};
final NetGraphMsgHandler router;
final Watch chain_watch;
final HashSet<String> filter_additions;
- final Filter filter;
+ final Option_FilterZ filter;
ChannelManager chan_manager;
PeerManager peer_manager;
final HashMap<String, ChannelMonitor> monitors; // Wow I forgot just how terrible Java is - we can't put a byte array here.
filter_additions = new HashSet<>();
if (use_filter) {
- this.filter = Filter.new_impl(new Filter.FilterInterface() {
+ this.filter = Option_FilterZ.some(Filter.new_impl(new Filter.FilterInterface() {
@Override public void register_tx(byte[] txid, byte[] script_pubkey) {
filter_additions.add(Arrays.toString(txid));
}
filter_additions.add(Arrays.toString(output.get_outpoint().get_txid()) + ":" + output.get_outpoint().get_index());
return Option_C2Tuple_usizeTransactionZZ.none();
}
- });
+ }));
} else {
- this.filter = null;
+ this.filter = Option_FilterZ.none();
}
if (use_manual_watch) {
this.keys_interface = keys.as_KeysInterface();
this.explicit_keys_manager = keys;
}
- this.router = NetGraphMsgHandler.of(new byte[32], null, logger);
+ this.router = NetGraphMsgHandler.of(new byte[32], Option_AccessZ.none(), logger);
}
private void bind_nio() {
if (!use_nio_peer_handler) return;
ChainParameters params = ChainParameters.of(Network.LDKNetwork_Bitcoin, BestBlock.of(new byte[32], 0));
this.chan_manager = ChannelManager.of(this.fee_estimator, chain_watch, tx_broadcaster, logger, this.keys_interface, UserConfig.with_default(), params);
byte[] random_data = keys_interface.get_secure_random_bytes();
- this.peer_manager = PeerManager.of(chan_manager.as_ChannelMessageHandler(), router.as_RoutingMessageHandler(), keys_interface.get_node_secret(), random_data, logger);
+ this.peer_manager = PeerManager.of(chan_manager.as_ChannelMessageHandler(), router.as_RoutingMessageHandler(), keys_interface.get_node_secret(), random_data, logger, IgnoringMessageHandler.of().as_CustomMessageHandler());
}
this.node_id = chan_manager.get_our_node_id();
byte[][] monitors = {orig.monitors.values().stream().iterator().next().write()};
byte[] serialized = orig.chan_manager.write();
try {
+ Filter filter_nullable = null;
+ if (this.filter instanceof Option_FilterZ.Some) {
+ filter_nullable = ((Option_FilterZ.Some) this.filter).some;
+ }
this.constructor = new ChannelManagerConstructor(serialized, monitors, this.keys_interface,
- this.fee_estimator, this.chain_monitor, this.filter, this.router, this.tx_broadcaster, this.logger);
+ this.fee_estimator, this.chain_monitor, filter_nullable, this.router, this.tx_broadcaster, this.logger);
constructor.chain_sync_completed(new ChannelManagerConstructor.EventHandler() {
@Override public void handle_event(Event event) {
synchronized (pending_manager_events) {
this.chan_manager = ((Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK) read_res).res.b;
this.chain_watch.watch_channel(monitors[0].get_funding_txo().a, monitors[0]);
byte[] random_data = keys_interface.get_secure_random_bytes();
- this.peer_manager = PeerManager.of(chan_manager.as_ChannelMessageHandler(), router.as_RoutingMessageHandler(), keys_interface.get_node_secret(), random_data, logger);
+ this.peer_manager = PeerManager.of(chan_manager.as_ChannelMessageHandler(), router.as_RoutingMessageHandler(), keys_interface.get_node_secret(), random_data, logger, IgnoringMessageHandler.of().as_CustomMessageHandler());
if (!break_cross_peer_refs && (use_manual_watch || use_km_wrapper)) {
// When we pass monitors[0] into chain_watch.watch_channel we create a reference from the new Peer to a
// field in the old peer, preventing freeing of the original Peer until the new Peer is freed. Thus, we
InvoiceFeatures invoice_features = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.features();
RouteHint[] route_hints = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.route_hints();
- Route route;
- try (LockedNetworkGraph netgraph = peer1.router.read_locked_graph()) {
- NetworkGraph graph = netgraph.graph();
- Result_RouteLightningErrorZ route_res = UtilMethods.get_route(peer1.chan_manager.get_our_node_id(), graph, peer2.node_id, invoice_features, peer1_chans, route_hints, 10000000, 42, peer1.logger);
- assert route_res instanceof Result_RouteLightningErrorZ.Result_RouteLightningErrorZ_OK;
- route = ((Result_RouteLightningErrorZ.Result_RouteLightningErrorZ_OK) route_res).res;
- }
+ Result_RouteLightningErrorZ route_res = UtilMethods.get_route(peer1.chan_manager.get_our_node_id(), peer1.router.get_network_graph(), peer2.node_id, invoice_features, peer1_chans, route_hints, 10000000, 42, peer1.logger);
+ assert route_res instanceof Result_RouteLightningErrorZ.Result_RouteLightningErrorZ_OK;
+ Route route = ((Result_RouteLightningErrorZ.Result_RouteLightningErrorZ_OK) route_res).res;
Result_NonePaymentSendFailureZ payment_res = peer1.chan_manager.send_payment(route, payment_hash, payment_secret);
assert payment_res instanceof Result_NonePaymentSendFailureZ.Result_NonePaymentSendFailureZ_OK;
final long router;
final long route_handler;
final long message_handler;
+ final long custom_message_handler;
final long peer_manager;
HashMap<String, Long> monitors; // Wow I forgot just how terrible Java is - we can't put a byte array here.
byte[] node_id;
this.chan_manager_events = bindings.ChannelManager_as_EventsProvider(chan_manager);
this.chan_handler = bindings.ChannelManager_as_ChannelMessageHandler(chan_manager);
- this.router = bindings.NetGraphMsgHandler_new(new byte[32], 0, logger);
+ this.router = bindings.NetGraphMsgHandler_new(bindings.NetworkGraph_new(new byte[32]), bindings.COption_AccessZ_none(), logger);
this.route_handler = bindings.NetGraphMsgHandler_as_RoutingMessageHandler(router);
this.message_handler = bindings.MessageHandler_new(chan_handler, route_handler);
+ this.custom_message_handler = bindings.IgnoringMessageHandler_new();
byte[] random_data = new byte[32];
for (byte i = 0; i < 32; i++) { random_data[i] = (byte) ((i ^ seed) ^ 0xf0); }
- this.peer_manager = bindings.PeerManager_new(message_handler, bindings.KeysInterface_get_node_secret(keys_interface), random_data, logger);
+ this.peer_manager = bindings.PeerManager_new(message_handler, bindings.KeysInterface_get_node_secret(keys_interface), random_data,
+ logger, bindings.IgnoringMessageHandler_as_CustomMessageHandler(this.custom_message_handler));
}
void connect_block(Block b, Transaction t, int height) {
long no_min_val = bindings.COption_u64Z_none();
long inbound_payment = bindings.ChannelManager_create_inbound_payment(peer2.chan_manager, no_min_val, 7200, 42);
bindings.COption_u64Z_free(no_min_val);
- long netgraph = bindings.NetGraphMsgHandler_read_locked_graph(peer1.router);
- long route = bindings.get_route(peer1.node_id, bindings.LockedNetworkGraph_graph(netgraph), peer2.node_id, 0L, peer1_chans,
+ long netgraph = bindings.NetGraphMsgHandler_get_network_graph(peer1.router);
+ long route = bindings.get_route(peer1.node_id, netgraph, peer2.node_id, 0L, peer1_chans,
new long[0], 1000, 42, peer1.logger);
for (long chan : peer1_chans) bindings.ChannelDetails_free(chan);
assert bindings.LDKCResult_RouteLightningErrorZ_result_ok(route);
- bindings.LockedNetworkGraph_free(netgraph);
+ bindings.NetworkGraph_free(netgraph);
long payment_res = bindings.ChannelManager_send_payment(peer1.chan_manager, bindings.LDKCResult_RouteLightningErrorZ_get_ok(route),
bindings.LDKC2Tuple_PaymentHashPaymentSecretZ_get_a(inbound_payment), bindings.LDKC2Tuple_PaymentHashPaymentSecretZ_get_b(inbound_payment));
bindings.CResult_RouteLightningErrorZ_free(route);