Methods Summary |
---|
public void | addListener(com.aelitis.azureus.core.dht.speed.DHTSpeedTesterListener listener)
synchronized( new_listeners ){
new_listeners.add( listener );
}
|
protected void | findContacts()
DHTTransportContact[] reachables = dht.getTransport().getReachableContacts();
for (int i=0;i<reachables.length;i++){
DHTTransportContact contact = reachables[i];
byte[] address = contact.getAddress().getAddress().getAddress();
if ( tried_bloom == null || tried_bloom.getEntryCount() > 500 ){
tried_bloom = BloomFilterFactory.createAddOnly( 4096 );
}
if ( !tried_bloom.contains( address )){
tried_bloom.add( address );
synchronized( pending_contacts ){
potentialPing ping =
new potentialPing(
contact,
DHTNetworkPositionManager.estimateRTT( contact.getNetworkPositions(), dht.getTransport().getLocalContact().getNetworkPositions()));
pending_contacts.add( 0, ping );
if ( pending_contacts.size() > 60 ){
pending_contacts.removeLast();
}
}
}
}
|
public int | getContactNumber()
return( contact_num );
|
protected void | informResults(com.aelitis.azureus.core.dht.speed.DHTSpeedTesterContact[] contacts, int[] rtts)
Iterator it = listeners.iterator();
while( it.hasNext()){
try{
((DHTSpeedTesterListener)it.next()).resultGroup( contacts, rtts );
}catch( Throwable e ){
Debug.printStackTrace(e);
}
}
|
protected void | pingContacts(int tick_count)
List copy = null;
synchronized( new_listeners ){
if ( new_listeners.size() > 0 ){
copy = new ArrayList( new_listeners );
new_listeners.clear();
}
}
if ( copy != null ){
for (int i=0;i<copy.size();i++){
DHTSpeedTesterListener listener = (DHTSpeedTesterListener)copy.get(i);
listeners.add( listener );
for ( int j=0;j<active_pings.size();j++){
activePing ping = (activePing)active_pings.get(j);
if ( ping.isInformedAlive()){
try{
listener.contactAdded( ping );
}catch( Throwable e ){
Debug.printStackTrace(e);
}
}
}
}
}
Iterator pit = active_pings.iterator();
pingInstanceSet ping_set = new pingInstanceSet( true );
while( pit.hasNext()){
activePing ping = (activePing)pit.next();
if ( ping.update( ping_set, tick_count )){
if ( !ping.isInformedAlive()){
ping.setInformedAlive();
Iterator it = listeners.iterator();
while( it.hasNext()){
try{
((DHTSpeedTesterListener)it.next()).contactAdded( ping );
}catch( Throwable e ){
Debug.printStackTrace(e);
}
}
}
}
if ( ping.isDead()){
pit.remove();
ping.informDead();
}
}
ping_set.setFull();
// we try and keep three active pings running so we can spot overall trends in ping time
// each active ping is selected from the best rtt from the current 3 best three rtt estimates
int num_active = active_pings.size();
if ( num_active < contact_num ){
Set pc = new TreeSet(
new Comparator()
{
public int
compare(
Object o1,
Object o2 )
{
potentialPing p1 = (potentialPing)o1;
potentialPing p2 = (potentialPing)o2;
return( p1.getRTT() - p2.getRTT());
}
});
synchronized( pending_contacts ){
pc.addAll( pending_contacts );
}
Iterator it = pc.iterator();
if ( pc.size() >= 3){
// find best candidates
List pps = new ArrayList();
for (int i=0;i<3;i++){
potentialPing pp = (potentialPing)it.next();
pps.add( pp );
it.remove();
synchronized( pending_contacts ){
pending_contacts.remove( pp );
}
}
active_pings.add( new activePing( pps ));
}
}else if ( num_active > contact_num ){
for (int i=0;i<num_active-contact_num;i++){
((activePing)active_pings.get(i)).destroy();
}
}
|
public void | removeListener(com.aelitis.azureus.core.dht.speed.DHTSpeedTesterListener listener)
listeners.remove( listener );
|
public void | setContactNumber(int number)
contact_num = number;
|