1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
|
Description: Removes the name service descriptor to build with Java 9+
Author: Emmanuel Bourg <ebourg@apache.org>
Forwarded: not-needed
--- a/core/src/META-INF/services/sun.net.spi.nameservice.NameServiceDescriptor
+++ /dev/null
@@ -1 +0,0 @@
-com.biglybt.core.util.spi.AENameServiceDescriptor
--- a/core/src/com/biglybt/core/util/spi/AENameServiceDescriptor.java
+++ /dev/null
@@ -1,452 +0,0 @@
-/*
- * Created on Aug 18, 2014
- * Created by Paul Gardner
- *
- * Copyright 2014 Azureus Software, 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; 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.
- */
-
-package com.biglybt.core.util.spi;
-
-import java.lang.reflect.*;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.List;
-
-import com.biglybt.core.Core;
-import com.biglybt.core.CoreFactory;
-import com.biglybt.core.config.COConfigurationListener;
-import com.biglybt.core.config.COConfigurationManager;
-import com.biglybt.core.config.ConfigKeys;
-import com.biglybt.core.internat.MessageText;
-import com.biglybt.core.networkmanager.admin.NetworkAdmin;
-import com.biglybt.core.util.AENetworkClassifier;
-import com.biglybt.core.util.NetUtils;
-import com.biglybt.core.util.TorrentUtils;
-import com.biglybt.pif.PluginAdapter;
-import com.biglybt.pif.PluginInterface;
-import com.biglybt.plugin.I2PHelpers;
-
-import sun.net.spi.nameservice.NameService;
-import sun.net.spi.nameservice.NameServiceDescriptor;
-import sun.net.spi.nameservice.dns.DNSNameService;
-
-/*
- * This proxy is controlled by the setting in ConfigurationManager
- *
- * System.setProperty("sun.net.spi.nameservice.provider.1","dns,aednsproxy");
- *
- * and also requires META-INF/services/sun.net.spi.nameservice.NameServiceDescriptor to contain the text
- *
- * com.biglybt.core.util.spi.AENameServiceDescriptor
- *
- * On OSX you will need to do the following to get things to compile:
- *
- * Windows -> Preferences -> Java -> Compiler -> Errors/Warnings -> Deprecated and restricted API -> Forbidden reference (access rules): -> change to warning
- *
- */
-
-public class
-AENameServiceDescriptor
- implements NameServiceDescriptor
-{
- // used in NetworkAdminImpl - not direct fixup due to loading issues observed...
-
- private final static NameService delegate_ns;
- private final static Method delegate_ns_method_lookupAllHostAddr;
-
- private final static Object delegate_iai;
- private final static Method delegate_iai_method_lookupAllHostAddr;
-
-
- private final static NameService proxy_name_service;
-
- static{
- NameService default_ns = null;
- Method default_lookupAllHostAddr = null;
-
- NameService new_ns = null;
-
- try{
- default_ns = new DNSNameService();
-
- if ( default_ns != null ){
-
- default_lookupAllHostAddr = default_ns.getClass().getMethod( "lookupAllHostAddr", String.class );
-
- new_ns =
- (NameService)Proxy.newProxyInstance(
- NameService.class.getClassLoader(),
- new Class[]{ NameService.class },
- new NameServiceProxy());
- }
- }catch( Throwable e ){
-
- e.printStackTrace();
- }
-
- /*
- * It almost works by delegating the the DNSNameService directly apart from InetAddress.getLocalHost() - rather than returning something sensible
- * it fails with unknown host. However, if we directly grab the InetAddressImpl and use this (which has already been set up to use the default name server)
- * things work better :( Hacked to support both at the moment...
- */
-
- Object iai = null;
- Method iai_lookupAllHostAddr = null;
-
- try{
- Field field = InetAddress.class.getDeclaredField( "impl" );
-
- field.setAccessible( true );
-
- iai = field.get( null );
-
- iai_lookupAllHostAddr = iai.getClass().getMethod( "lookupAllHostAddr", String.class );
-
- iai_lookupAllHostAddr.setAccessible( true );
-
- }catch( Throwable e ){
-
- System.err.println( "Issue resolving the default name service..." );
- }
-
- proxy_name_service = new_ns;
- delegate_ns = default_ns;
- delegate_ns_method_lookupAllHostAddr = default_lookupAllHostAddr;
- delegate_iai = iai;
- delegate_iai_method_lookupAllHostAddr = iai_lookupAllHostAddr;
- }
-
- private static boolean config_listener_added;
- private static volatile boolean tracker_dns_disabled;
- private static volatile boolean tracker_plugin_proxies_permit;
-
- @Override
- public NameService
- createNameService()
-
- throws Exception
- {
- if ( proxy_name_service == null ){
-
- throw( new Exception( "Failed to create proxy name service" ));
- }
-
- return( proxy_name_service );
- }
-
- @Override
- public String
- getType()
- {
- return( "dns" );
- }
-
- @Override
- public String
- getProviderName()
- {
- return( "aednsproxy" );
- }
-
- private static class
- NameServiceProxy
- implements InvocationHandler
- {
- @Override
- public Object
- invoke(
- Object proxy,
- Method method,
- Object[] args )
-
- throws Throwable
- {
- String method_name = method.getName();
-
- if ( method_name.equals( "lookupAllHostAddr" )){
-
- String host_name = (String)args[0];
-
- if ( host_name.equals( NetworkAdmin.DNS_SPI_TEST_HOST )){
-
- if ( delegate_ns == null ){
-
- throw( new RuntimeException( "Delegate Name Service unavailable" ));
- }
-
- List<String> domains = NetUtils.getTestDomains();
-
- if ( domains.isEmpty()){
-
- throw( new RuntimeException( "No test domains available" ));
- }
-
- RuntimeException last_error = null;
- boolean maybe_ok = false;
-
- for ( String domain: domains ){
-
- try{
- Object result = null;
-
- if ( delegate_iai_method_lookupAllHostAddr != null ){
-
- try{
- result = delegate_iai_method_lookupAllHostAddr.invoke( delegate_iai, domain );
-
- }catch( Throwable e ){
- }
- }
-
- if ( result == null ){
-
- result = delegate_ns_method_lookupAllHostAddr.invoke( delegate_ns, domain );
- }
-
- last_error = null;
-
- break;
-
- }catch( Throwable e ){
-
- if ( e instanceof InvocationTargetException ){
-
- e = ((InvocationTargetException)e).getTargetException();
- }
-
- if ( e instanceof UnknownHostException ){
-
- // guess their DNS might be down - don't treat as complete fail
-
- System.err.println( "DNS resolution of " + domain + " failed, DNS unavailable?" );
-
- maybe_ok = true;
-
- }else{
-
- last_error = new RuntimeException( "Delegate lookup failed", e );
- }
- }
- }
-
- if ( last_error != null && !maybe_ok ){
-
- throw( last_error );
- }
-
- // byte[][] or InetAddress[]
-
- Class ret_type = method.getReturnType();
-
- if ( ret_type.equals( byte[][].class )){
-
- return( new byte[][]{ {127,0,0,1}});
-
- }else{
-
- return( new InetAddress[]{ InetAddress.getByAddress( new byte[]{ 127, 0, 0, 1 })});
- }
- }
-
- boolean tracker_request = TorrentUtils.getTLSTorrentHash() != null;
-
- if ( tracker_request ){
-
- synchronized( this ){
-
- if ( !config_listener_added ){
-
- config_listener_added = true;
-
- COConfigurationManager.addAndFireListener(
- new COConfigurationListener()
- {
- @Override
- public void
- configurationSaved()
- {
- boolean enable_proxy = COConfigurationManager.getBooleanParameter("Enable.Proxy");
- boolean enable_socks = COConfigurationManager.getBooleanParameter("Enable.SOCKS");
- boolean prevent_dns = COConfigurationManager.getBooleanParameter("Proxy.SOCKS.Tracker.DNS.Disable");
-
- tracker_plugin_proxies_permit =
- enable_proxy&&
- enable_socks&&
- !COConfigurationManager.getBooleanParameter( "Proxy.SOCKS.disable.plugin.proxies" );
-
- tracker_dns_disabled = enable_proxy&&enable_socks&&prevent_dns;
- }
- });
- }
- }
-
- if ( tracker_plugin_proxies_permit ){
-
- // in this case we want non-public addresses to be sent to the plugin proxy, not handed
- // unresolved to a SOCKS proxy, so use a runtime exception to
- // prevent this (UnknownHostException causes SOCKS usage)
-
- if ( AENetworkClassifier.categoriseAddress( host_name ) != AENetworkClassifier.AT_PUBLIC ){
-
- throw( new RuntimeException( "Plugin proxies enabled for SOCKS"));
- }
- }
-
- if ( tracker_dns_disabled ){
-
- // this will normally result in the address being marked as 'unresolved' and
- // therefore be passed through socks 4a/5 for remote resolution
-
- throw( new UnknownHostException( host_name ));
- }
- }
- }
-
- return( invokeSupport( method_name, args ));
- }
-
- private Object
- invokeSupport(
- String method_name,
- Object[] args )
-
- throws Throwable
- {
- if ( method_name.equals( "getHostByAddr" )){
-
- byte[] address_bytes = (byte[])args[0];
-
- //System.out.println( method_name + ": " + ByteFormatter.encodeString( address_bytes ));
-
- return delegate_ns.getHostByAddr( address_bytes );
-
- }else if ( method_name.equals( "lookupAllHostAddr" )){
-
- String host_name = (String)args[0];
-
- //System.out.println( method_name + ": " + host_name );
-
- if ( host_name == null || host_name.equals( "null" )){
-
- // get quite a few of these from 3rd party libs :(
- // new Exception("Bad DNS lookup: " + host_name).printStackTrace();
-
- }else if ( host_name.endsWith( ".i2p" )){
-
- //new Exception( "Prevented DNS leak for " + host_name ).printStackTrace();
-
- checkI2PInstall( host_name );
-
- throw( new UnknownHostException( host_name ));
-
- }else if ( host_name.endsWith( ".onion" )){
-
- //new Exception( "Prevented DNS leak for " + host_name ).printStackTrace();
-
- throw( new UnknownHostException( host_name ));
- }
-
- // System.out.println( "DNS: " + host_name );
-
- try{
- if ( delegate_iai_method_lookupAllHostAddr != null ){
-
- try{
- return( delegate_iai_method_lookupAllHostAddr.invoke( delegate_iai, host_name ));
-
- }catch( Throwable e ){
- }
- }
-
- return( delegate_ns_method_lookupAllHostAddr.invoke( delegate_ns, host_name ));
-
- }catch( InvocationTargetException e ){
-
- throw(((InvocationTargetException)e).getTargetException());
- }
-
- }else{
-
- throw( new IllegalArgumentException( "Unknown method '" + method_name + "'" ));
- }
- }
- }
-
- private static boolean i2p_checked = false;
-
- private static void
- checkI2PInstall(
- final String host_name )
- {
- synchronized( AENameServiceDescriptor.class ){
-
- if ( i2p_checked ){
-
- return;
- }
-
-
- try{
- Core core = CoreFactory.getSingleton();
-
- if ( core != null ){
-
- i2p_checked = true;
-
- PluginInterface pi = core.getPluginManager().getDefaultPluginInterface();
-
- pi.addListener(
- new PluginAdapter()
- {
- @Override
- public void
- initializationComplete()
- {
- if ( I2PHelpers.isI2PInstalled()){
-
- return;
- }
-
- final boolean[] install_outcome = { false };
-
- String enable_i2p_reason =
- MessageText.getString( "azneti2phelper.install.reason.dns", new String[]{ host_name });
-
- I2PHelpers.installI2PHelper(
- enable_i2p_reason,
- "azneti2phelper.install.dns.resolve",
- install_outcome,
- new Runnable()
- {
- @Override
- public void
- run()
- {
- if ( !install_outcome[0] ){
-
- }
- }
- });
- }
- });
- }
- }catch( Throwable e ){
-
- }
- }
- }
-}
|