changeset 26234:bb5a6709d9b7

Add timeout to p2p server accepting connections
author Sulabh Mahajan <sulabh@soc.pidgin.im>
date Sun, 28 Sep 2008 16:03:24 +0000
parents 68f14660843e
children 1317a9ae66e8
files libpurple/protocols/yahoo/yahoo.c libpurple/protocols/yahoo/yahoo.h
diffstat 2 files changed, 25 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/yahoo/yahoo.c	Sun Sep 28 15:52:08 2008 +0000
+++ b/libpurple/protocols/yahoo/yahoo.c	Sun Sep 28 16:03:24 2008 +0000
@@ -2600,6 +2600,25 @@
 	p2p_data->source = acceptfd;
 }
 
+static gboolean yahoo_cancel_p2p_server_listen_cb(gpointer data)
+{
+	struct yahoo_p2p_data *p2p_data;
+	struct yahoo_data *yd;
+
+	if(!(p2p_data = data))
+		return FALSE;
+
+	yd = p2p_data->gc->proto_data;
+
+	purple_debug_warning("yahoo","yahoo p2p server timeout, peer failed to connect");
+	yahoo_p2p_disconnect_destroy_data(data);
+	purple_input_remove(yd->yahoo_p2p_server_watcher);
+	close(yd->yahoo_local_p2p_server_fd);
+	yd->yahoo_local_p2p_server_fd = -1;
+
+	return FALSE;
+}
+
 static void yahoo_p2p_server_listen_cb(int listenfd, gpointer data)
 {
 	struct yahoo_p2p_data *p2p_data;
@@ -2619,6 +2638,9 @@
 	/* Add an Input Read event to the file descriptor */
 	yd->yahoo_local_p2p_server_fd = listenfd;
 	yd->yahoo_p2p_server_watcher = purple_input_add(listenfd, PURPLE_INPUT_READ, yahoo_p2p_server_send_connected_cb,data);
+
+	/* add timeout */
+	yd->yahoo_p2p_server_timeout_handle = purple_timeout_add_seconds(YAHOO_P2P_SERVER_TIMEOUT, yahoo_cancel_p2p_server_listen_cb, data);
 }
 
 /* send p2p pkt containing our encoded ip, asking peer to connect to us */
@@ -2822,7 +2844,7 @@
 				val_11 = f->session_id;
 		}
 
-		p2p_data->host_username = g_strdup(who);
+		p2p_data->host_username = g_strdup(who);	
 		p2p_data->val_13 = val_13;
 		p2p_data->session_id = val_11;
 		p2p_data->host_ip = host_ip;
--- a/libpurple/protocols/yahoo/yahoo.h	Sun Sep 28 15:52:08 2008 +0000
+++ b/libpurple/protocols/yahoo/yahoo.h	Sun Sep 28 16:03:24 2008 +0000
@@ -32,6 +32,7 @@
 #define YAHOO_PAGER_PORT 5050
 #define YAHOO_PAGER_PORT_P2P 5101
 #define YAHOO_P2P_KEEPALIVE_SECS 300
+#define YAHOO_P2P_SERVER_TIMEOUT 10
 #define YAHOO_PROFILE_URL "http://profiles.yahoo.com/"
 #define YAHOO_MAIL_URL "https://login.yahoo.com/config/login?.src=ym"
 #define YAHOO_XFER_HOST "filetransfer.msg.yahoo.com"
@@ -205,6 +206,7 @@
 	int yahoo_local_p2p_server_fd;
 	int yahoo_p2p_server_watcher;
 	GHashTable *sms_carrier;	/* sms carrier data */
+	guint yahoo_p2p_server_timeout_handle;
 };
 
 #define YAHOO_MAX_STATUS_MESSAGE_LENGTH (255)