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