Changeset b695242d for router


Ignore:
Timestamp:
Nov 13, 2018 6:00:05 PM (19 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
cec94e9
Parents:
ddfc7c0
Message:

Router: LS2 handling for proposal 123

Location:
router/java/src/net/i2p
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/data/i2np/DatabaseStoreMessage.java

    rddfc7c0 rb695242d  
    1919import net.i2p.data.Hash;
    2020import net.i2p.data.LeaseSet;
     21import net.i2p.data.LeaseSet2;
    2122import net.i2p.data.router.RouterInfo;
    2223import net.i2p.data.TunnelId;
     
    114115       
    115116        // as of 0.9.18, ignore other 7 bits of the type byte, in preparation for future options
    116         int dbType = data[curIndex] & 0x01;
     117        // as of 0.9.38, ignore other 4 bits of the type byte, in preparation for future options
     118        int dbType = data[curIndex] & 0x0f;
    117119        curIndex++;
    118120       
     
    142144                throw new I2NPMessageException("Error reading the leaseSet", ioe);
    143145            }
    144         } else {   // dbType == DatabaseEntry.KEY_TYPE_ROUTERINFO
     146        } else if (dbType == DatabaseEntry.KEY_TYPE_LS2) {
     147            _dbEntry = new LeaseSet2();
     148            try {
     149                _dbEntry.readBytes(new ByteArrayInputStream(data, curIndex, data.length-curIndex));
     150            } catch (DataFormatException dfe) {
     151                throw new I2NPMessageException("Error reading the leaseSet", dfe);
     152            } catch (IOException ioe) {
     153                throw new I2NPMessageException("Error reading the leaseSet", ioe);
     154            }
     155        } else if ((dbType & 0x01) == DatabaseEntry.KEY_TYPE_ROUTERINFO) {
    145156            _dbEntry = new RouterInfo();
    146157            int compressedSize = (int)DataHelper.fromLong(data, curIndex, 2);
     
    161172                throw new I2NPMessageException("Error reading the routerInfo", dfe);
    162173            } catch (IOException ioe) {
     174                //net.i2p.util.Log log = new net.i2p.util.Log(DatabaseStoreMessage.class);
     175                //log.error("Corrupt compressed routerInfo size = " + compressedSize + " key " + _key, ioe);
    163176                throw new I2NPMessageException("Corrupt compressed routerInfo size = " + compressedSize, ioe);
    164177            }
     178        } else {
     179            throw new I2NPMessageException("Unknown type " + dbType);
    165180        }
    166181        //if (!key.equals(_dbEntry.getHash()))
     
    270285            buf.append("\n\tReply gateway: ").append(_replyGateway);
    271286        }
    272         buf.append("\n\tKey: ").append(getKey());
     287        buf.append("\n\tKey: ");
     288        if (_dbEntry.getType() == DatabaseEntry.KEY_TYPE_ROUTERINFO)
     289            buf.append(getKey());
     290        else
     291            buf.append(getKey().toBase32());
    273292        buf.append("\n\tEntry: ").append(_dbEntry);
    274293        buf.append(']');
  • router/java/src/net/i2p/router/RouterVersion.java

    rddfc7c0 rb695242d  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 2;
     21    public final static long BUILD = 3;
    2222
    2323    /** for example "-test" */
  • router/java/src/net/i2p/router/networkdb/HandleDatabaseLookupMessageJob.java

    rddfc7c0 rb695242d  
    9595        // only lookup once, then cast to correct type
    9696        DatabaseEntry dbe = getContext().netDb().lookupLocally(_message.getSearchKey());
    97         if (dbe != null && dbe.getType() == DatabaseEntry.KEY_TYPE_LEASESET &&
     97        int type = dbe != null ? dbe.getType() : -1;
     98        if ((type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2) &&
    9899            (lookupType == DatabaseLookupMessage.Type.ANY || lookupType == DatabaseLookupMessage.Type.LS)) {
    99100            LeaseSet ls = (LeaseSet) dbe;
     
    159160                sendClosest(_message.getSearchKey(), routerHashSet, fromKey, _message.getReplyTunnel());
    160161            }
    161         } else if (dbe != null && dbe.getType() == DatabaseEntry.KEY_TYPE_ROUTERINFO &&
     162        } else if (type == DatabaseEntry.KEY_TYPE_ROUTERINFO &&
    162163                   lookupType != DatabaseLookupMessage.Type.LS) {
    163164            RouterInfo info = (RouterInfo) dbe;
     
    260261                       + " tunnel " + replyTunnel);
    261262        DatabaseStoreMessage msg = new DatabaseStoreMessage(getContext());
    262         if (data.getType() == DatabaseEntry.KEY_TYPE_LEASESET) {
     263        int type = data.getType();
     264        if (type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2) {
    263265            getContext().statManager().addRateData("netDb.lookupsMatchedLeaseSet", 1);
    264266        }
  • router/java/src/net/i2p/router/networkdb/kademlia/ExpireLeasesJob.java

    rddfc7c0 rb695242d  
    6262        for (Map.Entry<Hash, DatabaseEntry> entry : _facade.getDataStore().getMapEntries()) {
    6363            DatabaseEntry obj = entry.getValue();
    64             if (obj.getType() == DatabaseEntry.KEY_TYPE_LEASESET) {
     64            int type = obj.getType();
     65            if (type == DatabaseEntry.KEY_TYPE_LEASESET ||
     66                type == DatabaseEntry.KEY_TYPE_LS2) {
    6567                LeaseSet ls = (LeaseSet)obj;
    6668                if (!ls.isCurrent(Router.CLOCK_FUDGE_FACTOR))
  • router/java/src/net/i2p/router/networkdb/kademlia/FloodOnlyLookupMatchJob.java

    rddfc7c0 rb695242d  
    5353            // runJob() and search.success() is called???
    5454            // Should we just pass the DataStructure directly back to somebody?
    55             if (dsm.getEntry().getType() == DatabaseEntry.KEY_TYPE_LEASESET) {
     55            DatabaseEntry entry = dsm.getEntry();
     56            int type = entry.getType();
     57            if (type == DatabaseEntry.KEY_TYPE_LEASESET ||
     58                type == DatabaseEntry.KEY_TYPE_LS2) {
    5659                // Since HFDSMJ wants to setReceivedAsPublished(), we have to
    5760                // set a flag saying this was really the result of a query,
     
    6063                ls.setReceivedAsReply();
    6164                getContext().netDb().store(dsm.getKey(), ls);
     65            } else if (type == DatabaseEntry.KEY_TYPE_ROUTERINFO) {
     66                getContext().netDb().store(dsm.getKey(), (RouterInfo) dsm.getEntry());
    6267            } else {
    63                 getContext().netDb().store(dsm.getKey(), (RouterInfo) dsm.getEntry());
     68                if (_log.shouldWarn())
     69                    _log.warn(_search.getJobId() + ": got a DSM of unknown type " + type
     70                              + " for " + dsm.getKey().toBase64());
    6471            }
    6572        } catch (UnsupportedCryptoException uce) {
  • router/java/src/net/i2p/router/networkdb/kademlia/HandleFloodfillDatabaseStoreMessageJob.java

    rddfc7c0 rb695242d  
    7070        Hash key = _message.getKey();
    7171        DatabaseEntry entry = _message.getEntry();
    72         if (entry.getType() == DatabaseEntry.KEY_TYPE_LEASESET) {
     72        int type = entry.getType();
     73        if (type == DatabaseEntry.KEY_TYPE_LEASESET ||
     74            type == DatabaseEntry.KEY_TYPE_LS2) {
    7375            getContext().statManager().addRateData("netDb.storeLeaseSetHandled", 1);
    7476            if (_log.shouldLog(Log.INFO))
     
    136138                invalidMessage = iae.getMessage();
    137139            }
    138         } else if (entry.getType() == DatabaseEntry.KEY_TYPE_ROUTERINFO) {
     140        } else if (type == DatabaseEntry.KEY_TYPE_ROUTERINFO) {
    139141            RouterInfo ri = (RouterInfo) entry;
    140142            getContext().statManager().addRateData("netDb.storeRouterInfoHandled", 1);
     
    182184        } else {
    183185            if (_log.shouldLog(Log.ERROR))
    184                 _log.error("Invalid DatabaseStoreMessage data type - " + entry.getType()
     186                _log.error("Invalid DatabaseStoreMessage data type - " + type
    185187                           + ": " + _message);
    186188            // don't ack or flood
  • router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java

    rddfc7c0 rb695242d  
    439439        int rv = 0;
    440440        for (DatabaseEntry ds : _ds.getEntries()) {
    441             if (ds.getType() == DatabaseEntry.KEY_TYPE_LEASESET &&
     441            int type = ds.getType();
     442            if ((type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2) &&
    442443                ((LeaseSet)ds).getReceivedAsPublished())
    443444                rv++;
     
    467468        if (rv == null)
    468469            return null;
    469         if (rv.getType() == DatabaseEntry.KEY_TYPE_LEASESET) {
     470        int type = rv.getType();
     471        if (type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2) {
    470472            LeaseSet ls = (LeaseSet)rv;
    471473            if (ls.isCurrent(Router.CLOCK_FUDGE_FACTOR))
     
    473475            else
    474476                fail(key);
    475         } else if (rv.getType() == DatabaseEntry.KEY_TYPE_ROUTERINFO) {
     477        } else if (type == DatabaseEntry.KEY_TYPE_ROUTERINFO) {
    476478            try {
    477479                if (validate((RouterInfo)rv) == null)
     
    552554        DatabaseEntry ds = _ds.get(key);
    553555        if (ds != null) {
    554             if (ds.getType() == DatabaseEntry.KEY_TYPE_LEASESET) {
     556            int type = ds.getType();
     557            if (type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2) {
    555558                LeaseSet ls = (LeaseSet)ds;
    556559                if (ls.isCurrent(Router.CLOCK_FUDGE_FACTOR)) {
     
    605608        DatabaseEntry ds = _ds.get(key);
    606609        if (ds != null) {
    607             if (ds.getType() == DatabaseEntry.KEY_TYPE_LEASESET) {
     610            int type = ds.getType();
     611            if (type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2) {
    608612                LeaseSet ls = (LeaseSet)ds;
    609613                return ls.getDestination();
     
    10781082    private void processStoreFailure(Hash h, DatabaseEntry entry) throws UnsupportedCryptoException {
    10791083        if (entry.getHash().equals(h)) {
    1080             if (entry.getType() == DatabaseEntry.KEY_TYPE_LEASESET) {
     1084            int etype = entry.getType();
     1085            if (etype == DatabaseEntry.KEY_TYPE_LEASESET || etype == DatabaseEntry.KEY_TYPE_LS2) {
    10811086                LeaseSet ls = (LeaseSet) entry;
    10821087                Destination d = ls.getDestination();
     
    10951100                    } catch (DataFormatException dfe) {}
    10961101                }
    1097             } else if (entry.getType() == DatabaseEntry.KEY_TYPE_ROUTERINFO) {
     1102            } else if (etype == DatabaseEntry.KEY_TYPE_ROUTERINFO) {
    10981103                RouterInfo ri = (RouterInfo) entry;
    10991104                RouterIdentity id = ri.getIdentity();
     
    12381243        Set<LeaseSet> leases = new HashSet<LeaseSet>();
    12391244        for (DatabaseEntry o : getDataStore().getEntries()) {
    1240             if (o.getType() == DatabaseEntry.KEY_TYPE_LEASESET)
     1245            int type = o.getType();
     1246            if (type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2)
    12411247                leases.add((LeaseSet)o);
    12421248        }
  • router/java/src/net/i2p/router/networkdb/kademlia/PersistentDataStore.java

    rddfc7c0 rb695242d  
    295295            String filename = null;
    296296
    297             if (data.getType() == DatabaseEntry.KEY_TYPE_LEASESET)
    298                 filename = getLeaseSetName(key);
    299             else if (data.getType() == DatabaseEntry.KEY_TYPE_ROUTERINFO)
     297            if (data.getType() == DatabaseEntry.KEY_TYPE_ROUTERINFO)
    300298                filename = getRouterInfoName(key);
    301299            else
     
    625623    }
    626624   
    627     private final static String LEASESET_PREFIX = "leaseSet-";
    628     private final static String LEASESET_SUFFIX = ".dat";
    629625    private final static String ROUTERINFO_PREFIX = "routerInfo-";
    630626    private final static String ROUTERINFO_SUFFIX = ".dat";
     
    633629    public static final FileFilter RI_FILTER = new FileSuffixFilter(ROUTERINFO_PREFIX, ROUTERINFO_SUFFIX);
    634630   
    635     private static String getLeaseSetName(Hash hash) {
    636         return LEASESET_PREFIX + hash.toBase64() + LEASESET_SUFFIX;
    637     }
    638 
    639631    private String getRouterInfoName(Hash hash) {
    640632        String b64 = hash.toBase64();
  • router/java/src/net/i2p/router/networkdb/kademlia/StoreJob.java

    rddfc7c0 rb695242d  
    7979        _expiration = context.clock().now() + timeoutMs;
    8080        _peerSelector = facade.getPeerSelector();
    81         if (data.getType() == DatabaseEntry.KEY_TYPE_LEASESET) {
     81        int type = data.getType();
     82        if (type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2) {
    8283            _connectChecker = null;
    8384            _connectMask = 0;
     
    309310        }
    310311        DatabaseStoreMessage msg = new DatabaseStoreMessage(getContext());
    311         if (_state.getData().getType() == DatabaseEntry.KEY_TYPE_ROUTERINFO) {
     312        int type = _state.getData().getType();
     313        if (type == DatabaseEntry.KEY_TYPE_ROUTERINFO) {
    312314            if (responseTime > MAX_DIRECT_EXPIRATION)
    313315                responseTime = MAX_DIRECT_EXPIRATION;
    314         } else if (_state.getData().getType() == DatabaseEntry.KEY_TYPE_LEASESET) {
     316        } else if (type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2) {
    315317        } else {
    316318            throw new IllegalArgumentException("Storing an unknown data type! " + _state.getData());
     
    339341     */
    340342    private void sendStore(DatabaseStoreMessage msg, RouterInfo peer, long expiration) {
    341         if (msg.getEntry().getType() == DatabaseEntry.KEY_TYPE_LEASESET) {
     343        int type = msg.getEntry().getType();
     344        if (type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2) {
    342345            getContext().statManager().addRateData("netDb.storeLeaseSetSent", 1);
    343346            // if it is an encrypted leaseset...
  • router/java/src/net/i2p/router/networkdb/kademlia/TransientDataStore.java

    rddfc7c0 rb695242d  
    100100        int count = 0;
    101101        for (DatabaseEntry d : _data.values()) {
    102             if (d.getType() == DatabaseEntry.KEY_TYPE_LEASESET)
     102            int type = d.getType();
     103            if (type == DatabaseEntry.KEY_TYPE_LEASESET ||
     104                type == DatabaseEntry.KEY_TYPE_LS2)
    103105                count++;
    104106        }
     
    123125        DatabaseEntry old = _data.putIfAbsent(key, data);
    124126        boolean rv = false;
    125         if (data.getType() == DatabaseEntry.KEY_TYPE_ROUTERINFO) {
     127        int type = data.getType();
     128        if (type == DatabaseEntry.KEY_TYPE_ROUTERINFO) {
    126129            // Don't do this here so we don't reset it at router startup;
    127130            // the StoreMessageJob calls this
     
    149152                rv = true;
    150153            }
    151         } else if (data.getType() == DatabaseEntry.KEY_TYPE_LEASESET) {
     154        } else if (type == DatabaseEntry.KEY_TYPE_LEASESET ||
     155                   type == DatabaseEntry.KEY_TYPE_LS2) {
    152156            LeaseSet ls = (LeaseSet)data;
    153157            if (old != null) {
Note: See TracChangeset for help on using the changeset viewer.