mirror of
https://github.com/transmission/transmission.git
synced 2025-12-24 12:28:52 +00:00
(trunk libT) #3162 "allow optional end-user configuration of TCP_CONGESTION" -- add jch's implementation of this to trunk for 2.00
This commit is contained in:
@@ -35,6 +35,9 @@
|
||||
#include <winsock2.h> /* inet_addr */
|
||||
#include <WS2tcpip.h>
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <arpa/inet.h> /* inet_addr */
|
||||
#include <netdb.h>
|
||||
#include <fcntl.h>
|
||||
@@ -210,6 +213,18 @@ tr_netSetTOS( int s, int tos )
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
tr_netSetCongestionControl( int s, const char *algorithm )
|
||||
{
|
||||
#ifdef TCP_CONGESTION
|
||||
return setsockopt( s, IPPROTO_TCP, TCP_CONGESTION,
|
||||
algorithm, strlen(algorithm) + 1 );
|
||||
#else
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
static socklen_t
|
||||
setup_sockaddr( const tr_address * addr,
|
||||
tr_port port,
|
||||
|
||||
@@ -115,6 +115,8 @@ int tr_netAccept( tr_session * session,
|
||||
int tr_netSetTOS( int s,
|
||||
int tos );
|
||||
|
||||
int tr_netSetCongestionControl( int s, const char *algorithm );
|
||||
|
||||
void tr_netClose( tr_session * session, int s );
|
||||
|
||||
void tr_netCloseSocket( int fd );
|
||||
|
||||
@@ -374,9 +374,21 @@ tr_peerIoNew( tr_session * session,
|
||||
assert( tr_isBool( isSeed ) );
|
||||
assert( tr_amInEventThread( session ) );
|
||||
|
||||
if( socket >= 0 )
|
||||
if( socket >= 0 ) {
|
||||
tr_netSetTOS( socket, session->peerSocketTOS );
|
||||
|
||||
if( session->peer_congestion_algorithm &&
|
||||
session->peer_congestion_algorithm[0] ) {
|
||||
int rc;
|
||||
rc = tr_netSetCongestionControl( socket,
|
||||
session->peer_congestion_algorithm );
|
||||
if(rc < 0) {
|
||||
tr_ninf( "Net",
|
||||
"Couldn't set congestion control algorithm: %s\n",
|
||||
strerror(errno));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
io = tr_new0( tr_peerIo, 1 );
|
||||
io->magicNumber = MAGIC_NUMBER;
|
||||
io->refCount = 1;
|
||||
@@ -646,6 +658,18 @@ tr_peerIoReconnect( tr_peerIo * io )
|
||||
if( io->socket >= 0 )
|
||||
{
|
||||
tr_netSetTOS( io->socket, session->peerSocketTOS );
|
||||
if( session->peer_congestion_algorithm &&
|
||||
session->peer_congestion_algorithm[0] ) {
|
||||
int rc;
|
||||
rc = tr_netSetCongestionControl( io->socket,
|
||||
session->peer_congestion_algorithm );
|
||||
if(rc < 0) {
|
||||
tr_ninf( "Net",
|
||||
"Couldn't set congestion control algorithm: %s\n",
|
||||
strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -322,6 +322,8 @@ tr_sessionGetSettings( tr_session * s, struct tr_benc * d )
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_PORT_RANDOM_LOW, s->randomPortLow );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_PORT_RANDOM_HIGH, s->randomPortHigh );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_SOCKET_TOS, s->peerSocketTOS );
|
||||
if(s->peer_congestion_algorithm && s->peer_congestion_algorithm[0])
|
||||
tr_bencDictAddStr ( d, TR_PREFS_KEY_PEER_CONGESTION_ALGORITHM, s->peer_congestion_algorithm );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_PEX_ENABLED, s->isPexEnabled );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_PORT_FORWARDING, tr_sessionIsPortForwardingEnabled( s ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_PREALLOCATION, s->preallocationMode );
|
||||
@@ -668,6 +670,8 @@ sessionSetImpl( void * vdata )
|
||||
tr_sessionSetEncryption( session, i );
|
||||
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_PEER_SOCKET_TOS, &i ) )
|
||||
session->peerSocketTOS = i;
|
||||
if( tr_bencDictFindStr( settings, TR_PREFS_KEY_PEER_CONGESTION_ALGORITHM, &str ) )
|
||||
session->peer_congestion_algorithm = tr_strdup(str);
|
||||
if( tr_bencDictFindBool( settings, TR_PREFS_KEY_BLOCKLIST_ENABLED, &boolVal ) )
|
||||
tr_blocklistSetEnabled( session, boolVal );
|
||||
if( tr_bencDictFindBool( settings, TR_PREFS_KEY_START, &boolVal ) )
|
||||
@@ -1656,6 +1660,7 @@ tr_sessionClose( tr_session * session )
|
||||
tr_free( session->proxy );
|
||||
tr_free( session->proxyUsername );
|
||||
tr_free( session->proxyPassword );
|
||||
tr_free( session->peer_congestion_algorithm );
|
||||
tr_free( session );
|
||||
}
|
||||
|
||||
|
||||
@@ -124,6 +124,7 @@ struct tr_session
|
||||
|
||||
int proxyPort;
|
||||
int peerSocketTOS;
|
||||
char * peer_congestion_algorithm;
|
||||
|
||||
int torrentCount;
|
||||
tr_torrent * torrentList;
|
||||
|
||||
@@ -178,6 +178,7 @@ const char* tr_getDefaultDownloadDir( void );
|
||||
#define TR_PREFS_KEY_PEER_PORT_RANDOM_LOW "peer-port-random-low"
|
||||
#define TR_PREFS_KEY_PEER_PORT_RANDOM_HIGH "peer-port-random-high"
|
||||
#define TR_PREFS_KEY_PEER_SOCKET_TOS "peer-socket-tos"
|
||||
#define TR_PREFS_KEY_PEER_CONGESTION_ALGORITHM "peer-congestion-algorithm"
|
||||
#define TR_PREFS_KEY_PEX_ENABLED "pex-enabled"
|
||||
#define TR_PREFS_KEY_PORT_FORWARDING "port-forwarding-enabled"
|
||||
#define TR_PREFS_KEY_PROXY_AUTH_ENABLED "proxy-auth-enabled"
|
||||
|
||||
Reference in New Issue
Block a user