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) {
133 @Override public void peer_connected(byte[] their_node_id, long init) { }
136 public long handle_reply_channel_range(byte[] their_node_id, long msg) {
141 public long handle_reply_short_channel_ids_end(byte[] their_node_id, long msg) {
146 public long handle_query_channel_range(byte[] their_node_id, long msg) {
151 public long handle_query_short_channel_ids(byte[] their_node_id, long msg) {
154 }, () -> new long[0]);
155 long message_handler = bindings.MessageHandler_new(chan_handler, route_handler);
156 byte[] our_node_secret = new byte[32];
157 byte[] random_data = new byte[32];
158 for (byte i = 0; i < 32; i++) { random_data[i] = i; our_node_secret[i] = (byte) (i ^ 0xff); }
160 long ignoring_message_handler = bindings.IgnoringMessageHandler_new();
161 long peer_manager = bindings.PeerManager_new(message_handler, our_node_secret, random_data, logger,
162 bindings.IgnoringMessageHandler_as_CustomMessageHandler(ignoring_message_handler));
164 // Test Level_max() since its the only place we create a java object from a Rust-returned enum.
165 assert bindings.Level_max() == Level.LDKLevel_Gossip;
167 // Note that we can't rely on finalizer order, so don't bother trying to rely on it here
168 bindings.Logger_free(logger);
169 bindings.ChannelMessageHandler_free(chan_handler);
170 bindings.RoutingMessageHandler_free(route_handler);
171 //bindings.MessageHandler_free(message_handler);
172 bindings.PeerManager_free(peer_manager);