Skip to content

Commit

Permalink
try to speed up startup
Browse files Browse the repository at this point in the history
  • Loading branch information
V V committed Oct 1, 2015
1 parent b16c44c commit a5e0705
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
13 changes: 12 additions & 1 deletion mtproto-client.c
Expand Up @@ -827,6 +827,12 @@ static int work_new_session_created (struct tgl_state *TLS, struct connection *c
fetch_long (); // first message id
fetch_long (); // unique_id
TLS->net_methods->get_dc (c)->server_salt = fetch_long ();

struct tgl_session *S = TLS->net_methods->get_session (c);
struct tgl_dc *DC = TLS->net_methods->get_dc (c);

tglq_regen_queries_from_old_session (TLS, DC, S);

if (TLS->started && !(TLS->locks & TGL_LOCK_DIFF) && (TLS->DC_working->flags & TGLDCF_LOGGED_IN)) {
tgl_do_get_difference (TLS, 0, 0, 0);
}
Expand Down Expand Up @@ -886,11 +892,11 @@ static int work_packed (struct tgl_state *TLS, struct connection *c, long long m
static int work_bad_server_salt (struct tgl_state *TLS, struct connection *c, long long msg_id) {
assert (fetch_int () == (int)CODE_bad_server_salt);
long long id = fetch_long ();
tglq_query_restart (TLS, id);
fetch_int (); // seq_no
fetch_int (); // error_code
long long new_server_salt = fetch_long ();
TLS->net_methods->get_dc (c)->server_salt = new_server_salt;
tglq_query_restart (TLS, id);
return 0;
}

Expand Down Expand Up @@ -933,6 +939,11 @@ static int work_bad_msg_notification (struct tgl_state *TLS, struct connection *
case 17:
tglq_regen_query (TLS, m1);
break;
// Bad container
case 64:
vlogprintf (E_NOTICE, "bad_msg_notification: msg_id = %lld, seq = %d, error = %d\n", m1, s, e);
tglq_regen_query (TLS, m1);
break;
default:
vlogprintf (E_NOTICE, "bad_msg_notification: msg_id = %lld, seq = %d, error = %d\n", m1, s, e);
break;
Expand Down
35 changes: 31 additions & 4 deletions queries.c
Expand Up @@ -122,7 +122,7 @@ static int alarm_query (struct tgl_state *TLS, struct query *q) {
assert (q);
vlogprintf (E_DEBUG - 2, "Alarm query %lld\n", q->msg_id);

TLS->timer_methods->insert (q->ev, QUERY_TIMEOUT);
TLS->timer_methods->insert (q->ev, q->methods->timeout ? q->methods->timeout : QUERY_TIMEOUT);

if (q->session && q->session_id && q->DC && q->DC->sessions[0] == q->session && q->session->session_id == q->session_id) {
clear_packet ();
Expand Down Expand Up @@ -166,6 +166,32 @@ void tglq_regen_query (struct tgl_state *TLS, long long id) {
TLS->timer_methods->insert (q->ev, 0.001);
}

struct regen_tmp_struct {
struct tgl_state *TLS;
struct tgl_dc *DC;
struct tgl_session *S;
};

void tglq_regen_query_from_old_session (struct query *q, void *ex) {
struct regen_tmp_struct *T = ex;
struct tgl_state *TLS = T->TLS;
if (q->DC == T->DC) {
if (!q->session || q->session_id != T->S->session_id || q->session != T->S) {
q->session_id = 0;
vlogprintf (E_NOTICE, "regen query %lld\n", q->msg_id);
TLS->timer_methods->insert (q->ev, 0.001);
}
}
}

void tglq_regen_queries_from_old_session (struct tgl_state *TLS, struct tgl_dc *DC, struct tgl_session *S) {
struct regen_tmp_struct T;
T.TLS = TLS;
T.DC = DC;
T.S = S;
tree_act_ex_query (TLS->queries_tree, tglq_regen_query_from_old_session, &T);
}

void tglq_query_restart (struct tgl_state *TLS, long long id) {
struct query *q = tglq_query_get (TLS, id);
if (q) {
Expand Down Expand Up @@ -209,7 +235,7 @@ struct query *tglq_send_query_ex (struct tgl_state *TLS, struct tgl_dc *DC, int
TLS->queries_tree = tree_insert_query (TLS->queries_tree, q, lrand48 ());

q->ev = TLS->timer_methods->alloc (TLS, alarm_query_gateway, q);
TLS->timer_methods->insert (q->ev, QUERY_TIMEOUT);
TLS->timer_methods->insert (q->ev, q->methods->timeout ? q->methods->timeout : QUERY_TIMEOUT);

q->extra = extra;
q->callback = callback;
Expand Down Expand Up @@ -560,7 +586,8 @@ static int help_get_config_on_answer (struct tgl_state *TLS, struct query *q, vo
static struct query_methods help_get_config_methods = {
.on_answer = help_get_config_on_answer,
.on_error = q_void_on_error,
.type = TYPE_TO_PARAM(config)
.type = TYPE_TO_PARAM(config),
.timeout = 1
};

void tgl_do_help_get_config (struct tgl_state *TLS, void (*callback)(struct tgl_state *,void *, int), void *callback_extra) {
Expand Down Expand Up @@ -3316,7 +3343,7 @@ void tgl_do_get_channel_difference (struct tgl_state *TLS, int id, void (*callba
out_int (CODE_updates_get_channel_difference);
out_int (CODE_input_channel);
out_int (tgl_get_peer_id (E->id));
out_int (E->channel.access_hash);
out_long (E->channel.access_hash);

out_int (CODE_channel_messages_filter_empty);
out_int (E->channel.pts);
Expand Down
2 changes: 2 additions & 0 deletions queries.h
Expand Up @@ -34,6 +34,7 @@ struct query_methods {
int (*on_timeout)(struct tgl_state *TLS, struct query *q);
struct paramed_type *type;
char *name;
double timeout;
};

struct query {
Expand Down Expand Up @@ -78,6 +79,7 @@ void tgl_do_abort_exchange (struct tgl_state *TLS, struct tgl_secret_chat *E);
void tglq_regen_query (struct tgl_state *TLS, long long id);
void tglq_query_delete (struct tgl_state *TLS, long long id);
void tglq_query_free_all (struct tgl_state *TLS);
void tglq_regen_queries_from_old_session (struct tgl_state *TLS, struct tgl_dc *DC, struct tgl_session *S);
// For binlog

//int get_dh_config_on_answer (struct query *q);
Expand Down

0 comments on commit a5e0705

Please sign in to comment.