Changeset 12382


Ignore:
Timestamp:
Apr 27, 2011, 5:29:05 AM (10 years ago)
Author:
jordan
Message:

(trunk libT) #4209 "Shortcut UDP tracker test" -- prioritize the UDP handler functions based on frequency (uTP, DHT, UTP tracker) as outlined by jch in comment:5. Also, don't call the uTP or DHT handlers when uTP or DHT is disabled in the system preferences.

To avoid the function call overhead described by jch, instead of calling tr_sessionIsUTPEnabled() and tr_sessionIsDHTEnabled(), we test for WITH_UTP to be defined and test the tr_session.isUTPEnabled and tr_session.isDHTEnabled flags directly.

File:
1 edited

Legend:

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

    r12381 r12382  
    188188event_callback(int s, short type UNUSED, void *sv)
    189189{
    190     tr_session *ss = sv;
     190    int rc;
     191    socklen_t fromlen;
    191192    unsigned char buf[4096];
    192193    struct sockaddr_storage from;
    193     socklen_t fromlen;
    194     int rc;
     194    tr_session *ss = sv;
    195195
    196196    assert(tr_isSession(sv));
     
    201201                  (struct sockaddr*)&from, &fromlen);
    202202
    203     /* Since most packets we receive here are µTP, make quick inline
    204        checks for the other protocols.  The logic is as follows:
    205        - all DHT packets start with 'd';
    206        - all UDP tracker packets start with a 32-bit (!) "action", which
    207          is between 0 and 3;
    208        - the above cannot be µTP packets, since these start with a 4-bit
    209          version number (1). */
    210     if(rc > 0) {
    211         if( buf[0] == 'd' ) {
    212             buf[rc] = '\0';     /* required by the DHT code */
    213             tr_dhtCallback(buf, rc, (struct sockaddr*)&from, fromlen, sv);
    214         } else if( rc >= 8 &&
    215                    buf[0] == 0 && buf[1] == 0 && buf[2] == 0 && buf[3] <= 3 ) {
    216             rc = tau_handle_message( ss, buf, rc );
    217             if( !rc )
    218                 tr_ndbg("UDP", "Couldn't parse UDP tracker packet.");
    219         } else {
    220             rc = tr_utpPacket(buf, rc, (struct sockaddr*)&from, fromlen, ss);
    221             if( !rc )
    222                 tr_ndbg("UDP", "Unexpected UDP packet");
     203    /* Test for the different packet types based on frequency:
     204       ÂµTP will be the most common, then DHT, then UDP trackers. */
     205    if( rc > 0 )
     206    {
     207#ifdef WITH_UTP
     208        if( ss->isUTPEnabled && tr_utpPacket( buf, rc, (struct sockaddr*)&from, fromlen, ss ) )
     209        {
     210            tr_ndbg( "UDP", "Handled uTP packet" );
     211        }
     212        else
     213#endif
     214        if( ss->isDHTEnabled && ( *buf == 'd' ) ) /* DHT */
     215        {
     216            buf[rc] = '\0'; /* required by the DHT code */
     217            tr_dhtCallback( buf, rc, (struct sockaddr*)&from, fromlen, sv );
     218            tr_ndbg( "UDP", "Handled DHT packet" );
     219        }
     220        else if( tau_handle_message( ss, buf, rc ) )
     221        {
     222            tr_ndbg( "UDP", "Handled UDP tracker packet" );
     223        }
     224        else
     225        {
     226            tr_ndbg( "UDP", "Unexpected UDP packet" );
    223227        }
    224228    }
Note: See TracChangeset for help on using the changeset viewer.