Created on Apr 17, 2007
Created by Alan Snyder
Copyright (C) 2007 Aelitis, All Rights Reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
AELITIS, SAS au capital de 63.529,40 euros
8 Allee Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France. |
Methods Summary |
---|
protected void | abort(java.lang.String reason, java.lang.Throwable cause)
String msg;
if ( cause instanceof RuntimeException ){
msg = Debug.getNestedExceptionMessageAndStack( cause );
}else{
msg = Debug.getNestedExceptionMessage( cause );
}
abort( reason + ": " + msg );
|
public void | abort(java.lang.String reason)
reason = "Test aborted: " + reason;
synchronized( this ){
if ( aborted ){
return;
}
aborted = true;
// we need to defer the reporting of a failure until the test is complete
// as this prevents us from starting another test while the current one is
// terminating
if ( test_started && !test_completed ){
deferred_abort = reason;
return;
}
}
sendResultToListeners( new BitTorrentResult( reason ));
|
private static java.lang.Double | autoboxDouble(double d)
return new Double(d);
|
private static long | autoboxLong(java.lang.Object o)
return autoboxLong( (Long) o );
|
private static long | autoboxLong(java.lang.Long l)
return l.longValue();
|
private static java.lang.Long | autoboxLong(long l)
return new Long(l);
|
public void | complete(com.aelitis.azureus.core.networkmanager.admin.NetworkAdminSpeedTesterResult result)
sendResultToListeners( result );
|
protected static com.aelitis.azureus.core.networkmanager.admin.NetworkAdminSpeedTesterResult | getLastResult()
return( lastResult );
|
public int | getMode()
return( testMode );
|
public com.aelitis.azureus.core.networkmanager.admin.NetworkAdminSpeedTesterResult | getResult()Get the result for
return lastResult;
|
public int | getTestType()
return( NetworkAdminSpeedTestScheduler.TEST_TYPE_BT );
|
public boolean | getUseCrypto()
return( use_crypto );
|
public void | setMode(int mode)
testMode = mode;
|
private static int | setStartPieceBasedOnMode(int mode, int totalPieces)Depending on the mode we want to upload all the set all, none or only
half the pieces to done.
//if(mode==TEST_TYPE_UPLOAD_AND_DOWNLOAD){
// //upload half the pieces
// return totalPieces/2;
//}else
if(mode==TEST_TYPE_UPLOAD_ONLY){
//upload all the pieces
return 0;
}else if(mode==TEST_TYPE_DOWNLOAD_ONLY){
//download all the pieces
return totalPieces;
}
else
throw new IllegalStateException("Did not recognize the NetworkAdmin Speed Test type. mode="+mode);
|
public void | setUseCrypto(boolean _use_crypto)
use_crypto = _use_crypto;
|
public synchronized void | start(org.gudy.azureus2.core3.torrent.TOTorrent tot)The downloads have been stopped just need to do the testing.
if ( test_started ){
Debug.out( "Test already started!" );
return;
}
test_started = true;
//OK lets start the test.
try{
TorrentUtils.setFlag( tot, TorrentUtils.TORRENT_FLAG_LOW_NOISE, true );
Torrent torrent = new TorrentImpl(tot);
String fileName = torrent.getName();
sendStageUpdateToListeners(MessageText.getString("SpeedTestWizard.stage.message.preparing"));
//create a blank file of specified size. (using the temporary name.)
File saveLocation = AETemporaryFileHandler.createTempFile();
File baseDir = saveLocation.getParentFile();
File blankFile = new File(baseDir,fileName);
File blankTorrentFile = new File( baseDir, "speedTestTorrent.torrent" );
torrent.writeToFile(blankTorrentFile);
URL announce_url = torrent.getAnnounceURL();
if ( announce_url.getProtocol().equalsIgnoreCase( "https" )){
SESecurityManager.setCertificateHandler(
announce_url,
new SECertificateListener()
{
public boolean
trustCertificate(
String resource,
X509Certificate cert )
{
return( true );
}
});
}
Download speed_download = plugin.getDownloadManager().addDownloadStopped( torrent, blankTorrentFile ,blankFile);
speed_download.setBooleanAttribute(speedTestAttrib,true);
DownloadManager core_download = PluginCoreUtils.unwrap( speed_download );
core_download.setPieceCheckingEnabled( false );
// make sure we've got a bunch of upload slots
core_download.getDownloadState().setIntParameter( DownloadManagerState.PARAM_MAX_UPLOADS, 32 );
core_download.getDownloadState().setIntParameter( DownloadManagerState.PARAM_MAX_UPLOADS_WHEN_SEEDING, 32 );
if ( use_crypto ){
core_download.setCryptoLevel( NetworkManager.CRYPTO_OVERRIDE_REQUIRED );
}
core_download.addPeerListener(
new DownloadManagerPeerListener()
{
public void
peerManagerWillBeAdded(
PEPeerManager peer_manager )
{
DiskManager disk_manager = peer_manager.getDiskManager();
DiskManagerPiece[] pieces = disk_manager.getPieces();
int startPiece = setStartPieceBasedOnMode(testMode,pieces.length);
for ( int i=startPiece; i<pieces.length; i++ ){
pieces[i].setDone( true );
}
}
public void
peerManagerAdded( PEPeerManager peer_manager )
{
}
public void
peerManagerRemoved(PEPeerManager manager )
{
}
public void
peerAdded(PEPeer peer )
{
}
public void
peerRemoved(PEPeer peer )
{
}
public void
pieceAdded(PEPiece piece )
{
}
public void
pieceRemoved(PEPiece piece )
{
}
});
speed_download.moveTo( 1 );
speed_download.setFlag( Download.FLAG_DISABLE_AUTO_FILE_MOVE, true );
core_download.initialize();
core_download.setForceStart( true );
TorrentSpeedTestMonitorThread monitor = new TorrentSpeedTestMonitorThread( speed_download );
monitor.start();
//The test has now started!!
}catch( Throwable e){
test_completed = true;
abort( "Could not start test", e );
}
|
protected static void | startUp(org.gudy.azureus2.plugins.PluginInterface plugin)
speedTestAttrib = plugin.getTorrentManager().getPluginAttribute(NetworkAdminSpeedTesterBTImpl.class.getName()+".test.attrib");
org.gudy.azureus2.plugins.download.DownloadManager dm = plugin.getDownloadManager();
Download[] downloads = dm.getDownloads();
if(downloads!=null){
int num = downloads.length;
for(int i=0; i<num; i++){
Download download = downloads[i];
if( download.getBooleanAttribute(speedTestAttrib) ){
try{
if (download.getState() != Download.ST_STOPPED ){
try{
download.stop();
}catch( Throwable e ){
Debug.out(e);
}
}
download.remove(true,true);
}catch(Throwable e ){
Debug.out("Had "+e.getMessage()+" while trying to remove "+downloads[i].getName());
}
}
}
}
|