Fixed work with updates

This commit is contained in:
vvaltman 2014-08-27 19:12:45 +04:00
parent 918694278a
commit 1602a33b45
5 changed files with 30 additions and 12 deletions

View File

@ -53,6 +53,7 @@ static int binlog_buffer[BINLOG_BUFFER_SIZE];
static int *rptr; static int *rptr;
static int *wptr; static int *wptr;
static int binlog_fd; static int binlog_fd;
static int in_replay_log; // should be used ONLY for DEBUG
#define MAX_LOG_EVENT_SIZE (1 << 17) #define MAX_LOG_EVENT_SIZE (1 << 17)
@ -140,13 +141,15 @@ static int fetch_comb_binlog_set_dh_params (void *extra) {
static int fetch_comb_binlog_set_pts (void *extra) { static int fetch_comb_binlog_set_pts (void *extra) {
int new_pts = fetch_int (); int new_pts = fetch_int ();
assert (new_pts >= tgl_state.pts); assert (new_pts >= tgl_state.pts);
vlogprintf (E_DEBUG - 1 + 2 * in_replay_log, "pts %d=>%d\n", tgl_state.pts, new_pts);
tgl_state.pts = new_pts; tgl_state.pts = new_pts;
return 0; return 0;
} }
static int fetch_comb_binlog_set_qts (void *extra) { static int fetch_comb_binlog_set_qts (void *extra) {
int new_qts = fetch_int (); int new_qts = fetch_int ();
//assert (new_qts >= qts); assert (new_qts >= tgl_state.qts);
vlogprintf (E_DEBUG - 1 + 2 * in_replay_log, "qts %d=>%d\n", tgl_state.qts, new_qts);
tgl_state.qts = new_qts; tgl_state.qts = new_qts;
return 0; return 0;
} }
@ -164,6 +167,7 @@ static int fetch_comb_binlog_set_seq (void *extra) {
vlogprintf (E_ERROR, "Error: old_seq = %d, new_seq = %d\n", tgl_state.seq, new_seq); vlogprintf (E_ERROR, "Error: old_seq = %d, new_seq = %d\n", tgl_state.seq, new_seq);
} }
assert (new_seq >= tgl_state.seq); assert (new_seq >= tgl_state.seq);
vlogprintf (E_DEBUG - 1 + 2 * in_replay_log, "seq %d=>%d\n", tgl_state.seq, new_seq);
tgl_state.seq = new_seq; tgl_state.seq = new_seq;
return 0; return 0;
} }
@ -1087,6 +1091,7 @@ static int fetch_comb_binlog_msg_seq_update (void *extra) {
struct tgl_message *M = tgl_message_get (fetch_long ()); struct tgl_message *M = tgl_message_get (fetch_long ());
assert (M); assert (M);
tgl_state.seq ++; tgl_state.seq ++;
vlogprintf (E_DEBUG - 1 + 2 * in_replay_log, "seq %d=>%d\n", tgl_state.seq - 1, tgl_state.seq);
if (tgl_state.callback.msg_receive) { if (tgl_state.callback.msg_receive) {
tgl_state.callback.msg_receive (M); tgl_state.callback.msg_receive (M);
@ -1234,6 +1239,7 @@ void tgl_replay_log (void) {
exit (2); exit (2);
} }
int end = 0; int end = 0;
in_replay_log = 1;
while (1) { while (1) {
if (!end && wptr - rptr < MAX_LOG_EVENT_SIZE / 4) { if (!end && wptr - rptr < MAX_LOG_EVENT_SIZE / 4) {
if (wptr == rptr) { if (wptr == rptr) {
@ -1259,6 +1265,7 @@ void tgl_replay_log (void) {
if (wptr == rptr) { break; } if (wptr == rptr) { break; }
replay_log_event (); replay_log_event ();
} }
in_replay_log = 0;
close (fd); close (fd);
} }
@ -1573,6 +1580,7 @@ void bl_do_encr_chat_init (int id, int user_id, unsigned char random[], unsigned
void bl_do_set_pts (int pts) { void bl_do_set_pts (int pts) {
if (tgl_state.locks & TGL_LOCK_DIFF) { return; } if (tgl_state.locks & TGL_LOCK_DIFF) { return; }
if (pts == tgl_state.pts) { return; }
int *ev = alloc_log_event (8); int *ev = alloc_log_event (8);
ev[0] = CODE_binlog_set_pts; ev[0] = CODE_binlog_set_pts;
ev[1] = pts; ev[1] = pts;
@ -1580,6 +1588,8 @@ void bl_do_set_pts (int pts) {
} }
void bl_do_set_qts (int qts) { void bl_do_set_qts (int qts) {
if (tgl_state.locks & TGL_LOCK_DIFF) { return; }
if (qts == tgl_state.qts) { return; }
int *ev = alloc_log_event (8); int *ev = alloc_log_event (8);
ev[0] = CODE_binlog_set_qts; ev[0] = CODE_binlog_set_qts;
ev[1] = qts; ev[1] = qts;
@ -1588,6 +1598,7 @@ void bl_do_set_qts (int qts) {
void bl_do_set_date (int date) { void bl_do_set_date (int date) {
if (tgl_state.locks & TGL_LOCK_DIFF) { return; } if (tgl_state.locks & TGL_LOCK_DIFF) { return; }
if (date == tgl_state.date) { return; }
int *ev = alloc_log_event (8); int *ev = alloc_log_event (8);
ev[0] = CODE_binlog_set_date; ev[0] = CODE_binlog_set_date;
ev[1] = date; ev[1] = date;
@ -1596,6 +1607,7 @@ void bl_do_set_date (int date) {
void bl_do_set_seq (int seq) { void bl_do_set_seq (int seq) {
if (tgl_state.locks & TGL_LOCK_DIFF) { return; } if (tgl_state.locks & TGL_LOCK_DIFF) { return; }
if (seq == tgl_state.seq) { return; }
int *ev = alloc_log_event (8); int *ev = alloc_log_event (8);
ev[0] = CODE_binlog_set_seq; ev[0] = CODE_binlog_set_seq;
ev[1] = seq; ev[1] = seq;

20
loop.c
View File

@ -138,7 +138,7 @@ static void stdin_read_callback_line (evutil_socket_t fd, short what, void *arg)
void net_loop (int flags, int (*is_end)(void)) { void net_loop (int flags, int (*is_end)(void)) {
delete_stdin_event = 0; delete_stdin_event = 0;
if (verbosity) { if (verbosity >= E_DEBUG) {
logprintf ("Starting netloop\n"); logprintf ("Starting netloop\n");
} }
struct event *ev = 0; struct event *ev = 0;
@ -184,7 +184,7 @@ void net_loop (int flags, int (*is_end)(void)) {
event_free (ev); event_free (ev);
} }
if (verbosity) { if (verbosity >= E_DEBUG) {
logprintf ("End of netloop\n"); logprintf ("End of netloop\n");
} }
} }
@ -474,9 +474,13 @@ int loop (void) {
if (binlog_enabled) { if (binlog_enabled) {
double t = tglt_get_double_time (); double t = tglt_get_double_time ();
logprintf ("replay log start\n"); if (verbosity >= E_DEBUG) {
logprintf ("replay log start\n");
}
tgl_replay_log (); tgl_replay_log ();
logprintf ("replay log end in %lf seconds\n", tglt_get_double_time () - t); if (verbosity >= E_DEBUG) {
logprintf ("replay log end in %lf seconds\n", tglt_get_double_time () - t);
}
tgl_reopen_binlog_for_writing (); tgl_reopen_binlog_for_writing ();
} else { } else {
read_auth_file (); read_auth_file ();
@ -497,7 +501,7 @@ int loop (void) {
tgl_do_help_get_config (on_get_config, 0); tgl_do_help_get_config (on_get_config, 0);
net_loop (0, got_config); net_loop (0, got_config);
if (verbosity) { if (verbosity >= E_DEBUG) {
logprintf ("DC_info: %d new DC got\n", new_dc_num); logprintf ("DC_info: %d new DC got\n", new_dc_num);
} }
@ -524,8 +528,10 @@ int loop (void) {
} }
tgl_do_send_code (default_username, sign_in_callback, 0); tgl_do_send_code (default_username, sign_in_callback, 0);
net_loop (0, sent_code); net_loop (0, sent_code);
logprintf ("%s\n", should_register ? "phone not registered" : "phone registered"); if (verbosity >= E_DEBUG) {
logprintf ("%s\n", should_register ? "phone not registered" : "phone registered");
}
if (!should_register) { if (!should_register) {
char *code = 0; char *code = 0;
size_t size = 0; size_t size = 0;

View File

@ -2917,7 +2917,7 @@ void tgl_do_get_difference (int sync_from_start, void (*callback)(void *callback
tgl_do_insert_header (); tgl_do_insert_header ();
if (tgl_state.seq > 0 || sync_from_start) { if (tgl_state.seq > 0 || sync_from_start) {
if (tgl_state.pts == 0) { tgl_state.pts = 1; } if (tgl_state.pts == 0) { tgl_state.pts = 1; }
if (tgl_state.qts == 0) { tgl_state.qts = 1; } //if (tgl_state.qts == 0) { tgl_state.qts = 1; }
if (tgl_state.date == 0) { tgl_state.date = 1; } if (tgl_state.date == 0) { tgl_state.date = 1; }
out_int (CODE_updates_get_difference); out_int (CODE_updates_get_difference);
out_int (tgl_state.pts); out_int (tgl_state.pts);

2
tgl.h
View File

@ -110,7 +110,7 @@ struct tgl_net_methods {
#define E_ERROR 0 #define E_ERROR 0
#define E_WARNING 1 #define E_WARNING 1
#define E_NOTICE 2 #define E_NOTICE 2
#define E_DEBUG 3 #define E_DEBUG 6
#define TGL_LOCK_DIFF 1 #define TGL_LOCK_DIFF 1

View File

@ -29,13 +29,13 @@
void tglu_fetch_pts (void) { void tglu_fetch_pts (void) {
int p = fetch_int (); int p = fetch_int ();
if (p <= tgl_state.pts) { return; } if (p <= tgl_state.pts) { return; }
bl_do_set_pts (tgl_state.pts); bl_do_set_pts (p);
} }
void tglu_fetch_qts (void) { void tglu_fetch_qts (void) {
int p = fetch_int (); int p = fetch_int ();
if (p <= tgl_state.qts) { return; } if (p <= tgl_state.qts) { return; }
bl_do_set_qts (tgl_state.qts); bl_do_set_qts (p);
} }
void tglu_fetch_date (void) { void tglu_fetch_date (void) {