socket

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package socket is the PvP transport: a WebSocket server around internal/room's registry, a dialling client, and the **mirror** that client needs in order to be a client at all.

It is the one boundary the WebSocket dependency is allowed to cross. internal/wire is the format with no I/O in it and internal/room is a state machine with none either — both refuse `github.com/coder/websocket` by name in an AST walk — so everything that opens, reads, writes or closes a connection is here and nothing of it leaks back.

⚠️ This package owns the clock, and it is the only clock in the PvP stack

internal/room and internal/wire both refuse to import `time`, held mechanically, because *whoever owns the transport owns the countdown*: the room takes a timeout as an **input** and never asks what time it is. This package is the owner. So `time` appears here and nowhere else in the three, and every duration below is a decision this package makes rather than one it reads off the wire.

What the room hands over is a number: Reading.Config.Allowance, **seconds as an int**, deliberately not a time.Duration (a Duration JSON-encodes as a nanosecond count, and the allowance rides on wire.Welcome). Turning that number into a timer is this package's whole share of the clock.

⚠️ The mirror is here because no client can be thinner than one

The mirror driver is filed in the design record under *The client* rather than under *The wire*, and it is in this package anyway because of one observation about the protocol: **nothing on the wire says whose turn it is.** wire.Turn carries a decision and a digest, and a client derives "I am being asked" from its own replayed battle — Mirror.Asking is that derivation, and it is the only one there is. That is deliberate (a "your turn" message would be a second declaration of state the mirror already computes), and it means an end-to-end test cannot exist without a mirror. Writing one as test code now and promoting it later would be writing it twice.

The same argument reaches the *end* of a match. There is no series-standing message, so a client stops when its own arithmetic says the series is over — its own Ended events against wire.Welcome.Battles — which is why Mirror.Over re-derives a rule the room also has. Two peers agreeing because they compute the same thing from the same configuration is the mirror contract itself, the same shape wire.Welcome.TurnCap already takes.

What is deliberately NOT in here

So a reader does not go looking for it:

  • **Any TUI screen**, the lobby, the waiting and countdown drawing, and the wordings. A wire.Code and a wire.Closure travel as ids precisely so the wording lives at the client's far end, and nothing here words one — every refusal comes out of this package as a *Refusal carrying the code, for a screen to say in the player's own language. → TODO.md § The client.
  • **The seat token and the rejoin.** Which is why CloseThreshold is what it is: with no rejoin, a socket closing is a match ending, so that threshold is currently guarding a whole match rather than a ping. → its own note.
  • **The host binary.** Nothing here opens a listener, picks a port, decides which address a room code should carry, reads a flag or prints a word: a Server is an http.Handler, and the end-to-end test is what proves the shell is wired up. That is cmd/hexarena-host, and it is built. ⚠️ **Server.Shutdown is the one thing that crossed back**, because it could not live out there: http.Server.Shutdown does not wait for hijacked connections, and only this package holds the sockets that were hijacked. It still opens nothing — the *listener* is the binary's, and closing it is the binary's too.
  • **Writing a finished match out as a battle.Log.** Another cursor over the battle, which is why the room reads its own that way.
  • **TLS** (→ README.md § Not in the first version).
  • **A watching client.** ⚠️ This bullet used to say spectators were not here at all, and most of that has moved in: a table carries watching connections now (→ table.watchers, Server.forward, MaxWatchers), so a welcomed watcher is kept, handed everything the match has recorded and then every body as it is recorded. ⚠️ **Whether a room takes watchers at all is not this package's question either**, and it is answered now: it is one field of the room's configuration (room.Config.Watchable, chosen by cmd/hexarena-host's -watch), so a watcher of a room that was never opened to spectators is refused by the *room* and this package forwards that refusal like any other. What is still elsewhere is the *client* — a mirror driven by a welcome with no seat, and a battle screen where no key answers. → TODO.md § *Spectators*, step 5.

A connection finds its room in the URL, not in a message

No message body carries a wire.RoomCode and none should: the code is what a person **pastes to connect**, which is addressing rather than protocol content, and keeping it out is why widening the code to twelve characters moved no golden. So the code rides in the request path. → roomOf, for why the code is decoded and re-encoded before it is used as a key, and why an undecodable code is not refused here.

Index

Constants

View Source
const DefaultCloseThreshold = 60 * time.Second

DefaultCloseThreshold is how long a silent, unresponsive peer is tolerated before the transport decides there is nobody there — at which point it tells the room, which ends the match as room.VerdictAbandoned.

⚠️ **It is not a ping timeout and it must not be picked as one.** There is no rejoin yet, so a socket closing is a *match* ending: this is the only dial standing between a wifi hiccup and losing a whole bo3, and the design record says so in as many words. → TODO.md, under the seat token and the rejoin, which is the item that turns this back into an ordinary liveness number.

Sixty seconds, and the two things it was picked against:

  • **Generous against a hiccup.** A LAN wifi roam or a switch reconvergence is seconds, and TCP retransmission backoff rides out tens of seconds without the socket noticing at all — so this is several times the worst plausible blip. Note what it therefore does *not* govern: a peer whose process exits sends a FIN, the read fails at once, and that is a real departure with nothing to threshold. This number is only ever spent on a peer that has gone **silent and unresponsive**, which is exactly the case it has to be forgiving about.
  • **Under the turn allowance**, which is ninety seconds (room.DefaultAllowance). A machine that dies mid-turn is then noticed as a departure *before* its allowance runs out, so the match ends as abandoned rather than grinding out one timeout per turn until the board kills the passing units — which is what would happen if this were the larger of the two, and is the slow, confusing version of the same ending.

It is configurable (Timings.CloseThreshold) because the two bounds above leave a range rather than a point, and because the number a host wants on a wired LAN is not the one a host wants over patchy wifi.

View Source
const DefaultKeepalive = 15 * time.Second

DefaultKeepalive is how often the transport pings a peer to find out whether it is still there.

It has to exist separately from the threshold because silence is not absence: a player thinking about a turn sends nothing for up to the whole allowance, so a read deadline would drop somebody for concentrating. A ping is answered by the *library* rather than by the player, which is what makes it a measurement of the machine rather than of the person.

View Source
const DefaultMessageLimit = 64 << 10

DefaultMessageLimit is the largest message either side will read.

⚠️ **This was written on a guess and the guess was wrong, so the figure is the measurement.** The reasoning was that wire.Start carries the whole resolved roster — every unit of both sides with its flat stat line, its kit and its traits — so a 5v5 start would approach the library's own 32 KiB default and a megabyte would be the safe answer. Measured (TestTheLargestStartFitsTheMessageLimit): the largest start a legal room can send is **2,911 bytes** over ten units. The library's default would have done perfectly well, and a megabyte was twenty times more allocation than a peer should be able to ask of this side for no reason at all.

So it is 64 KiB: explicit rather than inherited, twenty-two times the largest message the protocol can actually produce — room for a wider format, longer ids or a field added to a roster entry — and still a bound. The test holds both ends of that, because a limit with no headroom and a limit with nothing but headroom are both worth failing on.

View Source
const DefaultRejoinWindow = 60 * time.Second

DefaultRejoinWindow is how long a seat is held open for the client that had it, after the socket between them closed.

⚠️ **This is what the close threshold used to be doing on its own, and the two are now different jobs.** Before a rejoin existed, a socket closing ended the match, so the threshold was the only thing standing between two seconds of lag and losing a whole bo3 — and it had to be generous for a reason that was nothing to do with liveness. It can go back to answering its own question, "is anybody there", and this answers "how long do we wait for them to come back".

Sixty seconds, and the bounds are the same two the threshold's are, from the other side:

  • **Long enough to be worth having.** A wifi roam, a switch reconvergence or a laptop lid is seconds to tens of seconds; a window shorter than the blip it is meant to survive is a feature that never fires.
  • **Bounded by what the other player will sit through.** The room's clock does NOT stop while a seat is held — a player does not buy thinking time by pulling out a cable — so a seat that stays away past its allowance is passed by room.TimedOut exactly as if its holder were staring at the screen. The window therefore costs the other player nothing beyond the ordinary allowance, and what it bounds is only how long a *finished* match waits before the room is told nobody is coming back.

A zero or negative Timings.RejoinWindow takes this default; a room whose seats have no token holds nothing open whatever this says, because there would be nobody who could come back. → room.Admission.Rejoinable.

View Source
const DefaultWrite = 10 * time.Second

DefaultWrite is how long one message may take to go out before the peer it is addressed to counts as unreachable.

It bounds the one place this transport holds a lock across I/O: a room's exchange is ordered by a mutex (→ table.exchange) and the writes happen under it, so a stuck peer would otherwise hold its own room still. Ten seconds is far past a LAN write of a few kilobytes and far short of the close threshold, so a genuinely wedged connection is reported by the threshold rather than by this.

View Source
const MaxWatchers = 8

MaxWatchers is how many watching connections one table carries, and it is **not** a second seat count: it bounds a collection rather than naming one.

Eight, and the two things it was picked against. A room is a handful of people in one place on one LAN, so four times the two seats is more than a group watching a match ever needs — and the cost of the number is paid inside the room's exchange lock, where every watcher is written to in turn, so the worst case a stuck spectator can impose on the two people actually playing is this many Timings.Write. Uncapped is the real objection: a table's watchers are connections a stranger on the LAN opens, and nothing else in this transport would stop one machine opening thousands.

It is exported because the cap is a fact about the transport that its callers need: a host printing how many people are watching, a client wording wire.CodeTooManyWatchers, and the test that fills a table up.

⚠️ **It stayed here when the host's flag landed, and that is a decision.** Whether a room takes watchers at all is the room's own configuration (room.Config.Watchable, chosen by cmd/hexarena-host's -watch, refused at the gate with wire.CodeWatchingClosed); how many may watch it at once is this, and the two are different questions with different answers. Moving this onto room.Config would put a number about watchers on a struct whose whole point is that the room counts none of them — and the cost this bounds is paid here, inside the room's exchange lock, over connections only this package holds.

Variables

This section is empty.

Functions

func Allowance

func Allowance(seconds int) time.Duration

Allowance is a room's per-prompt allowance as a duration, which is the one conversion in the repository from the protocol's seconds-as-an-int to a clock.

It is a function rather than an expression at the call site because it is the seam the whole "the room reads no clock" arrangement turns on: there is exactly one place a wire.Welcome's number becomes a time.Duration, and it is this one.

⚠️ **It is exported because the countdown gave it a second caller, and that is what keeps "one conversion" true.** cmd/hexarena-tui counts down the seat on turn so a player can watch the other one think, and its chooser waits this long plus a grace before giving up on a prompt nothing can answer — both are this number becoming a duration, and a client doing that arithmetic itself would be a second declaration of what a wire.Welcome's seconds mean. The module-wide allowlist beside this package treats a caller of this function as a clock reader for exactly that reason.

func RoomPath

func RoomPath(code wire.RoomCode) string

RoomPath is the request path for one room code.

⚠️ The code goes in the **path** and not in a message, and that is a decision rather than a convenience: a code is what a person pastes to connect, so it is addressing rather than protocol content. Keeping it out of the eight messages is why widening it from ten characters to twelve moved no byte of messages.golden. → wire.RoomCode.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a dialled connection and the Mirror behind it.

It is the whole of what a screen would sit on top of: Dial gets past the gate, Mirror is the battle, and Play is the message loop. Nothing here draws anything and nothing here words a refusal — a wire.Code travels as an id precisely so the sentence lives at this end, in the player's own language. → the package comment on what is deliberately out of scope.

func Dial

func Dial(ctx context.Context, code wire.RoomCode, hello wire.Hello, books battle.Books,
	options ClientOptions) (*Client, error)

Dial connects to the room a code names and gets past its gate.

The **code carries the address**, so there is nothing else to be told: it decodes to an IPv4 address, a port and which of the rooms behind them is meant, and the path is where the code itself rides (→ RoomPath). A player who typed it in lower case is fine — the code is re-encoded into its canonical form, exactly as the server does, so the path names the key the registry holds.

On a refusal it returns a *Refusal and closes the connection: a refused join is the end of the conversation, and the code is everything the client needs in order to say why.

func (*Client) Close

func (c *Client) Close()

Close ends the connection with a normal closure, which is what the far end reads as an ordinary departure rather than a fault.

func (*Client) Code

func (c *Client) Code() wire.RoomCode

Code is the canonical code this client is connected under.

func (*Client) Mirror

func (c *Client) Mirror() *Mirror

Mirror is this client's own battle. → Mirror, on why a client cannot be thinner than one.

func (*Client) Play

func (c *Client) Play(ctx context.Context, choose battle.Chooser) error

Play is the client's message loop: read, step the mirror, and answer when the mirror says the turn is this client's.

It returns when the match is over by this client's **own** arithmetic (→ Mirror.Over — there is no series-standing message, so the client computes the ending), when the room closes the match for a reason the board cannot show, or when the connection ends in the ordinary way. A divergence is an error, on the turn it happens.

The chooser is what decides a turn. `(*battle.Battle).Suggest` is the shipped rating and satisfies it, which is what lets a whole match play out with nobody typing; a real client hands in the player's keystrokes instead. A **draft** decision is answered by ClientOptions.Draft, which is a different question and is why this signature did not have to grow one.

⚠️ **A WATCHER needs no chooser and one passed here cannot make it act.** The loop below is the whole of what a spectator runs — it reads, mirrors and checks every digest like any other client — and the only thing it does not do is answer, because Mirror.Asking is false for a watching mirror on every turn including the host's. So a nil chooser is legal here for a watcher and a non-nil one is never reached: answer returns before it, at the one derivation. → Mirror.asking.

⚠️ **It answers before the first read as well as after every message, and that is what makes a drafting room joinable at all.** A room that drafts announces nothing when its draft opens — a wire.Drafted carries recorded decisions, none have been taken, and a room must not send one carrying none — so the host's first ban is due with no message on its way to prompt it. A loop that read first would sit there for ever, and it did.

func (*Client) Seat

func (c *Client) Seat() wire.Seat

Seat is which of the room's two places this client took, for the match, and the empty seat for a client the room welcomed to watch. → Watching, which is the reading to branch on rather than this one.

func (*Client) Token added in v0.2.0

func (c *Client) Token() wire.SeatToken

Token is what this client shows to take its seat back after the socket closes, and is empty for a watcher and for a room that issues none.

⚠️ **It is kept and never drawn.** A seat token is a capability: whoever holds it is that seat, so it belongs in the memory of the process that took the seat and nowhere else — not on a screen, not in a log, not in a file. wire.SeatToken redacts itself under %s and %v, which is what makes a careless format string a non-event rather than a match given away.

It is a reading off the welcome rather than a field, for Watching's reason: the room said it once and a second copy is a second thing to keep in step.

func (*Client) Watching added in v0.2.0

func (c *Client) Watching() bool

Watching is the room having welcomed this client to watch rather than to play.

⚠️ **The handshake needed no change for it and that was measured rather than assumed.** NewMirror("") starts seatless, handshake calls takeSeat off the welcome before Receive, and welcomed's check is `welcome.Seat != m.seat` — so a welcome naming no seat is taken by a mirror that has just been told it has none, and the two agree. → Mirror.Watching for the one derivation.

type ClientOptions

type ClientOptions struct {
	// Timings is the transport's clock. The zero value takes every default.
	Timings Timings

	// Stepped is called on the Play goroutine after every message this client
	// has taken in, so a renderer knows there is something new to draw.
	//
	// ⚠️ **It is the other half of a client's redraw and a chooser cannot be
	// it.** A chooser only fires on *this* client's turns, so a screen driven by
	// one alone would sit still for the whole of the opponent's turn and then
	// jump — and in a match that is up to a ninety-second allowance of a board
	// that looks frozen.
	//
	// ⚠️ **It is handed NOTHING**, and both halves of that are deliberate.
	// Passing the Mirror out is exactly what Mirror.Read exists to refuse, and
	// passing the battle out would be the pointer escaping the lock. And it is
	// called with **no lock held**: a caller that Sends into a program whose
	// Update is inside Mirror.Read would otherwise deadlock the two against each
	// other, which is the same ordering Mirror.Decide is written under.
	//
	// A nil hook is the ordinary case — a client with nothing drawing it, which
	// is what every test that plays a match out with a rating is.
	Stepped func()

	// Characters is the cast a draft's pool is drawn from, and it is here rather
	// than a sixth positional parameter on Dial for the argument this struct's own
	// comment makes: a caller with no interest in drafting should not have to
	// write it down, and Dial's signature stays put.
	//
	// ⚠️ **It is the book and not a draft.Pool**, deliberately. draft.NewPool is
	// this repository's single declaration of "the cast minus every character held
	// back", so a caller handing a pool in could hand one built from the whole
	// book — which would offer a held-back character the room refuses. →
	// Mirror.openDraft.
	//
	// A nil book is the ordinary case, and a welcome saying the room drafts
	// refuses a client without one rather than joining and then failing to compute
	// its pool.
	Characters *cast.Book

	// Draft is what answers a draft decision, and it is on this struct for the
	// same reason Characters is: Play's signature is untouched, and a client that
	// never drafts needs no change at all.
	//
	// ⚠️ **It is not battle.Chooser and could not be.** Play's chooser answers a
	// *battle* prompt — a skill and a cell off a board — and a draft decision is a
	// different question in a different vocabulary: a character out of a pool, a
	// form and a kit, a formation. → DraftChooser.
	//
	// ⚠️ **A nil one is not a client that quietly answers nothing.** A client
	// dialled without this that lands in a drafting room fails loudly the moment
	// it is asked, because a chooser that answered nothing would be a client
	// sitting for ever on a decision — the hang the whole timeout mechanism exists
	// to prevent, and the one #316 just fixed an instance of. The failure is at
	// the point of being **asked** rather than at the point of joining, so that a
	// caller with nothing to decide — a spectator, when there is one — can still
	// dial a room that drafts. → Client.answer.
	Draft DraftChooser
}

ClientOptions is everything a caller may say about a dialled client, and it is a struct rather than a sixth positional parameter for the reason Options is one on the server side: a caller that wants the hook and not the clock should not have to write the clock down.

type Divergence

type Divergence struct {
	// Seat is the client that noticed, Battle which battle of the series it was
	// fighting, and Unit and Turn the decision the two disagreed about.
	//
	// ⚠️ Turn is battle.Decision.Turn, which is **the unit's own count of its
	// turns** and not a position in the battle. That is the number the log
	// records and the number a decision is identified by, so it is the right one
	// to carry — but a reader who takes it for "the nth turn of the battle" will
	// read `A1 turn 5` before `E1 turn 4` and think the report is wrong.
	Seat   wire.Seat
	Battle int
	Unit   string
	Turn   int
	// Room and Client are the two digests, the server's first.
	Room   wire.EventDigest
	Client wire.EventDigest
}

Divergence is two peers no longer fighting the same battle, reported on the turn it happens with both digests to compare.

It is a type rather than a sentence because the turn is the whole point: a caller that can name the turn can name the decision, and the two digests are what a bug report needs. → the note on Mirror.

func (*Divergence) Error

func (d *Divergence) Error() string

type DraftAnswer added in v0.2.0

type DraftAnswer struct {
	// For is the decision this answers, which a chooser copies off the prompt it
	// was handed.
	For DraftDue
	// Decision is the answer. Its Step has to be the one For names: this is one
	// answer to one question, and an answer disagreeing with itself about which
	// question is refused here rather than by the room.
	Decision wire.DraftDecision
}

DraftAnswer is a draft chooser's answer: the decision it is for, and the decision itself.

⚠️ **For is not derivable from Decision, and that is the point rather than an inconvenience.** A wire.DraftDecision carries its own Step, so an answer for the wrong stage could be caught without this — but nothing on a decision counts the record and a loadout's names no character, so an answer stale within one step is indistinguishable from a fresh one unless it says which decision it was given for. → DraftDue.

type DraftChooser added in v0.2.0

type DraftChooser func(DraftPrompt) (DraftAnswer, bool)

DraftChooser is what decides a draft decision, and it is a different question from battle.Chooser asked in a different vocabulary: a ban, a pick, a loadout or an arrangement, out of a pool rather than off a board.

⚠️ **A false is a failure and not a pass.** A battle has wire.Pass; a draft has nothing of the kind. A ban that names nobody is a **skip**, which is a decision somebody takes (→ draft.Draft.SkipBan) and not one this package may invent on a player's behalf, and a draft whose allowance runs out is cancelled outright with no auto-pick at all (→ draft.Draft.TimedOut). So Play reports a false rather than sending anything, which is the loud ending the whole timeout mechanism exists to have instead of a client sitting on a decision for ever.

type DraftDue added in v0.2.0

type DraftDue struct {
	// Seat is whose decision it is. It is this client's own wherever a chooser is
	// handed one, because DraftAsking answers nothing for the other seat — it is
	// carried so that a Due is a whole name for a decision rather than half of
	// one.
	Seat wire.Seat
	// Step is which of the kinds it is. → wire.DraftStep.
	Step wire.DraftStep
	// Character is what the step is about where it is about a character already
	// chosen: the pick a loadout is owed for. Empty on a ban, a pick and an
	// arrangement, none of which is about one.
	//
	// ⚠️ A loadout's own wire.DraftDecision cannot carry this — it names no
	// character, because the pick one decision earlier is what named it — which is
	// half of why an answer needs a Due beside its decision rather than only the
	// decision's own Step.
	Character string
	// Recorded is how many decisions the draft had recorded when this one was
	// raised. → the ⚠️ above, which is the whole reason it is here.
	Recorded int
}

DraftDue names one decision of a draft, and it is what an answer has to say it is for.

⚠️ **The discriminator is the decision and never the moment.** CLAUDE.md § *Mistakes already made here* carries this in full: the chooser's answer slot was drained on entry, on the premise that nothing could be in it for a turn that had not been asked about yet — but a client learns whose turn it is from its own mirror, a message and a redraw earlier, so a player answering off the board already in front of them landed in the slot first. The drain ate a real decision, the screen had recorded the turn as answered and would not offer it again, and both ends stood still for a whole allowance. The fix was that the answer names its turn and the chooser asks. A draft decision needs the same.

It is four scalars so that it is **comparable**: DecideDraft's whole check is `answer.For == prompt.Due`, and a struct carrying a slice could not be compared with one operator.

⚠️ **Recorded is what closes the hazard the step alone leaves open, and it is deliberately local.** wire.Decide carries no sequence number and says why: a draft has exactly one open decision, so the step tags a decision stale across a *stage* on its own — a ban arriving while a pick is due — and what it cannot tell apart is one stale **within** a step, a second ban meant for the first ban slot. Two of one seat's ban slots have the other seat's between them, so the record has grown and this number has moved. It never travels: the room holds its own record and has no use for a client's count of it, so this is routing between a screen and its own chooser rather than protocol content.

type DraftPrompt added in v0.2.0

type DraftPrompt struct {
	// Due names the decision, and is what an answer must say it is for.
	Due DraftDue
	// Candidates is what a ban or a pick may name: the pool minus every character
	// already banned or picked, in the pool's own order.
	//
	// Nil for a loadout and for an arrangement, neither of which chooses a
	// character — which is draft.Draft.Candidates' own answer, unchanged, and its
	// own comment says why nil is a different answer from an empty list.
	Candidates []cast.Character
	// Mine is this seat's own picks in the order it took them, which is what the
	// two decisions that are not about the pool need: a loadout is owed for the
	// last of them, and an arrangement names one cell per pick, so `Slots[i]` is
	// the cell for `Mine[i]`.
	Mine []draft.Pick
}

DraftPrompt is the open draft decision as the client being asked for it sees it: which decision, and what there is to choose from.

It is the draft's twin of *battle.Prompt and it is a **value** for the reason every field of DraftSight is one: a prompt read out from under the mirror's lock and kept would be a reading of a draft the Play goroutine is about to step.

type DraftSight added in v0.2.0

type DraftSight struct {
	// Mirrored is this client holding a draft at all, which is Welcome.Drafts
	// having said the room drafts. Every field below means nothing without it.
	Mirrored bool
	// OnTurn and Step are whose decision is due and which kind, and Open whether
	// one is — draft.Draft.Turn's three answers, unchanged.
	//
	// ⚠️ Open is **false during the arrange phase**, and that is not this reading
	// being incomplete: Turn answers one seat and the phase has two pending at
	// once, so the phase is asked about through Arranging and Awaiting instead. →
	// draft.Draft.Turn, which says why it never widened for it.
	OnTurn wire.Seat
	Step   wire.DraftStep
	Open   bool
	// Asking is the open decision when it is **this** client's to answer, and
	// Asked whether it is — the draft's twin of Sight.Asking, and the whole of how
	// a screen knows to offer a choice. It covers the arrange phase, where Open is
	// false and this client may still be one of the two being asked.
	Asking DraftPrompt
	Asked  bool
	// Candidates is what the open decision may choose from, **whosever it is**: a
	// screen draws the remaining pool while the other side thinks, so this is not
	// Asking.Candidates narrowed to this client's own turns. When Asked it is the
	// same list the prompt holds rather than a second reading of it.
	Candidates []cast.Character
	// Picks is both sides' picks so far, indexed by seat in the order a room hands
	// seats out — **[0] is wire.SeatHost and [1] is wire.SeatGuest** — which is
	// draft.Draft.Picks' own indexing. A pick with no skills is one whose loadout
	// is still open.
	Picks [2][]draft.Pick
	// Bans is the characters each side took out of the pool, indexed the way
	// Picks is. → draft.Draft.Bans, which is where a skipped slot's absence is
	// argued for.
	//
	// ⚠️ **It is here because it is the one thing about a draft a mirror cannot
	// derive.** Candidates minus Picks already says *which* characters are gone
	// to a ban; which **side** took each one is not on any reading of the state,
	// because the ban order is Config.First alternating and a skip moves the
	// count without naming anybody. A screen owes a player the difference between
	// their own ban having landed and the opponent's having, which is 5a's
	// measured gap drawn rather than described.
	Bans [2][]string
	// Arranging is the arrange phase being open, and Awaiting which seats have
	// still to arrange, in seats order.
	Arranging bool
	Awaiting  []wire.Seat
	// Picked is the ban and pick played out, Done that and both arrangements in,
	// and Cancelled the draft having been abandoned. → draft.Draft.Picked, which
	// says why the first two are two questions and not one.
	Picked    bool
	Done      bool
	Cancelled bool
	// Squads is what a whole draft produces, indexed the way Picks is, and two
	// squads with **nobody in them** until Done — draft.Draft.Squads' own promise,
	// which is an honestly incomplete answer rather than a plausible one.
	Squads [2]placement.Squad
	// Replayed is how many recorded decisions this client has taken back through
	// its own draft, so a caller can say the mirror ran rather than hope it did —
	// the same argument Mirror.Compared is exposed under.
	Replayed int
}

DraftSight is a consistent reading of this client's own mirror of the draft, by value.

⚠️ **It is a snapshot and never the *draft.Draft, and the decisive reason is the import graph rather than the lock.** internal/screen — where the screen that draws this lives — imports internal/core/battle and does **not** import internal/draft, which could not import it either way: internal/draft imports internal/wire, so pulling it into the package two clients share would drag the protocol in behind it. That is the same constraint that keeps the lobby's three screens in cmd/hexarena-tui. So a *draft.Draft handed out here would be a pointer no renderer could name, whatever the locking said.

The lock is the second reason and it is real but weaker: every field here is a copy, and internal/draft is what makes that cheap to be sure of — Picks, Squads, Candidates and AwaitingArrangement each build a fresh slice, so nothing here can alias the draft the Play goroutine is stepping.

⚠️ **This paragraph said "a pointer handed out from under an RWMutex is a shape this package has already paid for twice", and that overstates it** — it came from the brief for this step and is corrected here rather than repeated. What this package paid for twice was holding the lock **across a callback** (which deadlocks against the next writer → Decide, DecideDraft) and a **drain that ate a real answer** (→ CLAUDE.md § *Mistakes already made here*). Neither is a pointer escaping, and Sight.Fight is proof that one may.

⚠️ **Sight.Fight is the deliberate exception and stays one.** A renderer computes the board by computing the battle, so the *battle.Battle has to be handed over and Mirror.Read's comment is what holds the rule about it. A draft has no such computation: what a screen draws is the pool, the picks and whose decision is due, which is exactly what this carries.

type Fought

type Fought struct {
	// Battle is which battle of the series this was, counting from one.
	Battle int
	// Side is the half of the board this client played, which changes between
	// battles because a match is fought both ways round.
	Side hex.Side
	// Seed is the seed this battle was fought from.
	Seed uint64
	// Outcome is the engine's own, and is battle.Undecided for a battle this
	// client stopped at the turn cap — the engine concluded nothing about that
	// one, exactly as the room records it.
	Outcome battle.Outcome
	// Winner is the side that won and Decided whether anybody did.
	Winner  hex.Side
	Decided bool
	// Capped is the turn cap having stopped the battle.
	Capped bool
	// Turns is how many turns this client's battle opened, skipped included.
	Turns int
}

Fought is one battle of the series as a client's own engine settled it, which is the only place a client learns an outcome from: there is deliberately no series-standing message, because a standing would be a second declaration of something the mirror computes.

func (Fought) Mine

func (f Fought) Mine() bool

Mine reports whether this client won the battle.

type Mirror

type Mirror struct {
	// contains filtered or unexported fields
}

Mirror is a client's own battle, driven by the six messages a server sends.

It is a **mirror** in the sense the design record means: it builds its own *battle.Battle from the seed and roster on wire.Start and steps it with the decisions on wire.Turn, so it computes the state by computing the battle rather than by being told it. Nothing about the board, the health, the statuses or the queue ever crosses the wire, because none of it has to.

⚠️ **It mirrors the DRAFT the same way**, in a room that has one: it builds its own *draft.Draft from Welcome.Drafts and steps it with the decisions on wire.Drafted, so the pool, both sides' picks and whose decision is due are computed rather than told. → draft.go, which is the whole of the client's draft half, and which carries the measurement of what a client could not do before it existed.

⚠️ Why this is production code and not a test fixture

**Nothing on the wire says whose turn it is.** wire.Turn carries a decision and a digest; Asking is where "I am being asked" comes from, and it is derived from this battle. So a client that was not a mirror could not know when to enable input, and the thinnest possible client is therefore exactly this. An end-to-end test needs one too, so writing it as a fixture and promoting it later would be writing it twice. → the package comment.

The digest is what makes it a check rather than a hope

Every wire.Turn carries the digest of the events the *server's* battle produced. This one digests the events its own battle produced for the same decision and compares, every turn, so a divergence is loud on the turn it happens with two digests to compare — rather than a board that quietly drifts. A mismatch is a *Divergence naming the turn.

⚠️ The order the events are read in is what keeps the two equal, and it is easy to get wrong: Replay applies the decision, walks through whatever is forced after it, and stops on the prompt it cannot decide, so the run holds the decision, then every skipped turn, then the next turn's opening. That is the same order room.resolved reads its cursor in, and reading a step earlier on either side makes every digest disagree while both peers fight the same battle perfectly.

It is safe to DRAW while Play is stepping it, and that is new

⚠️ **This comment used to end "it is not safe for concurrent use and needs not to be: one client, one connection, one goroutine reading it", and that stopped being true the moment a terminal drew one.** A full-screen client runs Play on its own goroutine and redraws on bubbletea's, so the battle Play is stepping is the battle the screen is reading — which is exactly the concurrent use that sentence said would never happen. The answer is a lock rather than a copy: a *battle.Battle is a pointer and copying one is not a thing this repository can do, and handing a renderer the events instead would be the thin client README.md § *The client runs the engine too* refuses.

So: Receive takes the write lock and every reading accessor takes the read lock. Read is the only safe way for a renderer on another goroutine to look at more than one of those readings at once — a screen that asked for the battle, then the prompt, then the side would get three readings of three different moments.

⚠️ **Decide releases the lock before it calls the chooser**, and that is the one ordering here that must not be got wrong. → Decide, which carries the measurement of *why* — the reason is a writer queuing, not the two readers, and getting that wrong once made a test that could not see the mistake.

func NewMirror

func NewMirror(seat wire.Seat, books battle.Books, characters *cast.Book) *Mirror

NewMirror is a client's battle-to-be: it holds the books, holds the cast a draft would be drawn from, and knows which seat it is — and everything else arrives on a message.

⚠️ The cast is a **third book** rather than something read off a message, because it is the same kind of thing as the other two: a draft's pool is draft.NewPool over it, and what makes this client's pool the room's pool is the data digest at the gate refusing a peer whose cast is not this cast. A nil one is legal and is what a client that never drafts passes. → openDraft.

func (*Mirror) Asking

func (m *Mirror) Asking() (*battle.Prompt, bool)

Asking is the open prompt when it is **this** client's to answer, and it is the whole of how a client knows its turn has come.

⚠️ Nothing on the wire says so. The room knows whose turn it is — which is why wire.Act carries no unit — and it says nothing about it, because a "your turn" message would be a second declaration of a fact this battle already holds. So the derivation is: the battle stopped on a prompt, and the unit it names is on the side this client plays.

It is false past the turn cap, because the room stops asking on the turn this client stops at.

func (*Mirror) Battle

func (m *Mirror) Battle() *battle.Battle

Battle is this client's own battle, for a renderer or a rating. Nil between battles and before the first one.

⚠️ **The lock is around the pointer and not around the battle.** A caller that keeps what this returns and reads it later is reading a battle Play may be stepping, which is precisely what Read exists to do instead. This accessor is for a caller on the Play goroutine itself — the chooser is the one that matters, since Play calls it and nothing else is running.

func (*Mirror) Capped

func (m *Mirror) Capped() bool

Capped reports whether this client's battle in progress stopped at the turn cap the room named on wire.Welcome.

func (*Mirror) Closure

func (m *Mirror) Closure() (wire.Closure, bool)

Closure is the room having closed the match for a reason the board cannot show, and whether it has.

⚠️ This is the one ending a mirror cannot reach on its own: a departure leaves no Ended for the battle in progress and no further Start, so a client handed nothing would hang on its own open prompt. Every other ending is computed here. → wire.Closed.

func (*Mirror) Compared

func (m *Mirror) Compared() int

Compared is how many per-turn digests this client has checked. → the field.

func (*Mirror) Decide

func (m *Mirror) Decide(choose battle.Chooser) (wire.Body, bool)

Decide is the message this client sends for the open prompt, read off its own battle by the given chooser.

⚠️ It **applies nothing**. A mirror steps its battle from the wire.Turn that comes back rather than from its own input, so that the events it produces come out of the same call on both sides — which is why the room sends every turn to both clients including the one that asked for it. Deciding locally and applying locally would be two paths into one battle.

It reports false when there is no prompt to answer.

⚠️ **The read lock is taken to find the prompt and RELEASED before the chooser is called, and that ordering is load-bearing rather than tidy.** In a full-screen client the chooser *is the player*: it blocks until a keystroke arrives, and the keystroke is handled by a goroutine that needs the read lock in order to draw.

⚠️ **Why a held lock is fatal is NOT "two readers cannot both be in", and that was measured after being got wrong.** sync.RWMutex admits several readers, so a chooser that only ever reads would sit happily beside a renderer that only ever reads, and holding the lock across choose passes a test built on that prediction. What actually breaks is a **writer arriving while the chooser waits**: Go queues a waiting writer ahead of new readers, so the next Receive blocks behind the held read lock and the renderer then blocks behind the writer — and the renderer is what the player is waiting to see before they can answer. TestDecideDoesNotHoldTheLockAcrossTheChooser builds exactly that three way and is what says so; the failure it catches is a hang, bounded so it reports rather than hangs the suite.

The prompt handed to the chooser outlives the lock, which is safe for the one reason Play is what calls this: nothing steps the battle between the read and the answer, because the goroutine that would is the one waiting here.

func (*Mirror) DecideDraft added in v0.2.0

func (m *Mirror) DecideDraft(choose DraftChooser) (wire.Body, bool)

DecideDraft is the message this client sends for the open draft decision, read off its own draft by the given chooser.

⚠️ It **applies nothing**, for the reason Decide applies nothing: a mirror steps its draft from the wire.Drafted that comes back rather than from its own input, so that the state it computes comes out of the same call on both sides — which is why the room sends every recorded decision to both clients including the one that asked for it. Deciding locally and applying locally would be two paths into one draft.

It reports false four ways: nothing is due, there is no chooser, the chooser declined, and the answer names a decision that is not the open one.

⚠️ **The read lock is taken to find the decision and RELEASED before the chooser is called, and that ordering is load-bearing rather than a copy of Decide's shape.** An RWMutex held across a callback deadlocks against the next **writer**: Go queues a waiting writer ahead of new readers, so the next Receive blocks behind the held read lock and the renderer then blocks behind the writer — and the renderer is what the player is waiting to see before they can choose. Note what that means for a test: two readers sit happily beside each other, so a version built on "two readers cannot both be in" passes with the lock held. → Decide, which carries the measurement, and TestDecideDraftDoesNotHoldTheLockAcrossTheChooser, which builds the same three-way for a draft.

The prompt handed to the chooser outlives the lock, which is safe for the one reason Play is what calls this: nothing steps the draft between the read and the answer, because the goroutine that would is the one waiting here. And it is a **value**, so keeping it reaches nothing.

⚠️ **A stale answer is refused rather than applied to the next decision**, and it is counted so the refusal leaves a trace. → DraftDue, which is what an answer names and why naming it is not optional, and Stale.

func (*Mirror) Draft added in v0.2.0

func (m *Mirror) Draft() DraftSight

Draft is a consistent reading of this client's own mirror of the draft.

→ Read, which is how a renderer gets this and the battle in one reading, and which is the only safe way to look at more than one of them at once.

func (*Mirror) DraftAsking added in v0.2.0

func (m *Mirror) DraftAsking() (DraftPrompt, bool)

DraftAsking is the open draft decision when it is **this** client's to answer, and it is the draft's twin of Asking: the whole of how a client knows a decision has come to it.

⚠️ Nothing on the wire says so, exactly as nothing on the wire says whose turn it is in a battle. The room sends the decisions and each client derives the open one from its own replayed draft.

func (*Mirror) Events

func (m *Mirror) Events() []battle.Event

Events is everything this client's battle has produced in the battle in progress, which is what a renderer draws.

func (*Mirror) Fought

func (m *Mirror) Fought() []Fought

Fought is every battle of the series this client has settled, in order.

func (*Mirror) Over

func (m *Mirror) Over() bool

Over reports whether the match is finished, by this client's own arithmetic.

⚠️ **It re-derives a rule the room also has, and that is the design rather than a duplication to be tidied away.** There is no series-standing message — a standing would be a second declaration of something the client computes, and the one place two peers could disagree about who is winning while both of their battles agreed. So the client learns each battle's outcome from its own Ended event, knows the series length from wire.Welcome.Battles, and stops when a side is past taking back or every battle has been fought. Two peers agree because they compute the same thing from the same configuration, which is the mirror contract itself — the same shape wire.Welcome.TurnCap takes.

A closure ends it too, because that is the ending this arithmetic cannot see.

func (*Mirror) Read

func (m *Mirror) Read(fn func(Sight))

Read runs fn under this mirror's read lock, which is the only safe way for a renderer on another goroutine to look at a battle Play is stepping.

⚠️ **Nothing fn is handed may outlive fn.** That is the rule Registry.Read is written under, and here it is held by this comment and by nothing else: a *battle.Battle is handed over on purpose — a renderer computes the board by computing the battle, which is the whole design — so no type walk and no race detector can refuse one. A caller that keeps the pointer and reads it after fn returns is reading a battle the Play goroutine may be stepping, and the detector only fires if it actually does.

Several readers may be inside this at once, which is what makes an Update and a View both able to take it in a bubbletea client.

func (*Mirror) Receive

func (m *Mirror) Receive(body wire.Body) error

Receive is the client's whole message loop: one of the **six** messages a server sends in, and an error out when this client can no longer claim to be fighting the same battle.

⚠️ **It was five until the draft, and the missing arm was not a gap in a screen — it was a drafting room being unjoinable by any real client.** The default below answers *"was sent a X, which no server sends"*, so a wire.Drafted errored the client and closed the connection. → draft.go.

⚠️ It takes both a body and a pointer to one, because the two producers in this repository hand over different things: room.Outbound carries values, and wire.Decode hands back pointers so that an unknown kind never reaches a struct. Room.Deliver takes both for the same reason.

⚠️ **It takes the write lock for the whole of one message**, so a renderer on another goroutine never sees a battle half stepped: the events, the prompt, the cursor and the fought list all move together or not at all. Every private step below therefore runs with the lock already held and must not take it again.

func (*Mirror) Refusals

func (m *Mirror) Refusals() []wire.Code

Refusals is every wire.Code this client has been sent, in order, for a screen to word. Nothing here words one: the whole point of a code is that the sentence lives at this end, in the player's own language.

func (*Mirror) Seat

func (m *Mirror) Seat() wire.Seat

Seat is which of the room's two places this client took.

It takes the read lock like every other accessor even though the seat is written once, at the handshake, before Play exists: a rule that holds for "the fields that change" is a rule somebody has to classify a field under every time one is added, and the classification is what goes wrong.

func (*Mirror) Side

func (m *Mirror) Side() hex.Side

Side is the half of the board this client plays in the battle in progress.

⚠️ **For a WATCHER this is the host's half and not this client's**, because a watcher plays neither: the wire.Start on the room's record carries the host's side, so a spectator watches from the host's chair. That is what makes it the wrong thing to compare a prompt's unit against — → asking, which is where that comparison lives and where a watcher is refused before it is reached.

func (*Mirror) Stale added in v0.2.0

func (m *Mirror) Stale() int

Stale is how many draft answers this client refused for naming a decision that was not the open one.

It is exposed for the reason Compared is, and counted for the reason table.late is: a refusal that sends nothing and closes nothing leaves no other trace at all, so a test asserting the path was taken has to be able to read it.

func (*Mirror) Watching added in v0.2.0

func (m *Mirror) Watching() bool

Watching reports whether the room welcomed this client to **watch** rather than to play, which is exactly the absence of a seat.

⚠️ **It is one derivation off wire.Welcome.Watching and there must not be a second.** That function is already this repository's single declaration of the condition — the room, the transport and the screen each have to ask it — and it is deliberately not `Seat != SeatHost`, which is the same answer today and stops being one the moment anything else can sit down. So nothing here compares m.seat against anything, and nothing outside this file re-derives the question: what a caller gets is this reading, or Sight.Watching beside it.

func (*Mirror) Welcome

func (m *Mirror) Welcome() (wire.Welcome, bool)

Welcome is the room's configuration as this client was told it, and Seated whether it has been told.

type Options

type Options struct {
	// Timings is the transport's clock. The zero value takes every default.
	Timings Timings
	// Report is where an error nobody can be told about goes. Nil discards.
	Report func(error)
	// Finished is called once per match that ends, with the room's last reading.
	// Nil ignores it. → the field on Server for why it is a callback.
	Finished func(wire.RoomCode, room.Reading)
	// Joined is called once per seat a room hands out, with the seat and the name
	// the peer announced. Nil ignores it.
	//
	// ⚠️ **The name is the peer's own and is not checked for anything.** It is a
	// string a stranger on the network chose, so a caller printing it is printing
	// somebody else's bytes; nothing here trims, folds or bounds it, because
	// wire.Hello is the format and this is the transport handing a field on
	// unchanged. A caller that draws it owes it the same treatment as any other
	// text it did not write.
	//
	// ⚠️ It is called **under the room's exchange lock**, like Finished, so a
	// callback that blocks holds its own room's next message. Printing a line is
	// what it is for.
	Joined func(wire.RoomCode, wire.Seat, string)
}

Options is what a Server is handed rather than what it decides.

type Refusal

type Refusal struct {
	Code wire.Code
}

Refusal is the room turning this client away, and it carries the code and nothing else — for the reason wire.Refused does.

It is a typed error so that a caller can word it: `errors.As` gives the code, and the caller's own language book gives the sentence.

func (*Refusal) Error

func (r *Refusal) Error() string

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is the WebSocket side of a room.Registry: an http.Handler that turns a connection into a seat and carries messages between the two.

It opens no listener and picks no port — a caller mounts it — because the host binary is where the flag and output decisions live. → the package comment.

What it holds that the registry deliberately does not

The registry has no sockets, so a second map is unavoidable: the room's answers are addressed **per seat** (room.Outbound names one), and only something holding both connections can deliver them. That is what a table is, and it is the whole of this type's own state.

func NewServer

func NewServer(rooms *room.Registry, options Options) *Server

NewServer wraps a registry. The registry keeps owning the rooms; this owns the connections and the clock.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP is the handler. Every path but roomPattern is a 404, which is what a client dialling a server that is not this one should get.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown stops serving: it tells every connected peer why, stops every room, and returns when nothing is left running.

⚠️ **This exists because http.Server.Shutdown cannot do it.** That call waits for connections it can see finish a *request*, and a WebSocket is **hijacked** — net/http has handed the connection over and stopped counting it — so shutting the http server down leaves every socket open and every room goroutine alive. A caller that only closed its listener would exit with a match still being played inside it.

It is four steps and they are in this order for reasons, not for tidiness

  1. **Tell every connected peer**, with wire.ClosureStopped and then a close frame. The message goes first because it is the only thing that says *why*: a socket that simply dies leaves a player staring at a dead connection, and a client's mirror reads a Closed as an ending it could not have computed. The close frame goes after because a shutdown must not depend on the peer's cooperation — a wedged client that never reads the Closed still has its socket taken away, so the tables below empty on this side's own initiative.
  2. **room.Registry.CloseAll**, which stops the rooms.
  3. **room.Registry.Wait**, bounded by ctx. ⚠️ Two calls rather than one, for the reason Wait's own comment gives: Wait **closes nothing**, so it is a measurement rather than a tidy-up, and a goroutine left behind hangs it instead of being quietly collected. Merging the two would lose exactly that property.
  4. **Both readings at nought.** Tables and Running measure different things — a table outlives its match by however long two sockets take to close, and a room that has retired its entry but not returned is still a goroutine — so a shutdown that checked one of them would return with the other still going. They are exposed for this and are used for this.

⚠️ **CloseAll runs even on a context that is already done.** Only the *waiting* is bounded: closing is the point of the call, and a shutdown that skipped it because it was out of time would leave behind exactly what it was asked to stop. So an expired context gives up on the wait, not on the work — and the error names what was still running, because a caller printing "gave up" with no numbers tells its user nothing.

It is not safe for two callers at once, and it does not need to be: a binary has one shutdown, reached from the match ending or from a signal, and running both would only send a second Closed down a socket that had already gone.

func (*Server) Tables

func (s *Server) Tables() int

Tables is how many rooms this server is holding connections for, which is not the registry's Count: a table outlives the match by however long the two sockets take to close, and a room with nobody connected has no table at all.

It exists so a shutdown can be measured rather than assumed — the same argument room.Registry.Running is exposed under.

type Sight

type Sight struct {
	// Fight is the battle in progress, nil between battles and before the first.
	Fight *battle.Battle
	// Asking is the open prompt when it is this client's to answer, and nil
	// otherwise — which is the whole of how a client knows its turn has come.
	Asking *battle.Prompt
	// Side is the half of the board this client plays in the battle in progress,
	// and Seed and Index which battle of the series it is.
	Side  hex.Side
	Seed  uint64
	Index int
	// Seated is the room's configuration having arrived, Over the match being
	// finished by this client's own arithmetic.
	Seated bool
	Over   bool
	// Watching is the room having welcomed this client to watch rather than to
	// play, which is Mirror.Watching and therefore wire.Welcome.Watching.
	//
	// ⚠️ **A renderer reads this and never re-derives it.** Side is the *host's*
	// half on a watching mirror, so "am I the one being asked" is not a question a
	// screen may answer from the reading it draws — Asking is already nil here,
	// and this is what a screen needs in order to say so instead of offering keys
	// nothing will take.
	Watching bool
	// Capped is the battle in progress having stopped at the room's turn cap,
	// which is the one state where the battle still holds an open prompt that
	// **nobody is being asked about** — the room stops asking on the same turn.
	// A renderer reading the prompt off the battle rather than off Asking needs
	// this to tell the two apart. → Mirror.Capped.
	Capped bool
	// Welcome is the room's configuration, meaningful only when Seated.
	Welcome wire.Welcome
	// Closure is why the match stopped for a reason the board cannot show, and
	// is ClosureNone when nothing did.
	Closure wire.Closure
	// Fought is the series as this client's own engine settled it, and Refusals
	// every code the room has sent, in order.
	Fought   []Fought
	Refusals []wire.Code
	// Draft is this client's own mirror of the ban and pick, and it is the zero
	// DraftSight in a room that does not draft.
	//
	// ⚠️ **A snapshot, never the *draft.Draft** — → DraftSight, which carries the
	// argument and the reason Fight beside it is the one deliberate exception.
	Draft DraftSight
}

Sight is a consistent reading of this mirror, valid only for the duration of the call it is handed to.

It is one struct rather than a dozen accessors because a screen needs several of them to agree: a renderer that asked for the battle, then the prompt, then the side would get three readings taken at three different moments, and the prompt would name a unit on a board that had moved under it.

type Timings

type Timings struct {
	// CloseThreshold is how long a silent, unresponsive peer is tolerated.
	// → DefaultCloseThreshold, which is where what it guards is written down.
	CloseThreshold time.Duration
	// Keepalive is how often a peer is pinged.
	Keepalive time.Duration
	// Write is how long one outbound message may take.
	Write time.Duration
	// MessageLimit is the largest message that will be read, in bytes.
	MessageLimit int64
	// RejoinWindow is how long a seat is held for the client that had it.
	// → DefaultRejoinWindow.
	RejoinWindow time.Duration
}

Timings is the transport's clock: every duration this package reads, in one place, because this package is the only one in the PvP stack that reads any.

A zero field takes its default, so a caller that has no opinion passes the zero value and a test that needs a one-second allowance overrides one line.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL