Changeset 3951736


Ignore:
Timestamp:
Jul 21, 2011 3:34:23 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
370be48
Parents:
046175d8
Message:
  • Console: Use capability method for counting integrated peers
  • Netdb: Speed up collection of all the floodfill peers by using

PeerManager?.getPeersByCapability()

Files:
14 edited

Legend:

Unmodified
Added
Removed
  • apps/routerconsole/java/src/net/i2p/router/web/ProfileOrganizerRenderer.java

    r046175d8 r3951736  
    184184        buf.append("</table>");
    185185
    186         buf.append("<h2><a name=\"flood\"></a>").append(_("Floodfill and Integrated Peers")).append("</h2>\n");
     186        buf.append("<h2><a name=\"flood\"></a>").append(_("Floodfill and Integrated Peers"))
     187           .append(" (").append(integratedPeers.size()).append(")</h2>\n");
    187188        buf.append("<table>");
    188189        buf.append("<tr>");
  • apps/routerconsole/java/src/net/i2p/router/web/SummaryHelper.java

    r046175d8 r3951736  
    222222        if (_context == null)
    223223            return 0;
    224         else
    225             return _context.profileOrganizer().countWellIntegratedPeers();
     224        //return _context.profileOrganizer().countWellIntegratedPeers();
     225        return _context.peerManager().getPeersByCapability(FloodfillNetworkDatabaseFacade.CAPABILITY_FLOODFILL).size();
    226226    }
    227227    /**
  • core/java/src/net/i2p/data/RouterInfo.java

    r046175d8 r3951736  
    318318    /**
    319319     * what special capabilities this router offers
    320      *
     320     * @return non-null, empty string if none
    321321     */
    322322    public String getCapabilities() {
  • history.txt

    r046175d8 r3951736  
     12011-07-21 zzz
     2  * Atalk: Remove this terrible example
     3  * Console: Use capability method for counting integrated peers
     4  * i2psnark: Don't let connection problem crash the DirMonitor (ticket #495)
     5  * Netdb: Speed up collection of all the floodfill peers by using
     6           PeerManager.getPeersByCapability()
     7  * PeerManager: Capability cleanups
     8  * Tunnel TestJob:
     9    - Don't continue testing after the pool is dead
     10    - Tweak test intervals
     11  * TunnelPool: Make more methods package private
     12
    1132011-07-18 zzz
    214  * FileUtil: Add a rename method and a new copy method
  • router/java/src/net/i2p/router/DummyPeerManagerFacade.java

    r046175d8 r3951736  
    1111import java.io.Writer;
    1212import java.util.List;
     13import java.util.Set;
    1314
    1415import net.i2p.data.Hash;
     
    2627    public void renderStatusHTML(Writer out) { }   
    2728    public List<Hash> selectPeers(PeerSelectionCriteria criteria) { return null; }
    28     public List<Hash> getPeersByCapability(char capability) { return null; }
     29    public Set<Hash> getPeersByCapability(char capability) { return null; }
    2930    public void setCapabilities(Hash peer, String caps) {}
    3031    public void removeCapabilities(Hash peer) {}
  • router/java/src/net/i2p/router/PeerManagerFacade.java

    r046175d8 r3951736  
    1010
    1111import java.util.List;
     12import java.util.Set;
    1213
    1314import net.i2p.data.Hash;
     
    2728     */
    2829    public List<Hash> selectPeers(PeerSelectionCriteria criteria);
    29     public List<Hash> getPeersByCapability(char capability);
     30    public Set<Hash> getPeersByCapability(char capability);
    3031    public void setCapabilities(Hash peer, String caps);
    3132    public void removeCapabilities(Hash peer);
  • router/java/src/net/i2p/router/Router.java

    r046175d8 r3951736  
    552552        if (FloodfillNetworkDatabaseFacade.floodfillEnabled(_context) &&
    553553            !Boolean.valueOf(_context.getProperty("router.hideFloodfillParticipant")).booleanValue())
    554             ri.addCapability(FloodfillNetworkDatabaseFacade.CAPACITY_FLOODFILL);
     554            ri.addCapability(FloodfillNetworkDatabaseFacade.CAPABILITY_FLOODFILL);
    555555       
    556556        if(Boolean.valueOf(_context.getProperty(PROP_HIDDEN)).booleanValue())
  • router/java/src/net/i2p/router/RouterVersion.java

    r046175d8 r3951736  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 12;
     21    public final static long BUILD = 13;
    2222
    2323    /** for example "-test" */
  • router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseFacade.java

    r046175d8 r3951736  
    3333 */
    3434public class FloodfillNetworkDatabaseFacade extends KademliaNetworkDatabaseFacade {
    35     public static final char CAPACITY_FLOODFILL = 'f';
     35    public static final char CAPABILITY_FLOODFILL = 'f';
    3636    private final Map _activeFloodQueries;
    3737    private boolean _floodfillEnabled;
     
    224224        }
    225225        String caps = peer.getCapabilities();
    226         if ( (caps != null) && (caps.indexOf(FloodfillNetworkDatabaseFacade.CAPACITY_FLOODFILL) != -1) )
    227             return true;
    228         else
    229             return false;
     226        return caps.indexOf(FloodfillNetworkDatabaseFacade.CAPABILITY_FLOODFILL) >= 0;
    230227    }
    231228
  • router/java/src/net/i2p/router/networkdb/kademlia/FloodfillPeerSelector.java

    r046175d8 r3951736  
    108108     */
    109109    private List<Hash> selectFloodfillParticipants(Set<Hash> toIgnore, KBucketSet kbuckets) {
     110      /*****
    110111        if (kbuckets == null) return Collections.EMPTY_LIST;
    111112        // TODO this is very slow - use profile getPeersByCapability('f') instead
     
    114115        kbuckets.getAll(matches);
    115116        return matches.getFloodfillParticipants();
     117      *****/
     118        Set<Hash> set = _context.peerManager().getPeersByCapability(FloodfillNetworkDatabaseFacade.CAPABILITY_FLOODFILL);
     119        List<Hash> rv = new ArrayList(set.size());
     120        for (Hash h : set) {
     121            if ((toIgnore != null && toIgnore.contains(h)) ||
     122                _context.shitlist().isShitlistedForever(h))
     123               continue;
     124            rv.add(h);
     125        }
     126        return rv;
    116127    }
    117128   
     
    252263   
    253264    private class FloodfillSelectionCollector implements SelectionCollector {
    254         private TreeSet<Hash> _sorted;
    255         private List<Hash>  _floodfillMatches;
    256         private Hash _key;
    257         private Set<Hash> _toIgnore;
     265        private final TreeSet<Hash> _sorted;
     266        private final List<Hash>  _floodfillMatches;
     267        private final Hash _key;
     268        private final Set<Hash> _toIgnore;
    258269        private int _matches;
    259         private int _wanted;
     270        private final int _wanted;
    260271
    261272        /**
     
    268279            _floodfillMatches = new ArrayList(8);
    269280            _toIgnore = toIgnore;
    270             _matches = 0;
    271281            _wanted = wanted;
    272282        }
  • router/java/src/net/i2p/router/peermanager/PeerManager.java

    r046175d8 r3951736  
    1212import java.io.Writer;
    1313import java.util.ArrayList;
     14import java.util.Collections;
     15import java.util.HashMap;
    1416import java.util.HashSet;
    15 import java.util.Iterator;
    1617import java.util.List;
    1718import java.util.Map;
     
    2223import net.i2p.data.RouterInfo;
    2324import net.i2p.router.PeerSelectionCriteria;
     25import net.i2p.router.Router;
    2426import net.i2p.router.RouterContext;
    2527import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
     
    3133 * Manage the current state of the statistics
    3234 *
    33  * All the capabilities methods appear to be almost unused -
    34  * TunnelPeerSelector just looks for unreachables, and that's it?
    35  * If so, a lot of this can go away, including the array of 26 ArrayLists,
    36  * and a lot of synchronization on _capabilitiesByPeer.
    37  *
    38  * We don't trust any published capabilities except for 'K' and 'U'.
    39  * This should be cleaned up.
    40  *
    41  * setCapabilities() and removeCapabilities() can just add/remove the profile and that's it.
     35 * Also maintain Sets for each of the capabilities in TRACKED_CAPS.
    4236 *
    4337 */
     
    4741    private final ProfileOrganizer _organizer;
    4842    private final ProfilePersistenceHelper _persistenceHelper;
    49     private final Set<Hash> _peersByCapability[];
     43    private final Map<Character, Set<Hash>> _peersByCapability;
     44    /** value strings are lower case */
    5045    private final Map<Hash, String> _capabilitiesByPeer;
    5146    private static final long REORGANIZE_TIME = 45*1000;
     
    5348    private static final long REORGANIZE_TIME_LONG = 551*1000;
    5449   
     50    public static final String TRACKED_CAPS = "" +
     51        FloodfillNetworkDatabaseFacade.CAPABILITY_FLOODFILL +
     52        RouterInfo.CAPABILITY_HIDDEN +
     53        Router.CAPABILITY_BW12 +
     54        Router.CAPABILITY_BW32 +
     55        Router.CAPABILITY_BW64 +
     56        Router.CAPABILITY_BW128 +
     57        Router.CAPABILITY_BW256 +
     58        Router.CAPABILITY_REACHABLE +
     59        Router.CAPABILITY_UNREACHABLE;
     60
    5561    /**
    5662     *  Profiles are now loaded in a separate thread,
     
    6470        _organizer.setUs(context.routerHash());
    6571        _capabilitiesByPeer = new ConcurrentHashMap(128);
    66         _peersByCapability = new Set[26];
    67         for (int i = 0; i < _peersByCapability.length; i++)
    68             _peersByCapability[i] = new ConcurrentHashSet();
     72        _peersByCapability = new HashMap(TRACKED_CAPS.length());
     73        for (int i = 0; i < TRACKED_CAPS.length(); i++)
     74            _peersByCapability.put(Character.valueOf(Character.toLowerCase(TRACKED_CAPS.charAt(i))), new ConcurrentHashSet());
    6975        loadProfilesInBackground();
    7076        ////_context.jobQueue().addJob(new EvaluateProfilesJob(_context));
     
    97103   
    98104    void storeProfiles() {
    99         Set peers = selectPeers();
    100         for (Iterator<Hash> iter = peers.iterator(); iter.hasNext(); ) {
    101             Hash peer = iter.next();
     105        Set<Hash> peers = selectPeers();
     106        for (Hash peer : peers) {
    102107            storeProfile(peer);
    103108        }
     
    108113        _organizer.clearProfiles();
    109114        _capabilitiesByPeer.clear();
    110         for (int i = 0; i < _peersByCapability.length; i++)
    111             _peersByCapability[i].clear();
    112     }
    113 
    114     Set selectPeers() {
     115        for (Set p : _peersByCapability.values())
     116            p.clear();
     117    }
     118
     119    Set<Hash> selectPeers() {
    115120        return _organizer.selectAllPeers();
    116121    }
     
    153158    void loadProfiles() {
    154159        Set<PeerProfile> profiles = _persistenceHelper.readProfiles();
    155         for (Iterator<PeerProfile> iter = profiles.iterator(); iter.hasNext();) {
    156             PeerProfile prof = iter.next();
    157             if (prof != null) {
     160        for (PeerProfile prof : profiles) {
    158161                _organizer.addProfile(prof);
    159162                if (_log.shouldLog(Log.DEBUG))
    160163                    _log.debug("Profile for " + prof.getPeer().toBase64() + " loaded");
    161             }
    162164        }
    163165    }
     
    208210                _log.warn("We ran out of peers when looking for reachable ones after finding "
    209211                          + "0 with "
    210                           + _organizer.countWellIntegratedPeers() + "/"
    211212                          + _organizer.countHighCapacityPeers() + "/"
    212                           + _organizer.countFastPeers() + " integrated/high capacity/fast peers");
     213                          + _organizer.countFastPeers() + " high capacity/fast peers");
    213214        }
    214215        if (_log.shouldLog(Log.INFO))
     
    217218    }
    218219   
     220    /**
     221     *  @param caps non-null, case is ignored
     222     */
    219223    public void setCapabilities(Hash peer, String caps) {
    220224        if (_log.shouldLog(Log.DEBUG))
    221225            _log.debug("Setting capabilities for " + peer.toBase64() + " to " + caps);
    222         if (caps != null) caps = caps.toLowerCase();
    223 
    224             String oldCaps = null;
    225             if (caps != null)
    226                 oldCaps = _capabilitiesByPeer.put(peer, caps);
    227             else
    228                 oldCaps = _capabilitiesByPeer.remove(peer);
     226        caps = caps.toLowerCase();
     227
     228        String oldCaps = _capabilitiesByPeer.put(peer, caps);
     229        if (caps.equals(oldCaps))
     230            return;
    229231           
    230232            if (oldCaps != null) {
    231233                for (int i = 0; i < oldCaps.length(); i++) {
    232234                    char c = oldCaps.charAt(i);
    233                     if ( (caps == null) || (caps.indexOf(c) < 0) ) {
     235                    if (caps.indexOf(c) < 0) {
    234236                        Set<Hash> peers = locked_getPeers(c);
    235237                        if (peers != null)
     
    238240                }
    239241            }
    240             if (caps != null) {
     242
    241243                for (int i = 0; i < caps.length(); i++) {
    242244                    char c = caps.charAt(i);
     
    247249                        peers.add(peer);
    248250                }
    249             }
    250251    }
    251252   
     
    253254    private Set<Hash> locked_getPeers(char c) {
    254255        c = Character.toLowerCase(c);
    255         int i = c - 'a';
    256         if ( (i < 0) || (i >= _peersByCapability.length) ) {
    257             if (_log.shouldLog(Log.DEBUG))
    258                 _log.debug("Invalid capability " + c + " (" + i + ")");
    259             return null;
    260         }
    261         return _peersByCapability[i];
     256        return _peersByCapability.get(Character.valueOf(c));
    262257    }
    263258   
     
    266261            _log.debug("Removing capabilities from " + peer.toBase64());
    267262
    268             String oldCaps = (String)_capabilitiesByPeer.remove(peer);
     263            String oldCaps = _capabilitiesByPeer.remove(peer);
    269264            if (oldCaps != null) {
    270265                for (int i = 0; i < oldCaps.length(); i++) {
     
    292287
    293288    /**
    294      *  The only user of this is TunnelPeerSelector for unreachables?
    295      */
    296     public List<Hash> getPeersByCapability(char capability) {
    297         if (true) {
     289     *  @param capability case-insensitive
     290     *  @return non-null unmodifiable set
     291     */
     292    public Set<Hash> getPeersByCapability(char capability) {
    298293            Set<Hash> peers = locked_getPeers(capability);
    299294            if (peers != null)
    300                 return new ArrayList(peers);
    301             return null;
    302         } else {
    303             // Wow this looks really slow...
    304             // What is the point of keeping all the data structures above
    305             // if we are going to go through the whole netdb anyway?
    306             // Not sure why jrandom switched to do it this way,
    307             // the checkin comments aren't clear...
    308             // Since the locking is gone, switch back to the above.
    309             FloodfillNetworkDatabaseFacade f = (FloodfillNetworkDatabaseFacade)_context.netDb();
    310             List<RouterInfo> routerInfos = f.getKnownRouterData();
    311             List<Hash> rv = new ArrayList();
    312             for (Iterator<RouterInfo> iter = routerInfos.iterator(); iter.hasNext(); ) {
    313                 RouterInfo ri = iter.next();
    314                 String caps = ri.getCapabilities();
    315                 if (caps.indexOf(capability) >= 0)
    316                     rv.add(ri.getIdentity().calculateHash());
    317             }
    318             if (_log.shouldLog(Log.DEBUG))
    319                 _log.debug("Peers with capacity " + capability + ": " + rv.size());
    320             return rv;
    321         }
     295                return Collections.unmodifiableSet(peers);
     296            return Collections.EMPTY_SET;
    322297    }
    323298}
  • router/java/src/net/i2p/router/peermanager/PeerManagerFacadeImpl.java

    r046175d8 r3951736  
    1111import java.io.IOException;
    1212import java.io.Writer;
    13 import java.util.ArrayList;
     13import java.util.Collections;
     14import java.util.Iterator;
    1415import java.util.List;
     16import java.util.Set;
    1517
    1618import net.i2p.data.Hash;
     
    6466    }
    6567
     68    /**
     69     *  @param caps non-null
     70     */
    6671    public void setCapabilities(Hash peer, String caps) {
    6772        if (_manager == null) return;
    6873        _manager.setCapabilities(peer, caps);
    6974    }
     75
    7076    public void removeCapabilities(Hash peer) {
    7177        if (_manager == null) return;
     
    8086    }
    8187
    82     public List<Hash> getPeersByCapability(char capability) {
    83         if (_manager == null) return new ArrayList(0);
     88    /**
     89     *  @param capability case-insensitive
     90     *  @return non-null unmodifiable set
     91     */
     92    public Set<Hash> getPeersByCapability(char capability) {
     93        if (_manager == null) return Collections.EMPTY_SET;
    8494        return _manager.getPeersByCapability(capability);
    8595    }
  • router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java

    r046175d8 r3951736  
    4747    /** H(routerIdentity) to PeerProfile for all peers that have high capacities */
    4848    private final Map<Hash, PeerProfile> _highCapacityPeers;
    49     /** H(routerIdentity) to PeerProfile for all peers that well integrated into the network and not failing horribly */
     49    /** TO BE REMOVED H(routerIdentity) to PeerProfile for all peers that well integrated into the network and not failing horribly */
    5050    private final Map<Hash, PeerProfile> _wellIntegratedPeers;
    5151    /** H(routerIdentity) to PeerProfile for all peers that are not failing horribly */
     
    188188    public int countFastPeers() { return count(_fastPeers); }
    189189    public int countHighCapacityPeers() { return count(_highCapacityPeers); }
     190    /** @deprecated use ProfileManager.getPeersByCapability('f').size() */
    190191    public int countWellIntegratedPeers() { return count(_wellIntegratedPeers); }
    191192    public int countNotFailingPeers() { return count(_notFailingPeers); }
     
    409410     * Return a set of Hashes for peers that are well integrated into the network.
    410411     *
     412     * @deprecated unused
    411413     */
    412414    public void selectWellIntegratedPeers(int howMany, Set<Hash> exclude, Set<Hash> matches) {
     
    419421     * @param mask 0-4 Number of bytes to match to determine if peers in the same IP range should
    420422     *             not be in the same tunnel. 0 = disable check; 1 = /8; 2 = /16; 3 = /24; 4 = exact IP match
     423     * @deprecated unused
    421424     */
    422425    public void selectWellIntegratedPeers(int howMany, Set<Hash> exclude, Set<Hash> matches, int mask) {
  • router/java/src/net/i2p/router/tunnel/pool/TunnelPeerSelector.java

    r046175d8 r3951736  
    33import java.math.BigInteger;
    44import java.util.ArrayList;
     5import java.util.Collection;
    56import java.util.Collections;
    67import java.util.Comparator;
     
    199200            // NOTE: filterUnreachable returns true for inbound, false for outbound
    200201            // This is the only use for getPeersByCapability? And the whole set of datastructures in PeerManager?
    201             List<Hash> caps = ctx.peerManager().getPeersByCapability(Router.CAPABILITY_UNREACHABLE);
     202            Collection<Hash> caps = ctx.peerManager().getPeersByCapability(Router.CAPABILITY_UNREACHABLE);
    202203            if (caps != null)
    203204                peers.addAll(caps);
     
    353354        }
    354355        int maxLen = 0;
    355         if (cap.indexOf(FloodfillNetworkDatabaseFacade.CAPACITY_FLOODFILL) >= 0)
     356        if (cap.indexOf(FloodfillNetworkDatabaseFacade.CAPABILITY_FLOODFILL) >= 0)
    356357            maxLen++;
    357358        if (cap.indexOf(Router.CAPABILITY_REACHABLE) >= 0)
Note: See TracChangeset for help on using the changeset viewer.