Skip to content

Commit

Permalink
Fix types and docs after code review
Browse files Browse the repository at this point in the history
  • Loading branch information
chrzaszcz committed Apr 20, 2022
1 parent ef3e1e4 commit 01ed2ab
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion doc/configuration/listen.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
8 changes: 4 additions & 4 deletions src/ejabberd_c2s.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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(), _}.
Expand All @@ -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)).
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions src/ejabberd_s2s_in.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand All @@ -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">>,
Expand Down
8 changes: 5 additions & 3 deletions src/ejabberd_service.erl
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
"</stream:stream>">>
).

-type socket_data() :: {ejabberd:sockmod(), term()}.
-type options() :: #{access := atom(),
shaper_rule := atom(),
password := binary(),
Expand All @@ -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).
Expand Down Expand Up @@ -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">>,
Expand Down
4 changes: 2 additions & 2 deletions src/ejabberd_socket.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/mongoose_listener.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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]).
Expand Down

0 comments on commit 01ed2ab

Please sign in to comment.