Expand description
Node tls module: real TLS over blocking rustls (rustls::StreamOwned
wrapping a std::net::TcpStream).
Threading model mirrors net (see host::run_event_loop): background threads
only move raw bytes and post IoTask closures onto the host channel; every
JS-visible effect (building the TLSSocket, emitting secureConnect/data/
end/close, calling listeners) happens on the main thread when the loop runs
the posted closure. Background closures NEVER capture a Value (the heap is a
main-thread thread_local); they capture only Send data (u64 ids, byte
vectors, TcpStreams, channel senders) and look the emitter up by id inside
the posted IoTask.
Per TLS connection there is ONE owner thread that solely owns the
StreamOwned. It reads with a short socket read-timeout (so a WouldBlock
lets it loop) and drains an mpsc channel of WriteCmds produced by the main
thread (socket.write/socket.end). Because reads and writes share the one
rustls Connection, keeping both on a single thread avoids splitting the
stateful cipher across threads.
Constants§
- MODULE_
METHODS tlsmodule functions routed throughstdlib::call.- SERVER_
METHODS - Instance method names for the two
@@nativetags this module owns, exposed tostdlib::instance_has_method(property reads that yield a bound method). - SOCKET_
METHODS
Functions§
- build_
server_ config - Build a
ServerConfigfrom PEMkey+certbytes. - call
stdlib::callentry fortls.<method>.- client_
config - The shared client
ClientConfigfor a givenrejectUnauthorizedsetting. Public so thehttpsclient (https.request/https.get) reuses the same trust configuration astls.connect. - connect
tls.connect(options[, cb])/tls.connect(port[, host][, options][, cb]). Returns aTLSSocketimmediately; the TCP connect + handshake run on a background thread and emitsecureConnect(orerror) when complete.- create_
server tls.createServer([options][, secureConnectionListener]). Parseskey+certinto aServerConfigeagerly (so a bad cert throws synchronously) and returns aTLSServeremitter.- create_
server_ with_ config - Build a TLS server backed by a caller-supplied per-connection hook (used by
https::create_server). Returns theTLSServeremitter; the caller stores itsrequestListenerand registers the hook. - instance_
call - new_
emitter_ object - Build a native emitter object (
@@nativetag +@@on/@@oncemaps + extras), sharing the EventEmitter shape withevents/net. - socket_
end - Signal end-of-write (TLS close-notify + TCP write shutdown) on a socket.
- socket_
write - Queue plaintext to be written by the socket’s owner thread (no-op if closed).
Public so
httpsserver responses can write through the TLS channel.
Type Aliases§
- Conn
Hook - A native-thread hook run on the main thread for each freshly-handshaked
connection. Set by
httpsto attach its request parser;Nonefor a plaintlsserver (which emitssecureConnect/connectionand calls its listener).