Changeset c0c9582 for apps


Ignore:
Timestamp:
Mar 29, 2019 4:27:10 PM (20 months ago)
Author:
zab2 <zab2@…>
Branches:
master
Children:
e55702b
Parents:
fc9ad32
Message:

add logic to start and stop filter timers

Location:
apps
Files:
1 added
3 edited

Legend:

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

    rfc9ad32 rc0c9582  
    4141import net.i2p.client.streaming.RouterRestartException;
    4242import net.i2p.client.streaming.IncomingConnectionFilter;
     43import net.i2p.client.streaming.StatefulConnectionFilter;
    4344import net.i2p.crypto.SigType;
    4445import net.i2p.data.Base64;
     
    9798    private int DEFAULT_LOCALPORT = 4488;
    9899    protected int localPort = DEFAULT_LOCALPORT;
     100
     101    private volatile StatefulConnectionFilter _filter;
    99102
    100103    /**
     
    224227        }
    225228
    226         IncomingConnectionFilter filter = IncomingConnectionFilter.ALLOW;
    227229        if (getTunnel().filterDefinition != null) {
    228230            File filterDefinition = new File(getTunnel().filterDefinition);
    229231            I2PAppContext context = getTunnel().getContext();
    230232            try {
    231                 filter = FilterFactory.createFilter(context, filterDefinition, this);
     233                _filter = FilterFactory.createFilter(context, filterDefinition);
    232234            } catch (IOException | InvalidDefinitionException bad) {
    233235                throw new IllegalArgumentException("Can't create socket manager", bad);
    234236            }
    235         }
     237        }
     238
     239        IncomingConnectionFilter filter = _filter == null ? IncomingConnectionFilter.ALLOW : _filter;
     240
    236241        try {
    237242            I2PSocketManager rv = I2PSocketManagerFactory.createDisconnectedManager(privData, getTunnel().host,
     
    377382    public synchronized void startRunning() {
    378383        connectManager();
     384        StatefulConnectionFilter filter = _filter;
     385        if (filter != null)
     386            filter.start();
    379387        // prevent JVM exit when running outside the router
    380388        boolean isDaemon = getTunnel().getContext().isRouterContext();
     
    431439            task.close(forced);
    432440        }
     441        StatefulConnectionFilter filter = _filter;
     442        if (filter != null)
     443            filter.stop();
    433444        synchronized (lock) {
    434445            if (!forced && sockMgr.listSockets().size() != 0) {
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/access/AccessFilter.java

    rfc9ad32 rc0c9582  
    66import java.util.HashSet;
    77import java.util.Iterator;
     8import java.util.concurrent.atomic.AtomicBoolean;
    89
    910import java.io.File;
     
    2021import net.i2p.data.Destination;
    2122import net.i2p.data.Hash;
    22 import net.i2p.i2ptunnel.I2PTunnelTask;
    23 import net.i2p.client.streaming.IncomingConnectionFilter;
     23import net.i2p.client.streaming.StatefulConnectionFilter;
    2424
    2525/**
     
    3737 * @since 0.9.40
    3838 */
    39 class AccessFilter implements IncomingConnectionFilter {
     39class AccessFilter implements StatefulConnectionFilter {
    4040
    4141    private static final long PURGE_INTERVAL = 1000;
     
    4444    private final FilterDefinition definition;
    4545    private final I2PAppContext context;
    46     private final I2PTunnelTask task;
     46
     47    private final AtomicBoolean timersRunning = new AtomicBoolean();
    4748
    4849    /**
     
    6061     * @param task the task to query for liveness of the tunnel
    6162     */
    62     AccessFilter(I2PAppContext context, FilterDefinition definition, I2PTunnelTask task)
     63    AccessFilter(I2PAppContext context, FilterDefinition definition)
    6364            throws IOException {
    6465        this.context = context;
    6566        this.definition = definition;
    66         this.task = task;
    6767
    6868        reload();
    69 
    70         new Purger();
    71         new Syncer();
     69    }
     70
     71    @Override
     72    public void start() {
     73        if (timersRunning.compareAndSet(false, true)) {
     74            new Purger();
     75            new Syncer();
     76        }
     77    }
     78
     79    @Override
     80    public void stop() {
     81        timersRunning.set(false);
    7282    }
    7383
     
    170180        }
    171181        public void timeReached() {
    172             if (!task.isOpen()) {
     182            if (!timersRunning.get()) {
    173183                synchronized(knownDests) {
    174184                    knownDests.clear();
     
    189199        }
    190200        public void timeReached() {
    191             if (!task.isOpen())
     201            if (!timersRunning.get())
    192202                return;
    193203            try {
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/access/FilterFactory.java

    rfc9ad32 rc0c9582  
    1010
    1111import net.i2p.I2PAppContext;
    12 import net.i2p.i2ptunnel.I2PTunnelTask;
    13 import net.i2p.client.streaming.IncomingConnectionFilter;
     12import net.i2p.client.streaming.StatefulConnectionFilter;
    1413
    1514/**
     
    2625     * @param context the context this is running in
    2726     * @param definition file containing the filter definition
    28      * @param task the I2PTunnelTask instance to query for liveness
    2927     */
    30     public static IncomingConnectionFilter createFilter(I2PAppContext context,
    31                                                         File definition,
    32                                                         I2PTunnelTask task)
     28    public static StatefulConnectionFilter createFilter(I2PAppContext context,
     29                                                        File definition)
    3330        throws IOException, InvalidDefinitionException {
    3431        List<String> linesList = new ArrayList<String>();
     
    5148
    5249        FilterDefinition parsedDefinition = DefinitionParser.parse(linesList.toArray(new String[0]));
    53         return new AccessFilter(context, parsedDefinition, task);
     50        return new AccessFilter(context, parsedDefinition);
    5451    }
    5552}
Note: See TracChangeset for help on using the changeset viewer.