masque_handler behaviour (masque v0.7.0)

View Source

Server-side handler behaviour for MASQUE tunnels.

Callbacks:

  • accept/1 - synchronous accept/reject gate for the handshake. Return accept or {reject, masque_errors:handshake_error()}. Optional; default is accept.
  • init/2 - session start. Return {ok, State} or {ok, State, [action()]} or {stop, Reason}.
  • handle_packet/2 - inbound UDP payload (CONNECT-UDP tunnels).
  • handle_data/2 - inbound TCP bytes (CONNECT-TCP tunnels).
  • handle_capsule/3 - inbound capsule on the stream body.
  • handle_info/2 - any other Erlang message.
  • terminate/2 - session shutdown.

All callbacks are optional. Omitting a callback for a given event makes the session silently ignore it.

Summary

Functions

Default accept/1 behaviour - accept every well-formed request.

Types

accept_result/0

-type accept_result() ::
          accept |
          {reject, masque_errors:handshake_error()} |
          {reject, masque_errors:handshake_error(), [{binary(), binary()}]}.

req/0

-type req() ::
          #{method := binary(),
            protocol => udp | tcp | ip,
            path := binary(),
            authority := binary(),
            scheme := binary(),
            target_host => binary(),
            target_port => 1..65535,
            ip_target => masque_uri_ip:ip_target(),
            ip_ipproto => masque_uri_ip:ip_ipproto(),
            resolved_addresses => [inet:ip_address()],
            headers := [{binary(), binary()}],
            handler_opts => term(),
            peer => {inet:ip_address(), inet:port_number()},
            peer_cert => binary()}.

Callbacks

accept/1

(optional)
-callback accept(req()) -> accept_result().

handle_address_assign/2

(optional)
-callback handle_address_assign([term()], term()) ->
                                   {ok, term()} | {ok, term(), [term()]} | {stop, term(), term()}.

handle_address_request/2

(optional)
-callback handle_address_request([term()], term()) ->
                                    {ok, term()} | {ok, term(), [term()]} | {stop, term(), term()}.

handle_capsule/3

(optional)
-callback handle_capsule(non_neg_integer(), binary(), term()) ->
                            {ok, term()} | {ok, term(), [term()]} | {stop, term(), term()}.

handle_data/2

(optional)
-callback handle_data(binary(), term()) -> {ok, term()} | {ok, term(), [term()]} | {stop, term(), term()}.

handle_eof/1

(optional)
-callback handle_eof(term()) -> {ok, term()} | {ok, term(), [term()]} | {stop, term(), term()}.

handle_info/2

(optional)
-callback handle_info(term(), term()) -> {ok, term()} | {ok, term(), [term()]} | {stop, term(), term()}.

handle_ip_packet/2

(optional)
-callback handle_ip_packet(binary(), term()) ->
                              {ok, term()} | {ok, term(), [term()]} | {stop, term(), term()}.

handle_packet/2

(optional)
-callback handle_packet(binary(), term()) -> {ok, term()} | {ok, term(), [term()]} | {stop, term(), term()}.

handle_route_advertisement/2

(optional)
-callback handle_route_advertisement([term()], term()) ->
                                        {ok, term()} | {ok, term(), [term()]} | {stop, term(), term()}.

init/2

(optional)
-callback init(req(), term()) -> {ok, term()} | {ok, term(), [term()]} | {stop, term()}.

terminate/2

(optional)
-callback terminate(term(), term()) -> term().

Functions

default_accept(Req)

-spec default_accept(req()) -> accept_result().

Default accept/1 behaviour - accept every well-formed request.