ExternalSeedReaderWebSeedpublic class ExternalSeedReaderWebSeed extends com.aelitis.azureus.plugins.extseed.impl.ExternalSeedReaderImpl
Fields Summary |
---|
private URL | url | private String | ip | private int | port | private String | url_prefix | private boolean | supports_503 |
Constructors Summary |
---|
protected ExternalSeedReaderWebSeed(com.aelitis.azureus.plugins.extseed.ExternalSeedPlugin _plugin, org.gudy.azureus2.plugins.torrent.Torrent _torrent, URL _url, Map _params)
super( _plugin, _torrent, _params );
supports_503 = getBooleanParam( _params, "supports_503", true );
url = _url;
ip = url.getHost();
port = url.getPort();
if ( port == -1 ){
port = url.getDefaultPort();
}
try{
String hash_str = URLEncoder.encode(new String(_torrent.getHash(), "ISO-8859-1"), "ISO-8859-1").replaceAll("\\+", "%20");
url_prefix = url.toString()+"?info_hash=" + hash_str;
}catch( Throwable e ){
Debug.printStackTrace(e);
}
|
Methods Summary |
---|
public java.lang.String | getIP()
return( ip );
| public java.lang.String | getName()
return( "WS: " + url );
| protected int | getPieceGroupSize()
return( 1 );
| public int | getPort()
return( port );
| protected boolean | getRequestCanSpanPieces()
return( false );
| protected void | readData(com.aelitis.azureus.plugins.extseed.impl.ExternalSeedReaderRequest request)
long piece = request.getStartPieceNumber();
long piece_start = request.getStartPieceOffset();
long piece_end = piece_start + request.getLength()-1;
String str = url_prefix + "&piece=" + piece + "&ranges=" + piece_start + "-" + piece_end;
setReconnectDelay( RECONNECT_DEFAULT, false );
ExternalSeedHTTPDownloader http_downloader = null;
try{
http_downloader = new ExternalSeedHTTPDownloader( new URL( str ), getUserAgent());
// unfortunately using HttpURLConnection it isn't possible to read the 503 response as per
// protocol - however, for az http web seeds we don't uses 503 anyway so we cna use URLCon. The
// main benefit here is we also get http proxying which we don't get with our direct socket
// support...
if ( supports_503 ){
http_downloader.downloadSocket( request.getLength(), request, isTransient() );
}else{
http_downloader.download( request.getLength(), request, isTransient() );
}
}catch( ExternalSeedException ese ){
if ( http_downloader.getLastResponse() == 503 && http_downloader.getLast503RetrySecs() >= 0 ){
int retry_secs = http_downloader.getLast503RetrySecs();
setReconnectDelay( retry_secs * 1000, true );
throw( new ExternalSeedException( "Server temporarily unavailable, retrying in " + retry_secs + " seconds" ));
}else{
throw( ese );
}
}catch( MalformedURLException e ){
throw( new ExternalSeedException( "URL encode fails", e ));
}
| public boolean | sameAs(com.aelitis.azureus.plugins.extseed.ExternalSeedReader other)
if ( other instanceof ExternalSeedReaderWebSeed ){
return( url.toString().equals(((ExternalSeedReaderWebSeed)other).url.toString()));
}
return( false );
|
|