Changeset 9efa0ea


Ignore:
Timestamp:
Dec 1, 2018 6:18:59 PM (20 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
7c928f9
Parents:
700d4d3
Message:

Router: Only send/verify LS2 with router that supports it
Remove old commented-out code

Location:
router/java/src/net/i2p/router/networkdb/kademlia
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/networkdb/kademlia/FloodfillStoreJob.java

    r700d4d3 r9efa0ea  
    8080
    8181            long published = data.getDate();
     82            boolean isls2 = data.isLeaseSet() && data.getType() != DatabaseEntry.KEY_TYPE_LEASESET;
    8283
    8384            // we should always have exactly one successful entry
     
    8788            } catch (NoSuchElementException nsee) {}
    8889            getContext().jobQueue().addJob(new FloodfillVerifyStoreJob(getContext(), _state.getTarget(),
    89                                                                        published, isRouterInfo, sentTo, _facade));
     90                                                                       published, isRouterInfo, isls2,
     91                                                                       sentTo, _facade));
    9092    }
    9193   
  • router/java/src/net/i2p/router/networkdb/kademlia/FloodfillVerifyStoreJob.java

    r700d4d3 r9efa0ea  
    3939    private final long _published;
    4040    private final boolean _isRouterInfo;
     41    private final boolean _isLS2;
    4142    private MessageWrapper.WrappedMessage _wrappedMessage;
    4243    private final Set<Hash> _ignore;
     
    5354     *  @param sentTo who to give the credit or blame to, can be null
    5455     */
    55     public FloodfillVerifyStoreJob(RouterContext ctx, Hash key, long published, boolean isRouterInfo, Hash sentTo, FloodfillNetworkDatabaseFacade facade) {
     56    public FloodfillVerifyStoreJob(RouterContext ctx, Hash key, long published, boolean isRouterInfo,
     57                                   boolean isLS2, Hash sentTo, FloodfillNetworkDatabaseFacade facade) {
    5658        super(ctx);
    5759        facade.verifyStarted(key);
     
    5961        _published = published;
    6062        _isRouterInfo = isRouterInfo;
     63        _isLS2 = isLS2;
    6164        _log = ctx.logManager().getLog(getClass());
    6265        _sentTo = sentTo;
     
    196199                RouterInfo ri = _facade.lookupRouterInfoLocally(peer);
    197200                //if (ri != null && StoreJob.supportsCert(ri, keyCert)) {
    198                 if (ri != null && StoreJob.shouldStoreTo(ri)) {
     201                if (ri != null && StoreJob.shouldStoreTo(ri) &&
     202                    (!_isLS2 || StoreJob.shouldStoreLS2To(ri))) {
    199203                    Set<String> peerIPs = new MaskedIPSet(getContext(), ri, IP_CLOSE_BYTES);
    200204                    if (!_ipSet.containsAny(peerIPs)) {
  • router/java/src/net/i2p/router/networkdb/kademlia/StoreJob.java

    r700d4d3 r9efa0ea  
    181181            int queued = 0;
    182182            int skipped = 0;
     183            int type = _state.getData().getType();
     184            boolean isls2 = DatabaseEntry.isLeaseSet(type) && type != DatabaseEntry.KEY_TYPE_LEASESET;
    183185            for (Hash peer : closestHashes) {
    184186                DatabaseEntry ds = _facade.getDataStore().get(peer);
     
    193195                    _state.addSkipped(peer);
    194196                    skipped++;
    195 /****
    196    above shouldStoreTo() check is newer than these two checks, so we're covered
    197 
    198                 } else if (_state.getData().getType() == DatabaseEntry.KEY_TYPE_LEASESET &&
    199                            !supportsCert((RouterInfo)ds,
    200                                          ((LeaseSet)_state.getData()).getDestination().getCertificate())) {
     197                } else if (isls2 &&
     198                           !shouldStoreLS2To((RouterInfo)ds)) {
    201199                    if (_log.shouldLog(Log.INFO))
    202                         _log.info(getJobId() + ": Skipping router that doesn't support key certs " + peer);
     200                        _log.info(getJobId() + ": Skipping router that doesn't support LS2 " + peer);
    203201                    _state.addSkipped(peer);
    204202                    skipped++;
    205                 } else if (_state.getData().getType() == DatabaseEntry.KEY_TYPE_LEASESET &&
    206                            ((LeaseSet)_state.getData()).getLeaseCount() > 6 &&
    207                            !supportsBigLeaseSets((RouterInfo)ds)) {
    208                     if (_log.shouldLog(Log.INFO))
    209                         _log.info(getJobId() + ": Skipping router that doesn't support big leasesets " + peer);
    210                     _state.addSkipped(peer);
    211                     skipped++;
    212 ****/
    213203                } else {
    214204                    int peerTimeout = _facade.getPeerTimeout(peer);
     
    470460        if (outTunnel != null) {
    471461            I2NPMessage sent;
    472             boolean shouldEncrypt = supportsEncryption(peer);
    473             if (shouldEncrypt) {
     462
    474463                // garlic encrypt
    475464                MessageWrapper.WrappedMessage wm = MessageWrapper.wrap(getContext(), msg, client, peer);
     
    482471                sent = wm.getMessage();
    483472                _state.addPending(to, wm);
    484             } else {
    485                 _state.addPending(to);
    486                 // now that almost all floodfills are at 0.7.10,
    487                 // just refuse to store unencrypted to older ones.
    488                 _state.replyTimeout(to);
    489                 getContext().jobQueue().addJob(new WaitJob(getContext()));
    490                 return;
    491             }
    492473
    493474            SendSuccessJob onReply = new SendSuccessJob(getContext(), peer, outTunnel, sent.getMessageSize());
     
    528509    }
    529510
    530     private static final String MIN_ENCRYPTION_VERSION = "0.7.10";
    531 
    532     /**
    533      * *sigh*
    534      * sadly due to a bug in HandleFloodfillDatabaseStoreMessageJob, where
    535      * a floodfill would not flood anything that arrived garlic-wrapped
    536      * @since 0.7.10
    537      */
    538     private static boolean supportsEncryption(RouterInfo ri) {
    539         String v = ri.getVersion();
    540         return VersionComparator.comp(v, MIN_ENCRYPTION_VERSION) >= 0;
    541     }
    542 
    543     /**
    544      * Does this router understand this cert?
    545      * @return true if not a key cert
    546      * @since 0.9.12
    547      */
    548 /****
    549     public static boolean supportsCert(RouterInfo ri, Certificate cert) {
    550         if (cert.getCertificateType() != Certificate.CERTIFICATE_TYPE_KEY)
    551             return true;
    552         SigType type;
    553         try {
    554             type = cert.toKeyCertificate().getSigType();
    555         } catch (DataFormatException dfe) {
    556             return false;
    557         }
    558         if (type == null)
    559             return false;
    560         String v = ri.getVersion();
    561         String since = type.getSupportedSince();
    562         return VersionComparator.comp(v, since) >= 0;
    563     }
    564 
    565     private static final String MIN_BIGLEASESET_VERSION = "0.9";
    566 ****/
    567 
    568     /**
    569      * Does he support more than 6 leasesets?
    570      * @since 0.9.12
    571      */
    572 /****
    573     private static boolean supportsBigLeaseSets(RouterInfo ri) {
    574         String v = ri.getVersion();
    575         return VersionComparator.comp(v, MIN_BIGLEASESET_VERSION) >= 0;
    576     }
    577 ****/
    578 
    579     /** */
     511    /** @since 0.9.28 */
    580512    public static final String MIN_STORE_VERSION = "0.9.28";
    581513
     
    587519        String v = ri.getVersion();
    588520        return VersionComparator.comp(v, MIN_STORE_VERSION) >= 0;
     521    }
     522
     523    /** @since 0.9.38 */
     524    public static final String MIN_STORE_LS2_VERSION = "0.9.38";
     525
     526    /**
     527     * Is it too old?
     528     * @since 0.9.38
     529     */
     530    static boolean shouldStoreLS2To(RouterInfo ri) {
     531        String v = ri.getVersion();
     532        return VersionComparator.comp(v, MIN_STORE_LS2_VERSION) >= 0;
    589533    }
    590534
Note: See TracChangeset for help on using the changeset viewer.