Changeset d90fc42


Ignore:
Timestamp:
Mar 28, 2019 6:57:42 PM (17 months ago)
Author:
zab2 <zab2@…>
Branches:
master
Children:
3dbe8f20
Parents:
85db853
Message:

javadoc

Location:
apps/i2ptunnel/java/src/net/i2p/i2ptunnel/access
Files:
12 edited

Legend:

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

    r85db853 rd90fc42  
    55import java.util.Collections;
    66
     7/**
     8 * Counts connection attempts and decides if specified thresholds have been
     9 * breached.
     10 *
     11 * @since 0.9.40
     12 */
    713class AccessCounter {
    814
     15    /**
     16     * List of timestamps of each connection attempt
     17     */
    918    private final List<Long> accesses = new ArrayList<Long>();
    1019
     20    /**
     21     * records that a connection attempt was made
     22     *
     23     * @param now the current time
     24     */
    1125    void recordAccess(long now) {
    1226        accesses.add(now);
    1327    }
    1428
     29    /**
     30     * @param threshold definition of a threshold
     31     * @return true if the given threshold has been breached
     32     */
    1533    boolean isBreached(Threshold threshold) {
    1634        if (threshold.getConnections() == 0)
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/access/AccessFilter.java

    r85db853 rd90fc42  
    2323import net.i2p.client.streaming.IncomingConnectionFilter;
    2424
     25/**
     26 * A filter for incoming connections which can be configured
     27 * based on access list rules.
     28 *
     29 * It keeps a track of known destinations - those defined in existing access
     30 * lists and unknown ones - those who are not defined in such lists but have
     31 * recently attempted to connect to us.
     32 *
     33 * Every SYNC_INTERVAL seconds the access lists are reloaded from disk which
     34 * allows the user to edit them.  Also, if any recorders are defined in the
     35 * access rules, they will write to disk at such interval.
     36 *
     37 * @since 0.9.40
     38 */
    2539class AccessFilter implements IncomingConnectionFilter {
    2640
     
    4155    private final Map<Hash, DestTracker> unknownDests = new HashMap<Hash, DestTracker>();
    4256
     57    /**
     58     * @param context the context, used for scheduling and timer purposes
     59     * @param definition definition of this filter
     60     * @param task the task to query for liveness of the tunnel
     61     */
    4362    AccessFilter(I2PAppContext context, FilterDefinition definition, I2PTunnelTask task)
    4463            throws IOException {
     
    5776        Hash hash = d.getHash();
    5877        long now = context.clock().now();
    59         DestTracker tracker = null;
     78        DestTracker tracker;
    6079        synchronized(knownDests) {
    6180            tracker = knownDests.get(hash);
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/access/DefinitionParser.java

    r85db853 rd90fc42  
    88import net.i2p.data.DataHelper;
    99
     10/**
     11 * Utility class for parsing filter definitions
     12 *
     13 * @since 0.9.40
     14 */
    1015class DefinitionParser {
    1116
     17    /**
     18     * Processes an array of String objects containing the human-readable definition of
     19     * the filter.
     20     *
     21     * TODO: format
     22     *
     23     * @return a FilterDefinition POJO representation for internal use
     24     * @throws InvalidDefinitionException if the definition is malformed
     25     */
    1226    static FilterDefinition parse(String []definition) throws InvalidDefinitionException {
    1327       
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/access/DestTracker.java

    r85db853 rd90fc42  
    33import net.i2p.data.Hash;
    44
     5/**
     6 * Tracks the connection attempts for a given remote Destination
     7 *
     8 * @since 0.9.40
     9 */
    510class DestTracker {
    611   
     
    914    private final AccessCounter counter;
    1015
     16    /**
     17     * @param hash hash of the remote destination
     18     * @param threshold threshold defined in the access rule
     19     */
    1120    DestTracker(Hash hash, Threshold threshold) {
    1221        this.hash = hash;
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/access/ExplicitFilterDefinitionElement.java

    r85db853 rd90fc42  
    55import net.i2p.data.Hash;
    66
     7/**
     8 * A filter definition element that includes a single, explicitly defined
     9 * remote destination
     10 *
     11 * @since 0.9.40
     12 */
    713class ExplicitFilterDefinitionElement extends FilterDefinitionElement {
    814
    915    private final Hash hash;
    1016
     17    /**
     18     * @param b32 A string with the .b32 representation of the remote destination
     19     * @param threshold threshold to apply to that destination
     20     * @throws InvalidDefinitionException if the b32 string is not valid b32
     21     */
    1122    ExplicitFilterDefinitionElement(String b32, Threshold threshold) throws InvalidDefinitionException {
    1223        super(threshold);
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/access/FileFilterDefinitionElement.java

    r85db853 rd90fc42  
    1010import net.i2p.data.Hash;
    1111
     12/**
     13 * An element of filter definition that reads hashes of remote destinations
     14 * from a file.
     15 *
     16 * @since 0.9.40
     17 */
    1218class FileFilterDefinitionElement extends FilterDefinitionElement {
    1319
    1420    private final File file;
    1521
     22    /**
     23     * @param file file to read the remote destinations from
     24     * @param threshold threshold to apply to all those destinations
     25     */
    1626    FileFilterDefinitionElement(File file, Threshold threshold) {
    1727        super(threshold);
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/access/FilterDefinition.java

    r85db853 rd90fc42  
    11package net.i2p.i2ptunnel.access;
    22
     3/**
     4 * Definition of an access filter.
     5 *
     6 * This POJO contains the parsed representation from the filter definition file.
     7 *
     8 * @since 0.9.40
     9 */
    310class FilterDefinition {
    411
     
    815    private final int purgeMinutes;
    916
     17    /**
     18     * @param defaultThreshold threshold to apply to unknown remote destinations
     19     * @param elements the elements defined in the filter definition, if any
     20     * @param recorders the recorders defined in the filter definition, if any
     21     */
    1022    FilterDefinition(Threshold defaultThreshold,
    1123                        FilterDefinitionElement[] elements,
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/access/FilterDefinitionElement.java

    r85db853 rd90fc42  
    77import net.i2p.data.Base32;
    88
     9/**
     10 * Base class for elements found in filter definition files
     11 *
     12 * @since 0.9.40
     13 */
    914abstract class FilterDefinitionElement {
    1015
     
    1520    }
    1621
     22    /**
     23     * Updates the provided map with the hash(es) of remote destinations
     24     * mentioned in this element
     25     */
    1726    abstract void update(Map<Hash, DestTracker> map) throws IOException;
    1827
     
    2130    }
    2231
     32    /**
     33     * Utility method to create a Hash object from a .b32 string
     34     */
    2335    protected static Hash fromBase32(String b32) throws InvalidDefinitionException {
    2436        if (!b32.endsWith(".b32.i2p"))
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/access/FilterFactory.java

    r85db853 rd90fc42  
    1313import net.i2p.client.streaming.IncomingConnectionFilter;
    1414
     15/**
     16 * Factory for incoming connection filters.  Only public class in this package.
     17 *
     18 * @since 0.9.40
     19 */
    1520public class FilterFactory {
     21
     22    /**
     23     * Creates an instance of IncomingConnectionFilter based on the definition
     24     * contained in the given file.
     25     *
     26     * @param context the context this is running in
     27     * @param definition file containing the filter definition
     28     * @param task the I2PTunnelTask instance to query for liveness
     29     */
    1630    public static IncomingConnectionFilter createFilter(I2PAppContext context,
    1731                                                        File definition,
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/access/InvalidDefinitionException.java

    r85db853 rd90fc42  
    11package net.i2p.i2ptunnel.access;
    22
     3/**
     4 * Exception thrown if the filter definition file cannot be
     5 * parsed for some reason.
     6 */
    37public class InvalidDefinitionException extends Exception {
    48    public InvalidDefinitionException(String reason) {
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/access/Recorder.java

    r85db853 rd90fc42  
    33import java.io.File;
    44
     5/**
     6 * Definition of a recorder.  If any remote destinations attempt
     7 * enough connections to cause a breach of the specified threshold,
     8 * their hash will be recorded in the specified file.
     9 *
     10 * @since 0.9.40
     11 */
    512class Recorder {
    613
     
    815    private final Threshold threshold;
    916
     17    /**
     18     * @param file to record hashes of destinations that breach the threshold
     19     * @param threshold the threshold that needs to be breached to trigger recording
     20     */
    1021    Recorder(File file, Threshold threshold) {
    1122        this.file = file;
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/access/Threshold.java

    r85db853 rd90fc42  
    11package net.i2p.i2ptunnel.access;
    22
     3/**
     4 * Definition of a Threshold. 
     5 *
     6 * A Threshold is defined by a number of connections over a period of minutes
     7 *
     8 * @since 0.9.40
     9 */
    310class Threshold {
    411
     12    /** A Threshold that is never breached */
    513    static final Threshold ALLOW = new Threshold(Integer.MAX_VALUE, 1);
     14    /** A Threshold that is always breached */
    615    static final Threshold DENY = new Threshold(0, 1);
    716
Note: See TracChangeset for help on using the changeset viewer.