Changeset faeb58f7


Ignore:
Timestamp:
Aug 21, 2009 3:40:26 PM (11 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
3f3d43d
Parents:
4d4538a
Message:
  • ClientManager?:
    • Prevent client destination theft by rejecting duplicates
    • Java 5 cleanups
Location:
router/java/src/net/i2p/router
Files:
3 edited

Legend:

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

    r4d4538a rfaeb58f7  
    8686     * @return set of Destination objects
    8787     */
    88     public Set listClients() { return Collections.EMPTY_SET; }
     88    public Set<Destination> listClients() { return Collections.EMPTY_SET; }
    8989   
    9090    /**
  • router/java/src/net/i2p/router/client/ClientManager.java

    r4d4538a rfaeb58f7  
    4343    private Log _log;
    4444    private ClientListenerRunner _listener;
    45     private final HashMap _runners;        // Destination --> ClientConnectionRunner
    46     private final Set _pendingRunners; // ClientConnectionRunner for clients w/out a Dest yet
     45    private final HashMap<Destination, ClientConnectionRunner> _runners;        // Destination --> ClientConnectionRunner
     46    private final Set<ClientConnectionRunner> _pendingRunners; // ClientConnectionRunner for clients w/out a Dest yet
    4747    private RouterContext _ctx;
    4848
     
    9191        _log.info("Shutting down the ClientManager");
    9292        _listener.stopListening();
    93         Set runners = new HashSet();
    94         synchronized (_runners) {
    95             for (Iterator iter = _runners.values().iterator(); iter.hasNext();) {
    96                 ClientConnectionRunner runner = (ClientConnectionRunner)iter.next();
     93        Set<ClientConnectionRunner> runners = new HashSet();
     94        synchronized (_runners) {
     95            for (Iterator<ClientConnectionRunner> iter = _runners.values().iterator(); iter.hasNext();) {
     96                ClientConnectionRunner runner = iter.next();
    9797                runners.add(runner);
    9898            }
    9999        }
    100100        synchronized (_pendingRunners) {
    101             for (Iterator iter = _pendingRunners.iterator(); iter.hasNext();) {
    102                 ClientConnectionRunner runner = (ClientConnectionRunner)iter.next();
     101            for (Iterator<ClientConnectionRunner> iter = _pendingRunners.iterator(); iter.hasNext();) {
     102                ClientConnectionRunner runner = iter.next();
    103103                runners.add(runner);
    104104            }
    105105        }
    106         for (Iterator iter = runners.iterator(); iter.hasNext(); ) {
    107             ClientConnectionRunner runner = (ClientConnectionRunner)iter.next();
     106        for (Iterator<ClientConnectionRunner> iter = runners.iterator(); iter.hasNext(); ) {
     107            ClientConnectionRunner runner = iter.next();
    108108            runner.stopRunning();
    109109        }
     
    132132    }
    133133   
     134    /**
     135     * Add to the clients list. Check for a dup destination.
     136     */
    134137    public void destinationEstablished(ClientConnectionRunner runner) {
     138        Destination dest = runner.getConfig().getDestination();
    135139        if (_log.shouldLog(Log.DEBUG))
    136             _log.debug("DestinationEstablished called for destination " + runner.getConfig().getDestination().calculateHash().toBase64());
     140            _log.debug("DestinationEstablished called for destination " + dest.calculateHash().toBase64());
    137141
    138142        synchronized (_pendingRunners) {
    139143            _pendingRunners.remove(runner);
    140144        }
    141         synchronized (_runners) {
    142             _runners.put(runner.getConfig().getDestination(), runner);
     145        boolean fail = false;
     146        synchronized (_runners) {
     147            fail = _runners.containsKey(dest);
     148            if (!fail)
     149                _runners.put(dest, runner);
     150        }
     151        if (fail) {
     152            _log.log(Log.CRIT, "Client attempted to register duplicate destination " + dest.calculateHash().toBase64());
     153            runner.disconnectClient("Duplicate destination");
    143154        }
    144155    }
     
    279290    }
    280291
    281     public Set listClients() {
    282         Set rv = new HashSet();
     292    public Set<Destination> listClients() {
     293        Set<Destination> rv = new HashSet();
    283294        synchronized (_runners) {
    284295            rv.addAll(_runners.keySet());
     
    294305        synchronized (_runners) {
    295306            inLock = _ctx.clock().now();
    296             rv = (ClientConnectionRunner)_runners.get(dest);
     307            rv = _runners.get(dest);
    297308        }
    298309        long afterLock = _ctx.clock().now();
     
    332343            return null;
    333344        synchronized (_runners) {
    334             for (Iterator iter = _runners.values().iterator(); iter.hasNext(); ) {
    335                 ClientConnectionRunner cur = (ClientConnectionRunner)iter.next();
     345            for (Iterator<ClientConnectionRunner> iter = _runners.values().iterator(); iter.hasNext(); ) {
     346                ClientConnectionRunner cur = iter.next();
    336347                if (cur.getDestHash().equals(destHash))
    337348                    return cur;
     
    355366    }
    356367   
    357     Set getRunnerDestinations() {
    358         Set dests = new HashSet();
     368    Set<Destination> getRunnerDestinations() {
     369        Set<Destination> dests = new HashSet();
    359370        long beforeLock = _ctx.clock().now();
    360371        long inLock = 0;
     
    391402        buf.append("<u><b>Local destinations</b></u><br>");
    392403       
    393         Map runners = null;
     404        Map<Destination, ClientConnectionRunner> runners = null;
    394405        synchronized (_runners) {
    395406            runners = (Map)_runners.clone();
    396407        }
    397         for (Iterator iter = runners.keySet().iterator(); iter.hasNext(); ) {
    398             Destination dest = (Destination)iter.next();
    399             ClientConnectionRunner runner = (ClientConnectionRunner)runners.get(dest);
     408        for (Iterator<Destination> iter = runners.keySet().iterator(); iter.hasNext(); ) {
     409            Destination dest = iter.next();
     410            ClientConnectionRunner runner = runners.get(dest);
    400411            buf.append("<b>*</b> ").append(dest.calculateHash().toBase64().substring(0,6)).append("<br>\n");
    401412            LeaseSet ls = runner.getLeaseSet();
  • router/java/src/net/i2p/router/client/ClientManagerFacadeImpl.java

    r4d4538a rfaeb58f7  
    216216     */
    217217    @Override
    218     public Set listClients() {
     218    public Set<Destination> listClients() {
    219219        if (_manager != null)
    220220            return _manager.listClients();
Note: See TracChangeset for help on using the changeset viewer.