Skip to main content

Module connection

Module connection 

Source
Expand description

One connection: the upgrade, what the server says first, and the loop that answers what a client asks for.

Re-exportsยง

use std::path::Path; ๐Ÿ”’
use std::sync::Arc; ๐Ÿ”’
use std::sync::atomic::AtomicBool; ๐Ÿ”’
use std::sync::atomic::Ordering; ๐Ÿ”’
use std::time::Duration; ๐Ÿ”’
use std::time::Instant; ๐Ÿ”’
use axum::extract::ws::Message; ๐Ÿ”’
use axum::extract::ws::WebSocketUpgrade; ๐Ÿ”’
use axum::extract::ConnectInfo; ๐Ÿ”’
use axum::extract::State; ๐Ÿ”’
use axum::http::HeaderMap; ๐Ÿ”’
use axum::http::StatusCode; ๐Ÿ”’
use axum::http::header; ๐Ÿ”’
use axum::response::IntoResponse as _; ๐Ÿ”’
use axum::response::Response; ๐Ÿ”’
use futures_util::SinkExt as _; ๐Ÿ”’
use futures_util::StreamExt; ๐Ÿ”’
use tokio::sync::mpsc; ๐Ÿ”’
use tokio::sync::oneshot; ๐Ÿ”’
use base64::Engine as _; ๐Ÿ”’
use forge_primitives::SessionSlot; ๐Ÿ”’
use forge_primitives::browser::BrowserFrame; ๐Ÿ”’
use forge_primitives::browser::BrowserInputEvent; ๐Ÿ”’
use forge_primitives::browser::BrowserTabList; ๐Ÿ”’
use forge_primitives::browser::BrowserViewState; ๐Ÿ”’
use forge_primitives::browser::MouseAction; ๐Ÿ”’
use forge_primitives::document::DocumentRead; ๐Ÿ”’
use forge_primitives::wire::COMPRESSED_JSON_TAG; ๐Ÿ”’
use forge_workspace::browser::BrowserAttachment; ๐Ÿ”’
use serde_json::json; ๐Ÿ”’
use super::batch; ๐Ÿ”’
use super::batch::Batch; ๐Ÿ”’
use super::envelope::ClientMessage; ๐Ÿ”’
use super::envelope::ClientSettings; ๐Ÿ”’
use super::envelope::SeatFrameWire; ๐Ÿ”’
use super::envelope::ServerMessage; ๐Ÿ”’
use super::envelope::SettingsRefusal; ๐Ÿ”’
use super::envelope::Subject; ๐Ÿ”’
use super::frame::FrameTransport as _; ๐Ÿ”’
use super::origin as origin_gate; ๐Ÿ”’
use super::wire::FileContentWire; ๐Ÿ”’
use super::wire::OpenTimings; ๐Ÿ”’
use super::wire::ReviewedThreadWire; ๐Ÿ”’
use super::wire::cap_message_record; ๐Ÿ”’
use super::wire::cap_tool_records; ๐Ÿ”’
use super::wire::conversation_for; ๐Ÿ”’
use super::wire::encode_subject; ๐Ÿ”’
use super::wire::encode_subject_timed; ๐Ÿ”’
use super::wire::floor_cursor; ๐Ÿ”’
use super::wire::page_within; ๐Ÿ”’
use super::wire::placement_wire; ๐Ÿ”’
use super::PROTOCOL_VERSION; ๐Ÿ”’
use super::TransportState; ๐Ÿ”’
use super::WRITE_BOUND; ๐Ÿ”’
use super::WriteStalled; ๐Ÿ”’
use super::write_within; ๐Ÿ”’
use crate::live::Live; ๐Ÿ”’
use crate::surface::DictateOutcome; ๐Ÿ”’
use crate::surface::ViewSurface; ๐Ÿ”’
use crate::Command; ๐Ÿ”’
use crate::DispatchError; ๐Ÿ”’
use crate::SeatUpdate; ๐Ÿ”’
use crate::SessionUpdate; ๐Ÿ”’

Structsยง

AbortOnDrop ๐Ÿ”’
A task that is aborted when its handle drops, so a read nobody will answer does not outlive the subscription or the socket that asked for it.
AnswerLanes ๐Ÿ”’
The connectionโ€™s own loop, so that every way out of it runs the detach above rather than only the clean one. The connectionโ€™s answer lanes, bundled so the loopโ€™s signature carries them as one piece of state rather than two.
Arrival ๐Ÿ”’
A message on its way through the loop: who sent it, and when it reached this connection. The instant is the arrivalโ€™s rather than the handlingโ€™s, so an ask that queued behind an earlier read pays that wait in its open.
AttachedClient ๐Ÿ”’
Counts this connection among the attached clients for as long as it lives, so a document hand-off can tell a viewer exists to open on. A guard, for the same reason Holds is one: the count must come back down however the connection ends, a dropped socket included.
BrowserViewing ๐Ÿ”’
This connectionโ€™s browser half: the tab it draws and the strip it follows.
Caller ๐Ÿ”’
This connection as the log names it: the number its takes are told apart by, and the address it is attached from.
Claim ๐Ÿ”’
One seatโ€™s claim: the seat, and the generation of the take that holds it.
ClientSocket ๐Ÿ”’
This connectionโ€™s socket, with the one fact the write path needs from the upgrade: whether the client declared it can inflate a compressed frame.
ConnectionLife ๐Ÿ”’
What a connection leaves behind when it ends.
FrameWrite ๐Ÿ”’
One frameโ€™s write, measured: its size, the time the socket took it, and whether the write yielded at least once before it was done.
Holds ๐Ÿ”’
The seats this connection is holding, each given back when this drops.
Keepalive ๐Ÿ”’
One connectionโ€™s keepalive: the ping it has out, if any.
OpenReport ๐Ÿ”’
One subscribeโ€™s open, as its write and its log state it.
PeerVanished ๐Ÿ”’
The peer stopped answering the keepaliveโ€™s ping, so the connection was ended from inside its own loop.
Progress ๐Ÿ”’
The connectionโ€™s own clock: one stamp per completed socket write, and the seat it last said it was showing.
ReadAnswer ๐Ÿ”’
One subscribe read finished off the loop.
ReadAnswerGuard ๐Ÿ”’
Answers the loop if the read task ends without doing so. A panic in the encode must not leave the connection waiting on a record nobody owes: no answer leaves the read in flight for the connectionโ€™s life, and every later subscribe queues behind it in silence.
Reading ๐Ÿ”’
The subscribe read this connection is waiting on, and what arrived for it while it ran.
Reads ๐Ÿ”’
The connectionโ€™s subscribe reads: the one served off the loop, the asks that queued behind it, and the channel its task answers on.
SentWords ๐Ÿ”’
The words a review write sends, the seat they were the readerโ€™s in, and what the writeโ€™s own reply says when it landed.
SettingsPush ๐Ÿ”’
The settings push this connection follows: the watch it hears and the frame its greeting already wrote.
Streaming ๐Ÿ”’
What this connection is streaming: the seats it has claimed takes for - a startโ€™s seat is claimed as soon as its dispatch answers, so a refused one keeps its entry, and a frame that follows a start always finds the seat - and whether it is recording the read-aloud set. A dictation frame carries no seat of its own - and the recording carries none at all - so these are what address one.
SystemClock ๐Ÿ”’
The shipping clock: the processโ€™s own monotonic one.
TerminalViewing ๐Ÿ”’
The terminal this connection is viewing.
TerminalViewingState ๐Ÿ”’
This connectionโ€™s terminal half.
Viewers ๐Ÿ”’
The viewer halves one connection carries: the browser tab it draws and the terminal it is attached to. One value rather than four arguments, because the read loop already carries the connectionโ€™s whole mutable state and the pair would push every handler past the arity a reader can hold.
Viewing ๐Ÿ”’
One tab this connection is viewing: its profile, its id, its frames and its state.
Watching ๐Ÿ”’
What this connection is watching, and which of it is on screen.
WedgeStalled ๐Ÿ”’
A connection task that stopped making progress.

Enumsยง

Answer ๐Ÿ”’
What a task off this loop asks it to send.
Ask ๐Ÿ”’
What a more asks for, out of the cursor it was sent.
Beat ๐Ÿ”’
What one beat should do.
BelowFloor ๐Ÿ”’
What a paging read below the held windowโ€™s floor resolves to.
FrameRoute ๐Ÿ”’
Where one binary message went, decided without touching a take.
Queued ๐Ÿ”’
An ask waiting behind the connectionโ€™s read.
TerminalEvent ๐Ÿ”’
What the terminal has for the loop.
ViewEvent ๐Ÿ”’
What a viewer has to say to the loop.

Constantsยง

BOUNDARY_TRIES ๐Ÿ”’
How many of a windowโ€™s rows a below-floor page tries to start from.
COMPRESSED_MIN_BYTES ๐Ÿ”’
The JSON bytes at which a frame crosses compressed, for a connection that declared the capability.
HEARTBEAT_DEAD ๐Ÿ”’
How long a ping may go unanswered before the connection is reaped. Four missed beats: long enough that a busy peer is never cut, short enough that a role is not held by a corpse for the minutes a TCP retransmission timeout takes. Chosen, not measured: the one number it changes for a person is how fast a call on a paused host fails (a tool callโ€™s own bound is longer).
HEARTBEAT_EVERY ๐Ÿ”’
How often a connection is asked to prove it is still there.
MAX_CLIENT_MESSAGE_BYTES ๐Ÿ”’
The largest message a client may send.
MAX_HELD_READ_FRAMES ๐Ÿ”’
Frames held for a seat whose record is being read. The record is encoded after them, so everything below its seq is discarded by the client and the newest are the ones worth keeping; a read that never ends stays bounded.
WEDGE_DEAD ๐Ÿ”’
How long a connection may write nothing before a watchdog outside its future ends it.

Traitsยง

WriteClock ๐Ÿ”’
The clock a measured write reads.

Functionsยง

answer_ask ๐Ÿ”’
Answer one strip ask: through the reply it carried, or as the error frame when it carried none.
answered ๐Ÿ”’
Dispatch one of those, and answer the client that asked.
answers_through_a_reply ๐Ÿ”’
Whether a command reports its outcome through the reply rather than through an update on the subscription.
attach_terminal ๐Ÿ”’
Attach this connection to a seatโ€™s terminal as a viewer.
attach_view ๐Ÿ”’
One viewerโ€™s attach: the same body for a tab number and for a hand-offโ€™s page, because everything after the resolution is identical.
below_the_floor ๐Ÿ”’
Two cursor forms, one walk. The windowโ€™s newest page hands back the frame index its front sits at; every page below the floor hands back a row cursor (r:<byte>[:<id>]) minted from the row it reached. A frame cursor cannot be resolved to a row, because the frames the CLI streams and never writes sit between the windowโ€™s rows, so no arithmetic lines the two numberings up. It is answered from the windowโ€™s oldest row the file resolves instead: overlap at worst, never a gap, and a walk from any cursor converges on the same descending chain.
boundary_candidates ๐Ÿ”’
The rows a walk below the window may start from, the walkโ€™s own stop first and the rest of the window behind it.
call_output ๐Ÿ”’
A callโ€™s own output, read from the transportโ€™s held copy of its seat.
carries_a_result ๐Ÿ”’
Whether a frame is a user row carrying a tool result - the frame a stop may not land on, because the call it answers sits just beneath it.
cron_names_off_loop ๐Ÿ”’
The cron pairings a pageโ€™s rows need, read off the connection loop.
discrete_gesture ๐Ÿ”’
Whether one gesture is worth its own record: a pointer move and a wheel are streams, so their refusal is the clickโ€™s that follows and logging every one would bury the answer in it.
dispatch_answering ๐Ÿ”’
Dispatch one reply-carrying command and hand its answer to the connection.
dispatch_refusal ๐Ÿ”’
One refused dispatch, as the frame the asking client reads: the operation the refusal names, the coreโ€™s own words, and the dispatch id the press that made it minted - echoed so a press can attribute this refusal to itself rather than to whatever was pressed last.
dispatched ๐Ÿ”’
Which hand sent what (issue #2372: a parked hand-offโ€™s answer arrived over the socket and could not be attributed - no dispatch named its connection). Logged where a command is actually dispatched: a refusal never was.
document_answer ๐Ÿ”’
One document readโ€™s outcome, as the asking client reads it: the answer with the documentโ€™s bytes base64, or the refusal under the seat that asked - the seat is what lets a client holding several seats drain only its own.
drive ๐Ÿ”’
Read what a client sends, and hear what its subscriptions asked for.
ending ๐Ÿ”’
Why a connection ended, for the teardown records that run after it: a wedge and a clean close leave the same marks to release, and a reader looking at one of them has to know which it was.
finish ๐Ÿ”’
Everything a connection leaves behind, undone on every way out of it: a clean close, a failed read, and a connection the watchdog dropped.
finish_read ๐Ÿ”’
Answer a subscribe read that ran off the loop: its record, its refusal, or nothing when the client let the seat go while it ran.
for_a_client ๐Ÿ”’
The update as it crosses to a client.
forward_queued ๐Ÿ”’
The frames a subscribe read out of the stream it replaced: filtered for this connection, and bounded like every other path to a client (#2374).
forwards ๐Ÿ”’
Whether this connection forwards one update.
frame_bytes ๐Ÿ”’
The bytes a frame carries, which is what the writeโ€™s own record reports.
frame_for ๐Ÿ”’
One message as the frame this connection sends: text as it always was, or a gzipped body behind COMPRESSED_JSON_TAG when the client declared the capability and the body is over the threshold.
frame_for_flag ๐Ÿ”’
frame_route ๐Ÿ”’
Decide one binary messageโ€™s destination.
gesture_kind ๐Ÿ”’
The gestureโ€™s kind, for a record that names what was refused without carrying it. A typed text is never logged, only how long it was.
greet ๐Ÿ”’
Greet, then serve the client until it goes.
greeting_for ๐Ÿ”’
The frame that tells a client it is speaking to a forge and carries the [client] sets it draws with. Built when the connection opens, so a reload applies to the next connection.
gzipped ๐Ÿ”’
handle_client ๐Ÿ”’
Answer one client message.
handle_message ๐Ÿ”’
handle_client with the message already read, so a subscribe that queued behind a read off the loop takes the same path the socketโ€™s own did.
is_take_news ๐Ÿ”’
Whether this update is one of a takeโ€™s own.
log_open ๐Ÿ”’
The openโ€™s two records: the snapshotโ€™s write, and the sessionโ€™s slices.
mint_connection_id ๐Ÿ”’
The next number for a connection, unique for the processโ€™s life.
next_tab_change ๐Ÿ”’
The next tab list this connection asked to follow, or a future that never resolves while it follows none - the same shape next_view_event uses, so a connection with no strip parks rather than ending the loop.
next_terminal_event ๐Ÿ”’
The next thing this connectionโ€™s terminal has for the loop.
next_update ๐Ÿ”’
The streamโ€™s next update, or a future that never resolves while there is none - which is what keeps the branch out of the way until the client has subscribed and the role is known.
next_view_event ๐Ÿ”’
The next thing this connectionโ€™s viewer has for the loop.
open_stream ๐Ÿ”’
This connectionโ€™s stream from the core, opened when the client first subscribes and registered with the role that subscribe declares.
ours_to_hear ๐Ÿ”’
Whether this connection is one of an updateโ€™s readers.
page_of_span ๐Ÿ”’
The page a span of transcript rows answers with, cursors and all.
refusal_tag ๐Ÿ”’
The operation a dispatch refusal names, which a client routes by.
refuse_attach ๐Ÿ”’
Answer a refused attach: through the clientโ€™s reply when it sent one, and as the protocolโ€™s error frame otherwise.
released_subscribe ๐Ÿ”’
The answer a subscribe owes when the subject it named was released before any read for it could land.
row_cursor ๐Ÿ”’
The row a page below the floor is asked for, out of a cursor this server minted: the byte the walk reached next, and the id that row carries where it has one.
row_cursor_of ๐Ÿ”’
A row as the cursor a page below the floor hands back.
row_id ๐Ÿ”’
The id a transcript row names a frame by, for the frames that carry one.
rows_below_floor ๐Ÿ”’
Answer a page below the held windowโ€™s floor from the sessionโ€™s transcript.
run_connection ๐Ÿ”’
send ๐Ÿ”’
send_frame ๐Ÿ”’
send, answering how many bytes the frame carried.
send_frame_timed ๐Ÿ”’
send_frame, timing the socketโ€™s share of the write.
send_terminal_view ๐Ÿ”’
Send the attached terminalโ€™s screen as a VT stream, and where the stream continues from.
send_text ๐Ÿ”’
Write an already-encoded frame. The settings document is encoded once per reload and shared, so a connection writes its bytes rather than building the frame again.
set_showing ๐Ÿ”’
Move this connectionโ€™s shown seat, spending exactly what that showing earns.
spawn_read ๐Ÿ”’
Spawn a subscribe read off the connectionโ€™s loop, with its answer guard armed INSIDE the task: an encode that panics must still answer the loop, or its read stays in flight for the connectionโ€™s life and every later subscribe queues behind it in silence.
spend_showing ๐Ÿ”’
Spend what showing slot earns: its diamond, its failure mark and its death trace, and the home refresh a spent mark owes.
stamp ๐Ÿ”’
This connectionโ€™s own stamp on the commands that carry one.
submit_landed ๐Ÿ”’
Whether a submitโ€™s reply carries a sealed round, which null does not.
supervise ๐Ÿ”’
Run one connection under the wedge watchdog.
take_frame ๐Ÿ”’
Push one dictation frame into this connectionโ€™s takes or its read-aloud recording, recording anything else.
text_chars ๐Ÿ”’
How many characters a refused text carried, and nothing of what they were.
transcript_frames ๐Ÿ”’
The frames a range ask is answered with once the seatโ€™s own window has shed them: the conversationโ€™s own rows, numbered to END at the rangeโ€™s end.
upgrade
Take the upgrade and give the connection its own task.
upsert_landed ๐Ÿ”’
Whether an upsertโ€™s reply says the store took the write.
words_sent ๐Ÿ”’
write_snapshot ๐Ÿ”’
Write a subscribeโ€™s snapshot, register the subject, log the open and spend the showing marks the snapshot completes.