Changeset 071498c


Ignore:
Timestamp:
Mar 16, 2015 3:10:36 PM (6 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
819b35c7
Parents:
7125ed0
Message:

Router: Republish RI early if capabilities change

  • RI javadoc clarifications WRT caps
Location:
router/java/src/net/i2p
Files:
2 edited

Legend:

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

    r7125ed0 r071498c  
    287287     * Makes a copy.
    288288     *
     289     * Warning, clears all capabilities, must be called BEFORE addCapability().
     290     *
    289291     * @param options if null, clears current options
    290292     * @throws IllegalStateException if RouterInfo is already signed
     
    434436
    435437    /**
     438     * Warning, must be called AFTER setOptions().
     439     *
    436440     * @throws IllegalStateException if RouterInfo is already signed
    437441     */
  • router/java/src/net/i2p/router/networkdb/PublishLocalRouterInfoJob.java

    r7125ed0 r071498c  
    8282            List<RouterAddress> newAddrs = getContext().commSystem().createAddresses();
    8383            int count = _runCount.incrementAndGet();
     84            RouterInfo ri = new RouterInfo(oldRI);
     85            // this will get overwritten by setOptions() below, must restore it below
     86            getContext().router().addCapabilities(ri);
     87            String caps = ri.getCapabilities();
    8488            if (_notFirstTime && (count % 4) != 0 && oldAddrs.size() == newAddrs.size()) {
    8589                // 3 times out of 4, we don't republish if everything is the same...
    8690                // If something changed, including the cost, then publish,
    8791                // otherwise don't.
    88                 boolean different = false;
    89                 Comparator<RouterAddress> comp = new AddrComparator();
    90                 Collections.sort(oldAddrs, comp);
    91                 Collections.sort(newAddrs, comp);
    92                 for (int i = 0; i < oldAddrs.size(); i++) {
    93                     // deepEquals() includes cost
    94                     if (!oldAddrs.get(i).deepEquals(newAddrs.get(i))) {
    95                         different = true;
    96                         break;
     92                boolean different = !oldRI.getCapabilities().equals(ri.getCapabilities());
     93                if (!different) {
     94                    Comparator<RouterAddress> comp = new AddrComparator();
     95                    Collections.sort(oldAddrs, comp);
     96                    Collections.sort(newAddrs, comp);
     97                    for (int i = 0; i < oldAddrs.size(); i++) {
     98                        // deepEquals() includes cost
     99                        if (!oldAddrs.get(i).deepEquals(newAddrs.get(i))) {
     100                            different = true;
     101                            break;
     102                        }
     103                    }
     104                    if (!different) {
     105                        if (_log.shouldLog(Log.INFO))
     106                            _log.info("Not republishing early because costs and caps and addresses are the same");
     107                        requeue(getDelay());
     108                        return;
    97109                    }
    98110                }
    99                 if (!different) {
    100                     if (_log.shouldLog(Log.INFO))
    101                         _log.info("Not republishing early because costs are the same");
    102                     requeue(getDelay());
    103                     return;
    104                 }
    105111                if (_log.shouldLog(Log.INFO))
    106                     _log.info("Republishing early because addresses or costs have changed - old:\n" +
     112                    _log.info("Republishing early because addresses or costs or caps have changed -" +
     113                              " oldCaps: " + oldRI.getCapabilities() + " newCaps: " + ri.getCapabilities() +
     114                              " old:\n" +
    107115                              oldAddrs + "\nnew:\n" + newAddrs);
    108116            }
    109             RouterInfo ri = new RouterInfo(oldRI);
    110117            ri.setPublished(getContext().clock().now());
    111118            Properties stats = getContext().statPublisher().publishStatistics();
    112             stats.setProperty(RouterInfo.PROP_NETWORK_ID, ""+Router.NETWORK_ID);
     119            stats.setProperty(RouterInfo.PROP_NETWORK_ID, String.valueOf(Router.NETWORK_ID));
     120            // restore caps generated above
     121            stats.setProperty(RouterInfo.PROP_CAPABILITIES, caps);
    113122            ri.setOptions(stats);
    114123            ri.setAddresses(newAddrs);
    115124
    116             getContext().router().addCapabilities(ri);
    117125            SigningPrivateKey key = getContext().keyManager().getSigningPrivateKey();
    118126            if (key == null) {
Note: See TracChangeset for help on using the changeset viewer.