rtailcat 0.0.0.9000
Initial version, embedding tailcat’s Go library through its C ABI (version 1).
Features
- R6 classes for both ends of a tailcat connection:
TailcatServer(registers with a relay and publishes a secret address),TailcatListener(accepts TCP connections or UDP flows on a port),TailcatClient(dials a server by its address), andTailcatConnection(reads, writes, half-close, and connection info). - Every blocking method has an
_async()twin that returns a promise settled on the later event loop current at the call, andTailcatListener$serve()runs an accept loop that hands each connection to a handler. Pending asynchronous operations can be canceled withtailcat_cancel(), and blocking calls can be interrupted without losing data that has already arrived. - Reads and writes on one connection run in the order they were started, while a read and a write can run at the same time.
$read_all()and$read_all_async()read to the end of a TCP stream, optionally limited bymax_bytes. - Errors are conditions of class
tailcat_errorwith one subclass per C ABI status (tailcat_invalid_argument,tailcat_closed,tailcat_timeout,tailcat_canceled,tailcat_failure), carrying thestatusand thebytestransferred. - Addresses, private keys, and pre-shared keys are
tailcat_secretstrings that print and format as<redacted>;format()andprint()of the R6 objects never show them.tailcat_keygen()creates keys for a stable server address or client identity,allowed_clientsand$allow_client()restrict who may connect, andtailcat_address_parse(),tailcat_address_resolve(), andtailcat_build_info()inspect addresses and the embedded library. - The option
rtailcat.max_operations(default 1024) caps the number of operations in flight, each of which holds an operating system thread. - Helpers for building protocols on top of a connection:
$write_message()and$read_message()send and receive length-prefixed messages over TCP (a 4-byte big-endian length, then the bytes), withmax_byteschecked before a message is read;$read_exact()reads exactlynbytes;$read_loop()and$stop_reading()read chunks, datagrams, or messages continuously on the event loop, like$serve()does for accepts. Each has an_async()twin where it blocks. -
tailcat_keys_save(),tailcat_keys_load(), andtailcat_keygen(path)keep keys in a JSON file that only the owner can read, andtailcat_address_write()andtailcat_address_read()do the same for an address.tailcat_reveal()returns the plain string of atailcat_secretwhere an application means to show it. -
$close(drain = )on servers and clients waits for TCP shutdown traffic before closing. - Methods and functions that change an object return it invisibly, so calls chain:
conn$write(data)$close_write()$read_all(). This includes$write()and$write_message(), which return the connection rather than a byte count (their_async()twins resolve with it), andtailcat_keys_save()andtailcat_address_write(), which return their first argument. -
TailcatListener$is_servingandTailcatConnection$is_readingtell whether a$serve()or$read_loop()loop is running, andTailcatConnection$is_readable()whether a TCP read would return at once. -
allowed_clientsand$allow_client()taketailcat_keysobjects as well as public key strings. - Subsetting a
tailcat_secretwith[or[[, and combining withc(), keep it a secret.tailcat_build_info()prints as a short summary. -
tailcat_wait()andtailcat_run()run the later event loop from a script, until a promise settles or a condition holds. - The options
rtailcat.regionandrtailcat.relay_map_urlset the relay for servers and clients created without those arguments. -
tailcat_udp_max_payload()gives the largest UDP datagram (1232 bytes).
Departures from the C ABI
-
timeout = 0is a non-blocking poll (data already received, a connection already waiting) rather than an already expired deadline. -
TailcatClient$ping()returns seconds rather than milliseconds, like$disco_ping()and the timeouts. -
TailcatClient$disco_ping()reports a ping that went through a relay asdirect = FALSEwithendpoint = NA, rather than as an emptyendpoint. - Field names in the results of
$info(),$disco_ping(), andtailcat_address_parse()are snake_case (relay_port,relay_region_id, and so on) instead of tailcat’s JSON names, and the relay map argument and option arerelay_map_urlandrtailcat.relay_map_urlrather thanderp_map_url;tailcat_build_info()$rawkeeps Go’s own names.