Documentation
¶
Index ¶
- type CommandHandler
- type Server
- func (s *Server) BuiltinForTest(name string) CommandHandler
- func (s *Server) Dial() (net.Conn, error)
- func (s *Server) MintClientConfig() (*sshstd.ClientConfig, error)
- func (s *Server) RegisterCommand(name string, h CommandHandler)
- func (s *Server) RevokeClientConfig(user string)
- func (s *Server) Start() error
- func (s *Server) Stop() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommandHandler ¶ added in v0.2.8
CommandHandler runs one session in-process instead of spawning a process. args are the argv the client sent after the command name, and the returned code is the session's exit status. sess carries the channel's stdio, and its context is canceled when the client goes away — a handler that blocks must select on it or on a read returning EOF.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server wraps an internal SSH server.
func New ¶
func New() *Server
New creates an internal SSH server that communicates in-process via net.Pipe (no TCP port).
func (*Server) BuiltinForTest ¶ added in v0.2.8
func (s *Server) BuiltinForTest(name string) CommandHandler
BuiltinForTest exposes builtin to package-external tests, which need to assert what a registration did (or did not) install. It has no production caller.
func (*Server) Dial ¶ added in v0.1.0
Dial creates a new in-memory connection to this server. The returned net.Conn is the client side of a net.Pipe(); the server side is handed to the SSH server goroutine for handshake and session handling.
func (*Server) MintClientConfig ¶ added in v0.0.4
func (s *Server) MintClientConfig() (*sshstd.ClientConfig, error)
MintClientConfig registers a new one-time username/password and returns a dial config. The entry is removed on the first successful SSH password authentication (single use). Call only after Start().
func (*Server) RegisterCommand ¶ added in v0.2.8
func (s *Server) RegisterCommand(name string, h CommandHandler)
RegisterCommand teaches the server a command it serves in-process: a session whose first argv word is name is handed to h instead of being exec'd. It is how the extension layer carries an HTTP MCP server over the in-memory channel without starting a second process, and it is deliberately an explicit registration rather than a name the server knows on its own — the sshserver stays a transport, and the thing being carried stays in the package that owns it.
func (*Server) RevokeClientConfig ¶ added in v0.2.0
RevokeClientConfig drops a pending one-time credential minted by MintClientConfig. Call it when the returned config will never complete a successful authentication (dial refused, handshake error), otherwise the entry would stay in the pending map for the lifetime of the process — a memory leak on every failed session start. Revoking a credential that was already consumed is a no-op.
func (*Server) Stop ¶
Stop shuts down the SSH server.
This does not wait for in-flight session handlers: Close() tears down the connections, which cancels each session's context, and handleSession uses that to kill the child it started. Nothing here needs to join the handlers — the goroutine count comes back down on its own — and a WaitGroup on this path would add an Add/Wait race (a panic, not an error) to satisfy a wait nobody needs.