Changeset d73eb16


Ignore:
Timestamp:
Aug 30, 2011 1:41:26 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
a928f5e
Parents:
a6728a3
Message:
  • I2CP: Cache b32 lookups client-side
  • I2PTunnelHTTPClient: Use existing session for b32 lookups

rather than a new SimpleSession?

  • Naming: Increase b32 lookup timeout to 15 sec.
Files:
5 edited

Legend:

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

    ra6728a3 rd73eb16  
    2626import net.i2p.I2PAppContext;
    2727import net.i2p.I2PException;
     28import net.i2p.client.I2PSession;
    2829import net.i2p.client.naming.NamingService;
    2930import net.i2p.client.streaming.I2PSocket;
     
    3536import net.i2p.data.DataHelper;
    3637import net.i2p.data.Destination;
     38import net.i2p.data.Hash;
    3739import net.i2p.util.EventDispatcher;
    3840import net.i2p.util.FileUtil;
     
    800802            // look it up again as the naming service does not do negative caching
    801803            // so it will be slow.
    802             Destination clientDest;
     804            Destination clientDest = null;
    803805            String addressHelper = addressHelpers.get(destination.toLowerCase());
    804806            if (addressHelper != null) {
     
    809811            } else if ("i2p".equals(host)) {
    810812                clientDest = null;
     813            } else if (destination.length() == 60 && destination.toLowerCase().endsWith(".b32.i2p")) {
     814                // use existing session to look up for efficiency
     815                verifySocketManager();
     816                I2PSession sess = sockMgr.getSession();
     817                if (sess != null && !sess.isClosed()) {
     818                    byte[] hData = Base32.decode(destination.substring(0, 52));
     819                    if (hData != null) {
     820                        if (_log.shouldLog(Log.INFO))
     821                            _log.info("lookup in-session " + destination);
     822                        Hash hash = Hash.create(hData);
     823                        clientDest = sess.lookupDest(hash, 20*1000);
     824                    }
     825                } else {
     826                    clientDest = _context.namingService().lookup(destination);
     827                }
    811828            } else {
    812829                clientDest = _context.namingService().lookup(destination);
     
    823840                else if (ahelperPresent)
    824841                    header = getErrorPage("dnfb", ERR_DESTINATION_UNKNOWN);
    825                 else if (destination.length() == 60 && destination.endsWith(".b32.i2p"))
     842                else if (destination.length() == 60 && destination.toLowerCase().endsWith(".b32.i2p"))
    826843                    header = getErrorPage("dnf", ERR_DESTINATION_UNKNOWN);
    827844                else {
  • core/java/src/net/i2p/client/I2PSessionImpl.java

    ra6728a3 rd73eb16  
    1919import java.util.HashSet;
    2020import java.util.Iterator;
     21import java.util.LinkedHashMap;
    2122import java.util.List;
    2223import java.util.Map;
     
    141142    private boolean _isReduced;
    142143
     144    /**
     145     *  @since 0.8.9
     146     */
     147    private static final LookupCache _lookupCache = new LookupCache(16);
     148
    143149    /** SSL interface (only) @since 0.8.3 */
    144150    protected static final String PROP_ENABLE_SSL = "i2cp.SSL";
     
    810816    void destReceived(Destination d) {
    811817        Hash h = d.calculateHash();
     818        synchronized (_lookupCache) {
     819            _lookupCache.put(h, d);
     820        }
    812821        for (LookupWaiter w : _pendingLookups) {
    813822            if (w.hash.equals(h)) {
     
    873882     */
    874883    public Destination lookupDest(Hash h, long maxWait) throws I2PSessionException {
     884        synchronized (_lookupCache) {
     885            Destination rv = _lookupCache.get(h);
     886            if (rv != null)
     887                return rv;
     888        }
    875889        if (_closed)
    876890            return null;
     
    953967        return buf.toString();
    954968    }
     969
     970    /**
     971     *  @since 0.8.9
     972     */
     973    private static class LookupCache extends LinkedHashMap<Hash, Destination> {
     974        private final int _max;
     975
     976        public LookupCache(int max) {
     977            super(max, 0.75f, true);
     978            _max = max;
     979        }
     980
     981        @Override
     982        protected boolean removeEldestEntry(Map.Entry<Hash, Destination> eldest) {
     983            return size() > _max;
     984        }
     985    }
    955986}
  • core/java/src/net/i2p/client/naming/LookupDest.java

    ra6728a3 rd73eb16  
    2222 *
    2323 * All calls are blocking and return null on failure.
    24  * Timeout is set to 10 seconds in I2PSimpleSession.
     24 * Timeout is 15 seconds.
     25 * To do: Add methods that allow specifying the timeout.
    2526 *
    2627 * As of 0.8.3, standard I2PSessions support lookups,
     
    3233 */
    3334class LookupDest {
     35
     36    private static final long DEFAULT_TIMEOUT = 15*1000;
    3437
    3538    protected LookupDest(I2PAppContext context) {}
     
    6871            I2PSession session = client.createSession(null, opts);
    6972            session.connect();
    70             rv = session.lookupDest(key);
     73            rv = session.lookupDest(key, DEFAULT_TIMEOUT);
    7174            session.destroySession();
    7275        } catch (I2PSessionException ise) {}
  • history.txt

    ra6728a3 rd73eb16  
     12011-08-30 zzz
     2  * I2CP: Cache b32 lookups client-side
     3  * I2PTunnelHTTPClient: Use existing session for b32 lookups
     4                         rather than a new SimpleSession
     5  * Naming: Increase b32 lookup timeout to 15 sec.
     6
    172011-08-29 zzz
    28  * NetDB:
  • router/java/src/net/i2p/router/RouterVersion.java

    ra6728a3 rd73eb16  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 4;
     21    public final static long BUILD = 5;
    2222
    2323    /** for example "-test" */
Note: See TracChangeset for help on using the changeset viewer.