Documentation
¶
Overview ¶
Package rpcserver serves the maild API on lodge's kit (github.com/frostyard/lodge/kit/jsonrpc): rpc.hello, events.subscribe, a caller per connection and whether the app attends. The kit does the framing, the gating on rpc.hello, concurrent dispatch, panics and oversized replies.
Index ¶
- Constants
- func Listen(path string, log *slog.Logger) (net.Listener, error)
- type Options
- type Server
- func (s *Server) Activity() api.ActivityService
- func (s *Server) Attended() bool
- func (s *Server) Hello(ctx context.Context, p *api.RPCHelloParams) (*api.Hello, error)
- func (s *Server) Ping(context.Context, *api.RPCPingParams) error
- func (s *Server) Serve(ctx context.Context, ln net.Listener, r *api.Router) error
- func (s *Server) ServeConn(ctx context.Context, nc net.Conn, r *api.Router, caller api.Caller)
- func (s *Server) Shutdown(ctx context.Context, _ *api.RPCShutdownParams) error
- func (s *Server) Subscribe(ctx context.Context, p *api.EventsSubscribeParams) (*api.Subscription, error)
Constants ¶
const AppClient = "frostmail-app"
AppClient prefixes the rpc.hello client name of the Frostmail app.
Variables ¶
This section is empty.
Functions ¶
func Listen ¶
Listen creates the maild socket at path (docs/specs/rpc-protocol.md, Transport) with lodge's kit: mode 0600, in a directory that must be private (0700 and owned by the user; it is created if missing). A stale socket is replaced; a live one means maild is already running. Accept admits only processes of the user running maild, and closes the rest, logged to log.
Types ¶
type Options ¶
type Options struct {
// Name is reported by rpc.hello, e.g. "maild v0.1.0".
Name string
Broker *events.Broker
// Activity serves the activity domain (ADR-0055); nil answers
// activity.subscribe with unavailable and activity.recent with nothing.
Activity *activity.Hub
Logger *slog.Logger
// OnAttended, when set, learns when Attended changes.
OnAttended func(attended bool)
// Build is reported by rpc.hello as build: the Flatpak build maild runs
// from. Empty means none (outside the Flatpak, or unknown).
Build string
// Shutdown stops maild, as SIGTERM does (rpc.shutdown). It must return
// at once: the server calls it after the reply is on the wire, so the
// caller always has its answer. Nil means this server cannot be stopped
// by a call, and rpc.shutdown answers unavailable.
Shutdown func()
}
Options configures a Server.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server implements api.RPCService and api.EventsService, which need the connection, and serves a Router built with them.
func (*Server) Activity ¶ added in v0.6.0
func (s *Server) Activity() api.ActivityService
Activity is the activity domain (ADR-0055) over Options.Activity. Its methods admit the IDL's callers (local and session); agents get methodNotFound from the router.
func (*Server) Attended ¶
Attended reports whether the app is connected and receiving events: then what needs the user (reminders) goes to its windows rather than the desktop's notifications.
func (*Server) Serve ¶
Serve accepts connections until ctx ends, then waits for them to finish. Each serves a local caller.
func (*Server) ServeConn ¶
ServeConn serves one connection the caller has already authenticated, as caller, until it ends or ctx does: lodge's /api as a session.
func (*Server) Shutdown ¶ added in v0.2.0
Shutdown implements rpc.shutdown: the reply goes out first, then Options.Shutdown runs (jsonrpc.AfterReply), so the caller has its answer before maild stops. A call that fails never stops maild.
func (*Server) Subscribe ¶
func (s *Server) Subscribe(ctx context.Context, p *api.EventsSubscribeParams) (*api.Subscription, error)
Subscribe implements events.subscribe; delivery starts after the reply.