Changeset 3a12182


Ignore:
Timestamp:
Apr 2, 2009 8:33:54 PM (11 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
1aa7fbb, a8e43ab
Parents:
49c7fc3
Message:

Transport:

  • Maintain a router hash → IP map in transport, to support additional IP checks (unused for now)
  • Catch error on pre-2.6 kernels
  • Some concurrent conversion
  • Fix an HTML error on peers.jsp
Location:
router/java/src/net/i2p/router/transport
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java

    r49c7fc3 r3a12182  
    132132    public boolean wasUnreachable(Hash dest) {
    133133        return _manager.wasUnreachable(dest);
     134    }
     135   
     136    public byte[] getIP(Hash dest) {
     137        return _manager.getIP(dest);
    134138    }
    135139   
  • router/java/src/net/i2p/router/transport/TransportImpl.java

    r49c7fc3 r3a12182  
    2121import java.util.Set;
    2222import java.util.Vector;
     23import java.util.concurrent.ConcurrentHashMap;
    2324
    2425import net.i2p.data.Hash;
     
    3536import net.i2p.router.RouterContext;
    3637import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
     38import net.i2p.util.ConcurrentHashSet;
    3739import net.i2p.util.Log;
    3840
     
    4850    protected RouterContext _context;
    4951    /** map from routerIdentHash to timestamp (Long) that the peer was last unreachable */
    50     private Map _unreachableEntries;
    51     private Set _wasUnreachableEntries;
     52    private Map<Hash, Long>  _unreachableEntries;
     53    private Set<Hash> _wasUnreachableEntries;
     54    /** global router ident -> IP */
     55    private static Map<Hash, byte[]> _IPMap = new ConcurrentHashMap(128);
    5256
    5357    /**
     
    6872        _sendPool = new ArrayList(16);
    6973        _unreachableEntries = new HashMap(16);
    70         _wasUnreachableEntries = new HashSet(16);
     74        _wasUnreachableEntries = new ConcurrentHashSet(16);
    7175        _currentAddress = null;
    7276    }
     
    484488     */
    485489    public boolean wasUnreachable(Hash peer) {
    486         synchronized (_wasUnreachableEntries) {
    487             if (_wasUnreachableEntries.contains(peer))
    488                 return true;
    489         }
     490        if (_wasUnreachableEntries.contains(peer))
     491            return true;
    490492        RouterInfo ri = _context.netDb().lookupRouterInfoLocally(peer);
    491493        if (ri == null)
     
    497499     */
    498500    public void markWasUnreachable(Hash peer, boolean yes) {
    499         synchronized (_wasUnreachableEntries) {
    500             if (yes)
    501                 _wasUnreachableEntries.add(peer);
    502             else
    503                 _wasUnreachableEntries.remove(peer);
    504         }
     501        if (yes)
     502            _wasUnreachableEntries.add(peer);
     503        else
     504            _wasUnreachableEntries.remove(peer);
    505505        if (_log.shouldLog(Log.WARN))
    506506            _log.warn(this.getStyle() + " setting wasUnreachable to " + yes + " for " + peer);
     507    }
     508
     509    public static void setIP(Hash peer, byte[] ip) {
     510        _IPMap.put(peer, ip);
     511    }
     512
     513    public static byte[] getIP(Hash peer) {
     514        return _IPMap.get(peer);
    507515    }
    508516
  • router/java/src/net/i2p/router/transport/TransportManager.java

    r49c7fc3 r3a12182  
    3434public class TransportManager implements TransportEventListener {
    3535    private Log _log;
    36     private List _transports;
     36    private List<Transport> _transports;
    3737    private RouterContext _context;
    3838
     
    230230    }   
    231231   
     232    /**
     233     * IP of the peer from the last connection (in or out, any transport).
     234     * This may be different from that advertised in the netDb,
     235     * as the peer may be hidden, or connect from a different IP, or
     236     * change his netDb later, in an attempt to avoid restrictions.
     237     *
     238     * For blocking purposes, etc. it's worth checking both
     239     * the netDb addresses and this address.
     240     */
     241    public byte[] getIP(Hash dest) {
     242        return TransportImpl.getIP(dest);
     243    }   
     244   
    232245    Map getAddresses() {
    233246        Map rv = new HashMap(_transports.size());
  • router/java/src/net/i2p/router/transport/ntcp/EstablishState.java

    r49c7fc3 r3a12182  
    473473                        System.arraycopy(_e_bobSig, _e_bobSig.length-16, nextReadIV, 0, nextReadIV.length);
    474474                        _con.finishOutboundEstablishment(_dh.getSessionKey(), (_tsA-_tsB), nextWriteIV, nextReadIV); // skew in seconds
     475                       _transport.setIP(_con.getRemotePeer().calculateHash(),
     476                                        _con.getChannel().socket().getInetAddress().getAddress());
    475477                        return;
    476478                    }
     
    547549            _verified = _context.dsa().verifySignature(sig, toVerify, alice.getSigningPublicKey());
    548550            if (_verified) {
     551                byte[] ip = _con.getChannel().socket().getInetAddress().getAddress();
    549552                if (_context.shitlist().isShitlistedForever(alice.calculateHash())) {
    550553                    if (_log.shouldLog(Log.WARN))
     
    552555                    // So next time we will not accept the con from this IP,
    553556                    // rather than doing the whole handshake
    554                     _context.blocklist().add(_con.getChannel().socket().getInetAddress().getAddress());
     557                    _context.blocklist().add(ip);
    555558                    fail("Peer is shitlisted forever: " + alice.calculateHash().toBase64());
    556559                    return;
    557560                }
     561                _transport.setIP(alice.calculateHash(), ip);
    558562                if (_log.shouldLog(Log.DEBUG))
    559563                    _log.debug(prefix() + "verification successful for " + _con);
  • router/java/src/net/i2p/router/transport/ntcp/EventPumper.java

    r49c7fc3 r3a12182  
    6767        if (_log.shouldLog(Log.INFO))
    6868            _log.info("Starting pumper");
    69         _alive = true;
    7069        _wantsRead = new ArrayList(16);
    7170        _wantsWrite = new ArrayList(4);
     
    7473        try {
    7574            _selector = Selector.open();
     75            _alive = true;
     76            new I2PThread(this, "NTCP Pumper", true).start();
    7677        } catch (IOException ioe) {
    77             _log.error("Error opening the selector", ioe);
    78         }
    79         new I2PThread(this, "NTCP Pumper", true).start();
     78            _log.log(Log.CRIT, "Error opening the NTCP selector", ioe);
     79        } catch (java.lang.InternalError jlie) {
     80            // "unable to get address of epoll functions, pre-2.6 kernel?"
     81            _log.log(Log.CRIT, "Error opening the NTCP selector", jlie);
     82        }
    8083    }
    8184   
    8285    public void stopPumping() {
    8386        _alive = false;
    84         if (_selector.isOpen())
     87        if (_selector != null && _selector.isOpen())
    8588            _selector.wakeup();
    8689    }
  • router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java

    r49c7fc3 r3a12182  
    242242    }
    243243    public TransportBid bid(RouterInfo toAddress, long dataSize) {
     244        if (!isAlive())
     245            return null;
    244246        Hash peer = toAddress.getIdentity().calculateHash();
    245247        if (_context.shitlist().isShitlisted(peer, STYLE)) {
     
    592594            NTCPConnection con = (NTCPConnection)iter.next();
    593595            String name = con.getRemotePeer().calculateHash().toBase64().substring(0,6);
    594             buf.append("<tr><td><code><a href=\"netdb.jsp?r=").append(name).append("\">").append(name);
     596            buf.append("<tr><td><code><a href=\"netdb.jsp?r=").append(name).append("\">").append(name).append("</a>");
     597            //byte[] ip = getIP(con.getRemotePeer().calculateHash());
     598            //if (ip != null)
     599            //    buf.append(' ').append(_context.blocklist().toStr(ip));
    595600            buf.append("</code></td><td align=\"center\"><code>");
    596601            if (con.isInbound())
  • router/java/src/net/i2p/router/transport/udp/EstablishmentManager.java

    r49c7fc3 r3a12182  
    451451       
    452452        _transport.inboundConnectionReceived();
     453        _transport.setIP(remote.calculateHash(), state.getSentIP());
    453454       
    454455        _context.statManager().addRateData("udp.inboundEstablishTime", state.getLifetime(), 0);
     
    532533       
    533534        _transport.addRemotePeerState(peer);
     535        _transport.setIP(remote.calculateHash(), state.getSentIP());
    534536       
    535537        _context.statManager().addRateData("udp.outboundEstablishTime", state.getLifetime(), 0);
  • router/java/src/net/i2p/router/transport/udp/UDPTransport.java

    r49c7fc3 r3a12182  
    17631763                appended = true;
    17641764            }
     1765            //byte[] ip = getIP(peer.getRemotePeer());
     1766            //if (ip != null)
     1767            //    buf.append(' ').append(_context.blocklist().toStr(ip));
    17651768            buf.append("</code></td>");
    17661769           
Note: See TracChangeset for help on using the changeset viewer.