3 import org.junit.jupiter.api.Test;
4 import org.ldk.impl.bindings;
5 import org.ldk.enums.*;
6 import org.ldk.structs.Record;
8 public class ManualMsgHandlingPeerTest {
10 void test_message_handler() {
11 long logger = bindings.LDKLogger_new((long arg)->{
12 System.out.println(bindings.Record_get_args(arg));
13 bindings.Record_free(arg);
15 long chan_handler = bindings.LDKChannelMessageHandler_new(new bindings.LDKChannelMessageHandler() {
17 public void handle_open_channel(byte[] their_node_id, long their_features, long msg) {
22 public void handle_accept_channel(byte[] their_node_id, long their_features, long msg) {
27 public void handle_funding_created(byte[] their_node_id, long msg) {
32 public void handle_funding_signed(byte[] their_node_id, long msg) {
37 public void handle_channel_ready(byte[] their_node_id, long msg) {
42 public void handle_shutdown(byte[] their_node_id, long their_features, long msg) {
47 public void handle_closing_signed(byte[] their_node_id, long msg) {
52 public void handle_update_add_htlc(byte[] their_node_id, long msg) {
57 public void handle_update_fulfill_htlc(byte[] their_node_id, long msg) {
62 public void handle_update_fail_htlc(byte[] their_node_id, long msg) {
67 public void handle_update_fail_malformed_htlc(byte[] their_node_id, long msg) {
72 public void handle_commitment_signed(byte[] their_node_id, long msg) {
77 public void handle_revoke_and_ack(byte[] their_node_id, long msg) {
82 public void handle_update_fee(byte[] their_node_id, long msg) {
87 public void handle_announcement_signatures(byte[] their_node_id, long msg) {
92 public void peer_disconnected(byte[] their_node_id, boolean no_connection_possible) {
97 public void peer_connected(byte[] their_node_id, long msg) {
102 public void handle_channel_reestablish(byte[] their_node_id, long msg) {
107 public void handle_channel_update(byte[] their_node_id, long msg) {
112 public void handle_error(byte[] their_node_id, long msg) {
117 public long provided_node_features() {
123 public long provided_init_features(byte[] their_node_id) {
127 }, () -> new long[0]);
128 long route_handler = bindings.LDKRoutingMessageHandler_new(new bindings.LDKRoutingMessageHandler() {
129 @Override public long handle_node_announcement(long msg) {
132 @Override public long handle_channel_announcement(long msg) {
135 @Override public long handle_channel_update(long msg) {
140 public long get_next_channel_announcement(long starting_point) {
146 public long get_next_node_announcement(byte[] starting_point) {
151 @Override public void peer_connected(byte[] their_node_id, long init) { }
154 public long handle_reply_channel_range(byte[] their_node_id, long msg) {
159 public long handle_reply_short_channel_ids_end(byte[] their_node_id, long msg) {
164 public long handle_query_channel_range(byte[] their_node_id, long msg) {
169 public long handle_query_short_channel_ids(byte[] their_node_id, long msg) {
174 public long provided_node_features() {
180 public long provided_init_features(byte[] their_node_id) {
184 }, () -> new long[0]);
185 long ignoring_message_handler = bindings.IgnoringMessageHandler_new();
186 long onion_message_handler = bindings.IgnoringMessageHandler_as_OnionMessageHandler(ignoring_message_handler);
187 long message_handler = bindings.MessageHandler_new(chan_handler, route_handler, onion_message_handler);
188 byte[] our_node_secret = new byte[32];
189 byte[] random_data = new byte[32];
190 for (byte i = 0; i < 32; i++) { random_data[i] = i; our_node_secret[i] = (byte) (i ^ 0xff); }
192 long peer_manager = bindings.PeerManager_new(message_handler, our_node_secret, System.currentTimeMillis() / 1000,
194 bindings.IgnoringMessageHandler_as_CustomMessageHandler(ignoring_message_handler));
196 // Test Level_max() since its the only place we create a java object from a Rust-returned enum.
197 assert bindings.Level_max() == Level.LDKLevel_Gossip;
199 // Note that we can't rely on finalizer order, so don't bother trying to rely on it here
200 bindings.Logger_free(logger);
201 bindings.ChannelMessageHandler_free(chan_handler);
202 bindings.RoutingMessageHandler_free(route_handler);
203 bindings.OnionMessageHandler_free(onion_message_handler);
204 bindings.IgnoringMessageHandler_free(ignoring_message_handler);
205 //bindings.MessageHandler_free(message_handler);
206 bindings.PeerManager_free(peer_manager);