Mercurial > pidgin.yaz
comparison src/protocols/oscar/peer.c @ 14104:b0566d50291f
[gaim-migrate @ 16735]
Oscar peer connections now use the proxy_connect_cancel() function,
so they don't need to use GAIM_CONNECTION_IS_VALID() anymore.
Also, peer connection attempts will time out after 15 seconds. Yay.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 13 Aug 2006 08:41:07 +0000 |
parents | 10e8eb6a4910 |
children | 7a205b430d19 |
comparison
equal
deleted
inserted
replaced
14103:eec0c7fd8529 | 14104:b0566d50291f |
---|---|
137 if (conn->type == OSCAR_CAPABILITY_DIRECTIM) | 137 if (conn->type == OSCAR_CAPABILITY_DIRECTIM) |
138 peer_odc_close(conn); | 138 peer_odc_close(conn); |
139 else if (conn->type == OSCAR_CAPABILITY_SENDFILE) | 139 else if (conn->type == OSCAR_CAPABILITY_SENDFILE) |
140 peer_oft_close(conn); | 140 peer_oft_close(conn); |
141 | 141 |
142 if (conn->connect_info != NULL) | |
143 { | |
144 gaim_proxy_connect_cancel(conn->connect_info); | |
145 conn->connect_info = NULL; | |
146 } | |
147 | |
148 if (conn->connect_timeout_timer != 0) | |
149 { | |
150 gaim_timeout_remove(conn->connect_timeout_timer); | |
151 conn->connect_timeout_timer = 0; | |
152 } | |
153 | |
142 if (conn->watcher_incoming != 0) | 154 if (conn->watcher_incoming != 0) |
143 { | 155 { |
144 gaim_input_remove(conn->watcher_incoming); | 156 gaim_input_remove(conn->watcher_incoming); |
145 conn->watcher_incoming = 0; | 157 conn->watcher_incoming = 0; |
146 } | 158 } |
470 * either connected or failed to connect. | 482 * either connected or failed to connect. |
471 */ | 483 */ |
472 static void | 484 static void |
473 peer_connection_established_cb(gpointer data, gint source) | 485 peer_connection_established_cb(gpointer data, gint source) |
474 { | 486 { |
475 NewPeerConnectionData *new_conn_data; | 487 PeerConnection *conn; |
476 GaimConnection *gc; | 488 |
477 PeerConnection *conn; | 489 conn = data; |
478 | 490 |
479 new_conn_data = data; | 491 conn->connect_info = NULL; |
480 gc = new_conn_data->gc; | 492 gaim_timeout_remove(conn->connect_timeout_timer); |
481 conn = new_conn_data->conn; | 493 conn->connect_timeout_timer = 0; |
482 g_free(new_conn_data); | |
483 | |
484 if (!GAIM_CONNECTION_IS_VALID(gc)) | |
485 { | |
486 if (source >= 0) | |
487 close(source); | |
488 return; | |
489 } | |
490 | 494 |
491 if (source < 0) | 495 if (source < 0) |
492 { | 496 { |
493 peer_connection_trynext(conn); | 497 peer_connection_trynext(conn); |
494 return; | 498 return; |
625 conn->xferdata.size, conn->xferdata.totfiles); | 629 conn->xferdata.size, conn->xferdata.totfiles); |
626 } | 630 } |
627 } | 631 } |
628 | 632 |
629 /** | 633 /** |
634 * This is a callback function used when we're connecting to a peer | |
635 * using either the client IP or the verified IP and the connection | |
636 * took longer than 15 seconds to complete. We do this because | |
637 * waiting for the OS to time out the connection attempt is not | |
638 * practical--the default timeout on many OSes can be 3 minutes or | |
639 * more, and users are impatient. | |
640 * | |
641 * Worst case scenario: the user is connected to the Internet using | |
642 * a modem with severe lag. The peer connections fail and Gaim falls | |
643 * back to using a proxied connection. The lower bandwidth | |
644 * limitations imposed by the proxied connection won't matter because | |
645 * the user is using a modem. | |
646 * | |
647 * I suppose this line of thinking is discriminatory against people | |
648 * with very high lag but decent throughput who are transferring | |
649 * large files. But we don't care about those people. | |
650 */ | |
651 static gboolean | |
652 peer_connection_tooktoolong(gpointer data) | |
653 { | |
654 PeerConnection *conn; | |
655 | |
656 conn = data; | |
657 | |
658 gaim_debug_info("oscar", "Peer connection timed out after 15 seconds. " | |
659 "Trying next method...\n"); | |
660 | |
661 gaim_proxy_connect_cancel(conn->connect_info); | |
662 conn->connect_info = NULL; | |
663 conn->connect_timeout_timer = 0; | |
664 | |
665 peer_connection_trynext(conn); | |
666 | |
667 /* Cancel this timer. It'll be added again, if needed. */ | |
668 return FALSE; | |
669 } | |
670 | |
671 /** | |
630 * Try to establish the given PeerConnection using a defined | 672 * Try to establish the given PeerConnection using a defined |
631 * sequence of steps. | 673 * sequence of steps. |
632 */ | 674 */ |
633 void | 675 void |
634 peer_connection_trynext(PeerConnection *conn) | 676 peer_connection_trynext(PeerConnection *conn) |
635 { | 677 { |
636 NewPeerConnectionData *new_conn_data; | |
637 GaimAccount *account; | 678 GaimAccount *account; |
638 | 679 |
639 new_conn_data = g_new(NewPeerConnectionData, 1); | 680 account = gaim_connection_get_account(conn->od->gc); |
640 new_conn_data->gc = conn->od->gc; | |
641 new_conn_data->conn = conn; | |
642 | |
643 account = gaim_connection_get_account(new_conn_data->gc); | |
644 | 681 |
645 /* | 682 /* |
646 * Close any remnants of a previous failed connection attempt. | 683 * Close any remnants of a previous failed connection attempt. |
647 */ | 684 */ |
648 peer_connection_close(conn); | 685 peer_connection_close(conn); |
665 gaim_conversation_write(conv, NULL, tmp, | 702 gaim_conversation_write(conv, NULL, tmp, |
666 GAIM_MESSAGE_SYSTEM, time(NULL)); | 703 GAIM_MESSAGE_SYSTEM, time(NULL)); |
667 g_free(tmp); | 704 g_free(tmp); |
668 } | 705 } |
669 | 706 |
670 if (gaim_proxy_connect(account, conn->verifiedip, conn->port, | 707 conn->connect_info = gaim_proxy_connect(account, |
671 peer_connection_established_cb, NULL, new_conn_data) != NULL) | 708 conn->verifiedip, conn->port, |
709 peer_connection_established_cb, NULL, conn); | |
710 if (conn->connect_info != NULL) | |
672 { | 711 { |
673 /* Connecting... */ | 712 /* Connecting... */ |
713 conn->connect_timeout_timer = gaim_timeout_add(15000, | |
714 peer_connection_tooktoolong, conn); | |
674 return; | 715 return; |
675 } | 716 } |
676 } | 717 } |
677 | 718 |
678 /* | 719 /* |
696 gaim_conversation_write(conv, NULL, tmp, | 737 gaim_conversation_write(conv, NULL, tmp, |
697 GAIM_MESSAGE_SYSTEM, time(NULL)); | 738 GAIM_MESSAGE_SYSTEM, time(NULL)); |
698 g_free(tmp); | 739 g_free(tmp); |
699 } | 740 } |
700 | 741 |
701 if (gaim_proxy_connect(account, conn->clientip, conn->port, | 742 conn->connect_info = gaim_proxy_connect(account, |
702 peer_connection_established_cb, NULL, new_conn_data) != NULL) | 743 conn->clientip, conn->port, |
744 peer_connection_established_cb, NULL, conn); | |
745 if (conn->connect_info != NULL) | |
703 { | 746 { |
704 /* Connecting... */ | 747 /* Connecting... */ |
748 conn->connect_timeout_timer = gaim_timeout_add(15000, | |
749 peer_connection_tooktoolong, conn); | |
705 return; | 750 return; |
706 } | 751 } |
707 } | 752 } |
708 } | 753 } |
709 | 754 |
712 * our verifiedip and our clientip). | 757 * our verifiedip and our clientip). |
713 */ | 758 */ |
714 if (!(conn->flags & PEER_CONNECTION_FLAG_TRIED_INCOMING) && | 759 if (!(conn->flags & PEER_CONNECTION_FLAG_TRIED_INCOMING) && |
715 (!conn->use_proxy)) | 760 (!conn->use_proxy)) |
716 { | 761 { |
762 NewPeerConnectionData *new_conn_data; | |
763 | |
764 new_conn_data = g_new(NewPeerConnectionData, 1); | |
765 new_conn_data->gc = conn->od->gc; | |
766 new_conn_data->conn = conn; | |
767 | |
717 conn->flags |= PEER_CONNECTION_FLAG_TRIED_INCOMING; | 768 conn->flags |= PEER_CONNECTION_FLAG_TRIED_INCOMING; |
718 | 769 |
719 /* | 770 /* |
720 * Remote user is connecting to us, so we'll need to verify | 771 * Remote user is connecting to us, so we'll need to verify |
721 * that the user who connected is our friend. | 772 * that the user who connected is our friend. |
726 peer_connection_establish_listener_cb, new_conn_data)) | 777 peer_connection_establish_listener_cb, new_conn_data)) |
727 { | 778 { |
728 /* Opening listener socket... */ | 779 /* Opening listener socket... */ |
729 return; | 780 return; |
730 } | 781 } |
782 | |
783 g_free(new_conn_data); | |
731 } | 784 } |
732 | 785 |
733 /* | 786 /* |
734 * 4. Attempt to have both users connect to an intermediate proxy | 787 * 4. Attempt to have both users connect to an intermediate proxy |
735 * server. | 788 * server. |
755 gaim_conversation_write(conv, NULL, tmp, | 808 gaim_conversation_write(conv, NULL, tmp, |
756 GAIM_MESSAGE_SYSTEM, time(NULL)); | 809 GAIM_MESSAGE_SYSTEM, time(NULL)); |
757 g_free(tmp); | 810 g_free(tmp); |
758 } | 811 } |
759 | 812 |
760 if (gaim_proxy_connect(account, | 813 conn->connect_info = gaim_proxy_connect(account, |
761 (conn->proxyip != NULL) ? conn->proxyip : PEER_PROXY_SERVER, | 814 (conn->proxyip != NULL) ? conn->proxyip : PEER_PROXY_SERVER, |
762 PEER_PROXY_PORT, | 815 PEER_PROXY_PORT, |
763 peer_proxy_connection_established_cb, NULL, new_conn_data) != NULL) | 816 peer_proxy_connection_established_cb, NULL, conn); |
817 if (conn->connect_info != NULL) | |
764 { | 818 { |
765 /* Connecting... */ | 819 /* Connecting... */ |
766 return; | 820 return; |
767 } | 821 } |
768 } | 822 } |
769 | |
770 g_free(new_conn_data); | |
771 | 823 |
772 /* Give up! */ | 824 /* Give up! */ |
773 peer_connection_destroy(conn, OSCAR_DISCONNECT_COULD_NOT_CONNECT); | 825 peer_connection_destroy(conn, OSCAR_DISCONNECT_COULD_NOT_CONNECT); |
774 } | 826 } |
775 | 827 |