+ if (ptr != 0) { bindings.PeerManager_free(ptr); }
+ }
+
+ /**
+ * 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.
+ */
+ 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);
+ Reference.reachabilityFence(message_handler_chan_handler_arg);
+ Reference.reachabilityFence(message_handler_route_handler_arg);
+ Reference.reachabilityFence(our_node_secret);
+ 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);
+ return ret_hu_conv;
+ }
+
+ /**
+ * Get the list of node ids for peers which have completed the initial handshake.
+ *
+ * For outbound connections, this will be the same as the their_node_id parameter passed in to
+ * new_outbound_connection, however entries will only appear once the initial handshake has
+ * completed and we are sure the remote peer has the private key for the given node_id.
+ */
+ public byte[][] get_peer_node_ids() {
+ byte[][] ret = bindings.PeerManager_get_peer_node_ids(this.ptr);
+ Reference.reachabilityFence(this);
+ return ret;
+ }
+
+ /**
+ * Indicates a new outbound connection has been established to a node with the given node_id.
+ * Note that if an Err is returned here you MUST NOT call socket_disconnected for the new
+ * descriptor but must disconnect the connection immediately.
+ *
+ * Returns a small number of bytes to send to the remote node (currently always 50).
+ *
+ * Panics if descriptor is duplicative with some other descriptor which has not yet been
+ * [`socket_disconnected()`].
+ *
+ * [`socket_disconnected()`]: PeerManager::socket_disconnected
+ */
+ public Result_CVec_u8ZPeerHandleErrorZ new_outbound_connection(byte[] their_node_id, SocketDescriptor descriptor) {
+ long ret = bindings.PeerManager_new_outbound_connection(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), descriptor == null ? 0 : descriptor.ptr);
+ Reference.reachabilityFence(this);
+ Reference.reachabilityFence(their_node_id);
+ Reference.reachabilityFence(descriptor);
+ 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);
+ return ret_hu_conv;
+ }
+
+ /**
+ * Indicates a new inbound connection has been established.
+ *
+ * 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.
+ *
+ * Panics if descriptor is duplicative with some other descriptor which has not yet been
+ * [`socket_disconnected()`].
+ *
+ * [`socket_disconnected()`]: PeerManager::socket_disconnected
+ */
+ public Result_NonePeerHandleErrorZ new_inbound_connection(SocketDescriptor descriptor) {
+ long ret = bindings.PeerManager_new_inbound_connection(this.ptr, descriptor == null ? 0 : descriptor.ptr);
+ Reference.reachabilityFence(this);
+ Reference.reachabilityFence(descriptor);
+ if (ret >= 0 && ret <= 4096) { return null; }
+ Result_NonePeerHandleErrorZ ret_hu_conv = Result_NonePeerHandleErrorZ.constr_from_ptr(ret);
+ this.ptrs_to.add(descriptor);
+ return ret_hu_conv;