+ super.finalize();
+ 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) {
+ 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), our_node_secret, ephemeral_random_data, logger == null ? 0 : logger.ptr);
+ PeerManager 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);
+ 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);
+ 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 had a
+ * socket_disconnected().
+ */
+ public Result_CVec_u8ZPeerHandleErrorZ new_outbound_connection(byte[] their_node_id, SocketDescriptor descriptor) {
+ long ret = bindings.PeerManager_new_outbound_connection(this.ptr, their_node_id, descriptor == null ? 0 : descriptor.ptr);
+ Result_CVec_u8ZPeerHandleErrorZ ret_hu_conv = Result_CVec_u8ZPeerHandleErrorZ.constr_from_ptr(ret);
+ this.ptrs_to.add(descriptor);
+ return ret_hu_conv;