Changeset a5e568f for apps/ministreaming


Ignore:
Timestamp:
Mar 26, 2019 3:34:15 PM (15 months ago)
Author:
zab2 <zab2@…>
Branches:
master
Children:
62f7b2c
Parents:
64039ee
Message:

Hooks into streaming for filtering of incoming connections

Location:
apps/ministreaming/java/src/net/i2p/client/streaming
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketManagerFactory.java

    r64039ee ra5e568f  
    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) {
Note: See TracChangeset for help on using the changeset viewer.