mirror of
https://github.com/transmission/transmission
synced 2025-03-04 10:38:13 +00:00
(trunk libT) #2572: don't send empty dictionaries when PEXing
This commit is contained in:
parent
ac4edf277e
commit
03e9189333
1 changed files with 60 additions and 52 deletions
|
@ -1968,10 +1968,11 @@ sendPex( tr_peermsgs * msgs )
|
||||||
tr_bencInitDict( &val, 3 ); /* ipv6 support: left as 3:
|
tr_bencInitDict( &val, 3 ); /* ipv6 support: left as 3:
|
||||||
* speed vs. likelihood? */
|
* speed vs. likelihood? */
|
||||||
|
|
||||||
|
if( diffs.addedCount > 0)
|
||||||
|
{
|
||||||
/* "added" */
|
/* "added" */
|
||||||
tmp = walk = tr_new( uint8_t, diffs.addedCount * 6 );
|
tmp = walk = tr_new( uint8_t, diffs.addedCount * 6 );
|
||||||
for( i = 0; i < diffs.addedCount; ++i )
|
for( i = 0; i < diffs.addedCount; ++i ) {
|
||||||
{
|
|
||||||
memcpy( walk, &diffs.added[i].addr.addr, 4 ); walk += 4;
|
memcpy( walk, &diffs.added[i].addr.addr, 4 ); walk += 4;
|
||||||
memcpy( walk, &diffs.added[i].port, 2 ); walk += 2;
|
memcpy( walk, &diffs.added[i].port, 2 ); walk += 2;
|
||||||
}
|
}
|
||||||
|
@ -1986,22 +1987,26 @@ sendPex( tr_peermsgs * msgs )
|
||||||
assert( ( walk - tmp ) == diffs.addedCount );
|
assert( ( walk - tmp ) == diffs.addedCount );
|
||||||
tr_bencDictAddRaw( &val, "added.f", tmp, walk - tmp );
|
tr_bencDictAddRaw( &val, "added.f", tmp, walk - tmp );
|
||||||
tr_free( tmp );
|
tr_free( tmp );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( diffs.droppedCount > 0 )
|
||||||
|
{
|
||||||
/* "dropped" */
|
/* "dropped" */
|
||||||
tmp = walk = tr_new( uint8_t, diffs.droppedCount * 6 );
|
tmp = walk = tr_new( uint8_t, diffs.droppedCount * 6 );
|
||||||
for( i = 0; i < diffs.droppedCount; ++i )
|
for( i = 0; i < diffs.droppedCount; ++i ) {
|
||||||
{
|
|
||||||
memcpy( walk, &diffs.dropped[i].addr.addr, 4 ); walk += 4;
|
memcpy( walk, &diffs.dropped[i].addr.addr, 4 ); walk += 4;
|
||||||
memcpy( walk, &diffs.dropped[i].port, 2 ); walk += 2;
|
memcpy( walk, &diffs.dropped[i].port, 2 ); walk += 2;
|
||||||
}
|
}
|
||||||
assert( ( walk - tmp ) == diffs.droppedCount * 6 );
|
assert( ( walk - tmp ) == diffs.droppedCount * 6 );
|
||||||
tr_bencDictAddRaw( &val, "dropped", tmp, walk - tmp );
|
tr_bencDictAddRaw( &val, "dropped", tmp, walk - tmp );
|
||||||
tr_free( tmp );
|
tr_free( tmp );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( diffs6.addedCount > 0 )
|
||||||
|
{
|
||||||
/* "added6" */
|
/* "added6" */
|
||||||
tmp = walk = tr_new( uint8_t, diffs6.addedCount * 18 );
|
tmp = walk = tr_new( uint8_t, diffs6.addedCount * 18 );
|
||||||
for( i = 0; i < diffs6.addedCount; ++i )
|
for( i = 0; i < diffs6.addedCount; ++i ) {
|
||||||
{
|
|
||||||
memcpy( walk, &diffs6.added[i].addr.addr.addr6.s6_addr, 16 );
|
memcpy( walk, &diffs6.added[i].addr.addr.addr6.s6_addr, 16 );
|
||||||
walk += 16;
|
walk += 16;
|
||||||
memcpy( walk, &diffs6.added[i].port, 2 );
|
memcpy( walk, &diffs6.added[i].port, 2 );
|
||||||
|
@ -2018,11 +2023,13 @@ sendPex( tr_peermsgs * msgs )
|
||||||
assert( ( walk - tmp ) == diffs6.addedCount );
|
assert( ( walk - tmp ) == diffs6.addedCount );
|
||||||
tr_bencDictAddRaw( &val, "added6.f", tmp, walk - tmp );
|
tr_bencDictAddRaw( &val, "added6.f", tmp, walk - tmp );
|
||||||
tr_free( tmp );
|
tr_free( tmp );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( diffs6.droppedCount > 0 )
|
||||||
|
{
|
||||||
/* "dropped6" */
|
/* "dropped6" */
|
||||||
tmp = walk = tr_new( uint8_t, diffs6.droppedCount * 18 );
|
tmp = walk = tr_new( uint8_t, diffs6.droppedCount * 18 );
|
||||||
for( i = 0; i < diffs6.droppedCount; ++i )
|
for( i = 0; i < diffs6.droppedCount; ++i ) {
|
||||||
{
|
|
||||||
memcpy( walk, &diffs6.dropped[i].addr.addr.addr6.s6_addr, 16 );
|
memcpy( walk, &diffs6.dropped[i].addr.addr.addr6.s6_addr, 16 );
|
||||||
walk += 16;
|
walk += 16;
|
||||||
memcpy( walk, &diffs6.dropped[i].port, 2 );
|
memcpy( walk, &diffs6.dropped[i].port, 2 );
|
||||||
|
@ -2031,6 +2038,7 @@ sendPex( tr_peermsgs * msgs )
|
||||||
assert( ( walk - tmp ) == diffs6.droppedCount * 18);
|
assert( ( walk - tmp ) == diffs6.droppedCount * 18);
|
||||||
tr_bencDictAddRaw( &val, "dropped6", tmp, walk - tmp );
|
tr_bencDictAddRaw( &val, "dropped6", tmp, walk - tmp );
|
||||||
tr_free( tmp );
|
tr_free( tmp );
|
||||||
|
}
|
||||||
|
|
||||||
/* write the pex message */
|
/* write the pex message */
|
||||||
benc = tr_bencToStr( &val, TR_FMT_BENC, &bencLen );
|
benc = tr_bencToStr( &val, TR_FMT_BENC, &bencLen );
|
||||||
|
|
Loading…
Add table
Reference in a new issue