mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
Remove now() - part 1
This commit is contained in:
parent
daad71bc7e
commit
5c329a7699
@ -43,11 +43,11 @@ stop() -> ok.
|
|||||||
mech_new(Host, _GetPassword, _CheckPassword, _CheckPasswordDigest) ->
|
mech_new(Host, _GetPassword, _CheckPassword, _CheckPasswordDigest) ->
|
||||||
{ok, #state{server = Host}}.
|
{ok, #state{server = Host}}.
|
||||||
|
|
||||||
mech_step(#state{server = Server}, _ClientIn) ->
|
mech_step(#state{server = Server} = S, ClientIn) ->
|
||||||
User = iolist_to_binary([randoms:get_string()
|
User = iolist_to_binary([randoms:get_string(),
|
||||||
| [jlib:integer_to_binary(X)
|
randoms:get_string(),
|
||||||
|| X <- tuple_to_list(now())]]),
|
randoms:get_string()]),
|
||||||
case ejabberd_auth:is_user_exists(User, Server) of
|
case ejabberd_auth:is_user_exists(User, Server) of
|
||||||
true -> {error, <<"not-authorized">>};
|
true -> mech_step(S, ClientIn);
|
||||||
false -> {ok, [{username, User}, {auth_module, ejabberd_auth_anonymous}]}
|
false -> {ok, [{username, User}, {auth_module, ejabberd_auth_anonymous}]}
|
||||||
end.
|
end.
|
||||||
|
@ -105,7 +105,7 @@ start_app([], _Type, _StartFlag) ->
|
|||||||
ok.
|
ok.
|
||||||
|
|
||||||
check_app_modules(App, StartFlag) ->
|
check_app_modules(App, StartFlag) ->
|
||||||
{A, B, C} = now(),
|
{A, B, C} = p1_time_compat:timestamp(),
|
||||||
random:seed(A, B, C),
|
random:seed(A, B, C),
|
||||||
sleep(5000),
|
sleep(5000),
|
||||||
case application:get_key(App, modules) of
|
case application:get_key(App, modules) of
|
||||||
|
@ -661,8 +661,7 @@ clean_treap(Treap, CleanPriority) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
now_priority() ->
|
now_priority() ->
|
||||||
{MSec, Sec, USec} = now(),
|
-p1_time_compat:system_time(micro_seconds).
|
||||||
-((MSec * 1000000 + Sec) * 1000000 + USec).
|
|
||||||
|
|
||||||
opt_type(captcha_cmd) ->
|
opt_type(captcha_cmd) ->
|
||||||
fun (FileName) ->
|
fun (FileName) ->
|
||||||
|
@ -153,7 +153,8 @@ sql_call(Host, Msg) ->
|
|||||||
case ejabberd_odbc_sup:get_random_pid(Host) of
|
case ejabberd_odbc_sup:get_random_pid(Host) of
|
||||||
none -> {error, <<"Unknown Host">>};
|
none -> {error, <<"Unknown Host">>};
|
||||||
Pid ->
|
Pid ->
|
||||||
(?GEN_FSM):sync_send_event(Pid,{sql_cmd, Msg, now()},
|
(?GEN_FSM):sync_send_event(Pid,{sql_cmd, Msg,
|
||||||
|
p1_time_compat:monotonic_time(milli_seconds)},
|
||||||
?TRANSACTION_TIMEOUT)
|
?TRANSACTION_TIMEOUT)
|
||||||
end;
|
end;
|
||||||
_State -> nested_op(Msg)
|
_State -> nested_op(Msg)
|
||||||
@ -161,7 +162,8 @@ sql_call(Host, Msg) ->
|
|||||||
|
|
||||||
keep_alive(PID) ->
|
keep_alive(PID) ->
|
||||||
(?GEN_FSM):sync_send_event(PID,
|
(?GEN_FSM):sync_send_event(PID,
|
||||||
{sql_cmd, {sql_query, ?KEEPALIVE_QUERY}, now()},
|
{sql_cmd, {sql_query, ?KEEPALIVE_QUERY},
|
||||||
|
p1_time_compat:monotonic_time(milli_seconds)},
|
||||||
?KEEPALIVE_TIMEOUT).
|
?KEEPALIVE_TIMEOUT).
|
||||||
|
|
||||||
-spec sql_query_t(sql_query()) -> sql_query_result().
|
-spec sql_query_t(sql_query()) -> sql_query_result().
|
||||||
@ -373,7 +375,7 @@ print_state(State) -> State.
|
|||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
|
|
||||||
run_sql_cmd(Command, From, State, Timestamp) ->
|
run_sql_cmd(Command, From, State, Timestamp) ->
|
||||||
case timer:now_diff(now(), Timestamp) div 1000 of
|
case p1_time_compat:monotonic_time(milli_seconds) - Timestamp of
|
||||||
Age when Age < (?TRANSACTION_TIMEOUT) ->
|
Age when Age < (?TRANSACTION_TIMEOUT) ->
|
||||||
put(?NESTING_KEY, ?TOP_LEVEL_TXN),
|
put(?NESTING_KEY, ?TOP_LEVEL_TXN),
|
||||||
put(?STATE_KEY, State),
|
put(?STATE_KEY, State),
|
||||||
|
@ -113,7 +113,8 @@ handle(Host, Module, Function, Opts, From, To, IQ) ->
|
|||||||
{one_queue, Pid} ->
|
{one_queue, Pid} ->
|
||||||
Pid ! {process_iq, From, To, IQ};
|
Pid ! {process_iq, From, To, IQ};
|
||||||
{queues, Pids} ->
|
{queues, Pids} ->
|
||||||
Pid = lists:nth(erlang:phash(now(), length(Pids)), Pids),
|
Pid = lists:nth(erlang:phash(p1_time_compat:unique_integer(),
|
||||||
|
length(Pids)), Pids),
|
||||||
Pid ! {process_iq, From, To, IQ};
|
Pid ! {process_iq, From, To, IQ};
|
||||||
parallel ->
|
parallel ->
|
||||||
spawn(?MODULE, process_iq,
|
spawn(?MODULE, process_iq,
|
||||||
@ -179,4 +180,3 @@ code_change(_OldVsn, State, _Extra) -> {ok, State}.
|
|||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%%% Internal functions
|
%%% Internal functions
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -554,8 +554,7 @@ num_active_users(Host, Days) ->
|
|||||||
|
|
||||||
%% Code based on ejabberd/src/web/ejabberd_web_admin.erl
|
%% Code based on ejabberd/src/web/ejabberd_web_admin.erl
|
||||||
list_last_activity(Host, Integral, Days) ->
|
list_last_activity(Host, Integral, Days) ->
|
||||||
{MegaSecs, Secs, _MicroSecs} = now(),
|
TimeStamp = p1_time_compat:system_time(seconds),
|
||||||
TimeStamp = MegaSecs * 1000000 + Secs,
|
|
||||||
TS = TimeStamp - Days * 86400,
|
TS = TimeStamp - Days * 86400,
|
||||||
case catch mnesia:dirty_select(
|
case catch mnesia:dirty_select(
|
||||||
last_activity, [{{last_activity, {'_', Host}, '$1', '_'},
|
last_activity, [{{last_activity, {'_', Host}, '$1', '_'},
|
||||||
@ -620,8 +619,7 @@ delete_old_users(Days, Users) ->
|
|||||||
SecOlder = Days*24*60*60,
|
SecOlder = Days*24*60*60,
|
||||||
|
|
||||||
%% Get current time
|
%% Get current time
|
||||||
{MegaSecs, Secs, _MicroSecs} = now(),
|
TimeStamp_now = p1_time_compat:system_time(seconds),
|
||||||
TimeStamp_now = MegaSecs * 1000000 + Secs,
|
|
||||||
|
|
||||||
%% For a user, remove if required and answer true
|
%% For a user, remove if required and answer true
|
||||||
F = fun({LUser, LServer}) ->
|
F = fun({LUser, LServer}) ->
|
||||||
|
@ -186,8 +186,7 @@ process_get(#xmlel{name = <<"last">>, attrs = Attrs}) ->
|
|||||||
{'EXIT', _Reason} ->
|
{'EXIT', _Reason} ->
|
||||||
{error, ?ERR_INTERNAL_SERVER_ERROR};
|
{error, ?ERR_INTERNAL_SERVER_ERROR};
|
||||||
Vals ->
|
Vals ->
|
||||||
{MegaSecs, Secs, _MicroSecs} = now(),
|
TimeStamp = p1_time_compat:system_time(seconds),
|
||||||
TimeStamp = MegaSecs * 1000000 + Secs,
|
|
||||||
Str = list_to_binary(
|
Str = list_to_binary(
|
||||||
[[jlib:integer_to_binary(TimeStamp - V),
|
[[jlib:integer_to_binary(TimeStamp - V),
|
||||||
<<" ">>] || V <- Vals]),
|
<<" ">>] || V <- Vals]),
|
||||||
|
@ -149,7 +149,7 @@ normal_state({route, From, <<"">>,
|
|||||||
case xml:get_attr_s(<<"type">>, Attrs) of
|
case xml:get_attr_s(<<"type">>, Attrs) of
|
||||||
<<"groupchat">> ->
|
<<"groupchat">> ->
|
||||||
Activity = get_user_activity(From, StateData),
|
Activity = get_user_activity(From, StateData),
|
||||||
Now = now_to_usec(now()),
|
Now = p1_time_compat:system_time(micro_seconds),
|
||||||
MinMessageInterval =
|
MinMessageInterval =
|
||||||
trunc(gen_mod:get_module_opt(StateData#state.server_host,
|
trunc(gen_mod:get_module_opt(StateData#state.server_host,
|
||||||
mod_muc, min_message_interval, fun(MMI) when is_number(MMI) -> MMI end, 0)
|
mod_muc, min_message_interval, fun(MMI) when is_number(MMI) -> MMI end, 0)
|
||||||
@ -288,7 +288,7 @@ normal_state({route, From, <<"">>,
|
|||||||
(StateData#state.config)#config.voice_request_min_interval,
|
(StateData#state.config)#config.voice_request_min_interval,
|
||||||
BareFrom =
|
BareFrom =
|
||||||
jid:remove_resource(jid:tolower(From)),
|
jid:remove_resource(jid:tolower(From)),
|
||||||
NowPriority = -now_to_usec(now()),
|
NowPriority = -p1_time_compat:system_time(micro_seconds),
|
||||||
CleanPriority = NowPriority +
|
CleanPriority = NowPriority +
|
||||||
MinInterval *
|
MinInterval *
|
||||||
1000000,
|
1000000,
|
||||||
@ -472,7 +472,7 @@ normal_state({route, From, Nick,
|
|||||||
#xmlel{name = <<"presence">>} = Packet},
|
#xmlel{name = <<"presence">>} = Packet},
|
||||||
StateData) ->
|
StateData) ->
|
||||||
Activity = get_user_activity(From, StateData),
|
Activity = get_user_activity(From, StateData),
|
||||||
Now = now_to_usec(now()),
|
Now = p1_time_compat:system_time(micro_seconds),
|
||||||
MinPresenceInterval =
|
MinPresenceInterval =
|
||||||
trunc(gen_mod:get_module_opt(StateData#state.server_host,
|
trunc(gen_mod:get_module_opt(StateData#state.server_host,
|
||||||
mod_muc, min_presence_interval,
|
mod_muc, min_presence_interval,
|
||||||
@ -1526,7 +1526,7 @@ store_user_activity(JID, UserActivity, StateData) ->
|
|||||||
0)
|
0)
|
||||||
* 1000),
|
* 1000),
|
||||||
Key = jid:tolower(JID),
|
Key = jid:tolower(JID),
|
||||||
Now = now_to_usec(now()),
|
Now = p1_time_compat:system_time(micro_seconds),
|
||||||
Activity1 = clean_treap(StateData#state.activity,
|
Activity1 = clean_treap(StateData#state.activity,
|
||||||
{1, -Now}),
|
{1, -Now}),
|
||||||
Activity = case treap:lookup(Key, Activity1) of
|
Activity = case treap:lookup(Key, Activity1) of
|
||||||
@ -1997,8 +1997,7 @@ count_stanza_shift(Nick, Els, StateData) ->
|
|||||||
Shift1 = case Seconds of
|
Shift1 = case Seconds of
|
||||||
false -> 0;
|
false -> 0;
|
||||||
_ ->
|
_ ->
|
||||||
Sec =
|
Sec = calendar:datetime_to_gregorian_seconds(calendar:universal_time())
|
||||||
calendar:datetime_to_gregorian_seconds(calendar:now_to_universal_time(now()))
|
|
||||||
- Seconds,
|
- Seconds,
|
||||||
count_seconds_shift(Sec, HL)
|
count_seconds_shift(Sec, HL)
|
||||||
end,
|
end,
|
||||||
@ -2284,9 +2283,6 @@ send_existing_presences1(ToJID, StateData) ->
|
|||||||
end,
|
end,
|
||||||
(?DICT):to_list(StateData#state.nicks)).
|
(?DICT):to_list(StateData#state.nicks)).
|
||||||
|
|
||||||
now_to_usec({MSec, Sec, USec}) ->
|
|
||||||
(MSec * 1000000 + Sec) * 1000000 + USec.
|
|
||||||
|
|
||||||
change_nick(JID, Nick, StateData) ->
|
change_nick(JID, Nick, StateData) ->
|
||||||
LJID = jid:tolower(JID),
|
LJID = jid:tolower(JID),
|
||||||
{ok, #user{nick = OldNick}} = (?DICT):find(LJID,
|
{ok, #user{nick = OldNick}} = (?DICT):find(LJID,
|
||||||
@ -2454,7 +2450,7 @@ add_message_to_history(FromNick, FromJID, Packet, StateData) ->
|
|||||||
false -> false;
|
false -> false;
|
||||||
_ -> true
|
_ -> true
|
||||||
end,
|
end,
|
||||||
TimeStamp = now(),
|
TimeStamp = p1_time_compat:timestamp(),
|
||||||
AddrPacket = case (StateData#state.config)#config.anonymous of
|
AddrPacket = case (StateData#state.config)#config.anonymous of
|
||||||
true -> Packet;
|
true -> Packet;
|
||||||
false ->
|
false ->
|
||||||
@ -4630,4 +4626,3 @@ has_body_or_subject(Packet) ->
|
|||||||
(#xmlel{name = <<"subject">>}) -> false;
|
(#xmlel{name = <<"subject">>}) -> false;
|
||||||
(_) -> true
|
(_) -> true
|
||||||
end, Packet#xmlel.children).
|
end, Packet#xmlel.children).
|
||||||
|
|
||||||
|
@ -937,8 +937,7 @@ create_cache() ->
|
|||||||
{attributes, record_info(fields, multicastc)}]).
|
{attributes, record_info(fields, multicastc)}]).
|
||||||
|
|
||||||
add_response(RServer, Response) ->
|
add_response(RServer, Response) ->
|
||||||
Secs =
|
Secs = calendar:datetime_to_gregorian_seconds(calendar:local_time()),
|
||||||
calendar:datetime_to_gregorian_seconds(calendar:now_to_datetime(now())),
|
|
||||||
mnesia:dirty_write(#multicastc{rserver = RServer,
|
mnesia:dirty_write(#multicastc{rserver = RServer,
|
||||||
response = Response, ts = Secs}).
|
response = Response, ts = Secs}).
|
||||||
|
|
||||||
@ -949,8 +948,7 @@ search_server_on_cache(RServer, _LServerS, Maxmins) ->
|
|||||||
case look_server(RServer) of
|
case look_server(RServer) of
|
||||||
not_cached -> not_cached;
|
not_cached -> not_cached;
|
||||||
{cached, Response, Ts} ->
|
{cached, Response, Ts} ->
|
||||||
Now =
|
Now = calendar:datetime_to_gregorian_seconds(calendar:local_time()),
|
||||||
calendar:datetime_to_gregorian_seconds(calendar:now_to_datetime(now())),
|
|
||||||
case is_obsolete(Response, Ts, Now, Maxmins) of
|
case is_obsolete(Response, Ts, Now, Maxmins) of
|
||||||
false -> {cached, Response};
|
false -> {cached, Response};
|
||||||
true -> {obsolete, Response}
|
true -> {obsolete, Response}
|
||||||
@ -978,7 +976,7 @@ purge() ->
|
|||||||
Maxmins_positive = (?MAXTIME_CACHE_POSITIVE),
|
Maxmins_positive = (?MAXTIME_CACHE_POSITIVE),
|
||||||
Maxmins_negative = (?MAXTIME_CACHE_NEGATIVE),
|
Maxmins_negative = (?MAXTIME_CACHE_NEGATIVE),
|
||||||
Now =
|
Now =
|
||||||
calendar:datetime_to_gregorian_seconds(calendar:now_to_datetime(now())),
|
calendar:datetime_to_gregorian_seconds(calendar:local_time()),
|
||||||
purge(Now, {Maxmins_positive, Maxmins_negative}).
|
purge(Now, {Maxmins_positive, Maxmins_negative}).
|
||||||
|
|
||||||
purge(Now, Maxmins) ->
|
purge(Now, Maxmins) ->
|
||||||
|
@ -78,8 +78,7 @@ update(Server, JID, Dir) ->
|
|||||||
TimeInterval = gen_mod:get_module_opt(Server, ?MODULE, interval,
|
TimeInterval = gen_mod:get_module_opt(Server, ?MODULE, interval,
|
||||||
fun(I) when is_integer(I), I>0 -> I end,
|
fun(I) when is_integer(I), I>0 -> I end,
|
||||||
60),
|
60),
|
||||||
{MegaSecs, Secs, _MicroSecs} = now(),
|
TimeStamp = p1_time_compat:system_time(seconds),
|
||||||
TimeStamp = MegaSecs * 1000000 + Secs,
|
|
||||||
case read(Dir) of
|
case read(Dir) of
|
||||||
undefined ->
|
undefined ->
|
||||||
write(Dir,
|
write(Dir,
|
||||||
|
@ -223,7 +223,7 @@ write_roster_version_t(LUser, LServer) ->
|
|||||||
write_roster_version(LUser, LServer, true).
|
write_roster_version(LUser, LServer, true).
|
||||||
|
|
||||||
write_roster_version(LUser, LServer, InTransaction) ->
|
write_roster_version(LUser, LServer, InTransaction) ->
|
||||||
Ver = p1_sha:sha(term_to_binary(now())),
|
Ver = p1_sha:sha(term_to_binary(p1_time_compat:unique_integer())),
|
||||||
write_roster_version(LUser, LServer, InTransaction, Ver,
|
write_roster_version(LUser, LServer, InTransaction, Ver,
|
||||||
gen_mod:db_type(LServer, ?MODULE)),
|
gen_mod:db_type(LServer, ?MODULE)),
|
||||||
Ver.
|
Ver.
|
||||||
|
Loading…
Reference in New Issue
Block a user