Commit 7affcd89 authored by vvaltman's avatar vvaltman

Merge github.com:vysheng/tg

parents 11bf4177 b9cf49e9
......@@ -1332,13 +1332,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) {
......@@ -1558,7 +1598,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);
......
......@@ -1030,7 +1030,7 @@ struct command commands[] = {
{"chat_del_user", {ca_chat, ca_user, ca_none}, do_chat_del_user, "chat_del_user <chat> <user>\tDeletes user from chat"},
{"status_online", {ca_none}, do_status_online, "status_online\tSets status as online"},
{"status_offline", {ca_none}, do_status_offline, "status_offline\tSets status as offline"},
{"quit", {ca_none}, do_quit, "quit\tQuits immideatly"},
{"quit", {ca_none}, do_quit, "quit\tQuits immediately"},
{"safe_quit", {ca_none}, do_safe_quit, "safe_quit\tWaits for all queries to end, then quits"},
{"set", {ca_string, ca_number, ca_none}, do_set, "set <param> <value>\tSets value of param. Currently available: log_level, debug_verbosity, alarm, msg_num"},
{"chat_with_peer", {ca_peer, ca_none}, do_chat_with_peer, "chat_with_peer <peer>\tInterface option. All input will be treated as messages to this peer. Type /quit to end this mode"},
......
......@@ -205,6 +205,7 @@ void net_loop (int flags, int (*is_end)(void)) {
if (term_ev) {
event_free (term_ev);
term_ev = 0;
}
if (verbosity >= E_DEBUG) {
......@@ -499,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;
......
......@@ -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 = {
......
......@@ -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);
......
......@@ -24,10 +24,16 @@
#include <string.h>
#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"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment