session.go RawHistoryFolder
1package ports
2
3import (
4 "context"
5 "time"
6
7 "github.com/bnema/vev/internal/protocol"
8)
9
10// ClientConnection is one typed client-side session channel. Close must be
11// concurrent-safe, required to unblock ReceiveServer (and every send mode),
12// and must not need a prior graceful exchange: a retained dormant attachment
13// is closed by the client when it is evicted, replaced, or the runner exits.
14type ClientConnection interface {
15 SendClient(protocol.ClientMessage) error
16 ReceiveServer() (protocol.ServerMessage, error)
17 Capabilities() protocol.ConnectionCapabilities
18 LinkState() LinkState
19 LinkEvents() <-chan LinkEvent
20 Close() error
21}
22
23// ClientDialer establishes typed client-side session connections.
24type ClientDialer interface {
25 Dial(context.Context) (ClientConnection, error)
26}
27
28// ServerConnection is one typed client/daemon session channel. Close must be
29// concurrent-safe and unblock ReceiveClient and every send mode.
30type ServerConnection interface {
31 ReceiveClient() (protocol.ClientMessage, error)
32 SendServer(protocol.ServerMessage) error
33 SendServerAsync(protocol.ServerMessage) error
34 SendServerSynchronous(protocol.ServerMessage) error
35 SendOutput(protocol.Output) error
36 SendOutputAsync(protocol.Output) error
37 SendOutputSynchronous(protocol.Output) error
38 Capabilities() protocol.ConnectionCapabilities
39 LinkState() LinkState
40 LinkEvents() <-chan LinkEvent
41 Close() error
42}
43
44// HandshakeDeadlineProvider is an optional boundary-safe port implemented by
45// accepted server connections that already own an absolute handshake deadline
46// fixed before the daemon saw them - for example a connection admitted by a mux
47// listener whose stream spent part of its budget waiting in an accept queue.
48//
49// HandshakeDeadline returns that absolute deadline, stable for the connection's
50// lifetime and never restarted. A daemon-consuming use case adopts it verbatim
51// for the one handshake context that covers the first ReceiveClient through
52// Welcome and the committed initial publication, so queue delay and the
53// handshake share a single budget; an already-elapsed deadline fails the
54// handshake promptly instead of starting a second protocol.HandshakeTimeout. A
55// connection that does not implement this port keeps the ordinary behavior of a
56// fresh budget started when the daemon takes it.
57//
58// Completion is deliberately not part of this port: an accepted connection may
59// finish its transport preamble earlier, but the daemon's budget must end only
60// where it commits its initial publication.
61type HandshakeDeadlineProvider interface {
62 HandshakeDeadline() time.Time
63}
64
65// ServerListener accepts typed server-side session connections.
66type ServerListener interface {
67 Accept() (ServerConnection, error)
68 Close() error
69 Addr() string
70}