Changeset 026ddb3 for router


Ignore:
Timestamp:
Dec 1, 2018 1:13:51 PM (18 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
700d4d3
Parents:
79440f84
Message:

Router: Add preliminary support for more LS2 types (proposal 123)
I2CP: Don't require privkeys for meta in CLS2 message

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

Legend:

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

    r79440f84 r026ddb3  
    1717import net.i2p.data.DataFormatException;
    1818import net.i2p.data.DataHelper;
     19import net.i2p.data.EncryptedLeaseSet;
    1920import net.i2p.data.Hash;
    2021import net.i2p.data.LeaseSet;
    2122import net.i2p.data.LeaseSet2;
     23import net.i2p.data.MetaLeaseSet;
    2224import net.i2p.data.router.RouterInfo;
    2325import net.i2p.data.TunnelId;
     
    135137        }
    136138       
    137         if (dbType == DatabaseEntry.KEY_TYPE_LEASESET) {
    138             _dbEntry = new LeaseSet();
    139             try {
    140                 _dbEntry.readBytes(new ByteArrayInputStream(data, curIndex, data.length-curIndex));
    141             } catch (DataFormatException dfe) {
    142                 throw new I2NPMessageException("Error reading the leaseSet", dfe);
    143             } catch (IOException ioe) {
    144                 throw new I2NPMessageException("Error reading the leaseSet", ioe);
    145             }
    146         } else if (dbType == DatabaseEntry.KEY_TYPE_LS2) {
    147             _dbEntry = new LeaseSet2();
     139        if (DatabaseEntry.isLeaseSet(dbType)) {
     140            if (dbType == DatabaseEntry.KEY_TYPE_LEASESET)
     141                _dbEntry = new LeaseSet();
     142            else if (dbType == DatabaseEntry.KEY_TYPE_LS2)
     143                _dbEntry = new LeaseSet2();
     144            else if (dbType == DatabaseEntry.KEY_TYPE_ENCRYPTED_LS2)
     145                _dbEntry = new EncryptedLeaseSet();
     146            else
     147                _dbEntry = new MetaLeaseSet();
    148148            try {
    149149                _dbEntry.readBytes(new ByteArrayInputStream(data, curIndex, data.length-curIndex));
     
    197197            len += 4 + Hash.HASH_LENGTH; // replyTunnel+replyGateway
    198198        int type = _dbEntry.getType();
    199         if (type == DatabaseEntry.KEY_TYPE_LEASESET) {
     199        if (_dbEntry.isLeaseSet()) {
    200200            if (_byteCache == null) {
    201201                _byteCache = _dbEntry.toByteArray();
     
    219219        if (_dbEntry == null) throw new I2NPMessageException("Missing entry");
    220220        int type = _dbEntry.getType();
    221         if (type != DatabaseEntry.KEY_TYPE_LEASESET && type != DatabaseEntry.KEY_TYPE_ROUTERINFO)
     221        if (type != DatabaseEntry.KEY_TYPE_ROUTERINFO && !_dbEntry.isLeaseSet())
    222222            throw new I2NPMessageException("Invalid key type " + type);
    223223       
  • router/java/src/net/i2p/router/networkdb/HandleDatabaseLookupMessageJob.java

    r79440f84 r026ddb3  
    9696        DatabaseEntry dbe = getContext().netDb().lookupLocally(_message.getSearchKey());
    9797        int type = dbe != null ? dbe.getType() : -1;
    98         if ((type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2) &&
     98        if (DatabaseEntry.isLeaseSet(type) &&
    9999            (lookupType == DatabaseLookupMessage.Type.ANY || lookupType == DatabaseLookupMessage.Type.LS)) {
    100100            LeaseSet ls = (LeaseSet) dbe;
     
    261261                       + " tunnel " + replyTunnel);
    262262        DatabaseStoreMessage msg = new DatabaseStoreMessage(getContext());
    263         int type = data.getType();
    264         if (type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2) {
     263        if (data.isLeaseSet()) {
    265264            getContext().statManager().addRateData("netDb.lookupsMatchedLeaseSet", 1);
    266265        }
  • router/java/src/net/i2p/router/networkdb/kademlia/ExpireLeasesJob.java

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

    r79440f84 r026ddb3  
    5555            DatabaseEntry entry = dsm.getEntry();
    5656            int type = entry.getType();
    57             if (type == DatabaseEntry.KEY_TYPE_LEASESET ||
    58                 type == DatabaseEntry.KEY_TYPE_LS2) {
     57            if (DatabaseEntry.isLeaseSet(type)) {
    5958                // Since HFDSMJ wants to setReceivedAsPublished(), we have to
    6059                // set a flag saying this was really the result of a query,
  • router/java/src/net/i2p/router/networkdb/kademlia/HandleFloodfillDatabaseStoreMessageJob.java

    r79440f84 r026ddb3  
    7171        DatabaseEntry entry = _message.getEntry();
    7272        int type = entry.getType();
    73         if (type == DatabaseEntry.KEY_TYPE_LEASESET ||
    74             type == DatabaseEntry.KEY_TYPE_LS2) {
     73        if (DatabaseEntry.isLeaseSet(type)) {
    7574            getContext().statManager().addRateData("netDb.storeLeaseSetHandled", 1);
    7675            if (_log.shouldLog(Log.INFO))
  • router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java

    r79440f84 r026ddb3  
    439439        int rv = 0;
    440440        for (DatabaseEntry ds : _ds.getEntries()) {
    441             int type = ds.getType();
    442             if ((type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2) &&
     441            if (ds.isLeaseSet() &&
    443442                ((LeaseSet)ds).getReceivedAsPublished())
    444443                rv++;
     
    469468            return null;
    470469        int type = rv.getType();
    471         if (type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2) {
     470        if (DatabaseEntry.isLeaseSet(type)) {
    472471            LeaseSet ls = (LeaseSet)rv;
    473472            if (ls.isCurrent(Router.CLOCK_FUDGE_FACTOR))
     
    554553        DatabaseEntry ds = _ds.get(key);
    555554        if (ds != null) {
    556             int type = ds.getType();
    557             if (type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2) {
     555            if (ds.isLeaseSet()) {
    558556                LeaseSet ls = (LeaseSet)ds;
    559557                if (ls.isCurrent(Router.CLOCK_FUDGE_FACTOR)) {
     
    608606        DatabaseEntry ds = _ds.get(key);
    609607        if (ds != null) {
    610             int type = ds.getType();
    611             if (type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2) {
     608            if (ds.isLeaseSet()) {
    612609                LeaseSet ls = (LeaseSet)ds;
    613610                return ls.getDestination();
     
    10831080        if (entry.getHash().equals(h)) {
    10841081            int etype = entry.getType();
    1085             if (etype == DatabaseEntry.KEY_TYPE_LEASESET || etype == DatabaseEntry.KEY_TYPE_LS2) {
     1082            if (DatabaseEntry.isLeaseSet(etype)) {
    10861083                LeaseSet ls = (LeaseSet) entry;
    10871084                Destination d = ls.getDestination();
     
    12431240        Set<LeaseSet> leases = new HashSet<LeaseSet>();
    12441241        for (DatabaseEntry o : getDataStore().getEntries()) {
    1245             int type = o.getType();
    1246             if (type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2)
     1242            if (o.isLeaseSet())
    12471243                leases.add((LeaseSet)o);
    12481244        }
  • router/java/src/net/i2p/router/networkdb/kademlia/StoreJob.java

    r79440f84 r026ddb3  
    7979        _expiration = context.clock().now() + timeoutMs;
    8080        _peerSelector = facade.getPeerSelector();
    81         int type = data.getType();
    82         if (type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2) {
     81        if (data.isLeaseSet()) {
    8382            _connectChecker = null;
    8483            _connectMask = 0;
     
    314313            if (responseTime > MAX_DIRECT_EXPIRATION)
    315314                responseTime = MAX_DIRECT_EXPIRATION;
    316         } else if (type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2) {
    317         } else {
     315        } else if (!DatabaseEntry.isLeaseSet(type)) {
    318316            throw new IllegalArgumentException("Storing an unknown data type! " + _state.getData());
    319317        }
     
    341339     */
    342340    private void sendStore(DatabaseStoreMessage msg, RouterInfo peer, long expiration) {
    343         int type = msg.getEntry().getType();
    344         if (type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2) {
     341        if (msg.getEntry().isLeaseSet()) {
    345342            getContext().statManager().addRateData("netDb.storeLeaseSetSent", 1);
    346343            // if it is an encrypted leaseset...
  • router/java/src/net/i2p/router/networkdb/kademlia/TransientDataStore.java

    r79440f84 r026ddb3  
    100100        int count = 0;
    101101        for (DatabaseEntry d : _data.values()) {
    102             int type = d.getType();
    103             if (type == DatabaseEntry.KEY_TYPE_LEASESET ||
    104                 type == DatabaseEntry.KEY_TYPE_LS2)
     102            if (d.isLeaseSet())
    105103                count++;
    106104        }
     
    152150                rv = true;
    153151            }
    154         } else if (type == DatabaseEntry.KEY_TYPE_LEASESET ||
    155                    type == DatabaseEntry.KEY_TYPE_LS2) {
     152        } else if (DatabaseEntry.isLeaseSet(type)) {
    156153            LeaseSet ls = (LeaseSet)data;
    157154            if (old != null) {
Note: See TracChangeset for help on using the changeset viewer.