Changes in / [567bccb:491cd0a]


Ignore:
Location:
apps
Files:
15 added
11 edited

Legend:

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

    r567bccb r491cd0a  
    105105
    106106    public long readTimeout = -1;
     107
     108    public String filterDefinition;
    107109
    108110    private static final String nocli_args[] = { "-nocli", "-die"};
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java

    r567bccb r491cd0a  
    3131
    3232import net.i2p.I2PException;
     33import net.i2p.I2PAppContext;
    3334import net.i2p.client.I2PClient;
    3435import net.i2p.client.I2PSession;
     
    3940import net.i2p.client.streaming.I2PSocketManagerFactory;
    4041import net.i2p.client.streaming.RouterRestartException;
     42import net.i2p.client.streaming.IncomingConnectionFilter;
     43import net.i2p.client.streaming.StatefulConnectionFilter;
    4144import net.i2p.crypto.SigType;
    4245import net.i2p.data.Base64;
     
    4649import net.i2p.util.I2PSSLSocketFactory;
    4750import net.i2p.util.Log;
     51import net.i2p.i2ptunnel.access.FilterFactory;
     52import net.i2p.i2ptunnel.access.InvalidDefinitionException;
    4853
    4954public class I2PTunnelServer extends I2PTunnelTask implements Runnable {
     
    9398    private int DEFAULT_LOCALPORT = 4488;
    9499    protected int localPort = DEFAULT_LOCALPORT;
     100
     101    private volatile StatefulConnectionFilter _filter;
    95102
    96103    /**
     
    219226            }
    220227        }
     228
     229        if (getTunnel().filterDefinition != null) {
     230            File filterDefinition = new File(getTunnel().filterDefinition);
     231            I2PAppContext context = getTunnel().getContext();
     232            try {
     233                _filter = FilterFactory.createFilter(context, filterDefinition);
     234            } catch (IOException | InvalidDefinitionException bad) {
     235                throw new IllegalArgumentException("Can't create socket manager", bad);
     236            }
     237        }
     238
     239        IncomingConnectionFilter filter = _filter == null ? IncomingConnectionFilter.ALLOW : _filter;
     240
    221241        try {
    222242            I2PSocketManager rv = I2PSocketManagerFactory.createDisconnectedManager(privData, getTunnel().host,
    223                                                                                     portNum, props);
     243                                                                                    portNum, props, filter);
    224244            rv.setName("I2PTunnel Server");
    225245            getTunnel().addSession(rv.getSession());
     
    362382    public synchronized void startRunning() {
    363383        connectManager();
     384        StatefulConnectionFilter filter = _filter;
     385        if (filter != null)
     386            filter.start();
    364387        // prevent JVM exit when running outside the router
    365388        boolean isDaemon = getTunnel().getContext().isRouterContext();
     
    458481        close(true);
    459482        sockMgr.destroySocketManager();
     483        StatefulConnectionFilter filter = _filter;
     484        if (filter != null)
     485            filter.stop();
    460486        return true;
    461487    }
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java

    r567bccb r491cd0a  
    8686    public static final String PROP_TARGET_PORT = "targetPort";
    8787    public static final String PROP_TYPE = "type";
     88    public static final String PROP_FILTER = "filterDefinition";
    8889   
    8990    /**
     
    835836            }
    836837            if (!isClient(type)) {
     838                _tunnel.filterDefinition = _config.getProperty(PROP_FILTER);
     839             
    837840                String p1 = _config.getProperty(OPT_MAX_CONNS_MIN, "0");
    838841                String p2 = _config.getProperty(OPT_MAX_CONNS_HOUR, "0");
     
    932935    public String getI2CPHost() { return _config.getProperty(PROP_I2CP_HOST); }
    933936    public String getI2CPPort() { return _config.getProperty(PROP_I2CP_PORT); }
     937    public String getFilter() { return _config.getProperty(PROP_FILTER); }
    934938
    935939    /**
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/ui/GeneralHelper.java

    r567bccb r491cd0a  
    622622        return getProperty(tunnel, "i2cp.accessList", "").replace(",", "\n");
    623623    }
     624
     625    public String getFilterDefinition(int tunnel) {
     626        TunnelController tunnelController = getController(tunnel);
     627        String filter = tunnelController.getFilter();
     628        return filter == null ? "" : filter;
     629    }
    624630   
    625631    public String getJumpList(int tunnel) {
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/ui/TunnelConfig.java

    r567bccb r491cd0a  
    7676    private String _newProxyPW;
    7777    private Destination _dest;
     78    private String _filterDefinition;
    7879
    7980    public TunnelConfig() {
     
    327328            _booleanOptions.remove(PROP_ENABLE_ACCESS_LIST);
    328329            _booleanOptions.remove(PROP_ENABLE_BLACKLIST);
     330        }
     331    }
     332
     333    public void setFilterDefinition(String filterDefinition) {
     334        if (filterDefinition != null) {
     335            filterDefinition = filterDefinition.trim();
     336            if (!filterDefinition.isEmpty())
     337                _filterDefinition = filterDefinition;
    329338        }
    330339    }
     
    614623            if (_targetPort >= 0)
    615624                config.setProperty(TunnelController.PROP_TARGET_PORT, Integer.toString(_targetPort));
     625
     626            if (_filterDefinition != null)
     627                config.setProperty(TunnelController.PROP_FILTER, _filterDefinition);
     628           
    616629            // see TunnelController.setConfig()
    617630            _booleanOptions.add(TunnelController.PROP_LIMITS_SET);
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/EditBean.java

    r567bccb r491cd0a  
    270270    public String getAccessList(int tunnel) {
    271271        return _helper.getAccessList(tunnel);
     272    }
     273
     274    public String getFilterDefinition(int tunnel) {
     275        return _helper.getFilterDefinition(tunnel);
    272276    }
    273277   
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/IndexBean.java

    r567bccb r491cd0a  
    889889    }
    890890
     891    public void setFilterDefinition(String val) {
     892        if (val != null)
     893            _config.setFilterDefinition(val);
     894    }
     895
    891896    public void setDelayOpen(String moo) {
    892897        _config.setDelayOpen(true);
  • apps/i2ptunnel/jsp/editServer.jsi

    r567bccb r491cd0a  
    539539        <tr>
    540540            <td colspan="2">
    541                 <b><%=intl._t("Access List")%></b> (<%=intl._t("Specify clients, 1 per line")%>)
     541                <b><%=intl._t("Access List Description")%></b> (<%=intl._t("Specify clients, 1 per line or describe access list")%>)
    542542            </td>
    543543        </tr>
     
    546546            <td colspan="2">
    547547                <textarea rows="2" style="height: 8em;" cols="60" name="accessList" title="<%=intl._t("Control access to this service")%>" wrap="off" spellcheck="false"><%=editBean.getAccessList(curTunnel)%></textarea>
     548            </td>
     549        </tr>
     550
     551        <tr>
     552            <td colspan="2">
     553                <b><%=intl._t("Filter Definition File")%></b>
     554            </td>
     555        </tr>
     556
     557        <tr>
     558            <td colspan="2">
     559                <%=intl._t("You can define an advanced filter for this tunnel.")%> (<a href="http://i2p-projekt.i2p/spec/filter-format" target="_blank"><%=intl._t("Format Specification")%></a>) 
     560            </td>
     561        </tr>
     562
     563        <tr>
     564            <td colspan="2">
     565                <label for="filterDefinition"><%=intl._t("Absolute path to file containing filter definition")%></label>
     566                <input type="text" id="filterDefinition" name="filterDefinition" value="<%=editBean.getFilterDefinition(curTunnel)%>" size="30"/>
    548567            </td>
    549568        </tr>
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketManagerFactory.java

    r567bccb r491cd0a  
    5656     */
    5757    public static I2PSocketManager createManager() {
    58         return createManager(getHost(), getPort(), (Properties) System.getProperties().clone());
     58        return createManager(getHost(), getPort(), (Properties) System.getProperties().clone(),
     59                    IncomingConnectionFilter.ALLOW);
     60    }
     61
     62    /**
     63     * Create a socket manager using a brand new destination connected to the
     64     * I2CP router on the local machine on the default port (7654) with the
     65     * specified incoming connection filter.
     66     *
     67     * Blocks for a long time while the router builds tunnels.
     68     * The nonblocking createDisconnectedManager() is preferred.
     69     *
     70     * @since 0.9.40
     71     * @param filter The filter for incoming connections
     72     * @return the newly created socket manager, or null if there were errors
     73     */
     74    public static I2PSocketManager createManager(IncomingConnectionFilter filter) {
     75        return createManager(getHost(), getPort(), (Properties) System.getProperties().clone(), filter);
    5976    }
    6077   
     
    7087     */
    7188    public static I2PSocketManager createManager(Properties opts) {
    72         return createManager(getHost(), getPort(), opts);
     89        return createManager(getHost(), getPort(), opts, IncomingConnectionFilter.ALLOW);
     90    }
     91
     92    /**
     93     * Create a socket manager using a brand new destination connected to the
     94     * I2CP router on the local machine on the default port (7654).
     95     *
     96     * Blocks for a long time while the router builds tunnels.
     97     * The nonblocking createDisconnectedManager() is preferred.
     98     *
     99     * @since 0.9.40
     100     * @param opts Streaming and I2CP options, may be null
     101     * @param filter The filter to use for incoming connections
     102     * @return the newly created socket manager, or null if there were errors
     103     */
     104    public static I2PSocketManager createManager(Properties opts, IncomingConnectionFilter filter) {
     105        return createManager(getHost(), getPort(), opts, filter);
    73106    }
    74107
     
    85118     */
    86119    public static I2PSocketManager createManager(String host, int port) {
    87         return createManager(host, port, (Properties) System.getProperties().clone());
    88     }
    89 
     120        return createManager(host, port, (Properties) System.getProperties().clone(),
     121                      IncomingConnectionFilter.ALLOW);
     122    }
     123
     124    /**
     125     * Create a socket manager using a brand new destination connected to the
     126     * I2CP router on the specified host and port with the specified connection filter
     127     *
     128     * Blocks for a long time while the router builds tunnels.
     129     * The nonblocking createDisconnectedManager() is preferred.
     130     *
     131     * @param host I2CP host null to use default, ignored if in router context
     132     * @param port I2CP port &lt;= 0 to use default, ignored if in router context
     133     * @param filter The filter to use for incoming connections
     134     * @return the newly created socket manager, or null if there were errors
     135     */
     136    public static I2PSocketManager createManager(String host, int port, IncomingConnectionFilter filter) {
     137        return createManager(host, port, (Properties) System.getProperties().clone(), filter);
     138    }
     139   
    90140    /**
    91141     * Create a socket manager using a brand new destination connected to the
     
    101151     */
    102152    public static I2PSocketManager createManager(String i2cpHost, int i2cpPort, Properties opts) {
     153        return createManager(i2cpHost, i2cpPort, opts, IncomingConnectionFilter.ALLOW);
     154    }
     155
     156    /**
     157     * Create a socket manager using a brand new destination connected to the
     158     * I2CP router on the given machine reachable through the given port with
     159     * the specified connection filter
     160     *
     161     * Blocks for a long time while the router builds tunnels.
     162     * The nonblocking createDisconnectedManager() is preferred.
     163     *
     164     * @since 0.9.40
     165     * @param i2cpHost I2CP host null to use default, ignored if in router context
     166     * @param i2cpPort I2CP port &lt;= 0 to use default, ignored if in router context
     167     * @param opts Streaming and I2CP options, may be null
     168     * @param filter The filter to use for incoming connections
     169     * @return the newly created socket manager, or null if there were errors
     170     */
     171    public static I2PSocketManager createManager(String i2cpHost, int i2cpPort, Properties opts,
     172                    IncomingConnectionFilter filter) {
    103173        I2PClient client = I2PClientFactory.createClient();
    104174        ByteArrayOutputStream keyStream = new ByteArrayOutputStream(1024);
     
    106176            client.createDestination(keyStream, getSigType(opts));
    107177            ByteArrayInputStream in = new ByteArrayInputStream(keyStream.toByteArray());
    108             return createManager(in, i2cpHost, i2cpPort, opts);
     178            return createManager(in, i2cpHost, i2cpPort, opts, filter);
    109179        } catch (IOException ioe) {
    110180            getLog().error("Error creating the destination for socket manager", ioe);
     
    128198     */
    129199    public static I2PSocketManager createManager(InputStream myPrivateKeyStream) {
    130         return createManager(myPrivateKeyStream, getHost(), getPort(), (Properties) System.getProperties().clone());
     200        return createManager(myPrivateKeyStream, IncomingConnectionFilter.ALLOW);
     201    }
     202
     203    /**
     204     * Create a socket manager using the destination loaded from the given private key
     205     * stream and connected to the default I2CP host and port with the specified connection filter
     206     *
     207     * Blocks for a long time while the router builds tunnels.
     208     * The nonblocking createDisconnectedManager() is preferred.
     209     *
     210     * @since 0.9.40
     211     * @param myPrivateKeyStream private key stream, format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile}
     212     *                           or null for a transient destination. Caller must close.
     213     * @param filter The filter to use for incoming connections
     214     * @return the newly created socket manager, or null if there were errors
     215     */
     216    public static I2PSocketManager createManager(InputStream myPrivateKeyStream,
     217                    IncomingConnectionFilter filter) {
     218        return createManager(myPrivateKeyStream, getHost(), getPort(),
     219                             (Properties) System.getProperties().clone(),
     220                             filter);
     221
    131222    }
    132223   
     
    144235     */
    145236    public static I2PSocketManager createManager(InputStream myPrivateKeyStream, Properties opts) {
    146         return createManager(myPrivateKeyStream, getHost(), getPort(), opts);
     237        return createManager(myPrivateKeyStream, opts, IncomingConnectionFilter.ALLOW);
     238    }
     239
     240    /**
     241     * Create a socket manager using the destination loaded from the given private key
     242     * stream and connected to the default I2CP host and port.
     243     *
     244     * Blocks for a long time while the router builds tunnels.
     245     * The nonblocking createDisconnectedManager() is preferred.
     246     *
     247     * @param myPrivateKeyStream private key stream, format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile}
     248     *                           or null for a transient destination. Caller must close.
     249     * @param opts Streaming and I2CP options, may be null
     250     * @param filter The filter to use for incoming connections
     251     * @return the newly created socket manager, or null if there were errors
     252     */
     253    public static I2PSocketManager createManager(InputStream myPrivateKeyStream,
     254                                                 Properties opts,
     255                                                 IncomingConnectionFilter filter) {
     256        return createManager(myPrivateKeyStream, getHost(), getPort(), opts, filter);
    147257    }
    148258   
     
    164274    public static I2PSocketManager createManager(InputStream myPrivateKeyStream, String i2cpHost, int i2cpPort,
    165275                                                 Properties opts) {
     276         return createManager(myPrivateKeyStream, i2cpHost, i2cpPort, opts, IncomingConnectionFilter.ALLOW);
     277    }
     278
     279    /**
     280     * Create a socket manager using the destination loaded from the given private key
     281     * stream and connected to the I2CP router on the specified machine on the given
     282     * port.
     283     *
     284     * Blocks for a long time while the router builds tunnels.
     285     * The nonblocking createDisconnectedManager() is preferred.
     286     *
     287     * @param myPrivateKeyStream private key stream, format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile}
     288     *                           or null for a transient destination. Caller must close.
     289     * @param i2cpHost I2CP host null to use default, ignored if in router context
     290     * @param i2cpPort I2CP port &lt;= 0 to use default, ignored if in router context
     291     * @param opts Streaming and I2CP options, may be null
     292     * @param filter The filter to use for incoming connections
     293     * @return the newly created socket manager, or null if there were errors
     294     */
     295    public static I2PSocketManager createManager(InputStream myPrivateKeyStream,
     296                                                 String i2cpHost,
     297                                                 int i2cpPort,
     298                                                 Properties opts,
     299                                                 IncomingConnectionFilter filter) {
    166300        try {
    167             return createManager(myPrivateKeyStream, i2cpHost, i2cpPort, opts, true);
     301            return createManager(myPrivateKeyStream, i2cpHost, i2cpPort, opts, true, filter);
    168302        } catch (I2PSessionException ise) {
    169303            getLog().error("Error creating session for socket manager", ise);
    170304            return null;
    171305        }
    172     }
    173    
     306    }       
     307
    174308    /**
    175309     * Create a disconnected socket manager using the destination loaded from the given private key
     
    192326    public static I2PSocketManager createDisconnectedManager(InputStream myPrivateKeyStream, String i2cpHost,
    193327                                                             int i2cpPort, Properties opts) throws I2PSessionException {
     328        return createDisconnectedManager(myPrivateKeyStream,
     329                                         i2cpHost,
     330                                         i2cpPort,
     331                                         opts,
     332                                         IncomingConnectionFilter.ALLOW);       
     333    }
     334   
     335    /**
     336     * Create a disconnected socket manager using the destination loaded from the given private key
     337     * stream, or null for a transient destination.
     338     *
     339     * Non-blocking. Does not connect to the router or build tunnels.
     340     * For servers, caller MUST call getSession().connect() to build tunnels and start listening.
     341     * For clients, caller may do that to build tunnels in advance;
     342     * otherwise, the first call to connect() will initiate a connection to the router,
     343     * with significant delay for tunnel building.
     344     *
     345     * @param myPrivateKeyStream private key stream, format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile}
     346     *                           or null for a transient destination. Caller must close.
     347     * @param i2cpHost I2CP host null to use default, ignored if in router context
     348     * @param i2cpPort I2CP port &lt;= 0 to use default, ignored if in router context
     349     * @param opts Streaming and I2CP options, may be null
     350     * @param filter The filter to use for incoming connections
     351     * @return the newly created socket manager, non-null (throws on error)
     352     * @since 0.9.40
     353     */
     354    public static I2PSocketManager createDisconnectedManager(InputStream myPrivateKeyStream,
     355                                                             String i2cpHost,
     356                                                             int i2cpPort,
     357                                                             Properties opts,
     358                                                             IncomingConnectionFilter filter)
     359                                    throws I2PSessionException {
    194360        if (myPrivateKeyStream == null) {
    195361            I2PClient client = I2PClientFactory.createClient();
     
    204370            myPrivateKeyStream = new ByteArrayInputStream(keyStream.toByteArray());
    205371        }
    206         return createManager(myPrivateKeyStream, i2cpHost, i2cpPort, opts, false);
    207     }
    208    
     372        return createManager(myPrivateKeyStream, i2cpHost, i2cpPort, opts, false, filter);
     373    }
     374
    209375    /**
    210376     * Create a socket manager using the destination loaded from the given private key
     
    220386     * @param opts Streaming and I2CP options, may be null
    221387     * @param connect true to connect (blocking)
     388     * @param filter The filter to use for incoming connections
    222389     * @return the newly created socket manager, non-null (throws on error)
    223      * @since 0.9.7
     390     * @since 0.9.40
    224391     */
    225392    private static I2PSocketManager createManager(InputStream myPrivateKeyStream, String i2cpHost, int i2cpPort,
    226                                                  Properties opts, boolean connect) throws I2PSessionException {
     393                                                 Properties opts, boolean connect,
     394                                                 IncomingConnectionFilter filter) throws I2PSessionException {
    227395        I2PClient client = I2PClientFactory.createClient();
    228396        if (opts == null)
     
    246414        if (connect)
    247415            session.connect();
    248         I2PSocketManager sockMgr = createManager(session, opts, "manager");
     416        I2PSocketManager sockMgr = createManager(session, opts, "manager", filter);
    249417        return sockMgr;
    250418    }
    251419
    252     private static I2PSocketManager createManager(I2PSession session, Properties opts, String name) {
     420    private static I2PSocketManager createManager(I2PSession session, Properties opts, String name,
     421                                                  IncomingConnectionFilter filter) {
    253422        I2PAppContext context = I2PAppContext.getGlobalContext();
    254423        // As of 0.9.12, ignore this setting, as jwebcache and i2phex set it to the old value.
     
    261430                throw new IllegalArgumentException(classname + " is not an I2PSocketManager");
    262431            Constructor<?> con =
    263                   cls.getConstructor(I2PAppContext.class, I2PSession.class, Properties.class, String.class);
    264             I2PSocketManager mgr = (I2PSocketManager) con.newInstance(new Object[] {context, session, opts, name});
     432                  cls.getConstructor(I2PAppContext.class,
     433                                     I2PSession.class,
     434                                     Properties.class,
     435                                     String.class,
     436                                     IncomingConnectionFilter.class);
     437            I2PSocketManager mgr = (I2PSocketManager) con.newInstance(
     438                                   new Object[] {context, session, opts, name, filter});
    265439            return mgr;
    266440        } catch (Throwable t) {
  • apps/streaming/java/src/net/i2p/client/streaming/impl/ConnectionManager.java

    r567bccb r491cd0a  
    2222import net.i2p.util.Log;
    2323import net.i2p.util.SimpleTimer2;
     24import net.i2p.client.streaming.IncomingConnectionFilter;
    2425
    2526/**
     
    3940    private final ConnectionPacketHandler _conPacketHandler;
    4041    private final TCBShare _tcbShare;
     42    private final IncomingConnectionFilter _connectionFilter;
    4143    /** Inbound stream ID (Long) to Connection map */
    4244    private final ConcurrentHashMap<Long, Connection> _connectionByInboundId;
     
    8284     *  Manage all conns for this session
    8385     */
    84     public ConnectionManager(I2PAppContext context, I2PSession session, ConnectionOptions defaultOptions) {
     86    public ConnectionManager(I2PAppContext context,
     87                             I2PSession session,
     88                             ConnectionOptions defaultOptions,
     89                             IncomingConnectionFilter connectionFilter) {
    8590        _context = context;
    8691        _session = session;
    8792        _defaultOptions = defaultOptions;
     93        _connectionFilter = connectionFilter;
    8894        _log = _context.logManager().getLog(ConnectionManager.class);
    8995        _connectionByInboundId = new ConcurrentHashMap<Long,Connection>(32);
     
    656662        }
    657663
     664        if (!_connectionFilter.allowDestination(from)) {
     665            return "not allowed by filter";
     666        }
     667
    658668        return null;
    659669    }
  • apps/streaming/java/src/net/i2p/client/streaming/impl/I2PSocketManagerFull.java

    r567bccb r491cd0a  
    2929import net.i2p.client.streaming.I2PSocketManager;
    3030import net.i2p.client.streaming.I2PSocketOptions;
     31import net.i2p.client.streaming.IncomingConnectionFilter;
    3132import net.i2p.crypto.SigAlgo;
    3233import net.i2p.crypto.SigType;
     
    192193     * @param name non-null
    193194     */
    194     public I2PSocketManagerFull(I2PAppContext context, I2PSession session, Properties opts, String name) {
     195    public I2PSocketManagerFull(I2PAppContext context, I2PSession session, Properties opts, String name,
     196                IncomingConnectionFilter connectionFilter) {
    195197        _context = context;
    196198        _session = session;
     
    201203        _acceptTimeout = ACCEPT_TIMEOUT_DEFAULT;
    202204        _defaultOptions = new ConnectionOptions(opts);
    203         _connectionManager = new ConnectionManager(_context, _session, _defaultOptions);
     205        _connectionManager = new ConnectionManager(_context, _session, _defaultOptions, connectionFilter);
    204206        _serverSocket = new I2PServerSocketFull(this);
    205207       
Note: See TracChangeset for help on using the changeset viewer.