Changeset 12141


Ignore:
Timestamp:
Mar 13, 2011, 12:18:11 AM (11 years ago)
Author:
jordan
Message:

(trunk libT) #117 "UDP tracker protocol support" -- working implementation; needs testing and valgrinding and review.

Location:
trunk/libtransmission
Files:
1 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/Makefile.am

    r12127 r12141  
    2020    announcer.c \
    2121    announcer-http.c \
     22    announcer-udp.c \
    2223    bandwidth.c \
    2324    bencode.c \
  • trunk/libtransmission/announcer-common.h

    r12134 r12141  
    106106                             void                     * user_data );
    107107
     108void tr_tracker_udp_scrape( tr_session               * session,
     109                            const tr_scrape_request  * req,
     110                            tr_scrape_response_func    response_func,
     111                            void                     * user_data );
     112
    108113/***
    109114****  ANNOUNCE
     
    126131    tr_bool partial_seed;
    127132
     133    /* the port we listen for incoming peers on */
     134    int port;
     135
    128136    /* per-session key */
    129137    int key;
     
    226234                               void                       * user_data );
    227235
     236void tr_tracker_udp_announce( tr_session                 * session,
     237                              const tr_announce_request  * req,
     238                              tr_announce_response_func    response_func,
     239                              void                       * user_data );
    228240
    229241#endif /* _TR_ANNOUNCER_COMMON_H_ */
  • trunk/libtransmission/announcer-http.c

    r12135 r12141  
    7474                              escaped_info_hash,
    7575                              PEER_ID_LEN, PEER_ID_LEN, req->peer_id,
    76                               (int)tr_sessionGetPublicPeerPort( session ),
     76                              req->port,
    7777                              req->up,
    7878                              req->down,
  • trunk/libtransmission/announcer.c

    r12134 r12141  
    807807{
    808808    tr_announce_request * req = tr_new0( tr_announce_request, 1 );
     809    req->port = tr_sessionGetPublicPeerPort( announcer->session );
    809810    req->url = tr_strdup( tier->currentTracker->announce );
    810811    req->tracker_id_str = tr_strdup( tier->currentTracker->tracker_id_str );
     
    10461047    if( !memcmp( request->url, "http", 4 ) )
    10471048        tr_tracker_http_announce( session, request, callback, callback_data );
     1049    else if( !memcmp( request->url, "udp://", 6 ) )
     1050        tr_tracker_udp_announce( session, request, callback, callback_data );
    10481051    else
    1049         abort();//fprintf( stderr, "can't handle [%s] yet\n", request->url );
     1052        tr_err( "Unsupported ur: %s", request->url );
    10501053
    10511054    tr_free( request->tracker_id_str );
     
    12171220    if( !memcmp( request->url, "http", 4 ) )
    12181221        tr_tracker_http_scrape( session, request, callback, callback_data );
     1222    else if( !memcmp( request->url, "udp://", 6 ) )
     1223        tr_tracker_udp_scrape( session, request, callback, callback_data );
    12191224    else
    1220         abort();//fprintf( stderr, "can't handle [%s] yet\n", request->url );
     1225        tr_err( "Unsupported ur: %s", request->url );
    12211226}
    12221227
  • trunk/libtransmission/peer-io.c

    r12096 r12141  
    10701070}
    10711071
     1072void
     1073evbuffer_add_uint64( struct evbuffer * outbuf, uint64_t addme_hll )
     1074{
     1075    const uint64_t nll = tr_htonll( addme_hll );
     1076    evbuffer_add( outbuf, &nll, sizeof( nll ) );
     1077}
     1078
    10721079/***
    10731080****
  • trunk/libtransmission/peer-io.h

    r11945 r12141  
    292292void evbuffer_add_uint16( struct evbuffer * outbuf, uint16_t hs );
    293293void evbuffer_add_uint32( struct evbuffer * outbuf, uint32_t hl );
     294void evbuffer_add_uint64( struct evbuffer * outbuf, uint64_t hll );
     295
     296static inline void
     297evbuffer_add_hton_16( struct evbuffer * buf, uint16_t val )
     298{
     299   evbuffer_add_uint16( buf, val );
     300}
     301static inline void
     302evbuffer_add_hton_32( struct evbuffer * buf, uint32_t val )
     303{
     304   evbuffer_add_uint32( buf, val );
     305}
     306static inline void
     307evbuffer_add_hton_64( struct evbuffer * buf, uint64_t val )
     308{
     309   evbuffer_add_uint64( buf, val );
     310}
    294311
    295312void tr_peerIoReadBytes( tr_peerIo        * io,
  • trunk/libtransmission/ptrarray.h

    r11709 r12141  
    6868void tr_ptrArrayErase( tr_ptrArray * t, int begin, int end );
    6969
    70 
     70static inline void tr_ptrArrayRemove( tr_ptrArray * t, int pos )
     71{
     72    tr_ptrArrayErase( t, pos, pos+1 );
     73}
    7174
    7275/** @brief Peek at the array pointer and its size, for easy iteration */
  • trunk/libtransmission/session.h

    r12121 r12141  
    4242
    4343struct event_base;
     44struct evdns_base;
     45
    4446struct tr_address;
    4547struct tr_announcer;
     48struct tr_announcer_udp;
    4649struct tr_bandwidth;
    4750struct tr_bindsockets;
     
    125128
    126129    struct event_base          * event_base;
     130    struct evdns_base          * evdns_base;
    127131    struct tr_event_handle     * events;
    128132
     
    187191
    188192    struct tr_announcer        * announcer;
     193    struct tr_announcer_udp    * announcer_udp;
    189194
    190195    tr_benc                    * metainfoLookup;
  • trunk/libtransmission/tr-udp.c

    r12096 r12141  
    206206                  (struct sockaddr*)&from, &fromlen);
    207207    if(rc > 0) {
    208         if( buf[0] == 'd' ) {
     208        if( tau_handle_message( ss, buf, rc ) ) {
     209            tr_ndbg("UDP", "Received UDP Tracker packet");
     210        }
     211        else if( buf[0] == 'd' ) {
    209212            /* DHT packet. */
    210213            buf[rc] = '\0';
  • trunk/libtransmission/tr-udp.h

    r11956 r12141  
    2222*/
    2323
     24#ifndef TR_UDP_H
     25#define TR_UDP_H
     26
    2427#ifndef __TRANSMISSION__
    2528 #error only libtransmission should #include this header.
     
    2932void tr_udpUninit( tr_session * );
    3033void tr_udpSetSocketBuffers(tr_session *);
     34
     35tr_bool tau_handle_message( tr_session * session, const uint8_t  * msg, size_t msglen );
     36
     37#endif /* #ifndef TR_UDP_H */
  • trunk/libtransmission/trevent.c

    r11709 r12141  
    1919#include <signal.h>
    2020
     21#include <event2/dns.h>
    2122#include <event2/event.h>
    2223
     
    224225{
    225226    struct event_base * base;
     227    struct evdns_base * evdns_base;
    226228    tr_event_handle * eh = veh;
    227229
     
    231233#endif
    232234
     235    /* create the libevent bases */
    233236    base = event_base_new( );
     237    evdns_base = evdns_base_new( base, TRUE );
     238
     239    /* set the struct's fields */
    234240    eh->base = base;
    235241    eh->session->event_base = base;
     242    eh->session->evdns_base = evdns_base;
    236243    eh->session->events = eh;
    237244
     
    247254    /* shut down the thread */
    248255    tr_lockFree( eh->lock );
     256    evdns_base_free( evdns_base, FALSE );
    249257    event_base_free( base );
    250258    eh->session->events = NULL;
  • trunk/libtransmission/utils.c

    r12077 r12141  
    10291029         && !tr_urlParse( url, len, &scheme, NULL, NULL, NULL )
    10301030         && ( scheme != NULL )
    1031          && ( !strcmp(scheme,"http") || !strcmp(scheme,"https") );
     1031         && ( !strcmp(scheme,"http") || !strcmp(scheme,"https") || !strcmp(scheme,"udp") );
    10321032
    10331033    tr_free( scheme );
     
    16521652/***
    16531653****
     1654***/
     1655
     1656uint64_t
     1657tr_ntohll( uint64_t v )
     1658{
     1659#ifdef HAVE_NTOHLL
     1660    return ntohll( v );
     1661#else
     1662    union { unsigned long lv[2]; unsigned long long llv; } u;
     1663    u.lv[0] = ntohl(v >> 32);
     1664    u.lv[1] = ntohl(v & 0xFFFFFFFFULL);
     1665    return u.llv;
     1666#endif
     1667}
     1668
     1669uint64_t
     1670tr_htonll( uint64_t v )
     1671{
     1672#ifdef HAVE_HTONLL
     1673    return htonll( v );
     1674#else
     1675    union { unsigned long lv[2]; unsigned long long llv; } u;
     1676    u.lv[0] = htonl(v >> 32);
     1677    u.lv[1] = htonl(v & 0xFFFFFFFFULL);
     1678    return u.llv;
     1679#endif
     1680}
     1681
     1682/***
     1683****
    16541684****
    16551685****
  • trunk/libtransmission/utils.h

    r11881 r12141  
    563563char* tr_realpath( const char *path, char * resolved_path );
    564564
     565/** @brief Portability wrapper for htonll() that uses the system implementation if available */
     566uint64_t tr_htonll( uint64_t );
     567
     568/** @brief Portability wrapper for htonll() that uses the system implementation if available */
     569uint64_t tr_ntohll( uint64_t );
     570
    565571/***
    566572****
Note: See TracChangeset for help on using the changeset viewer.