# HG changeset patch # User Sean Egan # Date 1165365567 0 # Node ID cde909b9eb4bbb215b2a33e654937909a3727c0e # Parent 6cc89a43bf8fa70103df060f2e67051ed2706131 [gaim-migrate @ 17897] In the worst case, OSCAR file transfer waited 60 seconds before proxying. I've brought it down to 10 committer: Tailor Script diff -r 6cc89a43bf8f -r cde909b9eb4b libgaim/protocols/oscar/peer.c --- a/libgaim/protocols/oscar/peer.c Tue Dec 05 06:23:43 2006 +0000 +++ b/libgaim/protocols/oscar/peer.c Wed Dec 06 00:39:27 2006 +0000 @@ -139,10 +139,16 @@ else if (conn->type == OSCAR_CAPABILITY_SENDFILE) peer_oft_close(conn); - if (conn->connect_data != NULL) + if (conn->verified_connect_data != NULL) { - gaim_proxy_connect_cancel(conn->connect_data); - conn->connect_data = NULL; + gaim_proxy_connect_cancel(conn->verified_connect_data); + conn->verified_connect_data = NULL; + } + + if (conn->client_connect_data != NULL) + { + gaim_proxy_connect_cancel(conn->client_connect_data); + conn->client_connect_data = NULL; } if (conn->listen_data != NULL) @@ -497,13 +503,17 @@ * either connected or failed to connect. */ static void -peer_connection_established_cb(gpointer data, gint source, const gchar *error_message) +peer_connection_common_established_cb(gpointer data, gint source, const gchar *error_message, gboolean verified) { PeerConnection *conn; conn = data; - conn->connect_data = NULL; + if (verified) + conn->verified_connect_data = NULL; + else + conn->client_connect_data = NULL; + gaim_timeout_remove(conn->connect_timeout_timer); conn->connect_timeout_timer = 0; @@ -512,12 +522,32 @@ peer_connection_trynext(conn); return; } - + + if (verified) { + gaim_proxy_connect_cancel(conn->client_connect_data); + conn->client_connect_data = NULL; + } else { + gaim_proxy_connect_cancel(conn->verified_connect_data); + conn->verified_connect_data = NULL; + } + conn->fd = source; peer_connection_finalize_connection(conn); } +static void +peer_connection_verified_established_cb(gpointer data, gint source, const gchar *error_message) +{ + peer_connection_common_established_cb(data, source, error_message, TRUE); +} + +static void +peer_connection_client_established_cb(gpointer data, gint source, const gchar *error_message) +{ + peer_connection_common_established_cb(data, source, error_message, FALSE); +} + /** * This is the watcher callback for any listening socket that is * waiting for a peer to connect. When a peer connects we set the @@ -639,7 +669,7 @@ /** * This is a callback function used when we're connecting to a peer * using either the client IP or the verified IP and the connection - * took longer than 15 seconds to complete. We do this because + * took longer than 5 seconds to complete. We do this because * waiting for the OS to time out the connection attempt is not * practical--the default timeout on many OSes can be 3 minutes or * more, and users are impatient. @@ -653,6 +683,12 @@ * I suppose this line of thinking is discriminatory against people * with very high lag but decent throughput who are transferring * large files. But we don't care about those people. + * + * I (Sean) changed the timeout from 15 to 5 seconds, as 60 seconds is + * too long for a user to wait to send a file. I'm also parallelizing + * requests when possible. The longest we should have to wait now is 10 + * seconds. We shouldn't make it shorter than this. + * */ static gboolean peer_connection_tooktoolong(gpointer data) @@ -689,12 +725,14 @@ peer_connection_close(conn); /* - * 1. Attempt to connect to the remote user using their verifiedip. + * 1. Attempt to connect to the remote user using their verifiedip and clientip. + * We try these at the same time and use whichever succeeds first, so we don't + * have to wait for a timeout. */ - if (!(conn->flags & PEER_CONNECTION_FLAG_TRIED_VERIFIEDIP) && + if (!(conn->flags & PEER_CONNECTION_FLAG_TRIED_DIRECT) && (conn->verifiedip != NULL) && (conn->port != 0) && (!conn->use_proxy)) { - conn->flags |= PEER_CONNECTION_FLAG_TRIED_VERIFIEDIP; + conn->flags |= PEER_CONNECTION_FLAG_TRIED_DIRECT; if (conn->type == OSCAR_CAPABILITY_DIRECTIM) { @@ -708,48 +746,26 @@ g_free(tmp); } - conn->connect_data = gaim_proxy_connect(NULL, account, + conn->verified_connect_data = gaim_proxy_connect(NULL, account, conn->verifiedip, conn->port, - peer_connection_established_cb, conn); - if (conn->connect_data != NULL) + peer_connection_verified_established_cb, conn); + if (conn->verified_connect_data != NULL) { /* Connecting... */ - conn->connect_timeout_timer = gaim_timeout_add(15000, + conn->connect_timeout_timer = gaim_timeout_add(5000, peer_connection_tooktoolong, conn); - return; } - } - - /* - * 2. Attempt to connect to the remote user using their clientip. - */ - if (!(conn->flags & PEER_CONNECTION_FLAG_TRIED_CLIENTIP) && - (conn->clientip != NULL) && (conn->port != 0) && (!conn->use_proxy)) - { - conn->flags |= PEER_CONNECTION_FLAG_TRIED_CLIENTIP; if ((conn->verifiedip == NULL) || strcmp(conn->verifiedip, conn->clientip)) { - if (conn->type == OSCAR_CAPABILITY_DIRECTIM) - { - gchar *tmp; - GaimConversation *conv; - tmp = g_strdup_printf(_("Attempting to connect to %s:%hu."), - conn->clientip, conn->port); - conv = gaim_conversation_new(GAIM_CONV_TYPE_IM, account, conn->sn); - gaim_conversation_write(conv, NULL, tmp, - GAIM_MESSAGE_SYSTEM, time(NULL)); - g_free(tmp); - } - - conn->connect_data = gaim_proxy_connect(NULL, account, + conn->client_connect_data = gaim_proxy_connect(NULL, account, conn->clientip, conn->port, - peer_connection_established_cb, conn); - if (conn->connect_data != NULL) + peer_connection_client_established_cb, conn); + if (conn->connect_timeout_timer == 0 && conn->verified_connect_data != NULL) { /* Connecting... */ - conn->connect_timeout_timer = gaim_timeout_add(15000, + conn->connect_timeout_timer = gaim_timeout_add(5000, peer_connection_tooktoolong, conn); return; } @@ -757,7 +773,7 @@ } /* - * 3. Attempt to have the remote user connect to us (using both + * 2. Attempt to have the remote user connect to us (using both * our verifiedip and our clientip). */ if (!(conn->flags & PEER_CONNECTION_FLAG_TRIED_INCOMING) && @@ -781,7 +797,7 @@ } /* - * 4. Attempt to have both users connect to an intermediate proxy + * 3. Attempt to have both users connect to an intermediate proxy * server. */ if (!(conn->flags & PEER_CONNECTION_FLAG_TRIED_PROXY)) @@ -807,11 +823,11 @@ g_free(tmp); } - conn->connect_data = gaim_proxy_connect(NULL, account, + conn->verified_connect_data = gaim_proxy_connect(NULL, account, (conn->proxyip != NULL) ? conn->proxyip : PEER_PROXY_SERVER, PEER_PROXY_PORT, peer_proxy_connection_established_cb, conn); - if (conn->connect_data != NULL) + if (conn->verified_connect_data != NULL) { /* Connecting... */ return; diff -r 6cc89a43bf8f -r cde909b9eb4b libgaim/protocols/oscar/peer.h --- a/libgaim/protocols/oscar/peer.h Tue Dec 05 06:23:43 2006 +0000 +++ b/libgaim/protocols/oscar/peer.h Wed Dec 06 00:39:27 2006 +0000 @@ -36,11 +36,10 @@ #define PEER_CONNECTION_FLAG_INITIATED_BY_ME 0x0001 #define PEER_CONNECTION_FLAG_APPROVED 0x0002 -#define PEER_CONNECTION_FLAG_TRIED_VERIFIEDIP 0x0004 -#define PEER_CONNECTION_FLAG_TRIED_CLIENTIP 0x0008 -#define PEER_CONNECTION_FLAG_TRIED_INCOMING 0x0010 -#define PEER_CONNECTION_FLAG_TRIED_PROXY 0x0020 -#define PEER_CONNECTION_FLAG_IS_INCOMING 0x0040 +#define PEER_CONNECTION_FLAG_TRIED_DIRECT 0x0004 +#define PEER_CONNECTION_FLAG_TRIED_INCOMING 0x0008 +#define PEER_CONNECTION_FLAG_TRIED_PROXY 0x0010 +#define PEER_CONNECTION_FLAG_IS_INCOMING 0x0020 #define PEER_TYPE_PROMPT 0x0101 /* "I am going to send you this file, is that ok?" */ #define PEER_TYPE_RESUMESOMETHING 0x0106 /* I really don't know */ @@ -157,8 +156,9 @@ /** * This is only used when the peer connection is being established. */ - GaimProxyConnectData *connect_data; - + GaimProxyConnectData *client_connect_data; + GaimProxyConnectData *verified_connect_data; + /** * This is only used when the peer connection is being established. */ diff -r 6cc89a43bf8f -r cde909b9eb4b libgaim/protocols/oscar/peer_proxy.c --- a/libgaim/protocols/oscar/peer_proxy.c Tue Dec 05 06:23:43 2006 +0000 +++ b/libgaim/protocols/oscar/peer_proxy.c Wed Dec 06 00:39:27 2006 +0000 @@ -328,7 +328,7 @@ conn = data; - conn->connect_data = NULL; + conn->verified_connect_data = NULL; if (source < 0) {