diff --git a/vuze/com/aelitis/azureus/plugins/net/netstatus/swt/NetStatusPluginTester.java b/vuze/com/aelitis/azureus/plugins/net/netstatus/swt/NetStatusPluginTester.java deleted file mode 100644 index f7a575b..0000000 --- a/vuze/com/aelitis/azureus/plugins/net/netstatus/swt/NetStatusPluginTester.java +++ /dev/null @@ -1,1162 +0,0 @@ -/* - * Created on Jan 31, 2008 - * Created by Paul Gardner - * - * Copyright 2008 Vuze, Inc. 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; version 2 of the License only. - * - * 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. - */ - - -package com.aelitis.azureus.plugins.net.netstatus.swt; - -import java.io.BufferedInputStream; -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.net.Inet6Address; -import java.net.InetAddress; -import java.net.URL; -import java.util.*; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLSession; - -import java.security.cert.Certificate; - -import org.gudy.azureus2.core3.util.BDecoder; -import org.gudy.azureus2.core3.util.Constants; -import org.gudy.azureus2.core3.util.Debug; -import org.gudy.azureus2.core3.util.FileUtil; -import org.gudy.azureus2.pluginsimpl.local.utils.resourcedownloader.ResourceDownloaderFactoryImpl; - -import com.aelitis.azureus.core.AzureusCore; -import com.aelitis.azureus.core.networkmanager.admin.*; -import com.aelitis.azureus.core.proxy.AEProxyFactory; -import com.aelitis.azureus.core.proxy.AEProxyFactory.PluginProxy; -import com.aelitis.azureus.core.versioncheck.VersionCheckClient; -import com.aelitis.azureus.plugins.net.netstatus.NetStatusPlugin; -import com.aelitis.azureus.plugins.net.netstatus.NetStatusProtocolTesterBT; -import com.aelitis.azureus.plugins.net.netstatus.NetStatusProtocolTesterListener; - -public class -NetStatusPluginTester -{ - //public static final int TEST_PING_ROUTE = 0x00000001; - public static final int TEST_NAT_PROXIES = 0x00000002; - public static final int TEST_OUTBOUND = 0x00000004; - public static final int TEST_INBOUND = 0x00000008; - public static final int TEST_BT_CONNECT = 0x00000010; - public static final int TEST_IPV6 = 0x00000020; - public static final int TEST_VUZE_SERVICES = 0x00000040; - public static final int TEST_PROXY_CONNECT = 0x00000080; - - - private static final int ROUTE_TIMEOUT = 120*1000; - - private NetStatusPlugin plugin; - private int test_types; - private loggerProvider logger; - - private volatile boolean test_cancelled; - - public - NetStatusPluginTester( - NetStatusPlugin _plugin, - int _test_types, - loggerProvider _logger ) - { - plugin = _plugin; - test_types = _test_types; - logger = _logger; - } - - protected boolean - doTest( - int type ) - { - if ( test_cancelled ){ - - return( false ); - } - - return((test_types & type ) != 0 ); - } - - public void - run(AzureusCore core) - { - final NetworkAdmin admin = NetworkAdmin.getSingleton(); - - boolean checked_public = false; - - Set public_addresses = new HashSet(); - - InetAddress def_pa = admin.getDefaultPublicAddress(); - - if ( def_pa != null ){ - - log( "Default public address is " + def_pa.getHostAddress()); - - addPublicAddress( public_addresses, def_pa ); - - checked_public = true; - } - - /* this ain't working well and some users reporting crashes so boo - * - if ( doTest( TEST_PING_ROUTE )){ - - log( "Testing routing for the following interfaces:" ); - - NetworkAdminNetworkInterface[] interfaces = admin.getInterfaces(); - - for (int i=0;i 0 ){ - - log( " " + intf.getName() + "/" + intf.getDisplayName() + ": " + a_str ); - } - } - - if ( admin.canPing()){ - - log( "Running ping tests" ); - - try{ - InetAddress target_address = InetAddress.getByName( plugin.getPingTarget()); - - final Map active_pings = new HashMap(); - - admin.pingTargets( - target_address, - ROUTE_TIMEOUT, - new NetworkAdminRoutesListener() - { - private int timeouts; - - public boolean - foundNode( - NetworkAdminNetworkInterfaceAddress intf, - NetworkAdminNode[] route, - int distance, - int rtt ) - { - if ( test_cancelled ){ - - return( false ); - } - - synchronized( active_pings ){ - - active_pings.put( intf, route ); - } - - log( " " + intf.getAddress().getHostAddress() + " -> " + route[route.length-1].getAddress().getHostAddress()); - - return( false ); - } - - public boolean - timeout( - NetworkAdminNetworkInterfaceAddress intf, - NetworkAdminNode[] route, - int distance ) - { - if ( test_cancelled ){ - - return( false ); - } - - log( " " + intf.getAddress().getHostAddress() + " - timeout" ); - - timeouts++; - - if ( timeouts >= 3 ){ - - return( false ); - } - - return( true ); - } - }); - - if ( test_cancelled ){ - - return; - } - - int num_routes = active_pings.size(); - - if ( num_routes == 0 ){ - - logError( "No active pings found!" ); - - }else{ - - log( "Found " + num_routes + " pings(s)" ); - - Iterator it = active_pings.entrySet().iterator(); - - while( it.hasNext()){ - - Map.Entry entry = (Map.Entry)it.next(); - - NetworkAdminNetworkInterfaceAddress address = (NetworkAdminNetworkInterfaceAddress)entry.getKey(); - - NetworkAdminNode[] route = (NetworkAdminNode[])entry.getValue(); - - String node_str = ""; - - for (int i=0;i " + ia.getHostAddress() + " (hop=" + distance + ")" + (as.length()==0?"":( " - " + as ))); - - return( true ); - } - - public boolean - timeout( - NetworkAdminNetworkInterfaceAddress intf, - NetworkAdminNode[] route, - int distance ) - { - if ( test_cancelled ){ - - return( false ); - } - - log( " " + intf.getAddress().getHostAddress() + " - timeout (hop=" + distance + ")" ); - - // see if we're getting nowhere - - if ( route.length == 0 && distance >= 5 ){ - - logError( " giving up, no responses" ); - - return( false ); - } - - // see if we've got far enough - - if ( route.length >= 5 && distance > 6 ){ - - log( " truncating, sufficient responses" ); - - return( false ); - } - - return( true ); - } - }); - - if ( test_cancelled ){ - - return; - } - - int num_routes = active_routes.size(); - - if ( num_routes == 0 ){ - - logError( "No active routes found!" ); - - }else{ - - log( "Found " + num_routes + " route(s)" ); - - Iterator it = active_routes.entrySet().iterator(); - - while( it.hasNext()){ - - Map.Entry entry = (Map.Entry)it.next(); - - NetworkAdminNetworkInterfaceAddress address = (NetworkAdminNetworkInterfaceAddress)entry.getKey(); - - NetworkAdminNode[] route = (NetworkAdminNode[])entry.getValue(); - - String node_str = ""; - - for (int i=0;i it = public_addresses.iterator(); - - log( public_addresses.size() + " public/external addresses found" ); - - while( it.hasNext()){ - - InetAddress pub_address = it.next(); - - log( " " + pub_address.getHostAddress()); - - try{ - NetworkAdminASN asn = admin.lookupASN(pub_address); - - log( " AS details: " + asn.getString()); - - }catch( Throwable e ){ - - logError( " failed to lookup AS", e ); - } - } - } - } - - if ( doTest( TEST_VUZE_SERVICES )){ - - log( "Vuze Services test" ); - - String[][] services = { - { "Vuze Website", "https://www.vuze.com/" }, - { "Client Website", "https://client.vuze.com/" }, - { "Version Server", "http://version.vuze.com/?dee" }, - { "Pairing Server", "https://pair.vuze.com/pairing/web/view?" }, - { "License Server", "https://license.vuze.com/licence" }, - { "Plugins Website", "https://plugins.vuze.com/" }, - }; - - for ( String[] service: services ){ - - if ( test_cancelled ){ - - return; - } - - try{ - URL url = new URL( service[1] ); - - log( " " + service[0] + " - " + url.getHost()); - - boolean is_https = url.getProtocol().equals( "https" ); - - if ( is_https ){ - - String[] host_bits = url.getHost().split( "\\." ); - - String host_match = "." + host_bits[host_bits.length-2] + "." + host_bits[host_bits.length-1]; - - HttpsURLConnection con = (HttpsURLConnection)url.openConnection(); - - con.setHostnameVerifier( - new HostnameVerifier() - { - public boolean - verify( - String host, - SSLSession session ) - { - return( true ); - } - }); - - - con.setInstanceFollowRedirects( false ); - - con.setConnectTimeout( 30*1000 ); - con.setReadTimeout( 30*1000 ); - - con.getResponseCode(); - - con.getInputStream(); - - Certificate[] certs = con.getServerCertificates(); - - if ( certs == null || certs.length == 0 ){ - - logError( " No certificates returned" ); - - }else{ - - Certificate cert = certs[0]; - - java.security.cert.X509Certificate x509_cert; - - if ( cert instanceof java.security.cert.X509Certificate ){ - - x509_cert = (java.security.cert.X509Certificate)cert; - - }else{ - - java.security.cert.CertificateFactory cf = java.security.cert.CertificateFactory.getInstance("X.509"); - - x509_cert = (java.security.cert.X509Certificate)cf.generateCertificate(new ByteArrayInputStream(cert.getEncoded())); - } - - log( " Certificate: " + x509_cert.getSubjectDN()); - - Collection> alt_names = x509_cert.getSubjectAlternativeNames(); - - boolean match = false; - - for ( List alt_name: alt_names ){ - - int type = ((Number)alt_name.get(0)).intValue(); - - if ( type == 2 ){ // DNS name - - String dns_name = (String)alt_name.get(1); - - if ( dns_name.endsWith( host_match )){ - - match = true; - - break; - } - } - } - - if ( !match ){ - - logError( " Failed: Host '" + host_match + "' not found in certificate" ); - - }else{ - - logSuccess( " Connection result: " + con.getResponseCode() + "/" + con.getResponseMessage()); - } - } - }else{ - - HttpURLConnection con = (HttpURLConnection)url.openConnection(); - - con.setInstanceFollowRedirects( false ); - - con.setConnectTimeout( 30*1000 ); - con.setReadTimeout( 30*1000 ); - - if ( con.getResponseCode() != 200 ){ - - throw( new Exception( "Connection failed: " + con.getResponseCode() + "/" + con.getResponseMessage())); - } - - Map resp = BDecoder.decode( new BufferedInputStream( con.getInputStream(), 16*1024 )); - - if ( resp != null && resp.containsKey( "version" )){ - - logSuccess( " Connection result: " + con.getResponseCode() + "/" + con.getResponseMessage()); - - }else{ - - logError( " Unexpected reply from server: " + resp ); - } - } - }catch( Throwable e ){ - - logError( " Failed: " + Debug.getNestedExceptionMessage( e )); - } - } - } - - if ( doTest( TEST_PROXY_CONNECT )){ - - log( "Indirect Connect test" ); - - try{ - URL target = new URL( "https://www.vuze.com" ); - - PluginProxy proxy = AEProxyFactory.getPluginProxy( "Network Status test", target ); - - if ( proxy == null ){ - - String url_str = "http://azureus.sourceforge.net/plugin_detailssf.php?plugin=aznettor&os="; - - if ( Constants.isWindows ){ - - url_str += "Windows"; - - }else{ - - url_str += "Mac%20OSX"; - } - - URL url = new URL( url_str ); - - logError( " No plugin proxy available" ); - logInfo( " For the plugin installer see " + url.toExternalForm()); - - }else{ - - log( " Connecting to " + target.toExternalForm()); - - HttpURLConnection con = (HttpURLConnection)proxy.getURL().openConnection( proxy.getProxy()); - - if ( con instanceof HttpsURLConnection ){ - - ((HttpsURLConnection)con).setHostnameVerifier( - new HostnameVerifier() - { - public boolean - verify( - String host, - SSLSession session ) - { - return( true ); - } - }); - } - - con.setRequestProperty( "HOST", proxy.getURLHostRewrite()); - - con.setInstanceFollowRedirects( false ); - - con.setConnectTimeout( 60*1000 ); - con.setReadTimeout( 30*1000 ); - - try{ - int resp = con.getResponseCode(); - - if ( con instanceof HttpsURLConnection ){ - - Certificate[] certs = ((HttpsURLConnection)con).getServerCertificates(); - - if ( certs == null || certs.length == 0 ){ - - logError( " No certificates returned" ); - - }else{ - Certificate cert = certs[0]; - - java.security.cert.X509Certificate x509_cert; - - if ( cert instanceof java.security.cert.X509Certificate ){ - - x509_cert = (java.security.cert.X509Certificate)cert; - - }else{ - - java.security.cert.CertificateFactory cf = java.security.cert.CertificateFactory.getInstance("X.509"); - - x509_cert = (java.security.cert.X509Certificate)cf.generateCertificate(new ByteArrayInputStream(cert.getEncoded())); - } - - log( " Certificate: " + x509_cert.getSubjectDN()); - } - } - - if ( resp == 200 ){ - - logSuccess( " Connection result: " + con.getResponseCode() + "/" + con.getResponseMessage()); - - }else{ - - log( " Connection result: " + con.getResponseCode() + "/" + con.getResponseMessage()); - } - }finally{ - - proxy.setOK( true ); - } - } - }catch( Throwable e ){ - - logError( " Failed: " + Debug.getNestedExceptionMessage( e )); - logError( " Check the logs for the 'Tor Helper Plugin' (Tools->Plugins->Log Views)" ); - } - } - - if ( doTest( TEST_BT_CONNECT )){ - - log( "Distributed protocol test" ); - - NetStatusProtocolTesterBT bt_test = - plugin.getProtocolTester().runTest( - - new NetStatusProtocolTesterListener() - { - private List sessions = new ArrayList(); - - public void - complete( - NetStatusProtocolTesterBT tester ) - { - log( "Results", false ); - - if ( tester.getOutboundConnects() < 4 ){ - - log( " insufficient outbound connects for analysis", false ); - - return; - } - - int outgoing_seed_ok = 0; - int outgoing_leecher_ok = 0; - int outgoing_seed_bad = 0; - int outgoing_leecher_bad = 0; - - int incoming_connect_ok = 0; - - for (int i=0;i 0 && - outgoing_seed_ok == 0 && - outgoing_seed_bad > 0 ){ - - logError( " Outgoing seed connects appear to be failing while non-seeds succeed" ); - - good = false; - } - - if ( good ){ - - logSuccess( " Test successful" ); - } - } - - public void - sessionAdded( - NetStatusProtocolTesterBT.Session session ) - { - synchronized( sessions ){ - - sessions.add( session ); - } - } - - public void - log( - String str, - boolean detailed ) - { - NetStatusPluginTester.this.log( " " + str, detailed ); - } - - public void - logError( - String str ) - { - NetStatusPluginTester.this.logError( " " + str ); - } - - public void - logError( - String str, - Throwable e ) - { - NetStatusPluginTester.this.logError( " " + str, e ); - } - }); - - while( !bt_test.waitForCompletion( 5000 )){ - - if ( isCancelled()){ - - bt_test.destroy(); - - break; - } - - log( " Status: " + bt_test.getStatus()); - } - } - - if ( doTest( TEST_IPV6 )){ - - log( "IPv6 test" ); - - InetAddress ipv6_address = admin.getDefaultPublicAddressV6(); - - if ( ipv6_address == null ){ - - log( " No default public IPv6 address found" ); - - }else{ - - log( " Default public IPv6 address: " + ipv6_address.getHostAddress()); - - log( " Testing connectivity..." ); - - String res = VersionCheckClient.getSingleton().getExternalIpAddress( false, true, true ); - - if ( res != null && res.length() > 0 ){ - - logSuccess( " Connect succeeded, reported IPv6 address: " + res ); - - }else{ - - logError( " Connect failed" ); - } - } - } - } - - protected void - addPublicAddress( - Set addresses, - InetAddress address ) - { - if ( address == null ){ - - return; - } - - if ( address.isAnyLocalAddress() || - address.isLoopbackAddress() || - address.isLinkLocalAddress()|| - address.isSiteLocalAddress()){ - - return; - } - - addresses.add( address ); - } - - public void - cancel() - { - test_cancelled = true; - } - - public boolean - isCancelled() - { - return( test_cancelled ); - } - - protected void - log( - String str ) - { - log( str, false ); - } - - protected void - log( - String str, - boolean detailed ) - { - logger.log( str, detailed ); - } - - protected void - logSuccess( - String str ) - { - logger.logSuccess( str ); - } - - protected void - logInfo( - String str ) - { - logger.logInfo( str ); - } - - protected void - log( - String str, - Throwable e ) - { - logger.log( str + ": " + e.getLocalizedMessage(), false ); - } - - protected void - logError( - String str ) - { - logger.logFailure( str ); - } - - protected void - logError( - String str, - Throwable e ) - { - logger.logFailure( str + ": " + e.getLocalizedMessage()); - } - - public interface - loggerProvider - { - public void - log( - String str, - boolean is_detailed ); - - public void - logSuccess( - String str ); - - public void - logInfo( - String str ); - - public void - logFailure( - String str ); - } - -} diff --git a/vuze/com/aelitis/azureus/plugins/net/netstatus/swt/NetStatusPluginView.java b/vuze/com/aelitis/azureus/plugins/net/netstatus/swt/NetStatusPluginView.java deleted file mode 100644 index d673d67..0000000 --- a/vuze/com/aelitis/azureus/plugins/net/netstatus/swt/NetStatusPluginView.java +++ /dev/null @@ -1,613 +0,0 @@ -/* - * Created on Jan 30, 2008 - * Created by Paul Gardner - * - * Copyright 2008 Vuze, Inc. 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; version 2 of the License only. - * - * 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. - */ - - -package com.aelitis.azureus.plugins.net.netstatus.swt; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyleRange; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.gudy.azureus2.core3.config.COConfigurationManager; -import org.gudy.azureus2.core3.util.AEThread2; -import org.gudy.azureus2.core3.util.Constants; -import org.gudy.azureus2.core3.util.Debug; -import org.gudy.azureus2.plugins.ui.UIInstance; -import org.gudy.azureus2.ui.swt.Messages; -import org.gudy.azureus2.ui.swt.Utils; -import org.gudy.azureus2.ui.swt.mainwindow.ClipboardCopy; -import org.gudy.azureus2.ui.swt.mainwindow.Colors; -import org.gudy.azureus2.ui.swt.plugins.UISWTInstance; -import org.gudy.azureus2.ui.swt.plugins.UISWTViewEvent; -import org.gudy.azureus2.ui.swt.plugins.UISWTViewEventListener; -import org.gudy.azureus2.ui.swt.shells.CoreWaiterSWT; -import org.gudy.azureus2.ui.swt.shells.CoreWaiterSWT.TriggerInThread; - -import com.aelitis.azureus.core.AzureusCore; -import com.aelitis.azureus.core.AzureusCoreRunningListener; -import com.aelitis.azureus.core.proxy.AEProxyFactory; -import com.aelitis.azureus.plugins.net.netstatus.NetStatusPlugin; - -public class -NetStatusPluginView - implements UISWTViewEventListener -{ - private NetStatusPlugin plugin; - - private boolean created = false; - - private Composite composite; - private Button start_button; - private Button cancel_button; - private StyledText log; - - private int selected_tests; - - private NetStatusPluginTester current_test; - - private static final int LOG_NORMAL = 1; - private static final int LOG_SUCCESS = 2; - private static final int LOG_ERROR = 3; - private static final int LOG_INFO = 4; - - private int log_type = LOG_NORMAL; - - public - NetStatusPluginView( - NetStatusPlugin _plugin, - UIInstance _ui, - String VIEW_ID ) - { - plugin = _plugin; - - ((UISWTInstance)_ui).addView( UISWTInstance.VIEW_MAIN, VIEW_ID, this ); - } - - public boolean - eventOccurred( - UISWTViewEvent event ) - { - switch( event.getType() ){ - - case UISWTViewEvent.TYPE_CREATE:{ - - if ( created ){ - - return( false ); - } - - created = true; - - break; - } - case UISWTViewEvent.TYPE_INITIALIZE:{ - - initialise((Composite)event.getData()); - - break; - } - case UISWTViewEvent.TYPE_CLOSE: - case UISWTViewEvent.TYPE_DESTROY:{ - - try{ - destroy(); - - }finally{ - - created = false; - } - - break; - } - } - - return true; - } - - protected void - initialise( - Composite _composite ) - { - composite = _composite; - - Composite main = new Composite(composite, SWT.NONE); - GridLayout layout = new GridLayout(); - layout.numColumns = 1; - layout.marginHeight = 0; - layout.marginWidth = 0; - main.setLayout(layout); - GridData grid_data = new GridData(GridData.FILL_BOTH ); - main.setLayoutData(grid_data); - - // control - - Composite control = new Composite(main, SWT.NONE); - layout = new GridLayout(); - layout.numColumns = 3; - layout.marginHeight = 4; - layout.marginWidth = 4; - control.setLayout(layout); - - Label info = new Label( control, SWT.NULL ); - grid_data = new GridData(GridData.FILL_HORIZONTAL); - grid_data.horizontalSpan = 3; - info.setLayoutData( grid_data ); - Messages.setLanguageText( info, "label.test.internet" ); - - grid_data = new GridData(GridData.FILL_HORIZONTAL); - grid_data.horizontalSpan = 1; - control.setLayoutData(grid_data); - - List