From 01ed2ab8b561867e174f1e3f9b989668d8dcddf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chrz=C4=85szcz?= Date: Wed, 20 Apr 2022 11:02:46 +0200 Subject: [PATCH] Fix types and docs after code review --- doc/configuration/listen.md | 2 +- src/ejabberd_c2s.erl | 8 ++++---- src/ejabberd_s2s_in.erl | 7 ++++--- src/ejabberd_service.erl | 8 +++++--- src/ejabberd_socket.erl | 4 ++-- src/mongoose_listener.erl | 2 +- 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/doc/configuration/listen.md b/doc/configuration/listen.md index dd2028bffd6..4942e3795c2 100644 --- a/doc/configuration/listen.md +++ b/doc/configuration/listen.md @@ -39,7 +39,7 @@ The IP address to which the listening socket is bound. ### `listen.*.proto` * **Syntax:** string, only `"tcp"` is accepted * **Default:** `"tcp"` -* **Example:** `proto = "udp"` +* **Example:** `proto = "tcp"` The protocol, which is TCP by default. Currently this is the only valid option. diff --git a/src/ejabberd_c2s.erl b/src/ejabberd_c2s.erl index a734606d8c3..28bc1e6e971 100644 --- a/src/ejabberd_c2s.erl +++ b/src/ejabberd_c2s.erl @@ -82,7 +82,7 @@ -export_type([broadcast/0, packet/0, state/0]). -type packet() :: {jid:jid(), jid:jid(), exml:element()}. --type sock_data() :: term(). +-type socket_data() :: {ejabberd:sockmod(), term()}. -type start_result() :: {error, _} | {ok, undefined | pid()} | {ok, undefined | pid(), _}. @@ -100,11 +100,11 @@ start_listener(Opts) -> mongoose_tcp_listener:start_listener(Opts). --spec start(sock_data(), options()) -> start_result(). +-spec start(socket_data(), options()) -> start_result(). start(SockData, Opts) -> ?SUPERVISOR_START(SockData, Opts). --spec start_link(sock_data(), options()) -> start_result(). +-spec start_link(socket_data(), options()) -> start_result(). start_link(SockData, Opts) -> p1_fsm_old:start_link(ejabberd_c2s, {SockData, Opts}, ?FSMOPTS ++ fsm_limit_opts(Opts)). @@ -191,7 +191,7 @@ run_remote_hook_after(Delay, Pid, HandlerName, Args) -> %%% Callback functions from gen_fsm %%%---------------------------------------------------------------------- --spec init({sock_data(), options()}) -> +-spec init({socket_data(), options()}) -> {stop, normal} | {ok, wait_for_stream, state(), non_neg_integer()}. init({{SockMod, Socket}, Opts}) -> #{access := Access, shaper := Shaper, hibernate_after := HibernateAfter} = Opts, diff --git a/src/ejabberd_s2s_in.erl b/src/ejabberd_s2s_in.erl index 69b569c8220..955ee2bdc53 100644 --- a/src/ejabberd_s2s_in.erl +++ b/src/ejabberd_s2s_in.erl @@ -103,17 +103,18 @@ "id='", (StateData#state.streamid)/binary, "'", Version/binary, ">">>) ). +-type socket_data() :: {ejabberd:sockmod(), term()}. -type options() :: #{shaper := atom(), atom() => any()}. %%%---------------------------------------------------------------------- %%% API %%%---------------------------------------------------------------------- --spec start(tuple(), options()) -> +-spec start(socket_data(), options()) -> {error, _} | {ok, undefined | pid()} | {ok, undefined | pid(), _}. start(SockData, Opts) -> ?SUPERVISOR_START. --spec start_link(tuple(), options()) -> ignore | {error, _} | {ok, pid()}. +-spec start_link(socket_data(), options()) -> ignore | {error, _} | {ok, pid()}. start_link(SockData, Opts) -> gen_fsm_compat:start_link(ejabberd_s2s_in, [SockData, Opts], ?FSMOPTS). @@ -136,7 +137,7 @@ socket_type() -> %% ignore | %% {stop, StopReason} %%---------------------------------------------------------------------- --spec init([tuple() | options(), ...]) -> {ok, wait_for_stream, state()}. +-spec init([socket_data() | options(), ...]) -> {ok, wait_for_stream, state()}. init([{SockMod, Socket}, Opts = #{shaper := Shaper}]) -> ?LOG_DEBUG(#{what => s2n_in_started, text => <<"New incoming S2S connection">>, diff --git a/src/ejabberd_service.erl b/src/ejabberd_service.erl index 418e6cb93e0..72956d29e62 100644 --- a/src/ejabberd_service.erl +++ b/src/ejabberd_service.erl @@ -118,6 +118,7 @@ "">> ). +-type socket_data() :: {ejabberd:sockmod(), term()}. -type options() :: #{access := atom(), shaper_rule := atom(), password := binary(), @@ -129,12 +130,13 @@ %%%---------------------------------------------------------------------- %%% API %%%---------------------------------------------------------------------- --spec start(_, options()) -> {error, _} | {ok, undefined | pid()} | {ok, undefined | pid(), _}. +-spec start(socket_data(), options()) -> + {error, _} | {ok, undefined | pid()} | {ok, undefined | pid(), _}. start(SockData, Opts) -> supervisor:start_child(ejabberd_service_sup, [SockData, Opts]). --spec start_link(_, options()) -> ignore | {error, _} | {ok, pid()}. +-spec start_link(socket_data(), options()) -> ignore | {error, _} | {ok, pid()}. start_link(SockData, Opts) -> p1_fsm:start_link(ejabberd_service, [SockData, Opts], fsm_limit_opts(Opts) ++ ?FSMOPTS). @@ -168,7 +170,7 @@ process_packet(Acc, From, To, _El, #{pid := Pid}) -> %% ignore | %% {stop, StopReason} %%---------------------------------------------------------------------- --spec init([options() | {atom() | tuple(), _}, ...]) -> {'ok', 'wait_for_stream', state()}. +-spec init([socket_data() | options(), ...]) -> {'ok', 'wait_for_stream', state()}. init([{SockMod, Socket}, Opts]) -> ?LOG_INFO(#{what => comp_started, text => <<"External service connected">>, diff --git a/src/ejabberd_socket.erl b/src/ejabberd_socket.erl index 8afd340911d..43a6632d4a6 100644 --- a/src/ejabberd_socket.erl +++ b/src/ejabberd_socket.erl @@ -66,8 +66,8 @@ %% Function: %% Description: %%-------------------------------------------------------------------- --spec start(module(), ejabberd:sockmod(), - Socket :: port(), mongoose_tcp_listener:options(), +-spec start(module(), ejabberd:sockmod(), gen_tcp:socket(), + mongoose_tcp_listener:options(), mongoose_tcp_listener:connection_details()) -> ok. start(Module, SockMod, Socket, Opts, ConnectionDetails) -> case mongoose_listener:socket_type(Module) of diff --git a/src/mongoose_listener.erl b/src/mongoose_listener.erl index 265662a48f5..7d3117e083e 100644 --- a/src/mongoose_listener.erl +++ b/src/mongoose_listener.erl @@ -21,7 +21,7 @@ proto := proto(), any() => any()}. -type id() :: {inet:port_number(), inet:ip_address(), proto()}. --type proto() :: tcp | udp. +-type proto() :: tcp. -type socket_type() :: independent | xml_stream | raw. -export_type([options/0, id/0, proto/0, socket_type/0]).