Changeset 12180


Ignore:
Timestamp:
Mar 17, 2011, 4:16:19 AM (11 years ago)
Author:
jordan
Message:

(trunk libT) #117 "UDP tracker protocol suppoort" -- in case the tracker gives an error message in response to a connection response, store the error message in the scrape/announce response structs' errmsg fields.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/announcer-udp.c

    r12177 r12180  
    5252{
    5353    int sockfd;
    54 
    55     tau_sockaddr_setport( ai->ai_addr, port );
    5654   
    5755    if( ai->ai_addr->sa_family == AF_INET )
     
    6765    }
    6866
     67    tau_sockaddr_setport( ai->ai_addr, port );
    6968    return sendto( sockfd, buf, buflen, 0, ai->ai_addr, ai->ai_addrlen );
    7069}
     
    299298    switch( e )
    300299    {
    301         case TR_ANNOUNCE_EVENT_COMPLETED:  return TAU_ANNOUNCE_EVENT_COMPLETED;
    302         case TR_ANNOUNCE_EVENT_STARTED:    return TAU_ANNOUNCE_EVENT_STARTED;
    303         case TR_ANNOUNCE_EVENT_STOPPED:    return TAU_ANNOUNCE_EVENT_STOPPED;
    304         default:                           return TAU_ANNOUNCE_EVENT_NONE;
     300        case TR_ANNOUNCE_EVENT_COMPLETED: return TAU_ANNOUNCE_EVENT_COMPLETED;
     301        case TR_ANNOUNCE_EVENT_STARTED:   return TAU_ANNOUNCE_EVENT_STARTED;
     302        case TR_ANNOUNCE_EVENT_STOPPED:   return TAU_ANNOUNCE_EVENT_STOPPED;
     303        default:                          return TAU_ANNOUNCE_EVENT_NONE;
    305304    }
    306305}
     
    347346tau_announce_request_free( struct tau_announce_request * req )
    348347{
    349     tr_free( req->payload );
    350348    tr_free( req->response.tracker_id_str );
    351349    tr_free( req->response.warning );
     
    353351    tr_free( req->response.pex6 );
    354352    tr_free( req->response.pex );
     353    tr_free( req->payload );
    355354    tr_free( req );
    356355}
     
    591590            tau_tracker_send_request( tracker, req->payload, req->payload_len );
    592591        }
    593         else if( req->created_at && ( req->created_at + TAU_REQUEST_TTL < now ) ) {
     592        else if( req->created_at + TAU_REQUEST_TTL < now ) {
    594593            tau_announce_request_fail( tracker->session, req, FALSE, TRUE, NULL );
    595594            tau_announce_request_free( req );
     
    610609            tau_tracker_send_request( tracker, req->payload, req->payload_len );
    611610        }
    612         else if( req->created_at && ( req->created_at + TAU_REQUEST_TTL < now ) ) {
     611        else if( req->created_at + TAU_REQUEST_TTL < now ) {
    613612            tau_scrape_request_fail( tracker->session, req, FALSE, TRUE, NULL );
    614613            tau_scrape_request_free( req );
     
    639638    else
    640639    {
    641         const char * errmsg = _( "Connection refused" );
    642         assert( action == TAU_ACTION_ERROR );
     640        char * errmsg;
     641        const size_t buflen = evbuffer_get_length( buf );
     642
     643        if( ( action == TAU_ACTION_ERROR ) && ( buflen > 0 ) )
     644            errmsg = tr_strndup( evbuffer_pullup( buf, -1 ), buflen );
     645        else
     646            errmsg = tr_strdup( _( "Connection refused" ) );
     647
    643648        dbgmsg( tracker->key, "%s", errmsg );
    644649        tau_tracker_fail_all( tracker, TRUE, FALSE, errmsg );
     650        tr_free( errmsg );
    645651    }
    646652
     
    736742}
    737743
     744/* @brief process an incoming udp message if it's a tracker response.
     745 * @return true if msg was a tracker response; false otherwise */
    738746tr_bool
    739 tau_handle_message( tr_session     * session,
    740                     const uint8_t  * msg,
    741                     size_t           msglen )
     747tau_handle_message( tr_session * session, const uint8_t * msg, size_t msglen )
    742748{
    743749    int i;
     
    767773    tau = session->announcer_udp;
    768774    transaction_id = evbuffer_read_ntoh_32( buf );
    769     /*fprintf( stderr, "UDP got a transaction_id of %u...\n", transaction_id );*/
     775    /*fprintf( stderr, "UDP got a transaction_id %u...\n", transaction_id );*/
    770776    for( i=0, n=tr_ptrArraySize( &tau->trackers ); i<n; ++i )
    771777    {
     
    778784            && ( transaction_id == tracker->connection_transaction_id ) )
    779785        {
    780             dbgmsg( tracker->key, "%"PRIu32" matches my connection request!", transaction_id );
     786            dbgmsg( tracker->key, "%"PRIu32" is my connection request!", transaction_id );
    781787            on_tracker_connection_response( tracker, action_id, buf );
    782788            evbuffer_free( buf );
     
    789795            struct tau_announce_request * req = tr_ptrArrayNth( reqs, j );
    790796            if( req->sent_at && ( transaction_id == req->transaction_id ) ) {
    791                 dbgmsg( tracker->key, "%"PRIu32" matches one of my announce requests!", transaction_id );
     797                dbgmsg( tracker->key, "%"PRIu32" is an announce request!", transaction_id );
    792798                tr_ptrArrayRemove( reqs, j );
    793799                on_announce_response( session, req, action_id, buf );
     
    803809            struct tau_scrape_request * req = tr_ptrArrayNth( reqs, j );
    804810            if( req->sent_at && ( transaction_id == req->transaction_id ) ) {
    805                 dbgmsg( tracker->key, "%"PRIu32" matches one of my scrape requests!", transaction_id );
     811                dbgmsg( tracker->key, "%"PRIu32" is a scrape request!", transaction_id );
    806812                tr_ptrArrayRemove( reqs, j );
    807813                on_scrape_response( session, req, action_id, buf );
Note: See TracChangeset for help on using the changeset viewer.