Implement outgoing uTP connections.

This commit is contained in:
Juliusz Chroboczek 2011-02-18 00:36:19 +00:00
parent 456dbdd935
commit 88f4eac81f
5 changed files with 45 additions and 10 deletions

View File

@ -45,11 +45,13 @@
#include <unistd.h>
#include <event2/util.h>
#include <libutp/utp.h>
#include "transmission.h"
#include "fdlimit.h"
#include "natpmp.h"
#include "net.h"
#include "tr-utp.h"
#include "peer-io.h"
#include "platform.h"
#include "session.h"
@ -349,6 +351,20 @@ tr_netOpenPeerSocket( tr_session * session,
return s;
}
struct UTPSocket *
tr_netOpenPeerUTPSocket( tr_session * session,
const tr_address * addr,
tr_port port,
tr_bool clientIsSeed UNUSED )
{
struct sockaddr_storage ss;
socklen_t sslen;
sslen = setup_sockaddr( addr, port, &ss );
return UTP_Create( tr_utpSendTo, (void*)session,
(struct sockaddr*)&ss, sslen );
}
static int
tr_netBindTCPImpl( const tr_address * addr, tr_port port, tr_bool suppressMsgs, int * errOut )
{

View File

@ -102,6 +102,12 @@ int tr_netOpenPeerSocket( tr_session * session,
tr_port port,
tr_bool clientIsSeed );
struct UTPSocket *
tr_netOpenPeerUTPSocket( tr_session * session,
const tr_address * addr,
tr_port port,
tr_bool clientIsSeed);
int tr_netBindTCP( const tr_address * addr,
tr_port port,
tr_bool suppressMsgs );

View File

@ -588,7 +588,8 @@ tr_peerIoNew( tr_session * session,
UTP_SetCallbacks( utp_socket,
&utp_function_table,
io );
if( !isIncoming )
UTP_Connect( utp_socket );
}
io->write_enabled = 1;
@ -618,20 +619,29 @@ tr_peerIoNewOutgoing( tr_session * session,
const tr_address * addr,
tr_port port,
const uint8_t * torrentHash,
tr_bool isSeed )
tr_bool isSeed,
tr_bool utp )
{
int fd;
int fd = -1;
struct UTPSocket *utp_socket = NULL;
assert( session );
assert( tr_isAddress( addr ) );
assert( torrentHash );
fd = tr_netOpenPeerSocket( session, addr, port, isSeed );
dbgmsg( NULL, "tr_netOpenPeerSocket returned fd %d", fd );
if( !utp ) {
fd = tr_netOpenPeerSocket( session, addr, port, isSeed );
dbgmsg( NULL, "tr_netOpenPeerSocket returned fd %d", fd );
} else {
utp_socket =
tr_netOpenPeerUTPSocket( session, addr, port, isSeed );
}
return fd < 0 ? NULL
: tr_peerIoNew( session, parent, addr, port,
torrentHash, FALSE, isSeed, fd, NULL );
if( fd < 0 && utp_socket == NULL )
return NULL;
return tr_peerIoNew( session, parent, addr, port,
torrentHash, FALSE, isSeed, fd, utp_socket );
}
/***

View File

@ -123,7 +123,9 @@ tr_peerIo* tr_peerIoNewOutgoing( tr_session * session,
const struct tr_address * addr,
tr_port port,
const uint8_t * torrentHash,
tr_bool isSeed );
tr_bool isSeed,
tr_bool utp );
tr_peerIo* tr_peerIoNewIncoming( tr_session * session,
struct tr_bandwidth * parent,

View File

@ -3839,7 +3839,8 @@ initiateConnection( tr_peerMgr * mgr, Torrent * t, struct peer_atom * atom )
&atom->addr,
atom->port,
t->tor->info.hash,
t->tor->completeness == TR_SEED );
t->tor->completeness == TR_SEED,
0 );
if( io == NULL )
{