#include <event2/event.h>
#include <event2/bufferevent.h>
+#include "utp.h"
#include "transmission.h"
#include "session.h"
const uint8_t * torrentHash,
tr_bool isIncoming,
tr_bool isSeed,
- int socket )
+ int socket,
+ struct UTPSocket * utp_socket)
{
tr_peerIo * io;
assert( tr_isBool( isIncoming ) );
assert( tr_isBool( isSeed ) );
assert( tr_amInEventThread( session ) );
+ assert( (socket < 0) == (utp_socket != NULL) );
if( socket >= 0 ) {
tr_netSetTOS( socket, session->peerSocketTOS );
io->isSeed = isSeed;
io->port = port;
io->socket = socket;
+ io->utp_socket = utp_socket;
io->isIncoming = isIncoming != 0;
io->timeCreated = tr_time( );
io->inbuf = evbuffer_new( );
io->outbuf = evbuffer_new( );
- io->event_read = event_new( session->event_base, io->socket, EV_READ, event_read_cb, io );
- io->event_write = event_new( session->event_base, io->socket, EV_WRITE, event_write_cb, io );
tr_bandwidthConstruct( &io->bandwidth, session, parent );
tr_bandwidthSetPeer( &io->bandwidth, io );
dbgmsg( io, "bandwidth is %p; its parent is %p", &io->bandwidth, parent );
+ if( io->socket >= 0 ) {
+ io->event_read = event_new( session->event_base,
+ io->socket, EV_READ, event_read_cb, io );
+ io->event_write = event_new( session->event_base,
+ io->socket, EV_WRITE, event_write_cb, io );
+ }
+
return io;
}
tr_bandwidth * parent,
const tr_address * addr,
tr_port port,
- int fd )
+ int fd,
+ struct UTPSocket * utp_socket )
{
assert( session );
assert( tr_isAddress( addr ) );
- assert( fd >= 0 );
- return tr_peerIoNew( session, parent, addr, port, NULL, TRUE, FALSE, fd );
+ return tr_peerIoNew( session, parent, addr, port, NULL, TRUE, FALSE,
+ fd, utp_socket );
}
tr_peerIo*
dbgmsg( NULL, "tr_netOpenPeerSocket returned fd %d", fd );
return fd < 0 ? NULL
- : tr_peerIoNew( session, parent, addr, port, torrentHash, FALSE, isSeed, fd );
+ : tr_peerIoNew( session, parent, addr, port,
+ torrentHash, FALSE, isSeed, fd, NULL );
}
/***
assert( tr_amInEventThread( io->session ) );
assert( io->session != NULL );
assert( io->session->events != NULL );
- assert( event_initialized( io->event_read ) );
- assert( event_initialized( io->event_write ) );
if( io->socket < 0 )
return;
+ assert( io->session->events != NULL );
+ assert( event_initialized( io->event_read ) );
+ assert( event_initialized( io->event_write ) );
+
if( ( event & EV_READ ) && ! ( io->pendingEvents & EV_READ ) )
{
dbgmsg( io, "enabling libevent ready-to-read polling" );
{
assert( tr_amInEventThread( io->session ) );
assert( io->session != NULL );
+
+ if( io->socket < 0 )
+ return;
+
assert( io->session->events != NULL );
assert( event_initialized( io->event_read ) );
assert( event_initialized( io->event_write ) );
tr_bandwidthDestruct( &io->bandwidth );
evbuffer_free( io->outbuf );
evbuffer_free( io->inbuf );
- tr_netClose( io->session, io->socket );
+ if( io->socket >= 0 )
+ tr_netClose( io->session, io->socket );
+ if( io->utp_socket != NULL )
+ UTP_Close( io->utp_socket );
tr_cryptoFree( io->crypto );
tr_list_free( &io->outbuf_datatypes, tr_free );
pendingEvents = io->pendingEvents;
event_disable( io, EV_READ | EV_WRITE );
- if( io->socket >= 0 )
+ if( io->socket >= 0 ) {
tr_netClose( session, io->socket );
+ io->socket = -1;
+ }
+ if( io->utp_socket != NULL ) {
+ UTP_Close(io->utp_socket);
+ io->utp_socket = NULL;
+ }
event_free( io->event_read );
event_free( io->event_write );
#include <stdlib.h> /* qsort */
#include <event2/event.h>
+#include "utp.h"
#include "transmission.h"
#include "announcer.h"
tr_peerMgrAddIncoming( tr_peerMgr * manager,
tr_address * addr,
tr_port port,
- int socket )
+ int socket,
+ struct UTPSocket * utp_socket )
{
tr_session * session;
if( tr_sessionIsAddressBlocked( session, addr ) )
{
tr_dbg( "Banned IP address \"%s\" tried to connect to us", tr_ntop_non_ts( addr ) );
- tr_netClose( session, socket );
+ if(socket >= 0)
+ tr_netClose( session, socket );
+ else
+ UTP_Close( utp_socket );
}
else if( getExistingHandshake( &manager->incomingHandshakes, addr ) )
{
- tr_netClose( session, socket );
+ if(socket >= 0)
+ tr_netClose( session, socket );
+ else
+ UTP_Close( utp_socket );
}
else /* we don't have a connection to them yet... */
{
tr_peerIo * io;
tr_handshake * handshake;
- io = tr_peerIoNewIncoming( session, session->bandwidth, addr, port, socket );
+ io = tr_peerIoNewIncoming( session, session->bandwidth, addr, port, socket, utp_socket );
handshake = tr_handshakeNew( io,
session->encryptionMode,
stat->pendingReqsToClient = peer->pendingReqsToClient;
pch = stat->flagStr;
+ if( peer->io->utp_socket != NULL) *pch++ = 'T';
if( t->optimistic == peer ) *pch++ = 'O';
if( stat->isDownloadingFrom ) *pch++ = 'D';
else if( stat->clientIsInterested ) *pch++ = 'd';