Changeset 7cb5dab
- Timestamp:
- Jan 30, 2017 12:33:43 AM (4 years ago)
- Branches:
- master
- Children:
- 890ad25
- Parents:
- 1cf6030
- Location:
- apps/i2ptunnel/java/src/net/i2p/i2ptunnel
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelConnectClient.java
r1cf6030 r7cb5dab 15 15 import net.i2p.I2PAppContext; 16 16 import net.i2p.I2PException; 17 import net.i2p.app.ClientApp; 18 import net.i2p.app.ClientAppManager; 19 import net.i2p.app.Outproxy; 17 20 import net.i2p.client.streaming.I2PSocket; 18 21 import net.i2p.client.streaming.I2PSocketOptions; … … 35 38 * ) 36 39 * 37 * (p ort and protocol areignored for i2p destinations)40 * (protocol is ignored for i2p destinations) 38 41 * CONNECT host 39 42 * CONNECT host protocol … … 148 151 boolean usingWWWProxy = false; 149 152 String currentProxy = null; 153 // local outproxy plugin 154 boolean usingInternalOutproxy = false; 155 Outproxy outproxy = null; 150 156 long requestId = __requestId.incrementAndGet(); 151 157 try { … … 155 161 StringBuilder newRequest = new StringBuilder(); 156 162 String authorization = null; 163 int remotePort = 443; 157 164 while (true) { 158 165 // Use this rather than BufferedReader because we can't have readahead, … … 173 180 174 181 pos = request.indexOf(':'); 175 if (pos == -1) 182 if (pos == -1) { 176 183 pos = request.indexOf(' '); 184 } else { 185 int spos = request.indexOf(' '); 186 if (spos > 0) { 187 try { 188 remotePort = Integer.parseInt(request.substring(pos + 1, spos)); 189 } catch (NumberFormatException nfe) { 190 break; 191 } catch (IndexOutOfBoundsException ioobe) { 192 break; 193 } 194 } 195 } 177 196 if (pos == -1) { 178 197 host = request; … … 186 205 // Destination gets the host name 187 206 destination = host; 188 } else if (host.indexOf('.') != -1) { 189 // The request must be forwarded to a outproxy 190 currentProxy = selectProxy(); 191 if (currentProxy == null) { 192 if (_log.shouldLog(Log.WARN)) 193 _log.warn(getPrefix(requestId) + "Host wants to be outproxied, but we dont have any!"); 194 writeErrorMessage(ERR_NO_OUTPROXY, out); 195 s.close(); 196 return; 207 } else if (host.contains(".") || host.startsWith("[")) { 208 if (Boolean.parseBoolean(getTunnel().getClientOptions().getProperty(PROP_USE_OUTPROXY_PLUGIN, "true"))) { 209 ClientAppManager mgr = _context.clientAppManager(); 210 if (mgr != null) { 211 ClientApp op = mgr.getRegisteredApp(Outproxy.NAME); 212 if (op != null) { 213 outproxy = (Outproxy) op; 214 usingInternalOutproxy = true; 215 if (host.startsWith("[")) { 216 host = host.substring(1); 217 if (host.endsWith("]")) 218 host = host.substring(0, host.length() - 1); 219 } 220 } 221 } 197 222 } 198 destination = currentProxy; 199 usingWWWProxy = true; 200 newRequest.append("CONNECT ").append(host).append(restofline).append("\r\n"); // HTTP spec 223 if (!usingInternalOutproxy) { 224 // The request must be forwarded to a outproxy 225 currentProxy = selectProxy(); 226 if (currentProxy == null) { 227 if (_log.shouldLog(Log.WARN)) 228 _log.warn(getPrefix(requestId) + "Host wants to be outproxied, but we dont have any!"); 229 writeErrorMessage(ERR_NO_OUTPROXY, out); 230 s.close(); 231 return; 232 } 233 destination = currentProxy; 234 usingWWWProxy = true; 235 newRequest.append("CONNECT ").append(host).append(restofline).append("\r\n"); // HTTP spec 236 } 201 237 } else if (host.toLowerCase(Locale.US).equals("localhost")) { 202 238 writeErrorMessage(ERR_LOCALHOST, out); … … 209 245 210 246 if (_log.shouldLog(Log.DEBUG)) { 211 _log.debug(getPrefix(requestId) + "METHOD:" + method + ":"); 212 _log.debug(getPrefix(requestId) + "HOST :" + host + ":"); 213 _log.debug(getPrefix(requestId) + "REST :" + restofline + ":"); 214 _log.debug(getPrefix(requestId) + "DEST :" + destination + ":"); 247 _log.debug(getPrefix(requestId) + "METHOD:" + method + ":\n" + 248 "HOST :" + host + ":\n" + 249 "PORT :" + remotePort + ":\n" + 250 "REST :" + restofline + ":\n" + 251 "DEST :" + destination + ":\n" + 252 "www proxy? " + usingWWWProxy + " internal proxy? " + usingInternalOutproxy); 215 253 } 216 254 } else if (line.toLowerCase(Locale.US).startsWith("proxy-authorization: ")) { … … 251 289 } 252 290 253 if (destination == null || method == null || !"CONNECT".equals(method.toUpperCase(Locale.US))) { 291 if (method == null || !"CONNECT".equals(method.toUpperCase(Locale.US))) { 292 writeErrorMessage(ERR_BAD_PROTOCOL, out); 293 s.close(); 294 return; 295 } 296 297 // no destination, going to outproxy plugin 298 if (usingInternalOutproxy) { 299 Socket outSocket = outproxy.connect(host, remotePort); 300 OnTimeout onTimeout = new OnTimeout(s, s.getOutputStream(), targetRequest, usingWWWProxy, currentProxy, requestId); 301 byte[] response = SUCCESS_RESPONSE.getBytes("UTF-8"); 302 Thread t = new I2PTunnelOutproxyRunner(s, outSocket, sockLock, null, response, onTimeout); 303 // we are called from an unlimited thread pool, so run inline 304 t.run(); 305 return; 306 } 307 308 if (destination == null) { 254 309 writeErrorMessage(ERR_BAD_PROTOCOL, out); 255 310 s.close(); … … 283 338 } 284 339 285 I2PSocket i2ps = createI2PSocket(clientDest, getDefaultOptions()); 340 I2PSocketOptions sktOpts = getDefaultOptions(); 341 if (!usingWWWProxy && remotePort > 0) 342 sktOpts.setPort(remotePort); 343 I2PSocket i2ps = createI2PSocket(clientDest, sktOpts); 286 344 byte[] data = null; 287 345 byte[] response = null; -
apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java
r1cf6030 r7cb5dab 357 357 public static final String PROP_JUMP_SERVERS = "i2ptunnel.httpclient.jumpServers"; 358 358 public static final String PROP_DISABLE_HELPER = "i2ptunnel.httpclient.disableAddressHelper"; 359 /** @since 0.9.11 */360 public static final String PROP_USE_OUTPROXY_PLUGIN = "i2ptunnel.useLocalOutproxy";361 359 /** @since 0.9.11 */ 362 360 public static final String PROP_SSL_OUTPROXIES = "i2ptunnel.httpclient.SSLOutproxies"; -
apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClientBase.java
r1cf6030 r7cb5dab 60 60 private static final long MAX_NONCE_AGE = 60*60*1000L; 61 61 private static final int MAX_NONCE_COUNT = 1024; 62 /** @since 0.9.11, moved to Base in 0.9.29 */ 63 public static final String PROP_USE_OUTPROXY_PLUGIN = "i2ptunnel.useLocalOutproxy"; 62 64 63 65 private static final String ERR_AUTH1 = -
apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKSServer.java
r1cf6030 r7cb5dab 15 15 import net.i2p.app.Outproxy; 16 16 import net.i2p.client.streaming.I2PSocket; 17 import net.i2p.i2ptunnel.I2PTunnelHTTPClient ;17 import net.i2p.i2ptunnel.I2PTunnelHTTPClientBase; 18 18 import net.i2p.util.Log; 19 19 … … 90 90 */ 91 91 private boolean shouldUseOutproxyPlugin() { 92 return Boolean.parseBoolean(props.getProperty(I2PTunnelHTTPClient .PROP_USE_OUTPROXY_PLUGIN, "true"));92 return Boolean.parseBoolean(props.getProperty(I2PTunnelHTTPClientBase.PROP_USE_OUTPROXY_PLUGIN, "true")); 93 93 } 94 94 -
apps/i2ptunnel/java/src/net/i2p/i2ptunnel/ui/GeneralHelper.java
r1cf6030 r7cb5dab 580 580 */ 581 581 public boolean getUseOutproxyPlugin(int tunnel) { 582 return getBooleanProperty(tunnel, I2PTunnelHTTPClient .PROP_USE_OUTPROXY_PLUGIN, true);582 return getBooleanProperty(tunnel, I2PTunnelHTTPClientBase.PROP_USE_OUTPROXY_PLUGIN, true); 583 583 } 584 584 -
apps/i2ptunnel/java/src/net/i2p/i2ptunnel/ui/TunnelConfig.java
r1cf6030 r7cb5dab 410 410 public void setUseOutproxyPlugin(boolean val) { 411 411 if (val) 412 _booleanOptions.add(I2PTunnelHTTPClient .PROP_USE_OUTPROXY_PLUGIN);413 else 414 _booleanOptions.remove(I2PTunnelHTTPClient .PROP_USE_OUTPROXY_PLUGIN);412 _booleanOptions.add(I2PTunnelHTTPClientBase.PROP_USE_OUTPROXY_PLUGIN); 413 else 414 _booleanOptions.remove(I2PTunnelHTTPClientBase.PROP_USE_OUTPROXY_PLUGIN); 415 415 } 416 416 … … 696 696 private static final String _booleanProxyOpts[] = { 697 697 I2PTunnelHTTPClientBase.PROP_OUTPROXY_AUTH, 698 I2PTunnelHTTPClient .PROP_USE_OUTPROXY_PLUGIN,698 I2PTunnelHTTPClientBase.PROP_USE_OUTPROXY_PLUGIN, 699 699 I2PTunnelHTTPClient.PROP_USER_AGENT, 700 700 I2PTunnelHTTPClient.PROP_REFERER, -
apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/IndexBean.java
r1cf6030 r7cb5dab 500 500 if (TunnelController.TYPE_HTTP_CLIENT.equals(tun.getType())) { 501 501 Properties opts = tun.getClientOptionProps(); 502 if (Boolean.parseBoolean(opts.getProperty(I2PTunnelHTTPClient .PROP_USE_OUTPROXY_PLUGIN, "true"))) {502 if (Boolean.parseBoolean(opts.getProperty(I2PTunnelHTTPClientBase.PROP_USE_OUTPROXY_PLUGIN, "true"))) { 503 503 ClientAppManager mgr = _context.clientAppManager(); 504 504 if (mgr != null)
Note: See TracChangeset
for help on using the changeset viewer.