case ejabberd_c2s:start(?MODULE, Socket, [{receiver, self()}|Opts]) of
{ok, C2SPid} ->
ejabberd_c2s:accept(C2SPid),
- Inactivity = mod_bosh_opt:max_inactivity(XMPPDomain),
+ Inactivity = mod_bosh_opt:max_inactivity(XMPPDomain) div 1000,
MaxConcat = mod_bosh_opt:max_concat(XMPPDomain),
ShapedReceivers = buf_new(XMPPDomain, ?MAX_SHAPED_REQUESTS_QUEUE_LEN),
State = #state{host = XMPPDomain, sid = SID, ip = IP,
Wait == 0, Hold == 0 -> erlang:timestamp();
true -> undefined
end,
- MaxPause = mod_bosh_opt:max_pause(State#state.host),
+ MaxPause = mod_bosh_opt:max_pause(State#state.host) div 1000,
Resp = #body{attrs =
[{sid, State#state.sid}, {wait, Wait},
{ver, ?BOSH_VERSION}, {polling, ?DEFAULT_POLLING},
%%% gen_server API
%%%===================================================================
init([]) ->
- Ticktime = ejabberd_option:net_ticktime(),
+ Ticktime = ejabberd_option:net_ticktime() div 1000,
Nodes = ejabberd_option:cluster_nodes(),
_ = net_kernel:set_net_ticktime(Ticktime),
lists:foreach(fun(Node) ->
opt_type(negotiation_timeout) ->
econf:timeout(second);
opt_type(net_ticktime) ->
- econf:pos_int();
+ econf:timeout(second);
opt_type(new_sql_schema) ->
econf:bool();
opt_type(oauth_access) ->
opt_type(redis_server) ->
econf:string();
opt_type(registration_timeout) ->
- econf:pos_int(infinity);
+ econf:timeout(second, infinity);
opt_type(resource_conflict) ->
econf:enum([setresource, closeold, closenew, acceptnew]);
opt_type(riak_cacertfile) ->
opt_type(s2s_dns_timeout) ->
econf:timeout(second, infinity);
opt_type(s2s_max_retry_delay) ->
- econf:pos_int();
+ econf:timeout(second);
opt_type(s2s_protocol_options) ->
econf:and_then(
econf:list(econf:binary(), [unique]),
{max_fsm_queue, undefined},
{modules, []},
{negotiation_timeout, timer:seconds(30)},
- {net_ticktime, 60},
+ {net_ticktime, timer:seconds(60)},
{new_sql_schema, ?USE_NEW_SQL_SCHEMA_DEFAULT},
{oauth_access, none},
{oauth_cache_life_time,
{redis_queue_type,
fun(Host) -> ejabberd_config:get_option({queue_type, Host}) end},
{redis_server, "localhost"},
- {registration_timeout, 600},
+ {registration_timeout, timer:seconds(600)},
{resource_conflict, acceptnew},
{riak_cacertfile, nil},
{riak_password, nil},
{s2s_dhfile, undefined},
{s2s_dns_retries, 2},
{s2s_dns_timeout, timer:seconds(10)},
- {s2s_max_retry_delay, 300},
+ {s2s_max_retry_delay, timer:seconds(300)},
{s2s_protocol_options, undefined},
{s2s_queue_type,
fun(Host) -> ejabberd_config:get_option({queue_type, Host}) end},
Delay = get_delay(),
?WARNING_MSG("Failed to establish outbound s2s connection ~s -> ~s: "
"authentication failed; bouncing for ~p seconds",
- [LServer, RServer, Delay]),
+ [LServer, RServer, Delay div 1000]),
State1 = State#{on_route => bounce, stop_reason => Reason},
State2 = close(State1),
State3 = bounce_queue(State2),
- xmpp_stream_out:set_timeout(State3, timer:seconds(Delay));
+ xmpp_stream_out:set_timeout(State3, Delay);
process_auth_result(State, true) ->
State.
Delay = get_delay(),
?WARNING_MSG("Failed to establish outbound s2s connection ~s -> ~s: ~s; "
"bouncing for ~p seconds",
- [LServer, RServer, format_error(Reason), Delay]),
+ [LServer, RServer, format_error(Reason), Delay div 1000]),
State1 = State#{on_route => bounce},
State2 = bounce_queue(State1),
- xmpp_stream_out:set_timeout(State2, timer:seconds(Delay)).
+ xmpp_stream_out:set_timeout(State2, Delay).
handle_unexpected_info(State, Info) ->
?WARNING_MSG("Unexpected info: ~p", [Info]),
mod_opt_type(max_concat) ->
econf:pos_int(unlimited);
mod_opt_type(max_inactivity) ->
- econf:pos_int();
+ econf:timeout(second);
mod_opt_type(max_pause) ->
- econf:pos_int();
+ econf:timeout(second);
mod_opt_type(prebind) ->
econf:bool();
mod_opt_type(queue_type) ->
mod_options(Host) ->
[{json, false},
{max_concat, unlimited},
- {max_inactivity, 30},
- {max_pause, 120},
+ {max_inactivity, timer:seconds(30)},
+ {max_pause, timer:seconds(120)},
{prebind, false},
{ram_db_type, ejabberd_config:default_ram_db(Host, ?MODULE)},
{queue_type, ejabberd_option:queue_type(Host)},
false ->
BanLifetime = mod_fail2ban_opt:c2s_auth_ban_lifetime(LServer),
MaxFailures = mod_fail2ban_opt:c2s_max_auth_failures(LServer),
- UnbanTS = erlang:system_time(second) + BanLifetime,
+ UnbanTS = current_time() + BanLifetime,
Attempts = case ets:lookup(failed_auth, Addr) of
[{Addr, N, _, _}] ->
ets:insert(failed_auth,
c2s_stream_started(#{ip := {Addr, _}} = State, _) ->
case ets:lookup(failed_auth, Addr) of
[{Addr, N, TS, MaxFailures}] when N >= MaxFailures ->
- case TS > erlang:system_time(second) of
+ case TS > current_time() of
true ->
log_and_disconnect(State, N, TS);
false ->
handle_info(clean, State) ->
?DEBUG("Cleaning ~p ETS table", [failed_auth]),
- Now = erlang:system_time(second),
+ Now = current_time(),
ets:select_delete(
failed_auth,
ets:fun2ms(fun({_, _, UnbanTS, _}) -> UnbanTS =< Now end)),
log_and_disconnect(#{ip := {Addr, _}, lang := Lang} = State, Attempts, UnbanTS) ->
IP = misc:ip_to_list(Addr),
UnbanDate = format_date(
- calendar:now_to_universal_time(seconds_to_now(UnbanTS))),
+ calendar:now_to_universal_time(msec_to_now(UnbanTS))),
Format = ?T("Too many (~p) failed authentications "
"from this IP address (~s). The address "
"will be unblocked at ~s UTC"),
Access = mod_fail2ban_opt:access(Host),
acl:match_rule(Host, Access, Addr) == allow.
--spec seconds_to_now(non_neg_integer()) -> erlang:timestamp().
-seconds_to_now(Secs) ->
+-spec msec_to_now(pos_integer()) -> erlang:timestamp().
+msec_to_now(MSecs) ->
+ Secs = MSecs div 1000,
{Secs div 1000000, Secs rem 1000000, 0}.
-spec format_date(calendar:datetime()) -> iolist().
io_lib:format("~2..0w:~2..0w:~2..0w ~2..0w.~2..0w.~4..0w",
[Hour, Minute, Second, Day, Month, Year]).
+current_time() ->
+ erlang:system_time(millisecond).
+
mod_opt_type(access) ->
econf:acl();
mod_opt_type(c2s_auth_ban_lifetime) ->
- econf:pos_int();
+ econf:timeout(second);
mod_opt_type(c2s_max_auth_failures) ->
econf:pos_int().
mod_options(_Host) ->
[{access, none},
- {c2s_auth_ban_lifetime, 3600}, %% one hour
+ {c2s_auth_ban_lifetime, timer:hours(1)},
{c2s_max_auth_failures, 20}].
-record(state,
{host :: binary(),
send_pings :: boolean(),
- ping_interval :: non_neg_integer(),
+ ping_interval :: pos_integer(),
ping_ack_timeout :: undefined | non_neg_integer(),
timeout_action :: none | kill,
timers :: timers()}).
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_PING),
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_PING).
--spec add_timer(jid(), non_neg_integer(), timers()) -> timers().
+-spec add_timer(jid(), pos_integer(), timers()) -> timers().
add_timer(JID, Interval, Timers) ->
LJID = jid:tolower(JID),
NewTimers = case maps:find(LJID, Timers) of
maps:remove(LJID, Timers);
_ -> Timers
end,
- TRef = erlang:start_timer(Interval * 1000, self(),
- {ping, JID}),
+ TRef = erlang:start_timer(Interval, self(), {ping, JID}),
maps:put(LJID, TRef, NewTimers).
-spec del_timer(jid(), timers()) -> timers().
[].
mod_opt_type(ping_interval) ->
- econf:pos_int();
+ econf:timeout(second);
mod_opt_type(ping_ack_timeout) ->
econf:timeout(second);
mod_opt_type(send_pings) ->
econf:enum([none, kill]).
mod_options(_Host) ->
- [{ping_interval, 60},
+ [{ping_interval, timer:minutes(1)},
{ping_ack_timeout, undefined},
{send_pings, false},
{timeout_action, none}].
update(Server, JID, Dir) ->
StormCount = mod_pres_counter_opt:count(Server),
TimeInterval = mod_pres_counter_opt:interval(Server),
- TimeStamp = erlang:system_time(second),
+ TimeStamp = erlang:system_time(millisecond),
case read(Dir) of
undefined ->
write(Dir,
mod_opt_type(count) ->
econf:pos_int();
mod_opt_type(interval) ->
- econf:pos_int().
+ econf:timeout(second).
mod_options(_) ->
- [{count, 5}, {interval, 60}].
+ [{count, 5}, {interval, timer:seconds(60)}].
check_timeout(Source) ->
Timeout = ejabberd_option:registration_timeout(),
if is_integer(Timeout) ->
- Priority = -erlang:system_time(second),
+ Priority = -erlang:system_time(millisecond),
CleanPriority = Priority + Timeout,
F = fun () ->
Treap = case mnesia:read(mod_register_ip, treap, write)
mod_opt_type(always_record_route) ->
econf:bool();
mod_opt_type(flow_timeout_tcp) ->
- econf:pos_int();
+ econf:timeout(second);
mod_opt_type(flow_timeout_udp) ->
- econf:pos_int();
+ econf:timeout(second);
mod_opt_type(record_route) ->
econf:sip_uri();
mod_opt_type(routes) ->
host = Host,
params = [{<<"lr">>, <<>>}]},
[{always_record_route, true},
- {flow_timeout_tcp, 120},
- {flow_timeout_udp, 29},
+ {flow_timeout_tcp, timer:seconds(120)},
+ {flow_timeout_udp, timer:seconds(29)},
{record_route, Route},
{routes, [Route]},
{via, []}].
get_flow_timeout(LServer, #sip_socket{type = Type}) ->
case Type of
udp ->
- mod_sip_opt:flow_timeout_udp(LServer);
+ mod_sip_opt:flow_timeout_udp(LServer) div 1000;
_ ->
- mod_sip_opt:flow_timeout_tcp(LServer)
+ mod_sip_opt:flow_timeout_tcp(LServer) div 1000
end.
update_table() ->