(libT) #252: revert r7195 (jhujhiti's IPv6 test patch). It seems to be the culprit in a `thrashing' issue reported by Waldorf and m1b in irc -- the behavior appeared between r7183 and r7187 -- so this commit is to trigger off a nightly build w/o the patch to test with in irc.
This commit is contained in:
parent
a588eaddc8
commit
7fa9813955
|
@ -51,7 +51,7 @@ main( void )
|
|||
char * tmpfile_txt = "transmission-blocklist-test.txt";
|
||||
char * tmpfile_bin = "transmission-blocklist-test.bin";
|
||||
#endif
|
||||
struct tr_address addr;
|
||||
struct in_addr addr;
|
||||
int test = 0;
|
||||
tr_blocklist * b;
|
||||
|
||||
|
@ -63,31 +63,31 @@ main( void )
|
|||
_tr_blocklistSetContent( b, tmpfile_txt );
|
||||
|
||||
/* now run some tests */
|
||||
check( tr_pton( "216.16.1.143", &addr ) );
|
||||
check( !tr_netResolve( "216.16.1.143", &addr ) );
|
||||
check( !_tr_blocklistHasAddress( b, &addr ) );
|
||||
check( tr_pton( "216.16.1.144", &addr ) );
|
||||
check( !tr_netResolve( "216.16.1.144", &addr ) );
|
||||
check( _tr_blocklistHasAddress( b, &addr ) );
|
||||
check( tr_pton( "216.16.1.145", &addr ) );
|
||||
check( !tr_netResolve( "216.16.1.145", &addr ) );
|
||||
check( _tr_blocklistHasAddress( b, &addr ) );
|
||||
check( tr_pton( "216.16.1.146", &addr ) );
|
||||
check( !tr_netResolve( "216.16.1.146", &addr ) );
|
||||
check( _tr_blocklistHasAddress( b, &addr ) );
|
||||
check( tr_pton( "216.16.1.147", &addr ) );
|
||||
check( !tr_netResolve( "216.16.1.147", &addr ) );
|
||||
check( _tr_blocklistHasAddress( b, &addr ) );
|
||||
check( tr_pton( "216.16.1.148", &addr ) );
|
||||
check( !tr_netResolve( "216.16.1.148", &addr ) );
|
||||
check( _tr_blocklistHasAddress( b, &addr ) );
|
||||
check( tr_pton( "216.16.1.149", &addr ) );
|
||||
check( !tr_netResolve( "216.16.1.149", &addr ) );
|
||||
check( _tr_blocklistHasAddress( b, &addr ) );
|
||||
check( tr_pton( "216.16.1.150", &addr ) );
|
||||
check( !tr_netResolve( "216.16.1.150", &addr ) );
|
||||
check( _tr_blocklistHasAddress( b, &addr ) );
|
||||
check( tr_pton( "216.16.1.151", &addr ) );
|
||||
check( !tr_netResolve( "216.16.1.151", &addr ) );
|
||||
check( _tr_blocklistHasAddress( b, &addr ) );
|
||||
check( tr_pton( "216.16.1.152", &addr ) );
|
||||
check( !tr_netResolve( "216.16.1.152", &addr ) );
|
||||
check( !_tr_blocklistHasAddress( b, &addr ) );
|
||||
check( tr_pton( "216.16.1.153", &addr ) );
|
||||
check( !tr_netResolve( "216.16.1.153", &addr ) );
|
||||
check( !_tr_blocklistHasAddress( b, &addr ) );
|
||||
check( tr_pton( "217.0.0.1", &addr ) );
|
||||
check( !tr_netResolve( "217.0.0.1", &addr ) );
|
||||
check( !_tr_blocklistHasAddress( b, &addr ) );
|
||||
check( tr_pton( "255.0.0.1", &addr ) );
|
||||
check( !tr_netResolve( "255.0.0.1", &addr ) );
|
||||
|
||||
/* cleanup */
|
||||
_tr_blocklistFree( b );
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#include "transmission.h"
|
||||
#include "platform.h"
|
||||
#include "blocklist.h"
|
||||
#include "net.h"
|
||||
#include "net.h" /* tr_netResolve() */
|
||||
#include "utils.h"
|
||||
|
||||
/***
|
||||
|
@ -198,8 +198,8 @@ _tr_blocklistSetEnabled( tr_blocklist * b,
|
|||
}
|
||||
|
||||
int
|
||||
_tr_blocklistHasAddress( tr_blocklist * b,
|
||||
const tr_address * addr )
|
||||
_tr_blocklistHasAddress( tr_blocklist * b,
|
||||
const struct in_addr * addr )
|
||||
{
|
||||
uint32_t needle;
|
||||
const struct tr_ip_range * range;
|
||||
|
@ -211,7 +211,7 @@ _tr_blocklistHasAddress( tr_blocklist * b,
|
|||
if( !b->rules )
|
||||
return 0;
|
||||
|
||||
needle = ntohl( addr->addr.addr4.s_addr );
|
||||
needle = ntohl( addr->s_addr );
|
||||
|
||||
range = bsearch( &needle,
|
||||
b->rules,
|
||||
|
@ -259,7 +259,7 @@ _tr_blocklistSetContent( tr_blocklist * b,
|
|||
{
|
||||
char * rangeBegin;
|
||||
char * rangeEnd;
|
||||
tr_address addr;
|
||||
struct in_addr in_addr;
|
||||
struct tr_ip_range range;
|
||||
|
||||
rangeBegin = strrchr( line, ':' );
|
||||
|
@ -270,13 +270,13 @@ _tr_blocklistSetContent( tr_blocklist * b,
|
|||
if( !rangeEnd ){ free( line ); continue; }
|
||||
*rangeEnd++ = '\0';
|
||||
|
||||
if( !tr_pton( rangeBegin, &addr ) )
|
||||
if( tr_netResolve( rangeBegin, &in_addr ) )
|
||||
tr_err( "blocklist skipped invalid address [%s]\n", rangeBegin );
|
||||
range.begin = ntohl( addr.addr.addr4.s_addr );
|
||||
range.begin = ntohl( in_addr.s_addr );
|
||||
|
||||
if( !tr_pton( rangeEnd, &addr ) )
|
||||
if( tr_netResolve( rangeEnd, &in_addr ) )
|
||||
tr_err( "blocklist skipped invalid address [%s]\n", rangeEnd );
|
||||
range.end = ntohl( addr.addr.addr4.s_addr );
|
||||
range.end = ntohl( in_addr.s_addr );
|
||||
|
||||
free( line );
|
||||
|
||||
|
|
|
@ -17,8 +17,7 @@
|
|||
#ifndef TR_BLOCKLIST_H
|
||||
#define TR_BLOCKLIST_H
|
||||
|
||||
struct tr_address;
|
||||
|
||||
struct in_addr;
|
||||
typedef struct tr_blocklist tr_blocklist;
|
||||
|
||||
tr_blocklist* _tr_blocklistNew( const char * filename,
|
||||
|
@ -34,13 +33,16 @@ void _tr_blocklistFree( tr_blocklist * );
|
|||
|
||||
int _tr_blocklistIsEnabled( tr_blocklist * );
|
||||
|
||||
void _tr_blocklistSetEnabled( tr_blocklist * ,
|
||||
int isEnabled );
|
||||
void _tr_blocklistSetEnabled( tr_blocklist *,
|
||||
int isEnabled );
|
||||
|
||||
int _tr_blocklistHasAddress( tr_blocklist *,
|
||||
const tr_address * addr );
|
||||
int _tr_blocklistHasAddress(
|
||||
tr_blocklist *,
|
||||
const struct
|
||||
in_addr * addr );
|
||||
|
||||
int _tr_blocklistSetContent( tr_blocklist *,
|
||||
const char * filename );
|
||||
int _tr_blocklistSetContent(
|
||||
tr_blocklist *,
|
||||
const char * filename );
|
||||
|
||||
#endif
|
||||
|
|
|
@ -471,13 +471,13 @@ tr_fdSocketCreate( int type )
|
|||
}
|
||||
|
||||
int
|
||||
tr_fdSocketAccept( int b,
|
||||
tr_address * addr,
|
||||
tr_port_t * port )
|
||||
tr_fdSocketAccept( int b,
|
||||
struct in_addr * addr,
|
||||
tr_port_t * port )
|
||||
{
|
||||
int s = -1;
|
||||
unsigned int len;
|
||||
struct sockaddr_storage sock;
|
||||
int s = -1;
|
||||
unsigned int len;
|
||||
struct sockaddr_in sock;
|
||||
|
||||
assert( addr );
|
||||
assert( port );
|
||||
|
@ -485,28 +485,13 @@ tr_fdSocketAccept( int b,
|
|||
tr_lockLock( gFd->lock );
|
||||
if( gFd->socketCount < getSocketMax( gFd ) )
|
||||
{
|
||||
len = sizeof( struct sockaddr );
|
||||
len = sizeof( sock );
|
||||
s = accept( b, (struct sockaddr *) &sock, &len );
|
||||
}
|
||||
if( s > -1 )
|
||||
{
|
||||
/* "The ss_family field of the sockaddr_storage structure will always
|
||||
* align with the family field of any protocol-specific structure." */
|
||||
if( sock.ss_family == AF_INET )
|
||||
{
|
||||
struct sockaddr_in * sock4 = (struct sockaddr_in *)&sock;
|
||||
addr->type = TR_AF_INET;
|
||||
addr->addr.addr4.s_addr = sock4->sin_addr.s_addr;
|
||||
*port = sock4->sin_port;
|
||||
}
|
||||
else
|
||||
{
|
||||
struct sockaddr_in6 * sock6 = (struct sockaddr_in6 *)&sock;
|
||||
addr->type = TR_AF_INET6;
|
||||
memcpy( &addr->addr, &sock6->sin6_addr,
|
||||
sizeof( struct sockaddr_in6 ) );
|
||||
*port = sock6->sin6_port;
|
||||
}
|
||||
*addr = sock.sin_addr;
|
||||
*port = sock.sin_port;
|
||||
++gFd->socketCount;
|
||||
}
|
||||
tr_lockUnlock( gFd->lock );
|
||||
|
|
|
@ -87,9 +87,9 @@ void tr_fdFileClose( const char * filename );
|
|||
**********************************************************************/
|
||||
int tr_fdSocketCreate( int type );
|
||||
|
||||
int tr_fdSocketAccept( int b,
|
||||
tr_address * addr,
|
||||
tr_port_t * port );
|
||||
int tr_fdSocketAccept( int b,
|
||||
struct in_addr * addr,
|
||||
tr_port_t * port );
|
||||
|
||||
void tr_fdSocketClose( int s );
|
||||
|
||||
|
|
|
@ -1196,9 +1196,9 @@ tr_handshakeGetIO( tr_handshake * handshake )
|
|||
return handshake->io;
|
||||
}
|
||||
|
||||
const tr_address *
|
||||
const struct in_addr *
|
||||
tr_handshakeGetAddr( const struct tr_handshake * handshake,
|
||||
uint16_t * port )
|
||||
uint16_t * port )
|
||||
{
|
||||
assert( handshake );
|
||||
assert( handshake->io );
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "transmission.h"
|
||||
|
||||
struct in_addr;
|
||||
struct tr_peerIo;
|
||||
typedef struct tr_handshake tr_handshake;
|
||||
|
||||
|
@ -34,8 +35,10 @@ tr_handshake * tr_handshakeNew( struct tr_peerIo * io,
|
|||
handshakeDoneCB doneCB,
|
||||
void * doneUserData );
|
||||
|
||||
const tr_address * tr_handshakeGetAddr( const struct tr_handshake * handshake,
|
||||
uint16_t * setme_port );
|
||||
const struct in_addr * tr_handshakeGetAddr(
|
||||
const struct tr_handshake * handshake,
|
||||
uint16_t
|
||||
* setme_port );
|
||||
|
||||
void tr_handshakeAbort( tr_handshake * handshake );
|
||||
|
||||
|
|
|
@ -47,9 +47,6 @@
|
|||
#include "platform.h"
|
||||
#include "utils.h"
|
||||
|
||||
const tr_address tr_in6addr_any = { TR_AF_INET6, { IN6ADDR_ANY_INIT } };
|
||||
const tr_address tr_inaddr_any = { TR_AF_INET,
|
||||
{ { { { INADDR_ANY, 0x00, 0x00, 0x00 } } } } };
|
||||
|
||||
void
|
||||
tr_netInit( void )
|
||||
|
@ -66,79 +63,19 @@ tr_netInit( void )
|
|||
}
|
||||
}
|
||||
|
||||
const char *
|
||||
tr_ntop( const tr_address * src,
|
||||
char * dst,
|
||||
int size )
|
||||
{
|
||||
if( src->type == TR_AF_INET )
|
||||
return inet_ntop( AF_INET, &src->addr, dst, size );
|
||||
else
|
||||
return inet_ntop( AF_INET6, &src->addr, dst, size );
|
||||
}
|
||||
|
||||
/*
|
||||
* Non-threadsafe version of tr_ntop, which uses a static memory area for a buffer.
|
||||
* This function is suitable to be called from libTransmission's networking code,
|
||||
* which is single-threaded.
|
||||
*/
|
||||
const char *
|
||||
tr_ntop_non_ts( const tr_address * src )
|
||||
{
|
||||
static char buf[INET6_ADDRSTRLEN];
|
||||
return tr_ntop( src, buf, sizeof( buf ) );
|
||||
}
|
||||
|
||||
tr_address *
|
||||
tr_pton( const char * src,
|
||||
tr_address * dst )
|
||||
{
|
||||
int retval = inet_pton( AF_INET, src, &dst->addr );
|
||||
if( retval < 0 )
|
||||
return NULL;
|
||||
else if( retval == 0 )
|
||||
retval = inet_pton( AF_INET6, src, &dst->addr );
|
||||
else
|
||||
{
|
||||
dst->type = TR_AF_INET;
|
||||
return dst;
|
||||
}
|
||||
|
||||
if( retval < 1 )
|
||||
return NULL;
|
||||
dst->type = TR_AF_INET6;
|
||||
return dst;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare two tr_address structures.
|
||||
* Returns:
|
||||
* <0 if a < b
|
||||
* >0 if a > b
|
||||
* 0 if a == b
|
||||
*/
|
||||
/***********************************************************************
|
||||
* DNS resolution
|
||||
*
|
||||
* Synchronous "resolution": only works with character strings
|
||||
* representing numbers expressed in the Internet standard `.' notation.
|
||||
* Returns a non-zero value if an error occurs.
|
||||
**********************************************************************/
|
||||
int
|
||||
tr_compareAddresses( const tr_address * a,
|
||||
const tr_address * b)
|
||||
tr_netResolve( const char * address,
|
||||
struct in_addr * addr )
|
||||
{
|
||||
int retval;
|
||||
int addrlen;
|
||||
/* IPv6 addresses are always "greater than" IPv4 */
|
||||
if( a->type == TR_AF_INET && b->type == TR_AF_INET6 )
|
||||
return 1;
|
||||
if( a->type == TR_AF_INET6 && b->type == TR_AF_INET )
|
||||
return -1;
|
||||
|
||||
if( a->type == TR_AF_INET )
|
||||
addrlen = sizeof( struct in_addr );
|
||||
else
|
||||
addrlen = sizeof( struct in6_addr );
|
||||
|
||||
retval = memcmp( &a->addr, &b->addr, addrlen );
|
||||
if( retval == 0 )
|
||||
return 0;
|
||||
|
||||
return retval;
|
||||
addr->s_addr = inet_addr( address );
|
||||
return addr->s_addr == 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
|
@ -199,49 +136,27 @@ setSndBuf( tr_session * session UNUSED, int fd UNUSED )
|
|||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
setup_sockaddr( const tr_address * addr,
|
||||
tr_port_t port,
|
||||
struct sockaddr_storage * sockaddr)
|
||||
{
|
||||
struct sockaddr_in sock4;
|
||||
struct sockaddr_in6 sock6;
|
||||
if( addr->type == TR_AF_INET )
|
||||
{
|
||||
memset( &sock4, 0, sizeof( sock4 ) );
|
||||
sock4.sin_family = AF_INET;
|
||||
sock4.sin_addr.s_addr = addr->addr.addr4.s_addr;
|
||||
sock4.sin_port = port;
|
||||
memcpy( sockaddr, &sock4, sizeof( sock4 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
memset( &sock6, 0, sizeof( sock6 ) );
|
||||
sock6.sin6_family = AF_INET6;
|
||||
sock6.sin6_port = port;
|
||||
memcpy( &sock6.sin6_addr, &addr->addr, sizeof( struct in6_addr ) );
|
||||
memcpy( sockaddr, &sock6, sizeof( sock6 ) );
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
tr_netOpenTCP( tr_session * session,
|
||||
const tr_address * addr,
|
||||
tr_port_t port )
|
||||
tr_netOpenTCP( tr_session * session,
|
||||
const struct in_addr * addr,
|
||||
tr_port_t port )
|
||||
{
|
||||
int s;
|
||||
struct sockaddr_storage sock;
|
||||
const int type = SOCK_STREAM;
|
||||
int s;
|
||||
struct sockaddr_in sock;
|
||||
const int type = SOCK_STREAM;
|
||||
|
||||
if( ( s = createSocket( type ) ) < 0 )
|
||||
return -1;
|
||||
|
||||
setSndBuf( session, s );
|
||||
|
||||
setup_sockaddr( addr, port, &sock );
|
||||
memset( &sock, 0, sizeof( sock ) );
|
||||
sock.sin_family = AF_INET;
|
||||
sock.sin_addr.s_addr = addr->s_addr;
|
||||
sock.sin_port = port;
|
||||
|
||||
if( ( connect( s, (struct sockaddr *) &sock,
|
||||
sizeof( struct sockaddr ) ) < 0 )
|
||||
sizeof( struct sockaddr_in ) ) < 0 )
|
||||
#ifdef WIN32
|
||||
&& ( sockerrno != WSAEWOULDBLOCK )
|
||||
#endif
|
||||
|
@ -249,7 +164,7 @@ tr_netOpenTCP( tr_session * session,
|
|||
{
|
||||
tr_err( _(
|
||||
"Couldn't connect socket %d to %s, port %d (errno %d - %s)" ),
|
||||
s, tr_ntop_non_ts( addr ), port,
|
||||
s, inet_ntoa( *addr ), port,
|
||||
sockerrno, tr_strerror( sockerrno ) );
|
||||
tr_netClose( s );
|
||||
s = -1;
|
||||
|
@ -262,12 +177,11 @@ tr_netOpenTCP( tr_session * session,
|
|||
}
|
||||
|
||||
int
|
||||
tr_netBindTCP( const tr_address * addr,
|
||||
int port )
|
||||
tr_netBindTCP( int port )
|
||||
{
|
||||
int s;
|
||||
struct sockaddr_storage sock;
|
||||
const int type = SOCK_STREAM;
|
||||
int s;
|
||||
struct sockaddr_in sock;
|
||||
const int type = SOCK_STREAM;
|
||||
|
||||
#if defined( SO_REUSEADDR ) || defined( SO_REUSEPORT )
|
||||
int optval;
|
||||
|
@ -280,28 +194,30 @@ tr_netBindTCP( const tr_address * addr,
|
|||
optval = 1;
|
||||
setsockopt( s, SOL_SOCKET, SO_REUSEADDR, (char*)&optval, sizeof( optval ) );
|
||||
#endif
|
||||
|
||||
setup_sockaddr( addr, htons( port ), &sock );
|
||||
|
||||
memset( &sock, 0, sizeof( sock ) );
|
||||
sock.sin_family = AF_INET;
|
||||
sock.sin_addr.s_addr = INADDR_ANY;
|
||||
sock.sin_port = htons( port );
|
||||
|
||||
if( bind( s, (struct sockaddr *) &sock,
|
||||
sizeof( struct sockaddr ) ) )
|
||||
sizeof( struct sockaddr_in ) ) )
|
||||
{
|
||||
tr_err( _( "Couldn't bind port %d on %s: %s" ), port,
|
||||
tr_ntop_non_ts( addr ), tr_strerror( sockerrno ) );
|
||||
tr_err( _( "Couldn't bind port %d: %s" ), port,
|
||||
tr_strerror( sockerrno ) );
|
||||
tr_netClose( s );
|
||||
return -1;
|
||||
}
|
||||
|
||||
tr_dbg( "Bound socket %d to port %d on %s", s, port,
|
||||
tr_ntop_non_ts( addr ) );
|
||||
tr_dbg( "Bound socket %d to port %d", s, port );
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
tr_netAccept( tr_session * session,
|
||||
int b,
|
||||
tr_address * addr,
|
||||
tr_port_t * port )
|
||||
tr_netAccept( tr_session * session,
|
||||
int b,
|
||||
struct in_addr * addr,
|
||||
tr_port_t * port )
|
||||
{
|
||||
int fd = makeSocketNonBlocking( tr_fdSocketAccept( b, addr, port ) );
|
||||
setSndBuf( session, fd );
|
||||
|
@ -313,3 +229,16 @@ tr_netClose( int s )
|
|||
{
|
||||
tr_fdSocketClose( s );
|
||||
}
|
||||
|
||||
void
|
||||
tr_netNtop( const struct in_addr * addr,
|
||||
char * buf,
|
||||
int len )
|
||||
{
|
||||
const uint8_t * cast;
|
||||
|
||||
cast = (const uint8_t *)addr;
|
||||
tr_snprintf( buf, len, "%hhu.%hhu.%hhu.%hhu",
|
||||
cast[0], cast[1], cast[2], cast[3] );
|
||||
}
|
||||
|
||||
|
|
|
@ -60,54 +60,40 @@
|
|||
#define sockerrno errno
|
||||
#endif
|
||||
|
||||
struct in_addr;
|
||||
struct sockaddr_in;
|
||||
struct tr_session;
|
||||
|
||||
#define TR_AF_INET 0
|
||||
#define TR_AF_INET6 1
|
||||
|
||||
typedef struct tr_address {
|
||||
unsigned short type : 1;
|
||||
union {
|
||||
/* The order here is important for tr_in{,6}addr_any initialization,
|
||||
* since we can't use C99 designated initializers */
|
||||
struct in6_addr addr6;
|
||||
struct in_addr addr4;
|
||||
} addr;
|
||||
} tr_address;
|
||||
|
||||
extern const tr_address tr_inaddr_any;
|
||||
extern const tr_address tr_in6addr_any;
|
||||
|
||||
const char *tr_ntop( const tr_address * src,
|
||||
char * dst,
|
||||
int size );
|
||||
const char *tr_ntop_non_ts( const tr_address * src );
|
||||
tr_address *tr_pton( const char * src,
|
||||
tr_address * dst );
|
||||
int tr_compareAddresses( const tr_address * a,
|
||||
const tr_address * b);
|
||||
/***********************************************************************
|
||||
* DNS resolution
|
||||
**********************************************************************/
|
||||
int tr_netResolve( const char *,
|
||||
struct in_addr * );
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* Sockets
|
||||
**********************************************************************/
|
||||
int tr_netOpenTCP( struct tr_handle * session,
|
||||
const tr_address * addr,
|
||||
tr_port_t port );
|
||||
int tr_netOpenTCP( struct tr_handle * session,
|
||||
const struct in_addr * addr,
|
||||
tr_port_t port );
|
||||
|
||||
int tr_netBindTCP( const tr_address * addr,
|
||||
int port );
|
||||
int tr_netBindTCP( int port );
|
||||
|
||||
int tr_netAccept( struct tr_handle * session,
|
||||
int bound,
|
||||
tr_address * setme_addr,
|
||||
tr_port_t * setme_port );
|
||||
int tr_netAccept( struct tr_handle * session,
|
||||
int bound,
|
||||
struct in_addr * setme_addr,
|
||||
tr_port_t * setme_port );
|
||||
|
||||
int tr_netSetTOS( int s,
|
||||
int tos );
|
||||
|
||||
void tr_netClose( int s );
|
||||
|
||||
void tr_netNtop( const struct in_addr * addr,
|
||||
char * buf,
|
||||
int len );
|
||||
|
||||
void tr_netInit( void );
|
||||
|
||||
#endif /* _TR_NET_H_ */
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#ifdef WIN32
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#include <netinet/in.h> /* struct in_addr */
|
||||
#include <arpa/inet.h> /* inet_ntoa */
|
||||
#endif
|
||||
|
||||
|
@ -96,7 +97,7 @@ struct tr_peerIo
|
|||
|
||||
tr_session * session;
|
||||
|
||||
tr_address addr;
|
||||
struct in_addr in_addr;
|
||||
struct tr_iobuf * iobuf;
|
||||
tr_list * output_datatypes; /* struct tr_datatype */
|
||||
|
||||
|
@ -237,12 +238,12 @@ isPeerIo( const tr_peerIo * io )
|
|||
}
|
||||
|
||||
static tr_peerIo*
|
||||
tr_peerIoNew( tr_session * session,
|
||||
const tr_address * addr,
|
||||
uint16_t port,
|
||||
const uint8_t * torrentHash,
|
||||
int isIncoming,
|
||||
int socket )
|
||||
tr_peerIoNew( tr_session * session,
|
||||
const struct in_addr * in_addr,
|
||||
uint16_t port,
|
||||
const uint8_t * torrentHash,
|
||||
int isIncoming,
|
||||
int socket )
|
||||
{
|
||||
tr_peerIo * io;
|
||||
|
||||
|
@ -253,7 +254,7 @@ tr_peerIoNew( tr_session * session,
|
|||
io->magicNumber = MAGIC_NUMBER;
|
||||
io->crypto = tr_cryptoNew( torrentHash, isIncoming );
|
||||
io->session = session;
|
||||
io->addr = *addr;
|
||||
io->in_addr = *in_addr;
|
||||
io->port = port;
|
||||
io->socket = socket;
|
||||
io->isIncoming = isIncoming != 0;
|
||||
|
@ -265,38 +266,38 @@ tr_peerIoNew( tr_session * session,
|
|||
}
|
||||
|
||||
tr_peerIo*
|
||||
tr_peerIoNewIncoming( tr_session * session,
|
||||
const tr_address * addr,
|
||||
uint16_t port,
|
||||
int socket )
|
||||
tr_peerIoNewIncoming( tr_session * session,
|
||||
const struct in_addr * in_addr,
|
||||
uint16_t port,
|
||||
int socket )
|
||||
{
|
||||
assert( session );
|
||||
assert( addr );
|
||||
assert( in_addr );
|
||||
assert( socket >= 0 );
|
||||
|
||||
return tr_peerIoNew( session, addr, port,
|
||||
return tr_peerIoNew( session, in_addr, port,
|
||||
NULL, 1,
|
||||
socket );
|
||||
}
|
||||
|
||||
tr_peerIo*
|
||||
tr_peerIoNewOutgoing( tr_session * session,
|
||||
const tr_address * addr,
|
||||
int port,
|
||||
const uint8_t * torrentHash )
|
||||
tr_peerIoNewOutgoing( tr_session * session,
|
||||
const struct in_addr * in_addr,
|
||||
int port,
|
||||
const uint8_t * torrentHash )
|
||||
{
|
||||
int socket;
|
||||
|
||||
assert( session );
|
||||
assert( addr );
|
||||
assert( in_addr );
|
||||
assert( port >= 0 );
|
||||
assert( torrentHash );
|
||||
|
||||
socket = tr_netOpenTCP( session, addr, port );
|
||||
socket = tr_netOpenTCP( session, in_addr, port );
|
||||
|
||||
return socket < 0
|
||||
? NULL
|
||||
: tr_peerIoNew( session, addr, port, torrentHash, 0, socket );
|
||||
: tr_peerIoNew( session, in_addr, port, torrentHash, 0, socket );
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -335,37 +336,33 @@ tr_peerIoGetSession( tr_peerIo * io )
|
|||
return io->session;
|
||||
}
|
||||
|
||||
const tr_address*
|
||||
const struct in_addr*
|
||||
tr_peerIoGetAddress( const tr_peerIo * io,
|
||||
uint16_t * port )
|
||||
uint16_t * port )
|
||||
{
|
||||
assert( isPeerIo( io ) );
|
||||
|
||||
if( port )
|
||||
*port = io->port;
|
||||
|
||||
return &io->addr;
|
||||
return &io->in_addr;
|
||||
}
|
||||
|
||||
const char*
|
||||
tr_peerIoAddrStr( const tr_address * addr,
|
||||
uint16_t port )
|
||||
tr_peerIoAddrStr( const struct in_addr * addr,
|
||||
uint16_t port )
|
||||
{
|
||||
static char buf[512];
|
||||
|
||||
if( addr->type == TR_AF_INET )
|
||||
tr_snprintf( buf, sizeof( buf ), "%s:%u", tr_ntop_non_ts( addr ),
|
||||
ntohs( port ) );
|
||||
else
|
||||
tr_snprintf( buf, sizeof( buf ), "[%s]:%u", tr_ntop_non_ts( addr ),
|
||||
ntohs( port ) );
|
||||
tr_snprintf( buf, sizeof( buf ), "%s:%u", inet_ntoa( *addr ),
|
||||
ntohs( port ) );
|
||||
return buf;
|
||||
}
|
||||
|
||||
const char*
|
||||
tr_peerIoGetAddrStr( const tr_peerIo * io )
|
||||
{
|
||||
return tr_peerIoAddrStr( &io->addr, io->port );
|
||||
return tr_peerIoAddrStr( &io->in_addr, io->port );
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -404,7 +401,7 @@ tr_peerIoReconnect( tr_peerIo * io )
|
|||
if( io->socket >= 0 )
|
||||
tr_netClose( io->socket );
|
||||
|
||||
io->socket = tr_netOpenTCP( io->session, &io->addr, io->port );
|
||||
io->socket = tr_netOpenTCP( io->session, &io->in_addr, io->port );
|
||||
|
||||
if( io->socket >= 0 )
|
||||
{
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
***
|
||||
**/
|
||||
|
||||
struct in_addr;
|
||||
struct evbuffer;
|
||||
struct tr_bandwidth;
|
||||
struct tr_crypto;
|
||||
|
@ -31,15 +32,15 @@ typedef struct tr_peerIo tr_peerIo;
|
|||
***
|
||||
**/
|
||||
|
||||
tr_peerIo* tr_peerIoNewOutgoing( struct tr_handle * session,
|
||||
const tr_address * addr,
|
||||
int port,
|
||||
const uint8_t * torrentHash );
|
||||
tr_peerIo* tr_peerIoNewOutgoing( struct tr_handle * session,
|
||||
const struct in_addr * addr,
|
||||
int port,
|
||||
const uint8_t * torrentHash );
|
||||
|
||||
tr_peerIo* tr_peerIoNewIncoming( struct tr_handle * session,
|
||||
const tr_address * addr,
|
||||
uint16_t port,
|
||||
int socket );
|
||||
tr_peerIo* tr_peerIoNewIncoming( struct tr_handle * session,
|
||||
const struct in_addr * addr,
|
||||
uint16_t port,
|
||||
int socket );
|
||||
|
||||
void tr_peerIoFree( tr_peerIo * io );
|
||||
|
||||
|
@ -58,12 +59,12 @@ int tr_peerIoSupportsLTEP( const tr_peerIo * io );
|
|||
***
|
||||
**/
|
||||
|
||||
const char* tr_peerIoAddrStr( const tr_address * addr,
|
||||
uint16_t port );
|
||||
const char* tr_peerIoAddrStr( const struct in_addr * addr,
|
||||
uint16_t port );
|
||||
|
||||
const char* tr_peerIoGetAddrStr( const tr_peerIo * io );
|
||||
|
||||
const tr_address * tr_peerIoGetAddress( const tr_peerIo * io,
|
||||
const struct in_addr*tr_peerIoGetAddress( const tr_peerIo * io,
|
||||
uint16_t * port );
|
||||
|
||||
const uint8_t* tr_peerIoGetTorrentHash( tr_peerIo * io );
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
|
||||
#ifdef WIN32
|
||||
#include <winsock2.h> /* struct in_addr */
|
||||
#else
|
||||
#include <netinet/in.h> /* struct in_addr */
|
||||
#endif
|
||||
|
||||
#include "publish.h" /* tr_publisher_tag */
|
||||
|
@ -50,7 +52,7 @@ typedef struct tr_peer
|
|||
|
||||
uint8_t encryption_preference;
|
||||
uint16_t port;
|
||||
tr_address addr;
|
||||
struct in_addr in_addr;
|
||||
struct tr_peerIo * io;
|
||||
|
||||
struct tr_bitfield * blame;
|
||||
|
|
|
@ -95,14 +95,14 @@ enum
|
|||
* into this list for new ones. */
|
||||
struct peer_atom
|
||||
{
|
||||
uint8_t from;
|
||||
uint8_t flags; /* these match the added_f flags */
|
||||
uint8_t myflags; /* flags that aren't defined in added_f */
|
||||
uint16_t port;
|
||||
uint16_t numFails;
|
||||
tr_address addr;
|
||||
time_t time; /* when the peer's connection status last changed */
|
||||
time_t piece_data_time;
|
||||
uint8_t from;
|
||||
uint8_t flags; /* these match the added_f flags */
|
||||
uint8_t myflags; /* flags that aren't defined in added_f */
|
||||
uint16_t port;
|
||||
uint16_t numFails;
|
||||
struct in_addr addr;
|
||||
time_t time; /* when the peer's connection status last changed */
|
||||
time_t piece_data_time;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
|
@ -183,13 +183,23 @@ torrentIsLocked( const Torrent * t )
|
|||
***
|
||||
**/
|
||||
|
||||
static int
|
||||
compareAddresses( const struct in_addr * a,
|
||||
const struct in_addr * b )
|
||||
{
|
||||
if( a->s_addr != b->s_addr )
|
||||
return a->s_addr < b->s_addr ? -1 : 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
handshakeCompareToAddr( const void * va,
|
||||
const void * vb )
|
||||
{
|
||||
const tr_handshake * a = va;
|
||||
|
||||
return tr_compareAddresses( tr_handshakeGetAddr( a, NULL ), vb );
|
||||
return compareAddresses( tr_handshakeGetAddr( a, NULL ), vb );
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -200,11 +210,11 @@ handshakeCompare( const void * a,
|
|||
}
|
||||
|
||||
static tr_handshake*
|
||||
getExistingHandshake( tr_ptrArray * handshakes,
|
||||
const tr_address * addr )
|
||||
getExistingHandshake( tr_ptrArray * handshakes,
|
||||
const struct in_addr * in_addr )
|
||||
{
|
||||
return tr_ptrArrayFindSorted( handshakes,
|
||||
addr,
|
||||
in_addr,
|
||||
handshakeCompareToAddr );
|
||||
}
|
||||
|
||||
|
@ -214,7 +224,7 @@ comparePeerAtomToAddress( const void * va,
|
|||
{
|
||||
const struct peer_atom * a = va;
|
||||
|
||||
return tr_compareAddresses( &a->addr, vb );
|
||||
return compareAddresses( &a->addr, vb );
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -266,7 +276,7 @@ peerCompare( const void * va,
|
|||
const tr_peer * a = va;
|
||||
const tr_peer * b = vb;
|
||||
|
||||
return tr_compareAddresses( &a->addr, &b->addr );
|
||||
return compareAddresses( &a->in_addr, &b->in_addr );
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -275,32 +285,32 @@ peerCompareToAddr( const void * va,
|
|||
{
|
||||
const tr_peer * a = va;
|
||||
|
||||
return tr_compareAddresses( &a->addr, vb );
|
||||
return compareAddresses( &a->in_addr, vb );
|
||||
}
|
||||
|
||||
static tr_peer*
|
||||
getExistingPeer( Torrent * torrent,
|
||||
const tr_address * addr )
|
||||
getExistingPeer( Torrent * torrent,
|
||||
const struct in_addr * in_addr )
|
||||
{
|
||||
assert( torrentIsLocked( torrent ) );
|
||||
assert( addr );
|
||||
assert( in_addr );
|
||||
|
||||
return tr_ptrArrayFindSorted( torrent->peers,
|
||||
addr,
|
||||
in_addr,
|
||||
peerCompareToAddr );
|
||||
}
|
||||
|
||||
static struct peer_atom*
|
||||
getExistingAtom( const Torrent * t,
|
||||
const tr_address * addr )
|
||||
getExistingAtom( const Torrent * t,
|
||||
const struct in_addr * addr )
|
||||
{
|
||||
assert( torrentIsLocked( t ) );
|
||||
return tr_ptrArrayFindSorted( t->pool, addr, comparePeerAtomToAddress );
|
||||
}
|
||||
|
||||
static int
|
||||
peerIsInUse( const Torrent * ct,
|
||||
const tr_address * addr )
|
||||
peerIsInUse( const Torrent * ct,
|
||||
const struct in_addr * addr )
|
||||
{
|
||||
Torrent * t = (Torrent*) ct;
|
||||
|
||||
|
@ -312,29 +322,29 @@ peerIsInUse( const Torrent * ct,
|
|||
}
|
||||
|
||||
static tr_peer*
|
||||
peerConstructor( tr_torrent * tor, const tr_address * addr )
|
||||
peerConstructor( tr_torrent * tor, const struct in_addr * in_addr )
|
||||
{
|
||||
tr_peer * p;
|
||||
|
||||
p = tr_new0( tr_peer, 1 );
|
||||
memcpy( &p->addr, addr, sizeof( tr_address ) );
|
||||
memcpy( &p->in_addr, in_addr, sizeof( struct in_addr ) );
|
||||
p->bandwidth = tr_bandwidthNew( tor->session, tor->bandwidth );
|
||||
return p;
|
||||
}
|
||||
|
||||
static tr_peer*
|
||||
getPeer( Torrent * torrent,
|
||||
const tr_address * addr )
|
||||
getPeer( Torrent * torrent,
|
||||
const struct in_addr * in_addr )
|
||||
{
|
||||
tr_peer * peer;
|
||||
|
||||
assert( torrentIsLocked( torrent ) );
|
||||
|
||||
peer = getExistingPeer( torrent, addr );
|
||||
peer = getExistingPeer( torrent, in_addr );
|
||||
|
||||
if( peer == NULL )
|
||||
{
|
||||
peer = peerConstructor( torrent->tor, addr );
|
||||
peer = peerConstructor( torrent->tor, in_addr );
|
||||
tr_ptrArrayInsertSorted( torrent->peers, peer, peerCompare );
|
||||
}
|
||||
|
||||
|
@ -370,7 +380,7 @@ removePeer( Torrent * t,
|
|||
|
||||
assert( torrentIsLocked( t ) );
|
||||
|
||||
atom = getExistingAtom( t, &peer->addr );
|
||||
atom = getExistingAtom( t, &peer->in_addr );
|
||||
assert( atom );
|
||||
atom->time = time( NULL );
|
||||
|
||||
|
@ -520,9 +530,9 @@ clientIsUploadingTo( const tr_peer * peer )
|
|||
***/
|
||||
|
||||
int
|
||||
tr_peerMgrPeerIsSeed( const tr_peerMgr * mgr,
|
||||
const uint8_t * torrentHash,
|
||||
const tr_address * addr )
|
||||
tr_peerMgrPeerIsSeed( const tr_peerMgr * mgr,
|
||||
const uint8_t * torrentHash,
|
||||
const struct in_addr * addr )
|
||||
{
|
||||
int isSeed = FALSE;
|
||||
const Torrent * t = NULL;
|
||||
|
@ -895,12 +905,12 @@ addStrike( Torrent * t,
|
|||
tr_peer * peer )
|
||||
{
|
||||
tordbg( t, "increasing peer %s strike count to %d",
|
||||
tr_peerIoAddrStr( &peer->addr,
|
||||
tr_peerIoAddrStr( &peer->in_addr,
|
||||
peer->port ), peer->strikes + 1 );
|
||||
|
||||
if( ++peer->strikes >= MAX_BAD_PIECES_PER_PEER )
|
||||
{
|
||||
struct peer_atom * atom = getExistingAtom( t, &peer->addr );
|
||||
struct peer_atom * atom = getExistingAtom( t, &peer->in_addr );
|
||||
atom->myflags |= MYFLAG_BANNED;
|
||||
peer->doPurge = 1;
|
||||
tordbg( t, "banning peer %s",
|
||||
|
@ -965,7 +975,7 @@ peerCallbackFunc( void * vpeer,
|
|||
|
||||
/* update our atom */
|
||||
if( peer ) {
|
||||
struct peer_atom * a = getExistingAtom( t, &peer->addr );
|
||||
struct peer_atom * a = getExistingAtom( t, &peer->in_addr );
|
||||
a->piece_data_time = now;
|
||||
}
|
||||
|
||||
|
@ -994,7 +1004,7 @@ peerCallbackFunc( void * vpeer,
|
|||
|
||||
/* update our atom */
|
||||
if( peer ) {
|
||||
struct peer_atom * a = getExistingAtom( t, &peer->addr );
|
||||
struct peer_atom * a = getExistingAtom( t, &peer->in_addr );
|
||||
a->piece_data_time = now;
|
||||
}
|
||||
|
||||
|
@ -1005,7 +1015,8 @@ peerCallbackFunc( void * vpeer,
|
|||
{
|
||||
if( peer )
|
||||
{
|
||||
struct peer_atom * atom = getExistingAtom( t, &peer->addr );
|
||||
struct peer_atom * atom = getExistingAtom( t,
|
||||
&peer->in_addr );
|
||||
const int peerIsSeed = e->progress >= 1.0;
|
||||
if( peerIsSeed )
|
||||
{
|
||||
|
@ -1100,11 +1111,11 @@ peerCallbackFunc( void * vpeer,
|
|||
}
|
||||
|
||||
static void
|
||||
ensureAtomExists( Torrent * t,
|
||||
const tr_address * addr,
|
||||
uint16_t port,
|
||||
uint8_t flags,
|
||||
uint8_t from )
|
||||
ensureAtomExists( Torrent * t,
|
||||
const struct in_addr * addr,
|
||||
uint16_t port,
|
||||
uint8_t flags,
|
||||
uint8_t from )
|
||||
{
|
||||
if( getExistingAtom( t, addr ) == NULL )
|
||||
{
|
||||
|
@ -1141,13 +1152,13 @@ myHandshakeDoneCB( tr_handshake * handshake,
|
|||
const uint8_t * peer_id,
|
||||
void * vmanager )
|
||||
{
|
||||
int ok = isConnected;
|
||||
int success = FALSE;
|
||||
uint16_t port;
|
||||
const tr_address * addr;
|
||||
tr_peerMgr * manager = (tr_peerMgr*) vmanager;
|
||||
Torrent * t;
|
||||
tr_handshake * ours;
|
||||
int ok = isConnected;
|
||||
int success = FALSE;
|
||||
uint16_t port;
|
||||
const struct in_addr * addr;
|
||||
tr_peerMgr * manager = (tr_peerMgr*) vmanager;
|
||||
Torrent * t;
|
||||
tr_handshake * ours;
|
||||
|
||||
assert( io );
|
||||
assert( isConnected == 0 || isConnected == 1 );
|
||||
|
@ -1242,17 +1253,17 @@ myHandshakeDoneCB( tr_handshake * handshake,
|
|||
}
|
||||
|
||||
void
|
||||
tr_peerMgrAddIncoming( tr_peerMgr * manager,
|
||||
tr_address * addr,
|
||||
uint16_t port,
|
||||
int socket )
|
||||
tr_peerMgrAddIncoming( tr_peerMgr * manager,
|
||||
struct in_addr * addr,
|
||||
uint16_t port,
|
||||
int socket )
|
||||
{
|
||||
managerLock( manager );
|
||||
|
||||
if( tr_sessionIsAddressBlocked( manager->session, addr ) )
|
||||
{
|
||||
tr_dbg( "Banned IP address \"%s\" tried to connect to us",
|
||||
tr_ntop_non_ts( addr ) );
|
||||
inet_ntoa( *addr ) );
|
||||
tr_netClose( socket );
|
||||
}
|
||||
else if( getExistingHandshake( manager->incomingHandshakes, addr ) )
|
||||
|
@ -1289,8 +1300,8 @@ tr_peerMgrAddPex( tr_peerMgr * manager,
|
|||
managerLock( manager );
|
||||
|
||||
t = getExistingTorrent( manager, torrentHash );
|
||||
if( !tr_sessionIsAddressBlocked( t->manager->session, &pex->addr ) )
|
||||
ensureAtomExists( t, &pex->addr, pex->port, pex->flags, from );
|
||||
if( !tr_sessionIsAddressBlocked( t->manager->session, &pex->in_addr ) )
|
||||
ensureAtomExists( t, &pex->in_addr, pex->port, pex->flags, from );
|
||||
|
||||
managerUnlock( manager );
|
||||
}
|
||||
|
@ -1309,8 +1320,7 @@ tr_peerMgrCompactToPex( const void * compact,
|
|||
|
||||
for( i = 0; i < n; ++i )
|
||||
{
|
||||
pex[i].addr.type = TR_AF_INET;
|
||||
memcpy( &pex[i].addr.addr, walk, 4 ); walk += 4;
|
||||
memcpy( &pex[i].in_addr, walk, 4 ); walk += 4;
|
||||
memcpy( &pex[i].port, walk, 2 ); walk += 2;
|
||||
if( added_f && ( n == added_f_len ) )
|
||||
pex[i].flags = added_f[i];
|
||||
|
@ -1347,7 +1357,7 @@ tr_peerMgrSetBlame( tr_peerMgr * manager,
|
|||
tordbg(
|
||||
t,
|
||||
"peer %s contributed to corrupt piece (%d); now has %d strikes",
|
||||
tr_peerIoAddrStr( &peer->addr, peer->port ),
|
||||
tr_peerIoAddrStr( &peer->in_addr, peer->port ),
|
||||
pieceIndex, (int)peer->strikes + 1 );
|
||||
addStrike( t, peer );
|
||||
}
|
||||
|
@ -1361,7 +1371,8 @@ tr_pexCompare( const void * va,
|
|||
{
|
||||
const tr_pex * a = va;
|
||||
const tr_pex * b = vb;
|
||||
int i = tr_compareAddresses( &a->addr, &b->addr );
|
||||
int i =
|
||||
memcmp( &a->in_addr, &b->in_addr, sizeof( struct in_addr ) );
|
||||
|
||||
if( i ) return i;
|
||||
if( a->port < b->port ) return -1;
|
||||
|
@ -1409,7 +1420,7 @@ tr_peerMgrGetPeers( tr_peerMgr * manager,
|
|||
for( i = 0; i < peerCount; ++i, ++walk )
|
||||
{
|
||||
const tr_peer * peer = peers[i];
|
||||
walk->addr = peer->addr;
|
||||
walk->in_addr = peer->in_addr;
|
||||
walk->port = peer->port;
|
||||
walk->flags = 0;
|
||||
if( peerPrefersCrypto( peer ) ) walk->flags |= ADDED_F_ENCRYPTION_FLAG;
|
||||
|
@ -1646,7 +1657,7 @@ tr_peerMgrTorrentStats( const tr_peerMgr * manager,
|
|||
for( i = 0; i < size; ++i )
|
||||
{
|
||||
const tr_peer * peer = peers[i];
|
||||
const struct peer_atom * atom = getExistingAtom( t, &peer->addr );
|
||||
const struct peer_atom * atom = getExistingAtom( t, &peer->in_addr );
|
||||
|
||||
if( peer->io == NULL ) /* not connected */
|
||||
continue;
|
||||
|
@ -1734,10 +1745,10 @@ tr_peerMgrPeerStats( const tr_peerMgr * manager,
|
|||
{
|
||||
char * pch;
|
||||
const tr_peer * peer = peers[i];
|
||||
const struct peer_atom * atom = getExistingAtom( t, &peer->addr );
|
||||
const struct peer_atom * atom = getExistingAtom( t, &peer->in_addr );
|
||||
tr_peer_stat * stat = ret + i;
|
||||
|
||||
tr_ntop( &peer->addr, stat->addr, sizeof( stat->addr ) );
|
||||
tr_netNtop( &peer->in_addr, stat->addr, sizeof( stat->addr ) );
|
||||
tr_strlcpy( stat->client, ( peer->client ? peer->client : "" ),
|
||||
sizeof( stat->client ) );
|
||||
stat->port = ntohs( peer->port );
|
||||
|
@ -1933,7 +1944,7 @@ shouldPeerBeClosed( const Torrent * t,
|
|||
{
|
||||
const tr_torrent * tor = t->tor;
|
||||
const time_t now = time( NULL );
|
||||
const struct peer_atom * atom = getExistingAtom( t, &peer->addr );
|
||||
const struct peer_atom * atom = getExistingAtom( t, &peer->in_addr );
|
||||
|
||||
/* if it's marked for purging, close it */
|
||||
if( peer->doPurge )
|
||||
|
@ -2195,7 +2206,7 @@ reconnectPulse( void * vtorrent )
|
|||
for( i = 0; i < nBad; ++i )
|
||||
{
|
||||
tr_peer * peer = connections[i];
|
||||
struct peer_atom * atom = getExistingAtom( t, &peer->addr );
|
||||
struct peer_atom * atom = getExistingAtom( t, &peer->in_addr );
|
||||
if( peer->pieceDataActivityDate )
|
||||
atom->numFails = 0;
|
||||
else
|
||||
|
|
|
@ -21,10 +21,11 @@
|
|||
|
||||
#ifdef WIN32
|
||||
#include <winsock2.h> /* struct in_addr */
|
||||
#else
|
||||
#include <netinet/in.h> /* struct in_addr */
|
||||
#endif
|
||||
|
||||
#include "net.h"
|
||||
|
||||
struct in_addr;
|
||||
struct tr_handle;
|
||||
struct tr_peer_stat;
|
||||
struct tr_torrent;
|
||||
|
@ -41,9 +42,9 @@ enum
|
|||
|
||||
typedef struct tr_pex
|
||||
{
|
||||
tr_address addr;
|
||||
uint16_t port;
|
||||
uint8_t flags;
|
||||
struct in_addr in_addr;
|
||||
uint16_t port;
|
||||
uint8_t flags;
|
||||
}
|
||||
tr_pex;
|
||||
|
||||
|
@ -53,14 +54,14 @@ tr_peerMgr* tr_peerMgrNew( struct tr_handle * );
|
|||
|
||||
void tr_peerMgrFree( tr_peerMgr * manager );
|
||||
|
||||
int tr_peerMgrPeerIsSeed( const tr_peerMgr * mgr,
|
||||
const uint8_t * torrentHash,
|
||||
const tr_address * addr );
|
||||
int tr_peerMgrPeerIsSeed( const tr_peerMgr * mgr,
|
||||
const uint8_t * torrentHash,
|
||||
const struct in_addr * addr );
|
||||
|
||||
void tr_peerMgrAddIncoming( tr_peerMgr * manager,
|
||||
tr_address * addr,
|
||||
uint16_t port,
|
||||
int socket );
|
||||
void tr_peerMgrAddIncoming( tr_peerMgr * manager,
|
||||
struct in_addr * addr,
|
||||
uint16_t port,
|
||||
int socket );
|
||||
|
||||
tr_pex * tr_peerMgrCompactToPex( const void * compact,
|
||||
size_t compactLen,
|
||||
|
|
|
@ -1763,7 +1763,6 @@ pexElementCb( void * vpex,
|
|||
diffs->elements[diffs->elementCount++] = *pex;
|
||||
}
|
||||
|
||||
/* TODO: ipv6 pex */
|
||||
static void
|
||||
sendPex( tr_peermsgs * msgs )
|
||||
{
|
||||
|
@ -1815,7 +1814,7 @@ sendPex( tr_peermsgs * msgs )
|
|||
/* "added" */
|
||||
tmp = walk = tr_new( uint8_t, diffs.addedCount * 6 );
|
||||
for( i = 0; i < diffs.addedCount; ++i ) {
|
||||
memcpy( walk, &diffs.added[i].addr.addr, 4 ); walk += 4;
|
||||
memcpy( walk, &diffs.added[i].in_addr, 4 ); walk += 4;
|
||||
memcpy( walk, &diffs.added[i].port, 2 ); walk += 2;
|
||||
}
|
||||
assert( ( walk - tmp ) == diffs.addedCount * 6 );
|
||||
|
@ -1833,7 +1832,7 @@ sendPex( tr_peermsgs * msgs )
|
|||
/* "dropped" */
|
||||
tmp = walk = tr_new( uint8_t, diffs.droppedCount * 6 );
|
||||
for( i = 0; i < diffs.droppedCount; ++i ) {
|
||||
memcpy( walk, &diffs.dropped[i].addr.addr, 4 ); walk += 4;
|
||||
memcpy( walk, &diffs.dropped[i].in_addr, 4 ); walk += 4;
|
||||
memcpy( walk, &diffs.dropped[i].port, 2 ); walk += 2;
|
||||
}
|
||||
assert( ( walk - tmp ) == diffs.droppedCount * 6 );
|
||||
|
|
|
@ -114,8 +114,7 @@ incomingPeersPulse( tr_shared * s )
|
|||
{
|
||||
int socket;
|
||||
errno = 0;
|
||||
/* TODO: this is where we want to listen on another socket */
|
||||
socket = tr_netBindTCP( &tr_inaddr_any, s->publicPort );
|
||||
socket = tr_netBindTCP( s->publicPort );
|
||||
if( socket >= 0 )
|
||||
{
|
||||
tr_ninf( getKey( ),
|
||||
|
@ -139,9 +138,9 @@ incomingPeersPulse( tr_shared * s )
|
|||
|
||||
for( ; ; ) /* check for new incoming peer connections */
|
||||
{
|
||||
int socket;
|
||||
uint16_t port;
|
||||
tr_address addr;
|
||||
int socket;
|
||||
uint16_t port;
|
||||
struct in_addr addr;
|
||||
|
||||
if( s->bindSocket < 0 )
|
||||
break;
|
||||
|
|
|
@ -61,7 +61,6 @@ getResumeFilename( const tr_torrent * tor )
|
|||
****
|
||||
***/
|
||||
|
||||
/* TODO: fast resume is done with pex */
|
||||
static void
|
||||
savePeers( tr_benc * dict,
|
||||
const tr_torrent * tor )
|
||||
|
|
|
@ -799,8 +799,8 @@ tr_blocklistSetContent( tr_session * session,
|
|||
}
|
||||
|
||||
int
|
||||
tr_sessionIsAddressBlocked( const tr_session * session,
|
||||
const tr_address * addr )
|
||||
tr_sessionIsAddressBlocked( const tr_session * session,
|
||||
const struct in_addr * addr )
|
||||
{
|
||||
tr_list * l;
|
||||
|
||||
|
|
|
@ -39,8 +39,6 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#include "net.h"
|
||||
|
||||
|
||||
typedef enum { TR_NET_OK, TR_NET_ERROR, TR_NET_WAIT } tr_tristate_t;
|
||||
|
||||
|
@ -123,8 +121,10 @@ void tr_sessionSetTorrentFile( tr_session * session,
|
|||
const char * hashString,
|
||||
const char * filename );
|
||||
|
||||
int tr_sessionIsAddressBlocked( const tr_session * session,
|
||||
const tr_address * addr );
|
||||
struct in_addr;
|
||||
|
||||
int tr_sessionIsAddressBlocked( const tr_session * session,
|
||||
const struct in_addr * addr );
|
||||
|
||||
|
||||
void tr_globalLock( tr_session * );
|
||||
|
|
|
@ -280,7 +280,6 @@ static uint8_t *
|
|||
parseOldPeers( tr_benc * bePeers,
|
||||
size_t * byteCount )
|
||||
{
|
||||
/* TODO: wtf */
|
||||
int i;
|
||||
uint8_t * compact, *walk;
|
||||
const int peerCount = bePeers->val.l.count;
|
||||
|
@ -291,21 +290,17 @@ parseOldPeers( tr_benc * bePeers,
|
|||
|
||||
for( i = 0, walk = compact; i < peerCount; ++i )
|
||||
{
|
||||
const char * s;
|
||||
int64_t itmp;
|
||||
tr_address addr;
|
||||
tr_port_t port;
|
||||
tr_benc * peer = &bePeers->val.l.vals[i];
|
||||
const char * s;
|
||||
int64_t itmp;
|
||||
struct in_addr addr;
|
||||
tr_port_t port;
|
||||
tr_benc * peer = &bePeers->val.l.vals[i];
|
||||
|
||||
if( tr_bencDictFindStr( peer, "ip", &s ) )
|
||||
{
|
||||
if( tr_pton( s, &addr ) == NULL )
|
||||
continue;
|
||||
if( addr.type != TR_AF_INET )
|
||||
continue;
|
||||
}
|
||||
if( !tr_bencDictFindStr( peer, "ip",
|
||||
&s ) || tr_netResolve( s, &addr ) )
|
||||
continue;
|
||||
|
||||
memcpy( walk, &addr.addr.addr4.s_addr, 4 );
|
||||
memcpy( walk, &addr, 4 );
|
||||
walk += 4;
|
||||
|
||||
if( !tr_bencDictFindInt( peer, "port",
|
||||
|
|
|
@ -49,7 +49,6 @@ extern "C" {
|
|||
#define PRIu32 "lu"
|
||||
#endif
|
||||
#include <time.h> /* time_t */
|
||||
#include <netinet/in.h> /* INET6_ADDRSTRLEN */
|
||||
|
||||
#define SHA_DIGEST_LENGTH 20
|
||||
|
||||
|
@ -1062,7 +1061,7 @@ typedef struct tr_peer_stat
|
|||
uint8_t from;
|
||||
uint16_t port;
|
||||
|
||||
char addr[INET6_ADDRSTRLEN];
|
||||
char addr[16];
|
||||
char client[80];
|
||||
char flagStr[32];
|
||||
|
||||
|
|
Loading…
Reference in New Issue