diff --git a/libtransmission/Makefile.am b/libtransmission/Makefile.am index 73cd7dab9..3f8218cfb 100644 --- a/libtransmission/Makefile.am +++ b/libtransmission/Makefile.am @@ -26,8 +26,6 @@ libtransmission_a_SOURCES = \ publish.c \ ratecontrol.c \ shared.c \ - strlcat.c \ - strlcpy.c \ torrent.c \ tracker.c \ transmission.c \ diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index cd4e56d68..e49c369b7 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -913,6 +913,12 @@ myHandshakeDoneCB( tr_handshake * handshake, if( !ok || !t || !t->isRunning ) { + if( t ) { + struct peer_atom * atom = getExistingAtom( t, addr ); + if( atom ) + ++atom->numFails; + } + tr_peerIoFree( io ); } else /* looking good */ @@ -1583,12 +1589,18 @@ getPeersToClose( Torrent * t, int * setmeSize ) } static int -compareAtomByTime( const void * va, const void * vb ) +compareCandidates( const void * va, const void * vb ) { const struct peer_atom * a = * (const struct peer_atom**) va; const struct peer_atom * b = * (const struct peer_atom**) vb; - if( a->time < b->time ) return -1; - if( a->time > b->time ) return 1; + int i; + + if(( i = tr_compareUint16( a->numFails, b->numFails ))) + return i; + + if( a->time != b->time ) + return a->time < b->time ? -1 : 1; + return 0; } @@ -1632,10 +1644,17 @@ getPeerCandidates( Torrent * t, int * setmeSize ) continue; } + /* we're wasting our time trying to connect to this bozo. */ + if( atom->numFails > 10 ) { + tordbg( t, "RECONNECT peer %d (%s) gives us nothing but failure.", + i, tr_peerIoAddrStr(&atom->addr,atom->port) ); + continue; + } + /* if we used this peer recently, give someone else a turn */ - minWait = 60; /* one minute */ - maxWait = (60 * 10); /* ten minutes */ - wait = atom->numFails * 15; /* add 15 secs to the wait interval for each consecutive failure*/ + minWait = 10; /* ten seconds */ + maxWait = (60 * 20); /* twenty minutes */ + wait = atom->numFails * 30; /* add 15 secs to the wait interval for each consecutive failure*/ if( wait < minWait ) wait = minWait; if( wait > maxWait ) wait = maxWait; if( ( now - atom->time ) < wait ) { @@ -1647,7 +1666,7 @@ getPeerCandidates( Torrent * t, int * setmeSize ) ret[retCount++] = atom; } - qsort( ret, retCount, sizeof(struct peer_atom*), compareAtomByTime ); + qsort( ret, retCount, sizeof(struct peer_atom*), compareCandidates ); *setmeSize = retCount; return ret; } diff --git a/libtransmission/strlcat.c b/libtransmission/strlcat.c deleted file mode 100644 index 2af00a180..000000000 --- a/libtransmission/strlcat.c +++ /dev/null @@ -1,60 +0,0 @@ -/* $Id$ */ -/* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */ - -/* - * Copyright (c) 1998 Todd C. Miller - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include - -#ifndef HAVE_STRLCAT - -/* - * Appends src to string dst of size siz (unlike strncat, siz is the - * full size of dst, not space left). At most siz-1 characters - * will be copied. Always NUL terminates (unless siz <= strlen(dst)). - * Returns strlen(src) + MIN(siz, strlen(initial dst)). - * If retval >= siz, truncation occurred. - */ -size_t -strlcat(char *dst, const char *src, size_t siz) -{ - char *d = dst; - const char *s = src; - size_t n = siz; - size_t dlen; - - /* Find the end of dst and adjust bytes left but don't go past end */ - while (n-- != 0 && *d != '\0') - d++; - dlen = d - dst; - n = siz - dlen; - - if (n == 0) - return(dlen + strlen(s)); - while (*s != '\0') { - if (n != 1) { - *d++ = *s; - n--; - } - s++; - } - *d = '\0'; - - return(dlen + (s - src)); /* count does not include NUL */ -} - -#endif /* HAVE_STRLCAT */ diff --git a/libtransmission/strlcpy.c b/libtransmission/strlcpy.c deleted file mode 100644 index f4b6aee74..000000000 --- a/libtransmission/strlcpy.c +++ /dev/null @@ -1,56 +0,0 @@ -/* $Id$ */ -/* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */ - -/* - * Copyright (c) 1998 Todd C. Miller - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include - -#ifndef HAVE_STRLCPY - -/* - * Copy src to string dst of size siz. At most siz-1 characters - * will be copied. Always NUL terminates (unless siz == 0). - * Returns strlen(src); if retval >= siz, truncation occurred. - */ -size_t -strlcpy(char *dst, const char *src, size_t siz) -{ - char *d = dst; - const char *s = src; - size_t n = siz; - - /* Copy as many bytes as will fit */ - if (n != 0) { - while (--n != 0) { - if ((*d++ = *s++) == '\0') - break; - } - } - - /* Not enough room in dst, add NUL and traverse rest of src */ - if (n == 0) { - if (siz != 0) - *d = '\0'; /* NUL-terminate dst */ - while (*s++) - ; - } - - return(s - src - 1); /* count does not include NUL */ -} - -#endif /* HAVE_STRLCPY */ diff --git a/libtransmission/utils.c b/libtransmission/utils.c index 2d6e4d8e3..fb89d5ff6 100644 --- a/libtransmission/utils.c +++ b/libtransmission/utils.c @@ -760,3 +760,83 @@ tr_wait( uint64_t delay_milliseconds ) usleep( 1000 * delay_milliseconds ); #endif } + +/*** +**** +***/ + + +#ifndef HAVE_STRLCPY + +/* + * Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(src); if retval >= siz, truncation occurred. + */ +size_t +strlcpy(char *dst, const char *src, size_t siz) +{ + char *d = dst; + const char *s = src; + size_t n = siz; + + /* Copy as many bytes as will fit */ + if (n != 0) { + while (--n != 0) { + if ((*d++ = *s++) == '\0') + break; + } + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ +} + +#endif /* HAVE_STRLCPY */ + + +#ifndef HAVE_STRLCAT + +/* + * Appends src to string dst of size siz (unlike strncat, siz is the + * full size of dst, not space left). At most siz-1 characters + * will be copied. Always NUL terminates (unless siz <= strlen(dst)). + * Returns strlen(src) + MIN(siz, strlen(initial dst)). + * If retval >= siz, truncation occurred. + */ +size_t +strlcat(char *dst, const char *src, size_t siz) +{ + char *d = dst; + const char *s = src; + size_t n = siz; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end */ + while (n-- != 0 && *d != '\0') + d++; + dlen = d - dst; + n = siz - dlen; + + if (n == 0) + return(dlen + strlen(s)); + while (*s != '\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; + } + *d = '\0'; + + return(dlen + (s - src)); /* count does not include NUL */ +} + +#endif /* HAVE_STRLCAT */