Sovite.Policy.Server (sovite v0.6.0)

Copy Markdown View Source

A policy server: a Sovite.Listener whose connections speak the policy delegation protocol, with the decisions made by a Sovite.Policy.Handler.

children = [
  {Sovite.Policy.Server, port: 10023, ip: {127, 0, 0, 1}, handler: {Greylist, []}}
]

Postfix can then ask it with check_policy_service inet:127.0.0.1:10023. The server is also a Sovite.Listener.Handler, so it can be given to a listener directly, with the server options as :handler_opts:

{Sovite.Listener, port: 10023, handler: Sovite.Policy.Server, handler_opts: [handler: {Greylist, []}]}

Each connection serves requests one after the other until the client closes it. A request that is malformed (a line that is not name=value, or an empty one), has a line over :max_line bytes or more than :max_attributes attributes, or is not complete within :idle_timeout of the previous reply (or of the connection), closes the connection without a reply. When a name comes more than once in a request, the last value wins.

Options

Listener options (see Sovite.Listener): :port, :ip, :id, :name, :acceptors, :max_connections, :max_connections_per_ip.

  • :handler - {module, opts} or module, a Sovite.Policy.Handler. Required.
  • :max_line - bytes of a request line. Defaults to 8192.
  • :max_attributes - attributes of a request. Defaults to 100.
  • :idle_timeout - milliseconds. Defaults to 300 seconds, like Postfix's max_idle.

Telemetry

  • [:sovite, :policy, :server, :request, :stop] - %{duration}, %{listener, remote_ip, attributes, action}, for each request. duration is the time spent in the handler, attributes the request, and action the text sent, or nil when the handler closed the connection.
  • [:sovite, :policy, :server, :error] - %{}, %{listener, remote_ip, reason}, when a request closes the connection. reason is :malformed, :line_too_long, :too_many_attributes, or :timeout.

Summary

Functions

Starts the server. See the module docs for options.

Functions

start_link(opts)

@spec start_link(keyword()) :: Supervisor.on_start()

Starts the server. See the module docs for options.