Documentation
¶
Overview ¶
Package server implements the sshkey-chat SSH server.
Index ¶
- func ReadBackupStatsForCLI(dataDir string) (failures, successes int64, lastSuccess, lastFailure time.Time, ...)
- func SetBackupStartupGracePeriod(d time.Duration) time.Duration
- type Client
- type Server
- func (s *Server) BackupFailuresTotal() int64
- func (s *Server) BackupSuccessesTotal() int64
- func (s *Server) Close() error
- func (s *Server) CounterIncForTesting(signal, deviceID string)
- func (s *Server) CounterSnapshotForTesting() map[string]map[string]int64
- func (s *Server) ListenAndServe() error
- func (s *Server) ProcessAutoRevokeForTesting()
- func (s *Server) ProcessPendingDeviceRevocationsForTesting()
- func (s *Server) Reload()
- func (s *Server) Store() *store.Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadBackupStatsForCLI ¶ added in v0.2.0
func ReadBackupStatsForCLI(dataDir string) (failures, successes int64, lastSuccess, lastFailure time.Time, lastErrMsg string)
ReadBackupStatsForCLI is exposed so cmd/sshkey-ctl can read the scheduler's persisted stats from a separate process. Returns zero-valued stats if the file is absent or unreadable (operator just sees zeros, not an error).
func SetBackupStartupGracePeriod ¶ added in v0.2.0
SetBackupStartupGracePeriod overrides the default 60s startup grace period. Test-only — production code never calls this. Returns the previous value so tests can restore it via t.Cleanup.
Types ¶
type Client ¶
type Client struct {
UserID string // nanoid (usr_ prefix) — immutable identity
DeviceID string
// Encoder is the thread-safe write surface for this client's
// SSH Channel 1. All writes to the client — whether from a
// per-handler goroutine (direct response) or from the per-client
// writer goroutine (fanOut broadcast) — go through this wrapper,
// which serializes concurrent Encode calls via an internal mutex
// so they never interleave on the wire.
Encoder *safeEncoder
Decoder *protocol.Decoder
Channel ssh.Channel // NDJSON control-plane channel (1st "session" channel)
DownloadChannel ssh.Channel // shared download channel (2nd "session" channel); nil only if the client failed to open it within the grace period — downloads fail closed with not_found
Conn *ssh.ServerConn
// LastActivity is the unix-seconds timestamp of the most recent
// successful NDJSON decode on Channel 1. Updated by messageLoop
// on every frame; read by runIdleWatchdog (Phase 17b Step 5a)
// to detect NDJSON-level idleness and close the channel if the
// configured idle_timeout_seconds is exceeded.
//
// Zero value means "not yet stamped" — watchdog interprets 0 as
// "fresh client, no activity yet" and grants one full timeout
// window before closing.
LastActivity atomic.Int64
// contains filtered or unexported fields
}
Client represents a connected client session.
Three SSH session channels are opened per connection, in fixed order:
- Control / NDJSON (this struct's `Channel`). Long-lived control plane — protocol verbs including `download` requests.
- Download channel (`DownloadChannel`). Server writes raw file bytes here in response to `download` verbs. One in-flight download per session; client serializes.
- Upload channel (handled elsewhere). Client writes raw bytes.
Authorization (`authorizeDownload`), `file_contexts` binding, cascade cleanup, hash verification, and counter signals are all enforced on Channel 1's dispatch path before bytes move on Channel 2.
func (*Client) TryEnqueue ¶ added in v0.2.0
TryEnqueue attempts a non-blocking send of msg onto the outbound queue. Returns (true, 0) on success with consecutiveDrops reset; returns (false, drops) on full queue with the drops counter post-increment. Callers use the drops return to decide whether to trigger a consecutive-drop disconnect.
Phase 17b Step 5b. Nil sendCh (test-mode Client) returns (false, 0) — no queueing, no drop tracking; direct-Encode sites see the call as a no-op in tests that don't exercise the queue.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the sshkey-chat SSH server.
func (*Server) BackupFailuresTotal ¶ added in v0.2.0
BackupFailuresTotal is a test-only accessor that reads the in-process counter via the persisted file. atomic.Int64 isn't used because the stats are read/written under no concurrent contention — only the scheduler goroutine writes, and at most every interval.
Production code uses ReadBackupStatsForCLI; this is just a brief alias for tests that only care about the counter.
func (*Server) BackupSuccessesTotal ¶ added in v0.2.0
BackupSuccessesTotal mirrors BackupFailuresTotal for the success counter. Test-only.
func (*Server) CounterIncForTesting ¶ added in v0.2.0
CounterIncForTesting increments a counter entry directly. This is test-only plumbing used by integration tests that need to drive the auto-revoke pipeline across all signals without crafting one protocol-level trigger frame per signal.
func (*Server) CounterSnapshotForTesting ¶ added in v0.2.0
CounterSnapshotForTesting returns the current per-signal counter map. Exposed for integration-test assertions that need to verify launch-gate "no misbehavior signals" contracts against a running server instance.
func (*Server) ListenAndServe ¶
ListenAndServe starts the SSH listener and accepts connections.
func (*Server) ProcessAutoRevokeForTesting ¶ added in v0.2.0
func (s *Server) ProcessAutoRevokeForTesting()
ProcessAutoRevokeForTesting runs a single synchronous auto-revoke evaluation tick. Exposed so integration tests don't need to sleep for poll intervals.
func (*Server) ProcessPendingDeviceRevocationsForTesting ¶ added in v0.2.0
func (s *Server) ProcessPendingDeviceRevocationsForTesting()
ProcessPendingDeviceRevocationsForTesting drains pending revocations once. Integration tests use this to deterministically kick sessions immediately.
Source Files
¶
- add_to_room.go
- admin_state_changes.go
- audit.go
- auto_revoke.go
- backup_scheduler.go
- client.go
- delete.go
- device_revocations.go
- devicemgmt.go
- edit.go
- epoch.go
- filetransfer.go
- group_admin.go
- id.go
- idle_watchdog.go
- pending_keys_storm.go
- presence.go
- pushhandler.go
- ratelimit.go
- reject.go
- reload.go
- remove_from_room.go
- retirement.go
- room_admin.go
- room_retirements.go
- room_update.go
- room_updates.go
- safe_encoder.go
- send_queue.go
- server.go
- session.go
- state_fix.go
- sync.go
- typingexpiry.go
- upload_quotas.go
- user_retirements.go
- user_unretirements.go