From b9cf49e96f37423a05e97a0966ee8f4239c28fcc Mon Sep 17 00:00:00 2001 From: vvaltman Date: Sat, 27 Sep 2014 21:58:28 +0400 Subject: [PATCH] Hardcoded default ip's for all DC --- binlog.c | 56 +++++++++++++++++++++++++++++++++++++++++------- loop.c | 16 +++++++++++--- mtproto-client.c | 31 ++++++++++++++++----------- net.c | 4 ++++ tgl.h | 14 ++++++++---- 5 files changed, 94 insertions(+), 27 deletions(-) diff --git a/binlog.c b/binlog.c index 4cfb948..f855786 100644 --- a/binlog.c +++ b/binlog.c @@ -1316,13 +1316,53 @@ static void create_new_binlog (void) { static int s[1000]; packet_ptr = s; out_int (CODE_binlog_start); - out_int (CODE_binlog_dc_option); - out_int (tgl_state.test_mode ? TG_SERVER_TEST_DC : TG_SERVER_DC); - out_string (""); - out_string (tgl_state.test_mode ? TG_SERVER_TEST : TG_SERVER); - out_int (443); - out_int (CODE_binlog_default_dc); - out_int (tgl_state.test_mode ? TG_SERVER_TEST_DC : TG_SERVER_DC); + if (tgl_state.test_mode) { + out_int (CODE_binlog_dc_option); + out_int (1); + out_string (""); + out_string (TG_SERVER_TEST_1); + out_int (443); + out_int (CODE_binlog_dc_option); + out_int (2); + out_string (""); + out_string (TG_SERVER_TEST_2); + out_int (443); + out_int (CODE_binlog_dc_option); + out_int (3); + out_string (""); + out_string (TG_SERVER_TEST_3); + out_int (443); + out_int (CODE_binlog_default_dc); + out_int (2); + } else { + out_int (CODE_binlog_dc_option); + out_int (1); + out_string (""); + out_string (TG_SERVER_1); + out_int (443); + out_int (CODE_binlog_dc_option); + out_int (2); + out_string (""); + out_string (TG_SERVER_2); + out_int (443); + out_int (CODE_binlog_dc_option); + out_int (3); + out_string (""); + out_string (TG_SERVER_3); + out_int (443); + out_int (CODE_binlog_dc_option); + out_int (4); + out_string (""); + out_string (TG_SERVER_4); + out_int (443); + out_int (CODE_binlog_dc_option); + out_int (5); + out_string (""); + out_string (TG_SERVER_5); + out_int (443); + out_int (CODE_binlog_default_dc); + out_int (2); + } int fd = open (get_binlog_file_name (), O_WRONLY | O_EXCL | O_CREAT, 0600); if (fd < 0) { @@ -1542,7 +1582,7 @@ void bl_do_user_set_friend (struct tgl_user *U, int friend) { void bl_do_dc_option (int id, int l1, const char *name, int l2, const char *ip, int port) { struct tgl_dc *DC = tgl_state.DC_list[id]; - if (DC) { return; } + if (DC && !strncmp (ip, DC->ip, l2)) { return; } clear_packet (); out_int (CODE_binlog_dc_option); diff --git a/loop.c b/loop.c index f3ec7de..cab2815 100644 --- a/loop.c +++ b/loop.c @@ -500,9 +500,19 @@ void read_dc (int auth_file_fd, int id, unsigned ver) { } void empty_auth_file (void) { - char *ip = tgl_state.test_mode ? TG_SERVER_TEST : TG_SERVER; - bl_do_dc_option (tgl_state.test_mode ? TG_SERVER_TEST_DC : TG_SERVER_DC, 0, "", strlen (ip), ip, 443); - bl_do_set_working_dc (tgl_state.test_mode ? TG_SERVER_TEST_DC : TG_SERVER_DC); + if (tgl_state.test_mode) { + bl_do_dc_option (1, 0, "", strlen (TG_SERVER_TEST_1), TG_SERVER_TEST_1, 443); + bl_do_dc_option (2, 0, "", strlen (TG_SERVER_TEST_2), TG_SERVER_TEST_2, 443); + bl_do_dc_option (3, 0, "", strlen (TG_SERVER_TEST_3), TG_SERVER_TEST_3, 443); + bl_do_set_working_dc (2); + } else { + bl_do_dc_option (1, 0, "", strlen (TG_SERVER_1), TG_SERVER_1, 443); + bl_do_dc_option (2, 0, "", strlen (TG_SERVER_2), TG_SERVER_2, 443); + bl_do_dc_option (3, 0, "", strlen (TG_SERVER_3), TG_SERVER_3, 443); + bl_do_dc_option (4, 0, "", strlen (TG_SERVER_4), TG_SERVER_4, 443); + bl_do_dc_option (5, 0, "", strlen (TG_SERVER_5), TG_SERVER_5, 443); + bl_do_set_working_dc (2); + } } int need_dc_list_update; diff --git a/mtproto-client.c b/mtproto-client.c index 12ac336..13fd905 100644 --- a/mtproto-client.c +++ b/mtproto-client.c @@ -1341,19 +1341,26 @@ static void regen_temp_key_gw (evutil_socket_t fd, short what, void *arg) { } struct tgl_dc *tglmp_alloc_dc (int id, char *ip, int port UU) { - assert (!tgl_state.DC_list[id]); - struct tgl_dc *DC = talloc0 (sizeof (*DC)); - DC->id = id; - DC->ip = ip; - DC->port = port; - tgl_state.DC_list[id] = DC; - if (id > tgl_state.max_dc_num) { - tgl_state.max_dc_num = id; + //assert (!tgl_state.DC_list[id]); + if (!tgl_state.DC_list[id]) { + struct tgl_dc *DC = talloc0 (sizeof (*DC)); + DC->id = id; + DC->ip = ip; + DC->port = port; + tgl_state.DC_list[id] = DC; + if (id > tgl_state.max_dc_num) { + tgl_state.max_dc_num = id; + } + DC->ev = evtimer_new (tgl_state.ev_base, regen_temp_key_gw, DC); + static struct timeval p; + event_add (DC->ev, &p); + return DC; + } else { + struct tgl_dc *DC = tgl_state.DC_list[id]; + tfree_str (DC->ip); + DC->ip = tstrdup (ip); + return DC; } - DC->ev = evtimer_new (tgl_state.ev_base, regen_temp_key_gw, DC); - static struct timeval p; - event_add (DC->ev, &p); - return DC; } static struct mtproto_methods mtproto_methods = { diff --git a/net.c b/net.c index dd3c24e..8c682d5 100644 --- a/net.c +++ b/net.c @@ -345,6 +345,10 @@ static void restart_connection (struct connection *c) { struct sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_port = htons (c->port); + if (strcmp (c->ip, c->dc->ip)) { + tfree_str (c->ip); + c->ip = tstrdup (c->dc->ip); + } addr.sin_addr.s_addr = inet_addr (c->ip); diff --git a/tgl.h b/tgl.h index 529dccf..fdcbcfc 100644 --- a/tgl.h +++ b/tgl.h @@ -24,10 +24,16 @@ #include #define TGL_MAX_DC_NUM 100 -#define TG_SERVER "149.154.167.50" -#define TG_SERVER_TEST "149.154.167.40" -#define TG_SERVER_DC 2 -#define TG_SERVER_TEST_DC 2 +#define TG_SERVER_1 "173.240.5.1" +#define TG_SERVER_2 "149.154.167.51" +#define TG_SERVER_3 "174.140.142.6" +#define TG_SERVER_4 "149.154.167.91" +#define TG_SERVER_5 "149.154.171.5" + + +#define TG_SERVER_TEST_1 "173.240.5.253" +#define TG_SERVER_TEST_2 "149.154.167.40" +#define TG_SERVER_TEST_3 "174.140.142.5" // JUST RANDOM STRING #define TGL_BUILD "2014"