managerUnlock( manager );
}
+static int
+tr_isPex( const tr_pex * pex )
+{
+ return pex && tr_isAddress( &pex->addr );
+}
+
void
tr_peerMgrAddPex( tr_peerMgr * manager,
const uint8_t * torrentHash,
const tr_pex * pex )
{
Torrent * t;
-
managerLock( manager );
+ assert( tr_isPex( pex ) );
+
t = getExistingTorrent( manager, torrentHash );
if( !tr_sessionIsAddressBlocked( t->manager->session, &pex->addr ) )
ensureAtomExists( t, &pex->addr, pex->port, pex->flags, from );
{
const tr_pex * a = va;
const tr_pex * b = vb;
- int i = tr_compareAddresses( &a->addr, &b->addr );
+ int i;
+
+ assert( tr_isPex( a ) );
+ assert( tr_isPex( b ) );
+
+ if(( i = tr_compareAddresses( &a->addr, &b->addr )))
+ return i;
+
+ if( a->port != b->port )
+ return a->port < b->port ? -1 : 1;
- if( i ) return i;
- if( a->port < b->port ) return -1;
- if( a->port > b->port ) return 1;
return 0;
}
}
}
-#warning this for loop can be removed when we're sure the bug is fixed
+#warning this for loop can be removed when we are sure the bug is fixed
for( i=0; i<peersReturning; ++i )
assert( tr_isAddress( &pex[i].addr ) );
assert( ( walk - pex ) == peersReturning );
qsort( pex, peersReturning, sizeof( tr_pex ), tr_pexCompare );
-#warning this for loop can be removed when we're sure the bug is fixed
+#warning this for loop can be removed when we are sure the bug is fixed
for( i=0; i<peersReturning; ++i )
assert( tr_isAddress( &pex[i].addr ) );