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_funding_locked(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) {
115 }, () -> new long[0]);
116 long route_handler = bindings.LDKRoutingMessageHandler_new(new bindings.LDKRoutingMessageHandler() {
117 @Override public long handle_node_announcement(long msg) {
120 @Override public long handle_channel_announcement(long msg) {
123 @Override public long handle_channel_update(long msg) {
126 @Override public long[] get_next_channel_announcements(long starting_point, byte batch_amount) {
129 @Override public long[] get_next_node_announcements(byte[] starting_point, byte batch_amount) {
134 public void sync_routing_table(byte[] their_node_id, long init) {
139 public long handle_reply_channel_range(byte[] their_node_id, long msg) {
144 public long handle_reply_short_channel_ids_end(byte[] their_node_id, long msg) {
149 public long handle_query_channel_range(byte[] their_node_id, long msg) {
154 public long handle_query_short_channel_ids(byte[] their_node_id, long msg) {
157 }, () -> new long[0]);
158 long message_handler = bindings.MessageHandler_new(chan_handler, route_handler);
159 byte[] our_node_secret = new byte[32];
160 byte[] random_data = new byte[32];
161 for (byte i = 0; i < 32; i++) { random_data[i] = i; our_node_secret[i] = (byte) (i ^ 0xff); }
163 long ignoring_message_handler = bindings.IgnoringMessageHandler_new();
164 long peer_manager = bindings.PeerManager_new(message_handler, our_node_secret, random_data, logger,
165 bindings.IgnoringMessageHandler_as_CustomMessageHandler(ignoring_message_handler));
167 // Test Level_max() since its the only place we create a java object from a Rust-returned enum.
168 assert bindings.Level_max() == Level.LDKLevel_Gossip;
170 // Note that we can't rely on finalizer order, so don't bother trying to rely on it here
171 bindings.Logger_free(logger);
172 bindings.ChannelMessageHandler_free(chan_handler);
173 bindings.RoutingMessageHandler_free(route_handler);
174 //bindings.MessageHandler_free(message_handler);
175 bindings.PeerManager_free(peer_manager);