A tailcat client connects to the TailcatServer identified by a secret tailcat address. It can only dial that server. Network startup happens on the first $dial(), $ping(), or $disco_ping().
Blocking methods have an _async() counterpart that returns a promises::promise(); see TailcatServer for how asynchronous results are delivered, for timeouts (including timeout = 0), and for the error classes.
The address is a secret; printing a client never shows it or the private key, and the client does not keep a copy of the address in R.
Once a client is closed, every method other than $close(), $format(), and $print(), and every field other than $is_closed, raises a tailcat_closed error; nothing is kept from before. A client restored from a saved session is closed, because handles do not survive serialization.
A server with an allowlist (allowed_clients or TailcatServer$allow_client()) does not answer clients that are not on it, so for such a client $dial(), $ping(), and $disco_ping() fail with tailcat_timeout once their timeout runs out, rather than with a distinct error.
Active bindings
public_keyThe client's public key, for
TailcatServer$allow_client(). It is fetched from tailcat on each access.is_closedTRUEonce the client has been closed.
Methods
TailcatClient$new()
Create a client. No network access happens until it is used.
Usage
TailcatClient$new(address, key = NULL, relay_map_url = NULL)Arguments
addressThe server's secret tailcat address (a string or a tailcat_secret). Surrounding whitespace, such as a trailing newline from a file, is ignored.
keyPrivate node key (a string in text encoding, or a
tailcat_keysobject fromtailcat_keygen()), orNULLto generate one. A stable key gives the client a stable public key, for use withallowed_clients.relay_map_urlURL of a relay map to use instead of the default, or
NULLto use thertailcat.relay_map_urloption (see the section on relay options in TailcatServer) or, when that is unset, the default.
TailcatClient$dial()
Connect to a port on the server.
Usage
TailcatClient$dial(port, network = c("tcp", "udp"), timeout = 30)Arguments
portPort number (1 to 65535).
networkExactly
"tcp"(the default) or"udp".timeoutSeconds to wait, covering relay registration and the connection;
Infwaits indefinitely and0polls.
TailcatClient$dial_async()
Asynchronous version of $dial().
Usage
TailcatClient$dial_async(port, network = c("tcp", "udp"), timeout = 30)Arguments
portPort number (1 to 65535).
networkExactly
"tcp"(the default) or"udp".timeoutSeconds to wait;
Infwaits indefinitely and0polls.
Returns
A promise resolving with a TailcatConnection.
TailcatClient$ping()
Measure the round-trip time to the server through the relay.
Returns
The latency in seconds (a double). tailcat reports whole milliseconds, so the resolution is 0.001 and a ping faster than a millisecond reads as 0. This differs from tailcat's C ABI (tailcat.h), which returns the milliseconds; seconds match $disco_ping() and the timeouts.
TailcatClient$disco_ping()
Send a discovery ping, which also triggers direct path discovery.
Arguments
timeoutSeconds to wait; use a finite value since discovery may otherwise wait indefinitely.
Returns
A list with latency (seconds), direct (TRUE if the ping took a direct path to the server, FALSE if it went through a relay), endpoint (the direct path as "host:port", or NA when relayed), relay_region_id, and relay_region_code (the relay region the ping went through). tailcat's C ABI reports a relayed ping as an empty endpoint.
TailcatClient$drain()
Wait for TCP shutdown traffic to finish. Call it after closing connections (or reaching end of stream) and before closing the client or exiting R, so the server sees a clean end of stream.
TailcatClient$close()
Close the client and all of its connections. Closing twice is harmless. Closing tears the client down immediately, so the server may not see the end of its streams until its own reads time out. To give the server a clean end of stream, close the connections first and pass drain, which waits for their shutdown traffic before closing (see $drain()).
TailcatClient$format()
Format a summary, the lines that $print() shows. The address and private key are never shown. A closed client shows only its state.
Examples
if (FALSE) { # \dontrun{
address = readLines("address.txt")
cl = TailcatClient$new(address)
conn = cl$dial(8080)
conn$write("hello\n")$close()
cl$close(drain = 5)
} # }