mirror of
https://github.com/transmission/transmission
synced 2024-12-27 01:57:52 +00:00
implement bandwidth limiting for uploads to uTP peers
This commit is contained in:
parent
3c56dbea2a
commit
f6a85cb16b
1 changed files with 55 additions and 40 deletions
|
@ -395,6 +395,7 @@ utp_on_write(void *closure, unsigned char *buf, size_t buflen)
|
|||
assert( tr_isPeerIo( io ) );
|
||||
|
||||
rc = evbuffer_remove( io->outbuf, buf, buflen );
|
||||
assert( rc == (int)buflen ); /* if this fails, we've corrupted our bookkeeping somewhere */
|
||||
if( rc < (long)buflen ) {
|
||||
tr_nerr( "UTP", "Short write: %d < %ld", rc, (long)buflen);
|
||||
}
|
||||
|
@ -421,9 +422,7 @@ utp_on_state_change(void *closure, int state)
|
|||
assert( tr_isPeerIo( io ) );
|
||||
|
||||
if( state == UTP_STATE_CONNECT || state == UTP_STATE_WRITABLE ) {
|
||||
size_t count = evbuffer_get_length( io->outbuf );
|
||||
if( count > 0 )
|
||||
UTP_Write( io->utp_socket, count );
|
||||
/* noop */
|
||||
} else if( state == UTP_STATE_EOF ) {
|
||||
if( io->gotError )
|
||||
io->gotError( io, BEV_EVENT_EOF, io->userData );
|
||||
|
@ -448,7 +447,7 @@ utp_on_error(void *closure, int errcode)
|
|||
}
|
||||
|
||||
static void
|
||||
utp_on_overhead(void *closure, bool send, size_t count, int type)
|
||||
utp_on_overhead(void *closure, bool send, size_t count, int type UNUSED)
|
||||
{
|
||||
tr_peerIo *io = (tr_peerIo *)closure;
|
||||
assert( tr_isPeerIo( io ) );
|
||||
|
@ -1010,8 +1009,6 @@ tr_peerIoWriteBuf( tr_peerIo * io, struct evbuffer * buf, tr_bool isPieceData )
|
|||
maybeEncryptBuffer( io, buf );
|
||||
evbuffer_add_buffer( io->outbuf, buf );
|
||||
addDatatype( io, byteCount, isPieceData );
|
||||
if( io->utp_socket )
|
||||
UTP_Write( io->utp_socket, byteCount );
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1120,6 +1117,13 @@ tr_peerIoTryRead( tr_peerIo * io, size_t howmuch )
|
|||
int res = 0;
|
||||
|
||||
if(( howmuch = tr_bandwidthClamp( &io->bandwidth, TR_DOWN, howmuch )))
|
||||
{
|
||||
if( io->utp_socket != NULL ) /* utp peer connection */
|
||||
{
|
||||
/* currently a noop. tr-utp's call to UTP_CheckTimeouts()
|
||||
* keeps the pump primed, so no need to call UTP_RBDrained() */
|
||||
}
|
||||
else /* tcp peer connection */
|
||||
{
|
||||
int e;
|
||||
|
||||
|
@ -1143,6 +1147,7 @@ tr_peerIoTryRead( tr_peerIo * io, size_t howmuch )
|
|||
io->gotError( io, what, io->userData );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -1153,8 +1158,17 @@ tr_peerIoTryWrite( tr_peerIo * io, size_t howmuch )
|
|||
int n = 0;
|
||||
|
||||
if(( howmuch = tr_bandwidthClamp( &io->bandwidth, TR_UP, howmuch )))
|
||||
{
|
||||
if( io->utp_socket != NULL ) /* utp peer connection */
|
||||
{
|
||||
const size_t old_len = evbuffer_get_length( io->outbuf );
|
||||
UTP_Write( io->utp_socket, howmuch );
|
||||
n = old_len - evbuffer_get_length( io->outbuf );
|
||||
}
|
||||
else
|
||||
{
|
||||
int e;
|
||||
|
||||
EVUTIL_SET_SOCKET_ERROR( 0 );
|
||||
n = tr_evbuffer_write( io, io->socket, howmuch );
|
||||
e = EVUTIL_SOCKET_ERROR( );
|
||||
|
@ -1174,6 +1188,7 @@ tr_peerIoTryWrite( tr_peerIo * io, size_t howmuch )
|
|||
io->gotError( io, what, io->userData );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue