Changeset 6757
- Timestamp:
- Sep 16, 2008, 4:46:18 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.3x/libtransmission/peer-mgr.c
r6565 r6757 74 74 75 75 /* unreachable for now... but not banned. if they try to connect to us it's okay */ 76 MYFLAG_UNREACHABLE = 2 76 MYFLAG_UNREACHABLE = 2, 77 78 /* the absolute minimum we'll wait before attempting to reconnect to a peer */ 79 MINIMUM_RECONNECT_INTERVAL_SECS = 5 77 80 }; 78 81 … … 94 97 uint16_t numFails; 95 98 struct in_addr addr; 96 time_t time; 99 time_t time; /* the last time the peer's connection status changed */ 97 100 time_t piece_data_time; 98 101 }; … … 917 920 918 921 static int 919 getMaxPeerCount( const tr_torrent * tor UNUSED)922 getMaxPeerCount( const tr_torrent * tor ) 920 923 { 921 924 return tor->maxConnectedPeers; 925 } 926 927 static int 928 getPeerCount( const Torrent * t ) 929 { 930 return tr_ptrArraySize( t->peers ) + tr_ptrArraySize( t->outgoingHandshakes ); 922 931 } 923 932 … … 976 985 ensureAtomExists( t, addr, port, 0, TR_PEER_FROM_INCOMING ); 977 986 atom = getExistingAtom( t, addr ); 987 atom->time = time( NULL ); 978 988 979 989 if( atom->myflags & MYFLAG_BANNED ) … … 982 992 tr_peerIoFree( io ); 983 993 } 984 else if( tr_ptrArraySize( t->peers ) >= getMaxPeerCount( t->tor ) ) 994 else if( tr_peerIoIsIncoming( io ) 995 && ( getPeerCount( t ) >= getMaxPeerCount( t->tor ) ) ) 996 985 997 { 986 998 tr_peerIoFree( io ); … … 1009 1021 peer->io = io; 1010 1022 peer->msgs = tr_peerMsgsNew( t->tor, peer, peerCallbackFunc, t, &peer->msgsTag ); 1011 atom->time = time( NULL );1012 1023 } 1013 1024 } … … 1760 1771 { 1761 1772 int sec; 1762 1763 switch( atom->numFails ) 1764 { 1773 const time_t now = time( NULL ); 1774 1775 /* if we were recently connected to this peer and transferring piece 1776 * data, try to reconnect to them sooner rather that later -- we don't 1777 * want network troubles to get in the way of a good peer. */ 1778 if( ( now - atom->piece_data_time ) <= ( MINIMUM_RECONNECT_INTERVAL_SECS * 2 ) ) 1779 sec = MINIMUM_RECONNECT_INTERVAL_SECS; 1780 1781 /* don't allow reconnects more often than our minimum */ 1782 else if( ( now - atom->time ) < MINIMUM_RECONNECT_INTERVAL_SECS ) 1783 sec = MINIMUM_RECONNECT_INTERVAL_SECS; 1784 1785 /* otherwise, the interval depends on how many times we've tried 1786 * and failed to connect to the peer */ 1787 else switch( atom->numFails ) { 1765 1788 case 0: sec = 0; break; 1766 1789 case 1: sec = 5; break; … … 1790 1813 for( i=retCount=0; i<atomCount; ++i ) 1791 1814 { 1815 int interval; 1792 1816 struct peer_atom * atom = atoms[i]; 1793 1817 … … 1811 1835 continue; 1812 1836 1813 /* If we were connected to this peer recently and transferring 1814 * piece data, try to reconnect -- network troubles may have 1815 * disconnected us. but if we weren't sharing piece data, 1816 * hold off on this peer to give another one a try instead */ 1817 if( ( now - atom->piece_data_time ) > 10 ) 1818 { 1819 const int wait = getReconnectIntervalSecs( atom ); 1820 if( ( now - atom->time ) < wait ) { 1821 tordbg( t, "RECONNECT peer %d (%s) is in its grace period of %d seconds..", 1822 i, tr_peerIoAddrStr(&atom->addr,atom->port), wait ); 1823 continue; 1824 } 1837 /* don't reconnect too often */ 1838 interval = getReconnectIntervalSecs( atom ); 1839 if( ( now - atom->time ) < interval ) { 1840 tordbg( t, "RECONNECT peer %d (%s) is in its grace period of %d seconds..", 1841 i, tr_peerIoAddrStr(&atom->addr,atom->port), interval ); 1842 continue; 1825 1843 } 1826 1844 … … 1886 1904 1887 1905 /* add some new ones */ 1888 for( i=0; i < nCandidates 1889 && i < MAX_RECONNECTIONS_PER_PULSE 1890 && newConnectionsThisSecond < MAX_CONNECTIONS_PER_SECOND; ++i ) 1906 for( i=0; ( i < nCandidates ) 1907 && ( i < MAX_RECONNECTIONS_PER_PULSE ) 1908 && ( getPeerCount( t ) < getMaxPeerCount( t->tor ) ) 1909 && ( newConnectionsThisSecond < MAX_CONNECTIONS_PER_SECOND ); ++i ) 1891 1910 { 1892 1911 tr_peerMgr * mgr = t->manager;
Note: See TracChangeset
for help on using the changeset viewer.