Changeset d054e129
- Timestamp:
- Jan 5, 2014 12:52:00 AM (7 years ago)
- Branches:
- master
- Children:
- 0fae064
- Parents:
- b59aa1fb
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java
rb59aa1fb rd054e129 30 30 import net.i2p.data.Hash; 31 31 import net.i2p.i2ptunnel.localServer.LocalHTTPServer; 32 import net.i2p.outproxy.Outproxy; 32 33 import net.i2p.util.EventDispatcher; 33 34 import net.i2p.util.Log; … … 321 322 public static final String PROP_JUMP_SERVERS = "i2ptunnel.httpclient.jumpServers"; 322 323 public static final String PROP_DISABLE_HELPER = "i2ptunnel.httpclient.disableAddressHelper"; 324 public static final String PROP_OUTPROXY = "i2ptunnel.useLocalOutproxy"; 323 325 324 326 protected void clientConnectionRun(Socket s) { … … 331 333 332 334 boolean usingWWWProxy = false; 335 boolean usingOutproxy = false; 336 Outproxy outproxy = null; 333 337 boolean usingInternalServer = false; 334 338 String internalPath = null; … … 678 682 return; 679 683 } else if(host.contains(".") || host.startsWith("[")) { 680 if (port >= 0) {681 host = host + ':' + port;682 }683 // The request must be forwarded to a WWW proxy684 if(_log.shouldLog(Log.DEBUG)) {685 _log.debug("Before selecting outproxy for " + host);686 }687 currentProxy = selectProxy();688 if(_log.shouldLog(Log.DEBUG)) {689 _log.debug("After selecting outproxy for " + host + ": " + currentProxy);690 }691 if(currentProxy == null){692 if( _log.shouldLog(Log.WARN)) {693 _log.warn(getPrefix(requestId) + "Host wants to be outproxied, but we dont have any!");684 if (Boolean.parseBoolean(getTunnel().getClientOptions().getProperty(PROP_OUTPROXY)) && 685 (outproxy = _context.outproxy()) != null) { 686 int rPort = requestURI.getPort(); 687 if (rPort > 0) 688 remotePort = rPort; 689 else 690 remotePort = 80; 691 usingOutproxy = true; 692 targetRequest = requestURI.toASCIIString(); 693 if(_log.shouldLog(Log.DEBUG)) 694 _log.debug(getPrefix(requestId) + " [" + host + "]: outproxy!"); 695 } else { 696 if(port >= 0) { 697 host = host + ':' + port; 694 698 } 695 l.log("No HTTP outproxy found for the request."); 696 if(out != null) { 697 out.write(getErrorPage("noproxy", _ERR_NO_OUTPROXY)); 698 writeFooter(out); 699 // The request must be forwarded to a WWW proxy 700 if(_log.shouldLog(Log.DEBUG)) { 701 _log.debug("Before selecting outproxy for " + host); 699 702 } 700 s.close(); 701 return; 702 } 703 destination = currentProxy; 704 usingWWWProxy = true; 705 targetRequest = requestURI.toASCIIString(); 706 if(_log.shouldLog(Log.DEBUG)) { 707 _log.debug(getPrefix(requestId) + " [" + host + "]: wwwProxy!"); 703 currentProxy = selectProxy(); 704 if(_log.shouldLog(Log.DEBUG)) { 705 _log.debug("After selecting outproxy for " + host + ": " + currentProxy); 706 } 707 if(currentProxy == null) { 708 if(_log.shouldLog(Log.WARN)) { 709 _log.warn(getPrefix(requestId) + "Host wants to be outproxied, but we dont have any!"); 710 } 711 l.log("No HTTP outproxy found for the request."); 712 if(out != null) { 713 out.write(getErrorPage("noproxy", _ERR_NO_OUTPROXY)); 714 writeFooter(out); 715 } 716 s.close(); 717 return; 718 } 719 destination = currentProxy; 720 usingWWWProxy = true; 721 targetRequest = requestURI.toASCIIString(); 722 if(_log.shouldLog(Log.DEBUG)) { 723 _log.debug(getPrefix(requestId) + " [" + host + "]: wwwProxy!"); 724 } 708 725 } 709 726 } else { … … 723 740 } // end host name processing 724 741 725 boolean isValid = usingWWWProxy || usingInternalServer || isSupportedAddress(host, protocol); 742 boolean isValid = usingOutproxy || usingWWWProxy || 743 usingInternalServer || isSupportedAddress(host, protocol); 726 744 if(!isValid) { 727 745 if(_log.shouldLog(Log.INFO)) { … … 744 762 745 763 } else { 746 if(lowercaseLine.startsWith("host: ") && !usingWWWProxy ) {764 if(lowercaseLine.startsWith("host: ") && !usingWWWProxy && !usingOutproxy) { 747 765 // Note that we only pass the original Host: line through to the outproxy 748 766 // But we don't create a Host: line if it wasn't sent to us … … 816 834 if(!Boolean.parseBoolean(getTunnel().getClientOptions().getProperty(PROP_USER_AGENT))) { 817 835 // let's not advertise to external sites that we are from I2P 818 if(usingWWWProxy ) {836 if(usingWWWProxy || usingOutproxy) { 819 837 newRequest.append("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6\r\n"); 820 838 } else { … … 849 867 } 850 868 851 if(method == null || destination == null) {869 if(method == null || (destination == null && !usingOutproxy)) { 852 870 //l.log("No HTTP method found in the request."); 853 871 if(out != null) { … … 894 912 } 895 913 s.close(); 914 return; 915 } 916 917 // no destination, going to outproxy plugin 918 if (usingOutproxy) { 919 Socket outSocket = outproxy.connect(host, remotePort); 920 byte[] data = newRequest.toString().getBytes("ISO-8859-1"); 921 Runnable onTimeout = new OnTimeout(s, s.getOutputStream(), targetRequest, usingWWWProxy, currentProxy, requestId); 922 new I2PTunnelOutproxyRunner(s, outSocket, sockLock, data, onTimeout); 896 923 return; 897 924 } -
core/java/src/net/i2p/I2PAppContext.java
rb59aa1fb rd054e129 26 26 import net.i2p.data.RoutingKeyGenerator; 27 27 import net.i2p.internal.InternalClientManager; 28 import net.i2p.outproxy.Outproxy; 28 29 import net.i2p.stat.StatManager; 29 30 import net.i2p.update.UpdateManager; … … 95 96 private SimpleTimer2 _simpleTimer2; 96 97 private final PortMapper _portMapper; 98 private Outproxy _outproxy; 97 99 private volatile boolean _statManagerInitialized; 98 100 private volatile boolean _sessionKeyManagerInitialized; … … 128 130 _lock9 = new Object(), _lock10 = new Object(), _lock11 = new Object(), _lock12 = new Object(), 129 131 _lock13 = new Object(), _lock14 = new Object(), _lock15 = new Object(), _lock16 = new Object(), 130 _lock17 = new Object(), _lock18 = new Object(), _lock19 = new Object(), _lock20 = new Object(); 132 _lock17 = new Object(), _lock18 = new Object(), _lock19 = new Object(), _lock20 = new Object(), 133 _lock21 = new Object(); 131 134 132 135 /** … … 1024 1027 return null; 1025 1028 } 1029 1030 /** 1031 * A local outproxy 1032 * @return The outproxy if it is registered, else null 1033 * @since 0.9.11 1034 */ 1035 public Outproxy outproxy() { 1036 return _outproxy; 1037 } 1038 1039 /** 1040 * Register as the outproxy. For now, only one. 1041 * @throws IllegalStateException if one was already registered 1042 * @since 0.9.11 1043 */ 1044 public void registerOutproxy(Outproxy oproxy) { 1045 synchronized(_lock21) { 1046 if (_outproxy != null) 1047 throw new IllegalStateException(); 1048 _outproxy = oproxy; 1049 } 1050 } 1051 1052 /** 1053 * Unregister the outproxy. 1054 * @throws IllegalStateException if it was not registered 1055 * @since 0.9.11 1056 */ 1057 public void unregisterOutproxy(Outproxy oproxy) { 1058 synchronized(_lock21) { 1059 if (_outproxy != oproxy) 1060 throw new IllegalStateException(); 1061 _outproxy = null; 1062 } 1063 } 1026 1064 }
Note: See TracChangeset
for help on using the changeset viewer.