Changeset 8337 in josm for trunk/src/org/openstreetmap/josm/io
- Timestamp:
- 2015-05-06T20:05:57+02:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/io/remotecontrol
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/remotecontrol/RemoteControl.java
r7834 r8337 4 4 import java.io.File; 5 5 import java.net.InetAddress; 6 import java.net.Inet4Address; 7 import java.net.Inet6Address; 6 8 import java.net.UnknownHostException; 7 9 … … 83 85 * @since 7800 84 86 */ 87 @Deprecated 85 88 public static InetAddress getInetAddress() throws UnknownHostException { 86 89 // Return an address to the loopback interface by default 87 90 return InetAddress.getByName(Main.pref.get("remote.control.host", null)); 88 91 } 92 93 /** 94 * Returns the IPv6 address used for remote control. 95 * @return the IPv6 address used for remote control 96 * @throws UnknownHostException if the local host name could not be resolved into an address. 97 * @since 8337 98 */ 99 public static InetAddress getInet6Address() throws UnknownHostException { 100 for(InetAddress a : InetAddress.getAllByName(Main.pref.get("remote.control.host", "localhost"))) { 101 if(a instanceof Inet6Address) { 102 return a; 103 } 104 }; 105 throw new UnknownHostException(); 106 } 107 108 /** 109 * Returns the IPv4 address used for remote control. 110 * @return the IPv4 address used for remote control 111 * @throws UnknownHostException if the local host name could not be resolved into an address. 112 * @since 8337 113 */ 114 public static InetAddress getInet4Address() throws UnknownHostException { 115 // Return an address to the loopback interface by default 116 for(InetAddress a : InetAddress.getAllByName(Main.pref.get("remote.control.host", "localhost"))) { 117 if(a instanceof Inet4Address) { 118 return a; 119 } 120 }; 121 throw new UnknownHostException(); 122 } 89 123 } -
trunk/src/org/openstreetmap/josm/io/remotecontrol/RemoteControlHttpServer.java
r8126 r8337 20 20 public class RemoteControlHttpServer extends Thread { 21 21 22 /** The server socket */ 23 private ServerSocket server; 22 /** The server socket for IPv4 */ 23 private ServerSocket server4 = null; 24 /** The server socket for IPv6 */ 25 private ServerSocket server6 = null; 24 26 25 27 private static volatile RemoteControlHttpServer instance; … … 66 68 super("RemoteControl HTTP Server"); 67 69 this.setDaemon(true); 68 // Start the server socket with only 1 connection. 69 // Also make sure we only listen on the local interface so nobody from the outside can connect! 70 // NOTE: On a dual stack machine with old Windows OS this may not listen on both interfaces! 71 this.server = new ServerSocket(port, 1, RemoteControl.getInetAddress()); 70 try { 71 this.server4 = new ServerSocket(port, 1, RemoteControl.getInet4Address()); 72 } catch (IOException e) { 73 } 74 try { 75 this.server6 = new ServerSocket(port, 1, RemoteControl.getInet6Address()); 76 } catch (IOException e) { 77 if(this.server4 == null) /* both failed */ 78 throw e; 79 } 72 80 } 73 81 … … 77 85 @Override 78 86 public void run() { 79 Main.info(marktr("RemoteControl::Accepting connections on {0}:{1}"), 80 server.getInetAddress(), Integer.toString(server.getLocalPort())); 87 if(server4 != null) { 88 Main.info(marktr("RemoteControl::Accepting IPv4 connections on {0}:{1}"), 89 server4.getInetAddress(), Integer.toString(server4.getLocalPort())); 90 } 91 if(server6 != null) { 92 Main.info(marktr("RemoteControl::Accepting IPv6 connections on {0}:{1}"), 93 server6.getInetAddress(), Integer.toString(server6.getLocalPort())); 94 } 81 95 while (true) { 82 try { 83 @SuppressWarnings("resource") 84 Socket request = server.accept(); 85 RequestProcessor.processRequest(request); 86 } catch (SocketException se) { 87 if (!server.isClosed()) 88 Main.error(se); 89 } catch (IOException ioe) { 90 Main.error(ioe); 96 if(server4 != null) { 97 try { 98 @SuppressWarnings("resource") 99 Socket request = server4.accept(); 100 RequestProcessor.processRequest(request); 101 } catch (SocketException se) { 102 if (!server4.isClosed()) 103 Main.error(se); 104 } catch (IOException ioe) { 105 Main.error(ioe); 106 } 107 } 108 if(server6 != null) { 109 try { 110 @SuppressWarnings("resource") 111 Socket request = server6.accept(); 112 RequestProcessor.processRequest(request); 113 } catch (SocketException se) { 114 if (!server6.isClosed()) 115 Main.error(se); 116 } catch (IOException ioe) { 117 Main.error(ioe); 118 } 91 119 } 92 120 } … … 99 127 */ 100 128 public void stopServer() throws IOException { 101 server.close(); 129 if(server4 != null) 130 server4.close(); 131 if(server6 != null) 132 server6.close(); 102 133 Main.info(marktr("RemoteControl::Server stopped.")); 103 134 } -
trunk/src/org/openstreetmap/josm/io/remotecontrol/RemoteControlHttpsServer.java
r8126 r8337 72 72 public class RemoteControlHttpsServer extends Thread { 73 73 74 /** The server socket */ 75 private ServerSocket server; 74 /** The server socket for IPv4 */ 75 private ServerSocket server4 = null; 76 /** The server socket for IPv6 */ 77 private ServerSocket server6 = null; 76 78 77 79 private static volatile RemoteControlHttpsServer instance; … … 377 379 } 378 380 379 // Start the server socket with only 1 connection. 380 // Also make sure we only listen on the local interface so nobody from the outside can connect! 381 // NOTE: On a dual stack machine with old Windows OS this may not listen on both interfaces! 382 this.server = factory.createServerSocket(port, 1, RemoteControl.getInetAddress()); 383 384 if (Main.isTraceEnabled() && server instanceof SSLServerSocket) { 385 SSLServerSocket sslServer = (SSLServerSocket) server; 386 Main.trace("SSL server - Enabled Cipher suites: "+Arrays.toString(sslServer.getEnabledCipherSuites())); 387 Main.trace("SSL server - Enabled Protocols: "+Arrays.toString(sslServer.getEnabledProtocols())); 388 Main.trace("SSL server - Enable Session Creation: "+sslServer.getEnableSessionCreation()); 389 Main.trace("SSL server - Need Client Auth: "+sslServer.getNeedClientAuth()); 390 Main.trace("SSL server - Want Client Auth: "+sslServer.getWantClientAuth()); 391 Main.trace("SSL server - Use Client Mode: "+sslServer.getUseClientMode()); 381 try { 382 this.server4 = factory.createServerSocket(port, 1, RemoteControl.getInet4Address()); 383 } catch (IOException e) { 384 } 385 try { 386 this.server6 = factory.createServerSocket(port, 1, RemoteControl.getInet6Address()); 387 } catch (IOException e) { 388 if(this.server4 == null) /* both failed */ 389 throw e; 390 } 391 392 if (Main.isTraceEnabled()) { 393 if(server4 instanceof SSLServerSocket) { 394 SSLServerSocket sslServer = (SSLServerSocket) server4; 395 Main.trace("SSL server - Enabled Cipher suites: "+Arrays.toString(sslServer.getEnabledCipherSuites())); 396 Main.trace("SSL server - Enabled Protocols: "+Arrays.toString(sslServer.getEnabledProtocols())); 397 Main.trace("SSL server - Enable Session Creation: "+sslServer.getEnableSessionCreation()); 398 Main.trace("SSL server - Need Client Auth: "+sslServer.getNeedClientAuth()); 399 Main.trace("SSL server - Want Client Auth: "+sslServer.getWantClientAuth()); 400 Main.trace("SSL server - Use Client Mode: "+sslServer.getUseClientMode()); 401 } 402 if(server6 instanceof SSLServerSocket) { 403 SSLServerSocket sslServer = (SSLServerSocket) server6; 404 Main.trace("SSL server - Enabled Cipher suites: "+Arrays.toString(sslServer.getEnabledCipherSuites())); 405 Main.trace("SSL server - Enabled Protocols: "+Arrays.toString(sslServer.getEnabledProtocols())); 406 Main.trace("SSL server - Enable Session Creation: "+sslServer.getEnableSessionCreation()); 407 Main.trace("SSL server - Need Client Auth: "+sslServer.getNeedClientAuth()); 408 Main.trace("SSL server - Want Client Auth: "+sslServer.getWantClientAuth()); 409 Main.trace("SSL server - Use Client Mode: "+sslServer.getUseClientMode()); 410 } 392 411 } 393 412 } … … 398 417 @Override 399 418 public void run() { 400 Main.info(marktr("RemoteControl::Accepting secure connections on {0}:{1}"), 401 server.getInetAddress(), Integer.toString(server.getLocalPort())); 419 if(server4 != null) { 420 Main.info(marktr("RemoteControl::Accepting secure IPv4 connections on {0}:{1}"), 421 server4.getInetAddress(), Integer.toString(server4.getLocalPort())); 422 } 423 if(server6 != null) { 424 Main.info(marktr("RemoteControl::Accepting secure IPv6 connections on {0}:{1}"), 425 server6.getInetAddress(), Integer.toString(server6.getLocalPort())); 426 } 402 427 while (true) { 403 try { 404 @SuppressWarnings("resource") 405 Socket request = server.accept(); 406 if (Main.isTraceEnabled() && request instanceof SSLSocket) { 407 SSLSocket sslSocket = (SSLSocket) request; 408 Main.trace("SSL socket - Enabled Cipher suites: "+Arrays.toString(sslSocket.getEnabledCipherSuites())); 409 Main.trace("SSL socket - Enabled Protocols: "+Arrays.toString(sslSocket.getEnabledProtocols())); 410 Main.trace("SSL socket - Enable Session Creation: "+sslSocket.getEnableSessionCreation()); 411 Main.trace("SSL socket - Need Client Auth: "+sslSocket.getNeedClientAuth()); 412 Main.trace("SSL socket - Want Client Auth: "+sslSocket.getWantClientAuth()); 413 Main.trace("SSL socket - Use Client Mode: "+sslSocket.getUseClientMode()); 414 Main.trace("SSL socket - Session: "+sslSocket.getSession()); 415 } 416 RequestProcessor.processRequest(request); 417 } catch (SocketException se) { 418 if (!server.isClosed()) { 419 Main.error(se); 420 } 421 } catch (IOException ioe) { 422 Main.error(ioe); 428 if(server4 != null) { 429 try { 430 @SuppressWarnings("resource") 431 Socket request = server4.accept(); 432 if (Main.isTraceEnabled() && request instanceof SSLSocket) { 433 SSLSocket sslSocket = (SSLSocket) request; 434 Main.trace("SSL socket - Enabled Cipher suites: "+Arrays.toString(sslSocket.getEnabledCipherSuites())); 435 Main.trace("SSL socket - Enabled Protocols: "+Arrays.toString(sslSocket.getEnabledProtocols())); 436 Main.trace("SSL socket - Enable Session Creation: "+sslSocket.getEnableSessionCreation()); 437 Main.trace("SSL socket - Need Client Auth: "+sslSocket.getNeedClientAuth()); 438 Main.trace("SSL socket - Want Client Auth: "+sslSocket.getWantClientAuth()); 439 Main.trace("SSL socket - Use Client Mode: "+sslSocket.getUseClientMode()); 440 Main.trace("SSL socket - Session: "+sslSocket.getSession()); 441 } 442 RequestProcessor.processRequest(request); 443 } catch (SocketException se) { 444 if (!server4.isClosed()) { 445 Main.error(se); 446 } 447 } catch (IOException ioe) { 448 Main.error(ioe); 449 } 450 } 451 if(server6 != null) { 452 try { 453 @SuppressWarnings("resource") 454 Socket request = server6.accept(); 455 if (Main.isTraceEnabled() && request instanceof SSLSocket) { 456 SSLSocket sslSocket = (SSLSocket) request; 457 Main.trace("SSL socket - Enabled Cipher suites: "+Arrays.toString(sslSocket.getEnabledCipherSuites())); 458 Main.trace("SSL socket - Enabled Protocols: "+Arrays.toString(sslSocket.getEnabledProtocols())); 459 Main.trace("SSL socket - Enable Session Creation: "+sslSocket.getEnableSessionCreation()); 460 Main.trace("SSL socket - Need Client Auth: "+sslSocket.getNeedClientAuth()); 461 Main.trace("SSL socket - Want Client Auth: "+sslSocket.getWantClientAuth()); 462 Main.trace("SSL socket - Use Client Mode: "+sslSocket.getUseClientMode()); 463 Main.trace("SSL socket - Session: "+sslSocket.getSession()); 464 } 465 RequestProcessor.processRequest(request); 466 } catch (SocketException se) { 467 if (!server6.isClosed()) { 468 Main.error(se); 469 } 470 } catch (IOException ioe) { 471 Main.error(ioe); 472 } 423 473 } 424 474 } … … 431 481 */ 432 482 public void stopServer() throws IOException { 433 if (server != null) { 434 server.close(); 435 Main.info(marktr("RemoteControl::Server (https) stopped.")); 436 } 483 if(server4 != null) 484 server4.close(); 485 if(server6 != null) 486 server6.close(); 487 if(server6 != null || server4 != null) 488 Main.info(marktr("RemoteControl::Server (IPv6 https) stopped.")); 437 489 } 438 490 }
Note:
See TracChangeset
for help on using the changeset viewer.