X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FPeerManager.java;h=23ef8e347870666b845be8932e6d14acc24b7e46;hb=890e35a4387758c0447aab34166caa579bbf3a08;hp=e41024f8ed7b6397687d8a0748103959b8a56cee;hpb=9aa1eebc40df06586c7ab12f7c8eb22ebcb8b365;p=ldk-java diff --git a/src/main/java/org/ldk/structs/PeerManager.java b/src/main/java/org/ldk/structs/PeerManager.java index e41024f8..23ef8e34 100644 --- a/src/main/java/org/ldk/structs/PeerManager.java +++ b/src/main/java/org/ldk/structs/PeerManager.java @@ -42,22 +42,30 @@ public class PeerManager extends CommonBase { * Constructs a new PeerManager with the given message handlers and node_id secret key * ephemeral_random_data is used to derive per-connection ephemeral keys and must be * cryptographically secure random bytes. + * + * `current_time` is used as an always-increasing counter that survives across restarts and is + * incremented irregularly internally. In general it is best to simply use the current UNIX + * timestamp, however if it is not available a persistent counter that increases once per + * minute should suffice. */ - public static PeerManager of(ChannelMessageHandler message_handler_chan_handler_arg, RoutingMessageHandler message_handler_route_handler_arg, byte[] our_node_secret, byte[] ephemeral_random_data, Logger logger, CustomMessageHandler custom_message_handler) { - long ret = bindings.PeerManager_new(bindings.MessageHandler_new(message_handler_chan_handler_arg == null ? 0 : message_handler_chan_handler_arg.ptr, message_handler_route_handler_arg == null ? 0 : message_handler_route_handler_arg.ptr), InternalUtils.check_arr_len(our_node_secret, 32), InternalUtils.check_arr_len(ephemeral_random_data, 32), logger == null ? 0 : logger.ptr, custom_message_handler == null ? 0 : custom_message_handler.ptr); + public static PeerManager of(ChannelMessageHandler message_handler_chan_handler_arg, RoutingMessageHandler message_handler_route_handler_arg, OnionMessageHandler message_handler_onion_message_handler_arg, byte[] our_node_secret, long current_time, byte[] ephemeral_random_data, Logger logger, CustomMessageHandler custom_message_handler) { + long ret = bindings.PeerManager_new(bindings.MessageHandler_new(message_handler_chan_handler_arg == null ? 0 : message_handler_chan_handler_arg.ptr, message_handler_route_handler_arg == null ? 0 : message_handler_route_handler_arg.ptr, message_handler_onion_message_handler_arg == null ? 0 : message_handler_onion_message_handler_arg.ptr), InternalUtils.check_arr_len(our_node_secret, 32), current_time, InternalUtils.check_arr_len(ephemeral_random_data, 32), logger == null ? 0 : logger.ptr, custom_message_handler == null ? 0 : custom_message_handler.ptr); Reference.reachabilityFence(message_handler_chan_handler_arg); Reference.reachabilityFence(message_handler_route_handler_arg); + Reference.reachabilityFence(message_handler_onion_message_handler_arg); Reference.reachabilityFence(our_node_secret); + Reference.reachabilityFence(current_time); Reference.reachabilityFence(ephemeral_random_data); Reference.reachabilityFence(logger); Reference.reachabilityFence(custom_message_handler); if (ret >= 0 && ret <= 4096) { return null; } - PeerManager ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new PeerManager(null, ret); } - ret_hu_conv.ptrs_to.add(ret_hu_conv); - ret_hu_conv.ptrs_to.add(message_handler_chan_handler_arg); - ret_hu_conv.ptrs_to.add(message_handler_route_handler_arg); - ret_hu_conv.ptrs_to.add(logger); - ret_hu_conv.ptrs_to.add(custom_message_handler); + org.ldk.structs.PeerManager ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PeerManager(null, ret); } + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(message_handler_chan_handler_arg); }; + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(message_handler_route_handler_arg); }; + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(message_handler_onion_message_handler_arg); }; + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); }; + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(custom_message_handler); }; return ret_hu_conv; } @@ -82,8 +90,7 @@ public class PeerManager extends CommonBase { * peer using the init message. * The user should pass the remote network address of the host they are connected to. * - * Note that if an Err is returned here you MUST NOT call socket_disconnected for the new - * descriptor but must disconnect the connection immediately. + * If an `Err` is returned here you must disconnect the connection immediately. * * Returns a small number of bytes to send to the remote node (currently always 50). * @@ -100,7 +107,7 @@ public class PeerManager extends CommonBase { Reference.reachabilityFence(remote_network_address); if (ret >= 0 && ret <= 4096) { return null; } Result_CVec_u8ZPeerHandleErrorZ ret_hu_conv = Result_CVec_u8ZPeerHandleErrorZ.constr_from_ptr(ret); - this.ptrs_to.add(descriptor); + if (this != null) { this.ptrs_to.add(descriptor); }; return ret_hu_conv; } @@ -113,9 +120,8 @@ public class PeerManager extends CommonBase { * The user should pass the remote network address of the host they are connected to. * * May refuse the connection by returning an Err, but will never write bytes to the remote end - * (outbound connector always speaks first). Note that if an Err is returned here you MUST NOT - * call socket_disconnected for the new descriptor but must disconnect the connection - * immediately. + * (outbound connector always speaks first). If an `Err` is returned here you must disconnect + * the connection immediately. * * Panics if descriptor is duplicative with some other descriptor which has not yet been * [`socket_disconnected()`]. @@ -129,7 +135,7 @@ public class PeerManager extends CommonBase { Reference.reachabilityFence(remote_network_address); if (ret >= 0 && ret <= 4096) { return null; } Result_NonePeerHandleErrorZ ret_hu_conv = Result_NonePeerHandleErrorZ.constr_from_ptr(ret); - this.ptrs_to.add(descriptor); + if (this != null) { this.ptrs_to.add(descriptor); }; return ret_hu_conv; } @@ -193,6 +199,10 @@ public class PeerManager extends CommonBase { * You don't have to call this function explicitly if you are using [`lightning-net-tokio`] * or one of the other clients provided in our language bindings. * + * Note that if there are any other calls to this function waiting on lock(s) this may return + * without doing any work. All available events that need handling will be handled before the + * other calls return. + * * [`send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment * [`ChannelManager::process_pending_htlc_forwards`]: crate::ln::channelmanager::ChannelManager::process_pending_htlc_forwards * [`send_data`]: SocketDescriptor::send_data @@ -257,4 +267,29 @@ public class PeerManager extends CommonBase { Reference.reachabilityFence(this); } + /** + * Generates a signed node_announcement from the given arguments, sending it to all connected + * peers. Note that peers will likely ignore this message unless we have at least one public + * channel which has at least six confirmations on-chain. + * + * `rgb` is a node \"color\" and `alias` is a printable human-readable string to describe this + * node to humans. They carry no in-protocol meaning. + * + * `addresses` represent the set (possibly empty) of socket addresses on which this node + * accepts incoming connections. These will be included in the node_announcement, publicly + * tying these addresses together and to this node. If you wish to preserve user privacy, + * addresses should likely contain only Tor Onion addresses. + * + * Panics if `addresses` is absurdly large (more than 100). + * + * [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events + */ + public void broadcast_node_announcement(byte[] rgb, byte[] alias, NetAddress[] addresses) { + bindings.PeerManager_broadcast_node_announcement(this.ptr, InternalUtils.check_arr_len(rgb, 3), InternalUtils.check_arr_len(alias, 32), addresses != null ? Arrays.stream(addresses).mapToLong(addresses_conv_12 -> addresses_conv_12.ptr).toArray() : null); + Reference.reachabilityFence(this); + Reference.reachabilityFence(rgb); + Reference.reachabilityFence(alias); + Reference.reachabilityFence(addresses); + } + }