Changeset d397eaa


Ignore:
Timestamp:
Jul 19, 2011 9:17:52 PM (10 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
3834403
Parents:
91f2206
Message:
  • Cleanups, concurrent
  • Basic b32 verification
Location:
apps/i2ptunnel/java/src/net/i2p/i2ptunnel
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnel.java

    r91f2206 rd397eaa  
    5050import java.util.Set;
    5151import java.util.StringTokenizer;
     52import java.util.concurrent.CopyOnWriteArrayList;
    5253import java.util.concurrent.CopyOnWriteArraySet;
    5354
     
    7172
    7273/**
     74 *  An I2PTunnel tracks one or more I2PTunnelTasks and one or more I2PSessions.
     75 *  Usually one of each.
     76 *
    7377 *  Todo: Most events are not listened to elsewhere, so error propagation is poor
    7478 */
     
    96100    private static final String nocli_args[] = { "-nocli", "-die"};
    97101
    98     private final List tasks = new ArrayList();
     102    private final List<I2PTunnelTask> tasks = new ArrayList();
    99103    private int next_task_id = 1;
    100104
     
    213217            tsk.setId(next_task_id);
    214218            next_task_id++;
    215             synchronized (tasks) {
    216                 tasks.add(tsk);
    217             }
     219            tasks.add(tsk);
    218220        }
    219221    }
     
    12561258    public void runQuit(Logging l) {
    12571259        purgetasks(l);
    1258         synchronized (tasks) {
    1259             if (tasks.isEmpty()) {
    1260                 System.exit(0);
    1261             }
     1260        if (tasks.isEmpty()) {
     1261            System.exit(0);
    12621262        }
    12631263        l.log("There are running tasks. Try 'list'.");
     
    12751275    public void runList(Logging l) {
    12761276        purgetasks(l);
    1277         synchronized (tasks) {
    1278             for (int i = 0; i < tasks.size(); i++) {
    1279                 I2PTunnelTask t = (I2PTunnelTask) tasks.get(i);
    1280                 l.log("[" + t.getId() + "] " + t.toString());
    1281             }
     1277        for (I2PTunnelTask t : tasks) {
     1278            l.log("[" + t.getId() + "] " + t.toString());
    12821279        }
    12831280        notifyEvent("listDone", "done");
     
    13081305            }
    13091306            if (args[argindex].equalsIgnoreCase("all")) {
    1310                 List curTasks = null;
    1311                 synchronized (tasks) {
    1312                     curTasks = new LinkedList(tasks);
    1313                 }
    1314 
    13151307                boolean error = false;
    1316                 for (int i = 0; i < curTasks.size(); i++) {
    1317                     I2PTunnelTask t = (I2PTunnelTask) curTasks.get(i);
     1308                for (I2PTunnelTask t : tasks) {
    13181309                    if (!closetask(t, forced, l)) {
    13191310                        notifyEvent("closeResult", "error");
     
    14371428
    14381429        _log.debug(getPrefix() + "closetask(): looking for task " + num);
    1439         synchronized (tasks) {
    1440             for (Iterator it = tasks.iterator(); it.hasNext();) {
    1441                 I2PTunnelTask t = (I2PTunnelTask) it.next();
     1430            for (I2PTunnelTask t : tasks) {
    14421431                int id = t.getId();
    14431432                if (_log.shouldLog(Log.DEBUG))
     
    14491438                    break;
    14501439                }
    1451             }
    14521440        }
    14531441        return closed;
     
    14771465     */
    14781466    private void purgetasks(Logging l) {
    1479         synchronized (tasks) {
    1480             for (Iterator it = tasks.iterator(); it.hasNext();) {
    1481                 I2PTunnelTask t = (I2PTunnelTask) it.next();
     1467            List<I2PTunnelTask> removed = new ArrayList();
     1468            for (I2PTunnelTask t : tasks) {
    14821469                if (!t.isOpen()) {
    14831470                    _log.debug(getPrefix() + "Purging inactive tunnel: [" + t.getId() + "] " + t.toString());
    1484                     it.remove();
     1471                    removed.add(t);
    14851472                }
    14861473            }
    1487         }
     1474            tasks.removeAll(removed);
    14881475    }
    14891476
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java

    r91f2206 rd397eaa  
    687687            if (sockMgr != null) {
    688688                mySockets.retainAll(sockMgr.listSockets());
    689                 if (!forced && mySockets.size() != 0) {
    690                     l.log("There are still active connections!");
     689                if ((!forced) && (!mySockets.isEmpty())) {
     690                    l.log("Not closing, there are still active connections!");
    691691                    _log.debug("can't close: there are still active connections!");
    692                     for (Iterator it = mySockets.iterator(); it.hasNext();) {
    693                         l.log("->" + it.next());
     692                    for (I2PSocket s : mySockets) {
     693                        l.log("  -> " + s.toString());
    694694                    }
    695695                    return false;
     
    707707                if (ss != null) ss.close();
    708708            } catch (IOException ex) {
    709                 ex.printStackTrace();
     709                if (_log.shouldLog(Log.WARN))
     710                    _log.warn("error closing", ex);
    710711                return false;
    711712            }
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelTask.java

    r91f2206 rd397eaa  
    1414 */
    1515
    16 public abstract class I2PTunnelTask implements EventDispatcher {
    17 
    18     private final EventDispatcherImpl _event = new EventDispatcherImpl();
     16public abstract class I2PTunnelTask extends EventDispatcherImpl {
    1917
    2018    private int id;
     
    7876        return name;
    7977    }
    80 
    81     /* Required by the EventDispatcher interface */
    82     public EventDispatcher getEventDispatcher() {
    83         return _event;
    84     }
    85 
    86     public void attachEventDispatcher(EventDispatcher e) {
    87         _event.attachEventDispatcher(e.getEventDispatcher());
    88     }
    89 
    90     public void detachEventDispatcher(EventDispatcher e) {
    91         _event.detachEventDispatcher(e.getEventDispatcher());
    92     }
    93 
    94     public void notifyEvent(String e, Object a) {
    95         _event.notifyEvent(e, a);
    96     }
    97 
    98     public Object getEventValue(String n) {
    99         return _event.getEventValue(n);
    100     }
    101 
    102     public Set getEvents() {
    103         return _event.getEvents();
    104     }
    105 
    106     public void ignoreEvents() {
    107         _event.ignoreEvents();
    108     }
    109 
    110     public void unIgnoreEvents() {
    111         _event.unIgnoreEvents();
    112     }
    113 
    114     public Object waitEventValue(String n) {
    115         return _event.waitEventValue(n);
    116     }
    11778}
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java

    r91f2206 rd397eaa  
    2323
    2424/**
    25  * Coordinate the runtime operation and configuration of a tunnel. 
     25 * Coordinate the runtime operation and configuration of a single I2PTunnel.
     26 * An I2PTunnel tracks one or more I2PTunnelTasks and one or more I2PSessions.
     27 * Usually one of each.
     28 *
    2629 * These objects are bundled together under a TunnelControllerGroup where the
    2730 * entire group is stored / loaded from a single config file.
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/irc/DCCClientManager.java

    r91f2206 rd397eaa  
    66
    77import net.i2p.client.streaming.I2PSocketManager;
     8import net.i2p.data.Base32;
    89import net.i2p.i2ptunnel.I2PTunnel;
    910import net.i2p.i2ptunnel.Logging;
     
    9192     */
    9293    private int newIncoming(String b32, int port, String type, int localPort) {
     94        b32 = b32.toLowerCase();
     95        // do some basic verification before starting the client
     96        if (b32.length() != 60 || !b32.endsWith(".b32.i2p"))
     97            return -1;
     98        byte[] dec = Base32.decode(b32.substring(0, 52));
     99        if (dec == null || dec.length != 32)
     100            return -1;
    93101        expireInbound();
    94102        if (_incoming.size() >= MAX_INCOMING_PENDING ||
Note: See TracChangeset for help on using the changeset viewer.