continue;
}
}
DistributedDatabaseContact contact;
boolean live_contact;
try{
potential_contacts_mon.enter();
// System.out.println( "rem=" + remaining + ",pot=" + potential_contacts.size() + ",out=" + outstanding[0] );
if ( potential_contacts.size() == 0 ){
if ( outstanding[0] == 0 ){
break;
}else{
continue;
}
}else{
Object[] entry = (Object[])potential_contacts.remove(0);
live_contact = ((Boolean)entry[0]).booleanValue();
contact = (DistributedDatabaseContact)entry[1];
}
}finally{
potential_contacts_mon.exit();
}
// System.out.println( "magnetDownload: " + contact.getName() + ", live = " + live_contact );
if ( !live_contact ){
listener.reportActivity( getMessageText( "report.tunnel", contact.getName()));
contact.openTunnel();
}
try{
listener.reportActivity( getMessageText( "report.downloading", contact.getName()));
DistributedDatabaseValue value =
contact.read(
new DistributedDatabaseProgressListener()
{
public void
reportSize(
long size )
{
listener.reportSize( size );
}
public void
reportActivity(
String str )
{
listener.reportActivity( str );
}
public void
reportCompleteness(
int percent )
{
listener.reportCompleteness( percent );
}
},
db.getStandardTransferType( DistributedDatabaseTransferType.ST_TORRENT ),
db.createKey ( hash , "Torrent download content for '" + ByteFormatter.encodeString( hash ) + "'"),
timeout );
if ( value != null ){
// let's verify the torrent
byte[] data = (byte[])value.getValue(byte[].class);
try{
TOTorrent torrent = TOTorrentFactory.deserialiseFromBEncodedByteArray( data );
if ( Arrays.equals( hash, torrent.getHash())){
listener.reportContributor( contact.getAddress());
return( data );
}else{