Tahr.RPC.Handler behaviour (tahr v0.1.0)

Copy Markdown View Source

Behaviour for ONC RPC program handlers.

A handler is a module that implements handle_call/4 and is registered with Tahr.RPC.Dispatcher for one or more {program, version} pairs. The dispatcher peels the RPC envelope, validates the credential flavor, and invokes:

handle_call(proc, args_binary, auth_context, ctx)

The handler decodes args_binary (typically with Tahr.XDR helpers), produces a result, and returns one of the result tuples below. The dispatcher wraps the result in the RPC reply envelope.

Return values

  • {:ok, encoded_body} — successful reply, encoded_body is the already-XDR-encoded result body. May be a binary or iodata — streaming-aware procedures (NFSv3 READ) return chunked iodata so a multi-MiB read body never has to be flattened in memory. The dispatcher and RPC.RecordMarking propagate iodata through to :gen_tcp.send/2.
  • :proc_unavail — the procedure number isn't implemented; the dispatcher returns PROC_UNAVAIL.
  • :garbage_argsargs_binary couldn't be decoded; the dispatcher returns GARBAGE_ARGS.
  • :system_err — handler crashed or a downstream system error; the dispatcher returns SYSTEM_ERR.

The ctx argument is a map carrying the original call envelope as :call (Tahr.RPC.Message.Call.t()) and the connection's client address as :peer (an :inet.ip_address(), or nil if unavailable) — the latter for per-export host filtering. Further fields (e.g. TLS info) can be added without breaking handlers.

Summary

Types

The reply body — handler-encoded XDR or a structured error.

Types

ctx()

@type ctx() :: %{call: Tahr.RPC.Message.Call.t()}

result()

@type result() ::
  {:ok, body :: iodata()} | :proc_unavail | :garbage_args | :system_err

The reply body — handler-encoded XDR or a structured error.

Callbacks

handle_call(proc, args, auth, ctx)

@callback handle_call(
  proc :: non_neg_integer(),
  args :: binary(),
  auth :: Tahr.RPC.Auth.credential(),
  ctx()
) :: result()