Changeset 665f58d for router


Ignore:
Timestamp:
Mar 7, 2018 1:29:11 PM (2 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
ceac733
Parents:
0eb04fac
Message:

Router: Remove ancient version check in BuildRequestor?
Add method to get all connected peers from transports, for efficiency
Don't try to build non-zero-hop tunnels in VMCommSystem

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

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/CommSystemFacade.java

    r0eb04fac r665f58d  
    1313import java.util.Collections;
    1414import java.util.List;
     15import java.util.Set;
    1516import java.util.SortedMap;
    1617import java.util.TreeMap;
     
    4041     *  sent a message to or received a message from in the last five minutes.
    4142     */
    42     public int countActivePeers() { return 0; }
     43    public abstract int countActivePeers();
    4344
    4445    /**
     
    4748     *  Unused for anything, to be removed.
    4849     */
    49     public int countActiveSendPeers() { return 0; }
     50    public abstract int countActiveSendPeers();
    5051
    5152    public boolean haveInboundCapacity(int pct) { return true; }
     
    9192    public boolean isBacklogged(Hash peer) { return false; }
    9293    public boolean wasUnreachable(Hash peer) { return false; }
    93     public boolean isEstablished(Hash peer) { return false; }
     94    public abstract boolean isEstablished(Hash peer);
    9495    public byte[] getIP(Hash dest) { return null; }
    9596    public void queueLookup(byte[] ip) {}
     
    128129        return new TreeMap<String, Transport>();
    129130    }
     131   
     132    /**
     133     *  Get all the peers we are connected to.
     134     *  This should be more efficient than repeated calls to isEstablished()
     135     *  if you have to check a lot.
     136     *
     137     *  @return the hashes of all the routers we are connected to, non-null
     138     *  @since 0.9.34
     139     */
     140    public abstract Set<Hash> getEstablished();
    130141   
    131142    /** @since 0.8.13 */
  • router/java/src/net/i2p/router/dummy/VMCommSystem.java

    r0eb04fac r665f58d  
    55import java.util.Collections;
    66import java.util.HashMap;
     7import java.util.HashSet;
    78import java.util.Map;
     9import java.util.Set;
    810
    911import net.i2p.data.Hash;
     
    4850    }
    4951   
     52    public int countActivePeers() { return _commSystemFacades.size() - 1; }
     53
     54    public int countActiveSendPeers()  { return _commSystemFacades.size() - 1; }
     55
     56    public boolean isEstablished(Hash peer) { return _commSystemFacades.containsKey(peer); }
     57
     58    public Set<Hash> getEstablished() {
     59        Set<Hash> rv;
     60        synchronized (_commSystemFacades) {
     61            rv = new HashSet<Hash>(_commSystemFacades.keySet());
     62        }
     63        Hash us = _context.routerHash();
     64        if (us != null)
     65            rv.remove(us);
     66        return rv;
     67    }
     68
    5069    /**
    5170     * The router wants us to send the given message to the peer.  Do so, or fire
  • router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java

    r0eb04fac r665f58d  
    577577    public void selectActiveNotFailingPeers(int howMany, Set<Hash> exclude, Set<Hash> matches) {
    578578        if (matches.size() < howMany) {
     579            Set<Hash> connected = _context.commSystem().getEstablished();
    579580            getReadLock();
    580581            try {
    581582                for (Hash peer : _notFailingPeers.keySet()) {
    582                     if (!_context.commSystem().isEstablished(peer))
     583                    if (!connected.contains(peer))
    583584                        exclude.add(peer);
    584585                }
     
    603604    private void selectActiveNotFailingPeers2(int howMany, Set<Hash> exclude, Set<Hash> matches, int mask) {
    604605        if (matches.size() < howMany) {
    605             Map<Hash, PeerProfile> activePeers = new HashMap<Hash, PeerProfile>();
     606            Set<Hash> connected = _context.commSystem().getEstablished();
     607            Map<Hash, PeerProfile> activePeers = new HashMap<Hash, PeerProfile>(connected.size());
    606608            getReadLock();
    607609            try {
    608                 for (Map.Entry<Hash, PeerProfile> e : _notFailingPeers.entrySet()) {
    609                     if (_context.commSystem().isEstablished(e.getKey()))
    610                         activePeers.put(e.getKey(), e.getValue());
     610                for (Hash peer : connected) {
     611                    PeerProfile prof = _notFailingPeers.get(peer);
     612                    if (prof != null)
     613                        activePeers.put(peer, prof);
    611614                }
    612615                locked_selectPeers(activePeers, howMany, exclude, matches, mask);
  • router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java

    r0eb04fac r665f58d  
    1515import java.util.List;
    1616import java.util.Locale;
     17import java.util.Set;
    1718import java.util.SortedMap;
    1819import java.util.Vector;
     
    165166        return _manager.isEstablished(peer);
    166167    }
    167    
     168
     169    /**
     170     *  @return a new set, may be modified
     171     *  @since 0.9.34
     172     */   
     173    public Set<Hash> getEstablished() {
     174        return _manager.getEstablished();
     175    }
     176
    168177    @Override
    169178    public boolean wasUnreachable(Hash peer) {
  • router/java/src/net/i2p/router/transport/Transport.java

    r0eb04fac r665f58d  
    1212import java.io.Writer;
    1313import java.util.List;
     14import java.util.Set;
    1415import java.util.Vector;
    1516
     
    142143    public String getStyle();
    143144   
     145    /**
     146     * @return may or may not be modifiable; check implementation
     147     * @since 0.9.34
     148     */
     149    public Set<Hash> getEstablished();   
     150
    144151    public int countPeers();   
    145152    public int countActivePeers();   
  • router/java/src/net/i2p/router/transport/TransportManager.java

    r0eb04fac r665f58d  
    517517   
    518518    /**
     519     *  @return a new set, may be modified
     520     *  @since 0.9.34
     521     */
     522    public Set<Hash> getEstablished() {
     523        // for efficiency. NTCP is modifiable, SSU isn't
     524        Transport t = _transports.get("NTCP");
     525        Set<Hash> rv;
     526        if (t != null)
     527            rv = t.getEstablished();
     528        else
     529            rv = new HashSet<Hash>(256);
     530        t = _transports.get("SSU");
     531        if (t != null)
     532            rv.addAll(t.getEstablished());
     533        return rv;
     534    }
     535   
     536    /**
    519537     * Tell the transports that we may disconnect from this peer.
    520538     * This is advisory only.
  • router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java

    r0eb04fac r665f58d  
    536536        return _conByIdent.values();
    537537    }
     538   
     539    /**
     540     * Connected peers.
     541     *
     542     * @return a copy, modifiable
     543     * @since 0.9.34
     544     */
     545    public Set<Hash> getEstablished() {
     546        Set<Hash> rv = new HashSet<Hash>(_conByIdent.keySet());
     547        for (Map.Entry<Hash, NTCPConnection> e : _conByIdent.entrySet()) {
     548            NTCPConnection con = e.getValue();
     549            if (!con.isEstablished() || con.isClosed())
     550                rv.remove(e.getKey());
     551        }
     552        return rv;
     553    }
    538554
    539555    /**
  • router/java/src/net/i2p/router/transport/udp/UDPTransport.java

    r0eb04fac r665f58d  
    11741174    public Collection<PeerState> getPeers() {
    11751175        return _peersByIdent.values();
     1176    }
     1177   
     1178    /**
     1179     * Connected peers.
     1180     *
     1181     * @return not a copy, do not modify
     1182     * @since 0.9.34
     1183     */
     1184    public Set<Hash> getEstablished() {
     1185        return _peersByIdent.keySet();
    11761186    }
    11771187
     
    26392649    @Override
    26402650    public boolean isEstablished(Hash dest) {
    2641         return getPeerState(dest) != null;
     2651        return _peersByIdent.containsKey(dest);
    26422652    }
    26432653
  • router/java/src/net/i2p/router/tunnel/pool/BuildExecutor.java

    r0eb04fac r665f58d  
    1313import net.i2p.data.i2np.I2NPMessage;
    1414import net.i2p.data.router.RouterInfo;
     15import net.i2p.router.CommSystemFacade;
    1516import net.i2p.router.CommSystemFacade.Status;
    1617import net.i2p.router.RouterContext;
     
    112113
    113114    private int allowed() {
    114         if (_context.commSystem().getStatus() == Status.DISCONNECTED)
     115        CommSystemFacade csf = _context.commSystem();
     116        if (csf.getStatus() == Status.DISCONNECTED)
     117            return 0;
     118        if (csf.isDummy() && csf.getEstablished().size() <= 0)
    115119            return 0;
    116120        int maxKBps = _context.bandwidthLimiter().getOutboundKBytesPerSecond();
  • router/java/src/net/i2p/router/tunnel/pool/BuildRequestor.java

    r0eb04fac r665f58d  
    2626abstract class BuildRequestor {
    2727    private static final List<Integer> ORDER = new ArrayList<Integer>(TunnelBuildMessage.MAX_RECORD_COUNT);
    28     private static final String MIN_VARIABLE_VERSION = "0.7.12";
     28    //private static final String MIN_VARIABLE_VERSION = "0.7.12";
    2929    private static final boolean SEND_VARIABLE = true;
    3030    private static final int SHORT_RECORDS = 4;
     
    240240
    241241    /** @since 0.7.12 */
     242/****
     243we can assume everybody supports variable now...
     244keep this here for the next time we change the build protocol
    242245    private static boolean supportsVariable(RouterContext ctx, Hash h) {
    243246        RouterInfo ri = ctx.netDb().lookupRouterInfoLocally(h);
     
    247250        return VersionComparator.comp(v, MIN_VARIABLE_VERSION) >= 0;
    248251    }
     252****/
    249253
    250254    /**
     
    259263        Log log = ctx.logManager().getLog(BuildRequestor.class);
    260264        long replyTunnel = 0;
    261         Hash replyRouter = null;
     265        Hash replyRouter;
    262266        boolean useVariable = SEND_VARIABLE && cfg.getLength() <= MEDIUM_RECORDS;
     267
    263268        if (cfg.isInbound()) {
    264269            //replyTunnel = 0; // as above
    265270            replyRouter = ctx.routerHash();
     271/****
     272we can assume everybody supports variable now...
     273keep this here for the next time we change the build protocol
    266274            if (useVariable) {
    267275                // check the reply OBEP and all the tunnel peers except ourselves
     
    277285                }
    278286            }
     287****/
    279288        } else {
    280289            replyTunnel = pairedTunnel.getReceiveTunnelId(0).getTunnelId();
    281290            replyRouter = pairedTunnel.getPeer(0);
     291/****
     292we can assume everybody supports variable now
     293keep this here for the next time we change the build protocol
    282294            if (useVariable) {
    283295                // check the reply IBGW and all the tunnel peers except ourselves
     
    293305                }
    294306            }
     307****/
    295308        }
    296309
Note: See TracChangeset for help on using the changeset viewer.