Changeset 9512


Ignore:
Timestamp:
Nov 10, 2009, 4:32:14 PM (13 years ago)
Author:
charles
Message:

(trunk libT) #2572: don't send empty dictionaries when PEXing

File:
1 edited

Legend:

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

    r9499 r9512  
    19691969                                         * speed vs. likelihood? */
    19701970
    1971             /* "added" */
    1972             tmp = walk = tr_new( uint8_t, diffs.addedCount * 6 );
    1973             for( i = 0; i < diffs.addedCount; ++i )
     1971            if( diffs.addedCount > 0)
    19741972            {
    1975                 memcpy( walk, &diffs.added[i].addr.addr, 4 ); walk += 4;
    1976                 memcpy( walk, &diffs.added[i].port, 2 ); walk += 2;
     1973                /* "added" */
     1974                tmp = walk = tr_new( uint8_t, diffs.addedCount * 6 );
     1975                for( i = 0; i < diffs.addedCount; ++i ) {
     1976                    memcpy( walk, &diffs.added[i].addr.addr, 4 ); walk += 4;
     1977                    memcpy( walk, &diffs.added[i].port, 2 ); walk += 2;
     1978                }
     1979                assert( ( walk - tmp ) == diffs.addedCount * 6 );
     1980                tr_bencDictAddRaw( &val, "added", tmp, walk - tmp );
     1981                tr_free( tmp );
     1982
     1983                /* "added.f" */
     1984                tmp = walk = tr_new( uint8_t, diffs.addedCount );
     1985                for( i = 0; i < diffs.addedCount; ++i )
     1986                    *walk++ = diffs.added[i].flags;
     1987                assert( ( walk - tmp ) == diffs.addedCount );
     1988                tr_bencDictAddRaw( &val, "added.f", tmp, walk - tmp );
     1989                tr_free( tmp );
    19771990            }
    1978             assert( ( walk - tmp ) == diffs.addedCount * 6 );
    1979             tr_bencDictAddRaw( &val, "added", tmp, walk - tmp );
    1980             tr_free( tmp );
    1981 
    1982             /* "added.f" */
    1983             tmp = walk = tr_new( uint8_t, diffs.addedCount );
    1984             for( i = 0; i < diffs.addedCount; ++i )
    1985                 *walk++ = diffs.added[i].flags;
    1986             assert( ( walk - tmp ) == diffs.addedCount );
    1987             tr_bencDictAddRaw( &val, "added.f", tmp, walk - tmp );
    1988             tr_free( tmp );
    1989 
    1990             /* "dropped" */
    1991             tmp = walk = tr_new( uint8_t, diffs.droppedCount * 6 );
    1992             for( i = 0; i < diffs.droppedCount; ++i )
     1991
     1992            if( diffs.droppedCount > 0 )
    19931993            {
    1994                 memcpy( walk, &diffs.dropped[i].addr.addr, 4 ); walk += 4;
    1995                 memcpy( walk, &diffs.dropped[i].port, 2 ); walk += 2;
     1994                /* "dropped" */
     1995                tmp = walk = tr_new( uint8_t, diffs.droppedCount * 6 );
     1996                for( i = 0; i < diffs.droppedCount; ++i ) {
     1997                    memcpy( walk, &diffs.dropped[i].addr.addr, 4 ); walk += 4;
     1998                    memcpy( walk, &diffs.dropped[i].port, 2 ); walk += 2;
     1999                }
     2000                assert( ( walk - tmp ) == diffs.droppedCount * 6 );
     2001                tr_bencDictAddRaw( &val, "dropped", tmp, walk - tmp );
     2002                tr_free( tmp );
    19962003            }
    1997             assert( ( walk - tmp ) == diffs.droppedCount * 6 );
    1998             tr_bencDictAddRaw( &val, "dropped", tmp, walk - tmp );
    1999             tr_free( tmp );
    2000 
    2001             /* "added6" */
    2002             tmp = walk = tr_new( uint8_t, diffs6.addedCount * 18 );
    2003             for( i = 0; i < diffs6.addedCount; ++i )
     2004
     2005            if( diffs6.addedCount > 0 )
    20042006            {
    2005                 memcpy( walk, &diffs6.added[i].addr.addr.addr6.s6_addr, 16 );
    2006                 walk += 16;
    2007                 memcpy( walk, &diffs6.added[i].port, 2 );
    2008                 walk += 2;
     2007                /* "added6" */
     2008                tmp = walk = tr_new( uint8_t, diffs6.addedCount * 18 );
     2009                for( i = 0; i < diffs6.addedCount; ++i ) {
     2010                    memcpy( walk, &diffs6.added[i].addr.addr.addr6.s6_addr, 16 );
     2011                    walk += 16;
     2012                    memcpy( walk, &diffs6.added[i].port, 2 );
     2013                    walk += 2;
     2014                }
     2015                assert( ( walk - tmp ) == diffs6.addedCount * 18 );
     2016                tr_bencDictAddRaw( &val, "added6", tmp, walk - tmp );
     2017                tr_free( tmp );
     2018
     2019                /* "added6.f" */
     2020                tmp = walk = tr_new( uint8_t, diffs6.addedCount );
     2021                for( i = 0; i < diffs6.addedCount; ++i )
     2022                    *walk++ = diffs6.added[i].flags;
     2023                assert( ( walk - tmp ) == diffs6.addedCount );
     2024                tr_bencDictAddRaw( &val, "added6.f", tmp, walk - tmp );
     2025                tr_free( tmp );
    20092026            }
    2010             assert( ( walk - tmp ) == diffs6.addedCount * 18 );
    2011             tr_bencDictAddRaw( &val, "added6", tmp, walk - tmp );
    2012             tr_free( tmp );
    2013 
    2014             /* "added6.f" */
    2015             tmp = walk = tr_new( uint8_t, diffs6.addedCount );
    2016             for( i = 0; i < diffs6.addedCount; ++i )
    2017                 *walk++ = diffs6.added[i].flags;
    2018             assert( ( walk - tmp ) == diffs6.addedCount );
    2019             tr_bencDictAddRaw( &val, "added6.f", tmp, walk - tmp );
    2020             tr_free( tmp );
    2021 
    2022             /* "dropped6" */
    2023             tmp = walk = tr_new( uint8_t, diffs6.droppedCount * 18 );
    2024             for( i = 0; i < diffs6.droppedCount; ++i )
     2027
     2028            if( diffs6.droppedCount > 0 )
    20252029            {
    2026                 memcpy( walk, &diffs6.dropped[i].addr.addr.addr6.s6_addr, 16 );
    2027                 walk += 16;
    2028                 memcpy( walk, &diffs6.dropped[i].port, 2 );
    2029                 walk += 2;
     2030                /* "dropped6" */
     2031                tmp = walk = tr_new( uint8_t, diffs6.droppedCount * 18 );
     2032                for( i = 0; i < diffs6.droppedCount; ++i ) {
     2033                    memcpy( walk, &diffs6.dropped[i].addr.addr.addr6.s6_addr, 16 );
     2034                    walk += 16;
     2035                    memcpy( walk, &diffs6.dropped[i].port, 2 );
     2036                    walk += 2;
     2037                }
     2038                assert( ( walk - tmp ) == diffs6.droppedCount * 18);
     2039                tr_bencDictAddRaw( &val, "dropped6", tmp, walk - tmp );
     2040                tr_free( tmp );
    20302041            }
    2031             assert( ( walk - tmp ) == diffs6.droppedCount * 18);
    2032             tr_bencDictAddRaw( &val, "dropped6", tmp, walk - tmp );
    2033             tr_free( tmp );
    20342042
    20352043            /* write the pex message */
Note: See TracChangeset for help on using the changeset viewer.