Changeset 11903


Ignore:
Timestamp:
Feb 18, 2011, 12:23:51 AM (12 years ago)
Author:
jch
Message:

Modify peer-io to work with UTP sockets.

This is not supposed to work yet -- it just adds new fields to the data
structures to get the UTP code to compile.

Location:
trunk/libtransmission
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-io.c

    r11857 r11903  
    2626#include <event2/event.h>
    2727#include <event2/bufferevent.h>
     28#include "utp.h"
    2829
    2930#include "transmission.h"
     
    368369              tr_bool            isIncoming,
    369370              tr_bool            isSeed,
    370               int                socket )
     371              int                socket,
     372              struct UTPSocket * utp_socket)
    371373{
    372374    tr_peerIo * io;
     
    377379    assert( tr_isBool( isSeed ) );
    378380    assert( tr_amInEventThread( session ) );
     381    assert( (socket < 0) == (utp_socket != NULL) );
    379382
    380383    if( socket >= 0 ) {
     
    392395    io->port = port;
    393396    io->socket = socket;
     397    io->utp_socket = utp_socket;
    394398    io->isIncoming = isIncoming != 0;
    395399    io->timeCreated = tr_time( );
    396400    io->inbuf = evbuffer_new( );
    397401    io->outbuf = evbuffer_new( );
    398     io->event_read = event_new( session->event_base, io->socket, EV_READ, event_read_cb, io );
    399     io->event_write = event_new( session->event_base, io->socket, EV_WRITE, event_write_cb, io );
    400402    tr_bandwidthConstruct( &io->bandwidth, session, parent );
    401403    tr_bandwidthSetPeer( &io->bandwidth, io );
    402404    dbgmsg( io, "bandwidth is %p; its parent is %p", &io->bandwidth, parent );
     405
     406    if( io->socket >= 0 ) {
     407        io->event_read = event_new( session->event_base,
     408                                    io->socket, EV_READ, event_read_cb, io );
     409        io->event_write = event_new( session->event_base,
     410                                     io->socket, EV_WRITE, event_write_cb, io );
     411    }
    403412
    404413    return io;
     
    410419                      const tr_address  * addr,
    411420                      tr_port             port,
    412                       int                 fd )
     421                      int                 fd,
     422                      struct UTPSocket  * utp_socket )
    413423{
    414424    assert( session );
    415425    assert( tr_isAddress( addr ) );
    416     assert( fd >= 0 );
    417 
    418     return tr_peerIoNew( session, parent, addr, port, NULL, TRUE, FALSE, fd );
     426
     427    return tr_peerIoNew( session, parent, addr, port, NULL, TRUE, FALSE,
     428                         fd, utp_socket );
    419429}
    420430
     
    437447
    438448    return fd < 0 ? NULL
    439                   : tr_peerIoNew( session, parent, addr, port, torrentHash, FALSE, isSeed, fd );
     449                  : tr_peerIoNew( session, parent, addr, port,
     450                                  torrentHash, FALSE, isSeed, fd, NULL );
    440451}
    441452
     
    450461    assert( io->session != NULL );
    451462    assert( io->session->events != NULL );
     463
     464    if( io->socket < 0 )
     465        return;
     466
     467    assert( io->session->events != NULL );
    452468    assert( event_initialized( io->event_read ) );
    453469    assert( event_initialized( io->event_write ) );
    454 
    455     if( io->socket < 0 )
    456         return;
    457470
    458471    if( ( event & EV_READ ) && ! ( io->pendingEvents & EV_READ ) )
     
    476489    assert( tr_amInEventThread( io->session ) );
    477490    assert( io->session != NULL );
     491
     492    if( io->socket < 0 )
     493        return;
     494
    478495    assert( io->session->events != NULL );
    479496    assert( event_initialized( io->event_read ) );
     
    533550    evbuffer_free( io->outbuf );
    534551    evbuffer_free( io->inbuf );
    535     tr_netClose( io->session, io->socket );
     552    if( io->socket >= 0 )
     553        tr_netClose( io->session, io->socket );
     554    if( io->utp_socket != NULL )
     555        UTP_Close( io->utp_socket );
    536556    tr_cryptoFree( io->crypto );
    537557    tr_list_free( &io->outbuf_datatypes, tr_free );
     
    640660    event_disable( io, EV_READ | EV_WRITE );
    641661
    642     if( io->socket >= 0 )
     662    if( io->socket >= 0 ) {
    643663        tr_netClose( session, io->socket );
     664        io->socket = -1;
     665    }
     666    if( io->utp_socket != NULL ) {
     667        UTP_Close(io->utp_socket);
     668        io->utp_socket = NULL;
     669    }
    644670
    645671    event_free( io->event_read );
  • trunk/libtransmission/peer-io.h

    r11857 r11903  
    8484    tr_port               port;
    8585    int                   socket;
     86    struct UTPSocket      *utp_socket;
    8687
    8788    int                   refCount;
     
    126127                                  const struct tr_address * addr,
    127128                                  tr_port                   port,
    128                                   int                       socket );
     129                                  int                       socket,
     130                                  struct UTPSocket *        utp_socket );
    129131
    130132void tr_peerIoRefImpl           ( const char              * file,
  • trunk/libtransmission/peer-mgr.c

    r11900 r11903  
    1818
    1919#include <event2/event.h>
     20#include "utp.h"
    2021
    2122#include "transmission.h"
     
    20082009                       tr_address * addr,
    20092010                       tr_port      port,
    2010                        int          socket )
     2011                       int          socket,
     2012                       struct UTPSocket * utp_socket )
    20112013{
    20122014    tr_session * session;
     
    20202022    {
    20212023        tr_dbg( "Banned IP address \"%s\" tried to connect to us", tr_ntop_non_ts( addr ) );
    2022         tr_netClose( session, socket );
     2024        if(socket >= 0)
     2025            tr_netClose( session, socket );
     2026        else
     2027            UTP_Close( utp_socket );
    20232028    }
    20242029    else if( getExistingHandshake( &manager->incomingHandshakes, addr ) )
    20252030    {
    2026         tr_netClose( session, socket );
     2031        if(socket >= 0)
     2032            tr_netClose( session, socket );
     2033        else
     2034            UTP_Close( utp_socket );
    20272035    }
    20282036    else /* we don't have a connection to them yet... */
     
    20312039        tr_handshake * handshake;
    20322040
    2033         io = tr_peerIoNewIncoming( session, session->bandwidth, addr, port, socket );
     2041        io = tr_peerIoNewIncoming( session, session->bandwidth, addr, port, socket, utp_socket );
    20342042
    20352043        handshake = tr_handshakeNew( io,
     
    26132621
    26142622        pch = stat->flagStr;
     2623        if( peer->io->utp_socket != NULL) *pch++ = 'T';
    26152624        if( t->optimistic == peer ) *pch++ = 'O';
    26162625        if( stat->isDownloadingFrom ) *pch++ = 'D';
  • trunk/libtransmission/peer-mgr.h

    r11709 r11903  
    3535 */
    3636
     37struct UTPSocket;
    3738struct tr_peer_stat;
    3839struct tr_torrent;
     
    164165                            tr_address  * addr,
    165166                            tr_port       port,
    166                             int           socket );
     167                            int           socket,
     168                            struct UTPSocket *utp_socket );
    167169
    168170tr_pex * tr_peerMgrCompactToPex( const void    * compact,
  • trunk/libtransmission/session.c

    r11800 r11903  
    195195        tr_deepLog( __FILE__, __LINE__, NULL, "new incoming connection %d (%s)",
    196196                   clientSocket, tr_peerIoAddrStr( &clientAddr, clientPort ) );
    197         tr_peerMgrAddIncoming( session->peerMgr, &clientAddr, clientPort, clientSocket );
     197        tr_peerMgrAddIncoming( session->peerMgr, &clientAddr, clientPort,
     198                               clientSocket, NULL );
    198199    }
    199200}
Note: See TracChangeset for help on using the changeset viewer.