Hardcoded default ip's for all DC

This commit is contained in:
vvaltman 2014-09-27 21:58:28 +04:00
parent ddcd8ad44e
commit b9cf49e96f
5 changed files with 94 additions and 27 deletions

View File

@ -1316,13 +1316,53 @@ static void create_new_binlog (void) {
static int s[1000]; static int s[1000];
packet_ptr = s; packet_ptr = s;
out_int (CODE_binlog_start); out_int (CODE_binlog_start);
out_int (CODE_binlog_dc_option); if (tgl_state.test_mode) {
out_int (tgl_state.test_mode ? TG_SERVER_TEST_DC : TG_SERVER_DC); out_int (CODE_binlog_dc_option);
out_string (""); out_int (1);
out_string (tgl_state.test_mode ? TG_SERVER_TEST : TG_SERVER); out_string ("");
out_int (443); out_string (TG_SERVER_TEST_1);
out_int (CODE_binlog_default_dc); out_int (443);
out_int (tgl_state.test_mode ? TG_SERVER_TEST_DC : TG_SERVER_DC); 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); int fd = open (get_binlog_file_name (), O_WRONLY | O_EXCL | O_CREAT, 0600);
if (fd < 0) { 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) { 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]; struct tgl_dc *DC = tgl_state.DC_list[id];
if (DC) { return; } if (DC && !strncmp (ip, DC->ip, l2)) { return; }
clear_packet (); clear_packet ();
out_int (CODE_binlog_dc_option); out_int (CODE_binlog_dc_option);

16
loop.c
View File

@ -500,9 +500,19 @@ void read_dc (int auth_file_fd, int id, unsigned ver) {
} }
void empty_auth_file (void) { void empty_auth_file (void) {
char *ip = tgl_state.test_mode ? TG_SERVER_TEST : TG_SERVER; if (tgl_state.test_mode) {
bl_do_dc_option (tgl_state.test_mode ? TG_SERVER_TEST_DC : TG_SERVER_DC, 0, "", strlen (ip), ip, 443); bl_do_dc_option (1, 0, "", strlen (TG_SERVER_TEST_1), TG_SERVER_TEST_1, 443);
bl_do_set_working_dc (tgl_state.test_mode ? TG_SERVER_TEST_DC : TG_SERVER_DC); 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; int need_dc_list_update;

View File

@ -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) { struct tgl_dc *tglmp_alloc_dc (int id, char *ip, int port UU) {
assert (!tgl_state.DC_list[id]); //assert (!tgl_state.DC_list[id]);
struct tgl_dc *DC = talloc0 (sizeof (*DC)); if (!tgl_state.DC_list[id]) {
DC->id = id; struct tgl_dc *DC = talloc0 (sizeof (*DC));
DC->ip = ip; DC->id = id;
DC->port = port; DC->ip = ip;
tgl_state.DC_list[id] = DC; DC->port = port;
if (id > tgl_state.max_dc_num) { tgl_state.DC_list[id] = DC;
tgl_state.max_dc_num = id; 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 = { static struct mtproto_methods mtproto_methods = {

4
net.c
View File

@ -345,6 +345,10 @@ static void restart_connection (struct connection *c) {
struct sockaddr_in addr; struct sockaddr_in addr;
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
addr.sin_port = htons (c->port); 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); addr.sin_addr.s_addr = inet_addr (c->ip);

14
tgl.h
View File

@ -24,10 +24,16 @@
#include <string.h> #include <string.h>
#define TGL_MAX_DC_NUM 100 #define TGL_MAX_DC_NUM 100
#define TG_SERVER "149.154.167.50" #define TG_SERVER_1 "173.240.5.1"
#define TG_SERVER_TEST "149.154.167.40" #define TG_SERVER_2 "149.154.167.51"
#define TG_SERVER_DC 2 #define TG_SERVER_3 "174.140.142.6"
#define TG_SERVER_TEST_DC 2 #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 // JUST RANDOM STRING
#define TGL_BUILD "2014" #define TGL_BUILD "2014"