Changeset dab1b4d


Ignore:
Timestamp:
Sep 16, 2005 6:28:26 PM (15 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
177e0ae6
Parents:
3aba126
git-author:
jrandom <jrandom> (09/16/05 18:28:26)
git-committer:
zzz <zzz@…> (09/16/05 18:28:26)
Message:

2005-09-16 jrandom

  • Adjust I2PTunnelHTTPServer so it can be used for outproxy operators (just specify the spoofed host as an empty string), allowing them to honor x-i2p-gzip encoding.
  • Let windows users build the exes too (thanks bar and redzara!)
  • Allow I2PTunnel httpserver operators to disable gzip compression on individual tunnels with the i2ptunnel.gzip=false client option (good idea susi!)
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/HTTPResponseOutputStream.java

    r3aba126 rdab1b4d  
    4343        super(raw);
    4444        _context = I2PAppContext.getGlobalContext();
    45         _context.statManager().createRateStat("i2ptunnel.http.compressionRatio", "ratio of compressed size to decompressed size after transfer", "i2ptunnel", new long[] { 60*1000, 30*60*1000 });
    46         _context.statManager().createRateStat("i2ptunnel.http.compressed", "compressed size transferred", "i2ptunnel", new long[] { 60*1000, 30*60*1000 });
    47         _context.statManager().createRateStat("i2ptunnel.http.expanded", "size transferred after expansion", "i2ptunnel", new long[] { 60*1000, 30*60*1000 });
     45        _context.statManager().createRateStat("i2ptunnel.httpCompressionRatio", "ratio of compressed size to decompressed size after transfer", "i2ptunnel", new long[] { 60*1000, 30*60*1000 });
     46        _context.statManager().createRateStat("i2ptunnel.httpCompressed", "compressed size transferred", "i2ptunnel", new long[] { 60*1000, 30*60*1000 });
     47        _context.statManager().createRateStat("i2ptunnel.httpExpanded", "size transferred after expansion", "i2ptunnel", new long[] { 60*1000, 30*60*1000 });
    4848        _log = _context.logManager().getLog(getClass());
    4949        _cache = ByteCache.getInstance(8, CACHE_SIZE);
     
    176176           
    177177        finishHeaders();
     178
     179        boolean shouldCompress = shouldCompress();
     180        if (_log.shouldLog(Log.INFO))
     181            _log.info("After headers: gzip? " + _gzip + " compress? " + shouldCompress);
    178182       
    179183        // done, shove off
     
    182186        else
    183187            _headerBuffer = null;
    184         if (_log.shouldLog(Log.INFO))
    185             _log.info("After headers: gzip? " + _gzip);
    186         if (shouldCompress()) {
     188        if (shouldCompress) {
    187189            beginProcessing();
    188190        }
     
    213215            OutputStream to = null;
    214216            InternalGZIPInputStream in = null;
     217            long start = System.currentTimeMillis();
     218            long written = 0;
    215219            try {
    216                 long start = System.currentTimeMillis();
    217220                in = new InternalGZIPInputStream(_in);
    218221                byte buf[] = new byte[8192];
    219222                int read = -1;
    220223                while ( (read = in.read(buf)) != -1) {
    221                     if (_log.shouldLog(Log.INFO))
    222                         _log.info("Read " + read + " and writing it to the browser/streams");
     224                    if (_log.shouldLog(Log.DEBUG))
     225                        _log.debug("Read " + read + " and writing it to the browser/streams");
    223226                    _out.write(buf, 0, read);
     227                    _out.flush();
     228                    written += read;
    224229                }
    225230                if (_log.shouldLog(Log.INFO))
    226                     _log.info("Decompressed: " + _dataWritten + ", " + in.getTotalRead() + "/" + in.getTotalExpanded());
    227                 long end = System.currentTimeMillis();
    228                 long compressed = in.getTotalRead();
    229                 long expanded = in.getTotalExpanded();
    230                 double ratio = 0;
    231                 if (expanded > 0)
    232                     ratio = compressed/expanded;
    233                
    234                 _context.statManager().addRateData("i2ptunnel.http.compressionRatio", (int)(100d*ratio), end-start);
    235                 _context.statManager().addRateData("i2ptunnel.http.compressed", compressed, end-start);
    236                 _context.statManager().addRateData("i2ptunnel.http.expanded", expanded, end-start);
     231                    _log.info("Decompressed: " + written + ", " + in.getTotalRead() + "/" + in.getTotalExpanded());
    237232            } catch (IOException ioe) {
    238233                if (_log.shouldLog(Log.WARN))
    239                     _log.warn("Error decompressing: " + _dataWritten + ", " + in.getTotalRead() + "/" + in.getTotalExpanded(), ioe);
     234                    _log.warn("Error decompressing: " + written + ", " + in.getTotalRead() + "/" + in.getTotalExpanded(), ioe);
    240235            } finally {
    241236                if (_out != null) try { _out.close(); } catch (IOException ioe) {}
    242237            }
     238            long end = System.currentTimeMillis();
     239            long compressed = in.getTotalRead();
     240            long expanded = in.getTotalExpanded();
     241            double ratio = 0;
     242            if (expanded > 0)
     243                ratio = compressed/expanded;
     244
     245            _context.statManager().addRateData("i2ptunnel.httpCompressionRatio", (int)(100d*ratio), end-start);
     246            _context.statManager().addRateData("i2ptunnel.httpCompressed", compressed, end-start);
     247            _context.statManager().addRateData("i2ptunnel.httpExpanded", expanded, end-start);
    243248        }
    244249    }
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java

    r3aba126 rdab1b4d  
    6969            StringBuffer command = new StringBuffer(128);
    7070            Properties headers = readHeaders(in, command);
    71             headers.setProperty("Host", _spoofHost);
     71            if ( (_spoofHost != null) && (_spoofHost.trim().length() > 0) )
     72                headers.setProperty("Host", _spoofHost);
    7273            headers.setProperty("Connection", "close");
    7374            String modifiedHeader = formatHeaders(headers, command);
     
    8485            // server, reads the response headers, rewriting to include Content-encoding: x-i2p-gzip
    8586            // if it was one of the Accept-encoding: values, and gzip the payload       
     87            Properties opts = getTunnel().getClientOptions();
     88            boolean allowGZIP = true;
     89            if (opts != null) {
     90                String val = opts.getProperty("i2ptunnel.gzip");
     91                if ( (val != null) && (!Boolean.valueOf(val).booleanValue()) )
     92                    allowGZIP = false;
     93            }
    8694            String enc = headers.getProperty("Accept-encoding");
    8795            if (_log.shouldLog(Log.INFO))
    8896                _log.info("HTTP server encoding header: " + enc);
    89             if ( (enc != null) && (enc.indexOf("x-i2p-gzip") >= 0) ) {
     97            if ( allowGZIP && (enc != null) && (enc.indexOf("x-i2p-gzip") >= 0) ) {
    9098                I2PThread req = new I2PThread(new CompressedRequestor(s, socket, modifiedHeader), "http compressor");
    9199                req.start();
     
    140148                browserout = _browser.getOutputStream();
    141149                serverin = _webserver.getInputStream();
    142                 Sender s = new Sender(new CompressedResponseOutputStream(browserout), serverin, "server: server to browser");
     150                CompressedResponseOutputStream compressedOut = new CompressedResponseOutputStream(browserout);
     151                Sender s = new Sender(compressedOut, serverin, "server: server to browser");
    143152                if (_log.shouldLog(Log.INFO))
    144153                    _log.info("Before pumping the compressed response");
    145154                s.run(); // same thread
    146155                if (_log.shouldLog(Log.INFO))
    147                     _log.info("After pumping the compressed response");
     156                    _log.info("After pumping the compressed response: " + compressedOut.getTotalRead() + "/" + compressedOut.getTotalCompressed());
    148157            } catch (IOException ioe) {
    149158                if (_log.shouldLog(Log.WARN))
     
    183192                _out.flush();
    184193            } catch (IOException ioe) {
    185                 if (_log.shouldLog(Log.WARN))
    186                     _log.warn("Error sending", ioe);
     194                if (_log.shouldLog(Log.DEBUG))
     195                    _log.debug("Error sending", ioe);
    187196            } finally {
    188197                if (_in != null) try { _in.close(); } catch (IOException ioe) {}
     
    192201    }
    193202    private class CompressedResponseOutputStream extends HTTPResponseOutputStream {
     203        private InternalGZIPOutputStream _gzipOut;
    194204        public CompressedResponseOutputStream(OutputStream o) {
    195205            super(o);
     
    208218                _log.info("Beginning compression processing");
    209219            out.flush();
    210             out = new GZIPOutputStream(out);
    211         }
     220            _gzipOut = new InternalGZIPOutputStream(out);
     221            out = _gzipOut;
     222        }
     223        public long getTotalRead() { return _gzipOut.getTotalRead(); }
     224        public long getTotalCompressed() { return _gzipOut.getTotalCompressed(); }
     225    }
     226    private class InternalGZIPOutputStream extends GZIPOutputStream {
     227        public InternalGZIPOutputStream(OutputStream target) throws IOException {
     228            super(target);
     229        }
     230        public long getTotalRead() { return super.def.getTotalIn(); }
     231        public long getTotalCompressed() { return super.def.getTotalOut(); }
    212232    }
    213233
  • history.txt

    r3aba126 rdab1b4d  
    1 $Id: history.txt,v 1.250 2005/09/15 00:39:31 jrandom Exp $
     1$Id: history.txt,v 1.251 2005/09/15 23:12:27 jrandom Exp $
     2
     32005-09-16  jrandom
     4    * Adjust I2PTunnelHTTPServer so it can be used for outproxy operators
     5      (just specify the spoofed host as an empty string), allowing them to
     6      honor x-i2p-gzip encoding.
     7    * Let windows users build the exes too (thanks bar and redzara!)
     8    * Allow I2PTunnel httpserver operators to disable gzip compression on
     9      individual tunnels with the i2ptunnel.gzip=false client option
     10      (good idea susi!)
    211
    3122005-09-16  jrandom
  • router/java/src/net/i2p/router/RouterVersion.java

    r3aba126 rdab1b4d  
    1616 */
    1717public class RouterVersion {
    18     public final static String ID = "$Revision: 1.236 $ $Date: 2005/09/15 00:39:31 $";
     18    public final static String ID = "$Revision: 1.237 $ $Date: 2005/09/15 23:12:26 $";
    1919    public final static String VERSION = "0.6.0.5";
    20     public final static long BUILD = 11;
     20    public final static long BUILD = 12;
    2121    public static void main(String args[]) {
    2222        System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
Note: See TracChangeset for help on using the changeset viewer.