Changeset fccd0da for apps/ministreaming


Ignore:
Timestamp:
Dec 29, 2015 9:08:36 PM (5 years ago)
Author:
str4d <str4d@…>
Branches:
master
Children:
3c383ca
Parents:
bb00e91 (diff), 2698076 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

propagate from branch 'i2p.i2p' (head 833ef88c125ba48423bc704701303ba55858336f)

to branch 'i2p.i2p.str4d.test2' (head 6f21d8d6c6d4cca5b6442f8effb56841e81a07b6)

Location:
apps/ministreaming
Files:
18 added
11 edited
7 moved

Legend:

Unmodified
Added
Removed
  • apps/ministreaming/java/.classpath

    rbb00e91 rfccd0da  
    33        <classpathentry kind="src" path="src"/>
    44        <classpathentry kind="src" path="test/junit"/>
     5        <classpathentry kind="src" path="demo"/>
    56        <classpathentry combineaccessrules="false" kind="src" path="/i2p_sdk"/>
    67        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
  • apps/ministreaming/java/build.xml

    rbb00e91 rfccd0da  
    4141    </target>
    4242
    43     <target name="compileTest" depends="jar">
    44         <mkdir dir="./buildTest" />
    45         <mkdir dir="./buildTest/obj" />
     43    <target name="compileDemo" depends="jar">
     44        <mkdir dir="./buildDemo" />
     45        <mkdir dir="./buildDemo/obj" />
    4646        <javac
    47             srcdir="./test/junit"
     47            srcdir="./demo"
    4848            debug="true" deprecation="on" source="${javac.version}" target="${javac.version}"
    4949            includeAntRuntime="false"
    50             destdir="./buildTest/obj"
     50            destdir="./buildDemo/obj"
    5151            classpath="../../../core/java/build/i2p.jar:./build/mstreaming.jar" >
    5252            <compilerarg line="${javac.compilerargs}" />
     
    5454    </target>
    5555
    56     <target name="jarTest" depends="jar, compileTest">
    57         <jar destfile="./build/mstreamingTest.jar" basedir="./buildTest/obj" includes="**/*.class" update="true" />
     56    <target name="jarDemo" depends="jar, compileDemo">
     57        <jar destfile="./build/mstreamingDemo.jar" basedir="./buildDemo/obj" includes="**/*.class" update="true" />
    5858    </target>
    5959
     
    139139            windowtitle="I2P ministreaming library" />
    140140    </target>
     141
     142    <target name="builddeptest">
     143        <ant dir="../../../core/java" target="jar" />
     144    </target>
     145    <target name="junit.compileTest" depends="builddeptest, compile">
     146
     147        <echo message="[DEBUG] ant home is ${ant.home}" />
     148        <echo message="[DEBUG] junit home before override is ${junit.home}" />
     149        <echo message="[DEBUG] hamcrest home before override is ${hamcrest.home}" />
     150        <echo message="[DEBUG] mockito home before override is ${mockito.home}" />
     151
     152        <property name="junit.home" value="${ant.home}/lib" />
     153        <property name="hamcrest.home" value="${ant.home}/lib" />
     154        <property name="mockito.home" value="${ant.home}/lib" />
     155
     156        <echo message="[DEBUG] junit home after override is ${junit.home}" />
     157        <echo message="[DEBUG] hamcrest home after override is ${hamcrest.home}" />
     158        <echo message="[DEBUG] mockito home after override is ${mockito.home}" />
     159
     160        <javac
     161            srcdir="./test/junit"
     162            debug="true" deprecation="on" source="${javac.version}" target="${javac.version}"
     163            includeAntRuntime="false"
     164            destdir="./build/obj" >
     165            <classpath>
     166                <pathelement location="../../../core/java/build/i2p.jar" />
     167                <pathelement location="${junit.home}/junit4.jar" />
     168                <pathelement location="${hamcrest.home}/hamcrest.jar" />
     169                <pathelement location="${hamcrest.home}/hamcrest-all.jar" />
     170                <pathelement location="${mockito.home}/byte-buddy.jar" />
     171                <pathelement location="${mockito.home}/objenesis.jar" />
     172                <pathelement location="${mockito.home}/mockito-core.jar" />
     173            </classpath>
     174            <compilerarg line="${javac.compilerargs}" />
     175        </javac>
     176    </target>
     177
     178    <!-- preparation of code coverage tool of choice -->
     179    <target name="prepareClover" depends="compile" if="with.clover">
     180        <taskdef resource="clovertasks"/>
     181        <mkdir dir="../../../reports/ministreaming/clover" />
     182        <clover-setup initString="../../../reports/ministreaming/clover/coverage.db"/>
     183    </target>
     184    <target name="prepareCobertura" depends="compile" if="with.cobertura">
     185        <taskdef classpath="${with.cobertura}" resource="tasks.properties" onerror="report" />
     186        <mkdir dir="./build/obj_cobertura" />
     187        <delete file="./cobertura.ser" />
     188        <cobertura-instrument todir="./build/obj_cobertura">
     189            <fileset dir="./build/obj">
     190                <include name="**/*.class"/>
     191                <!-- exclude stub classes -->
     192                <exclude name="net/i2p/client/streaming/I2PSocketManagerFull.class" />
     193                <!-- exclude Test classes -->
     194                <exclude name="**/*Test.class" />
     195                <exclude name="net/i2p/client/streaming/impl/I2PSocketManagerFull.class" />
     196                <!-- exclude anything not in net.i2p.* -->
     197                <exclude name="org/cybergarage/**/*.class" />
     198                <exclude name="org/freenetproject/**/*.class" />
     199                <exclude name="org/xlattice/**/*.class" />
     200            </fileset>
     201        </cobertura-instrument>
     202    </target>
     203
     204    <target name="prepareTest" depends="prepareClover, prepareCobertura" />
     205
     206    <target name="junit.test" depends="clean, junit.compileTest, prepareTest">
     207        <mkdir dir="../../../reports/ministreaming/junit/" />
     208        <delete>
     209            <fileset dir="../../../reports/ministreaming/junit">
     210                <include name="TEST-*.xml"/>
     211            </fileset>
     212        </delete>
     213
     214        <property name="junit.home" value="${ant.home}/lib" />
     215        <property name="hamcrest.home" value="${ant.home}/lib" />
     216        <property name="mockito.home" value="${ant.home}/lib" />
     217
     218        <junit printsummary="withOutAndErr" fork="yes" showoutput="yes" >
     219            <sysproperty key="net.sourceforge.cobertura.datafile" file="./cobertura.ser" />
     220            <classpath>
     221                <pathelement path="${javac.classpath}" />
     222                <pathelement location="${hamcrest.home}/hamcrest-core.jar" />
     223                <pathelement location="${hamcrest.home}/hamcrest-library.jar" />
     224                <pathelement location="${hamcrest.home}/hamcrest-integration.jar" />
     225                <pathelement location="${hamcrest.home}/hamcrest-all.jar" />
     226                <pathelement location="${mockito.home}/byte-buddy.jar" />
     227                <pathelement location="${mockito.home}/objenesis.jar" />
     228                <pathelement location="${mockito.home}/mockito-core.jar" />
     229                <pathelement location="${junit.home}/junit4.jar" />
     230                <pathelement location="./build/obj_cobertura" />
     231                <pathelement location="./build/obj" />
     232                <pathelement location="../../../core/java/build/i2ptest.jar" />
     233                <pathelement location="../../../core/java/build/i2p.jar" />
     234                <pathelement location="../../build/jbigi.jar" />
     235                <pathelement location="${with.clover}" />
     236                <pathelement location="${with.cobertura}" />
     237            </classpath>
     238            <batchtest todir="../../../reports/ministreaming/junit/">
     239                <fileset dir="./test/junit">
     240                    <include name="**/*Test.java" />
     241                </fileset>
     242            </batchtest>
     243            <formatter type="xml"/>
     244        </junit>
     245        <!-- set if unset -->
     246        <property name="host.fakename" value="i2ptester" />
     247        <!-- replace hostname that junit inserts into reports with fake one -->
     248        <replaceregexp byline="true"
     249            match="(hostname=)&quot;[^&quot;]+&quot;"
     250            replace="\1&quot;${host.fakename}&quot;">
     251            <fileset dir="../../../reports/ministreaming/junit/" />
     252        </replaceregexp>
     253    </target>
     254    <target name="test" depends="junit.test"/>
     255    <!-- test reports -->
     256    <target name="junit.report">
     257        <junitreport todir="../../../reports/ministreaming/junit">
     258            <fileset dir="../../../reports/ministreaming/junit">
     259                <include name="TEST-*.xml"/>
     260            </fileset>
     261            <report format="frames" todir="../../../reports/ministreaming/html/junit"/>
     262        </junitreport>
     263    </target>
     264    <target name="clover.report" depends="test" if="with.clover">
     265        <clover-report>
     266            <current outfile="../../../reports/ministreaming/html/clover">
     267                <format type="html"/>
     268            </current>
     269        </clover-report>
     270    </target>
     271    <target name="cobertura.report" depends="test" if="with.cobertura">
     272        <mkdir dir="../../../reports/ministreaming/cobertura" />
     273        <cobertura-report format="xml" srcdir="./src" destdir="../../../reports/ministreaming/cobertura" />
     274        <mkdir dir="../../../reports/ministreaming/html/cobertura" />
     275        <cobertura-report format="html" srcdir="./src" destdir="../../../reports/ministreaming/html/cobertura" />
     276        <delete file="./cobertura.ser" />
     277    </target>
     278    <target name="test.report" depends="junit.report, clover.report, cobertura.report"/>
     279    <!-- end test reports -->
     280    <target name="fulltest" depends="cleandep, test, test.report" />
     281    <!-- end unit tests -->
     282
    141283    <target name="clean">
    142284        <delete dir="./build" />
    143         <delete dir="./buildTest" />
     285        <delete dir="./buildDemo" />
    144286    </target>
    145287    <target name="cleandep" depends="clean">
  • apps/ministreaming/java/bundle-messages.sh

    rbb00e91 rfccd0da  
    2626
    2727# on windows, one must specify the path of commnad find
    28 # since windows has its own retarded version of find.
     28# since windows has its own version of find.
    2929if which find|grep -q -i windows ; then
    3030        export PATH=.:/bin:/usr/local/bin:$PATH
    3131fi
    3232# Fast mode - update ondemond
    33 # set LG2 to the language you need in envrionment varibales to enable this
     33# set LG2 to the language you need in environment variables to enable this
    3434
    3535# add ../java/ so the refs will work in the po file
     
    5252        fi
    5353
    54         if [ -s build/obj/net/i2p/streaming/messages_$LG.class -a \
    55              build/obj/net/i2p/streaming/messages_$LG.class -nt $i -a \
     54        if [ -s build/obj/net/i2p/client/streaming/messages_$LG.class -a \
     55             build/obj/net/i2p/client/streaming/messages_$LG.class -nt $i -a \
    5656             ! -s $TMPFILE ]
    5757        then
     
    6464                # extract strings from java and jsp files, and update messages.po files
    6565                # translate calls must be one of the forms:
    66                 # _("foo")
     66                # _t("foo")
    6767                # _x("foo")
    6868                # To start a new translation, copy the header from an old translation to the new .po file,
     
    7070                find $JPATHS -name *.java > $TMPFILE
    7171                xgettext -f $TMPFILE -F -L java --from-code=UTF-8 --add-comments\
    72                          --keyword=_ --keyword=_x \
     72                         --keyword=_t --keyword=_x \
    7373                         -o ${i}t
    7474                if [ $? -ne 0 ]
  • apps/ministreaming/java/demo/net/i2p/client/streaming/StreamSinkServer.java

    rbb00e91 rfccd0da  
    1212import net.i2p.I2PException;
    1313import net.i2p.data.DataFormatException;
     14import net.i2p.data.DataHelper;
    1415import net.i2p.data.Destination;
    1516import net.i2p.util.I2PThread;
     
    142143                        _log.debug("read and wrote " + read + " (" + written + ")");
    143144                }
    144                 fos.write(("written: [" + written + "]\n").getBytes());
     145                fos.write((DataHelper.getUTF8("written: [" + written + "]\n")));
    145146                long lifetime = System.currentTimeMillis() - start;
    146147                _log.info("Got EOF from client socket [written=" + written + " lifetime=" + lifetime + "]");
  • apps/ministreaming/java/demo/net/i2p/client/streaming/StreamSinkTestClient.java

    rbb00e91 rfccd0da  
    1 package net.i2p.client.streaming.impl;
     1package net.i2p.client.streaming;
    22
    3 import net.i2p.client.streaming.I2PSocketManagerFactory;
    43import net.i2p.client.streaming.StreamSinkSend;
    5 import net.i2p.client.streaming.impl.I2PSocketManagerFull;
    64/**
    75 *
     
    97public class StreamSinkTestClient {
    108    public static void main(String args[]) {
    11         System.setProperty(I2PSocketManagerFactory.PROP_MANAGER, I2PSocketManagerFull.class.getName());
    129        //System.setProperty(I2PClient.PROP_TCP_HOST, "dev.i2p.net");
    1310        //System.setProperty(I2PClient.PROP_TCP_PORT, "4501");
  • apps/ministreaming/java/demo/net/i2p/client/streaming/StreamSinkTestServer.java

    rbb00e91 rfccd0da  
    1 package net.i2p.client.streaming.impl;
     1package net.i2p.client.streaming;
    22
    3 import net.i2p.client.streaming.I2PSocketManagerFactory;
    43import net.i2p.client.streaming.StreamSinkServer;
    5 import net.i2p.client.streaming.impl.I2PSocketManagerFull;
    64/**
    75 *
     
    97public class StreamSinkTestServer {
    108    public static void main(String args[]) {
    11         System.setProperty(I2PSocketManagerFactory.PROP_MANAGER, I2PSocketManagerFull.class.getName());
    129        //System.setProperty(I2PClient.PROP_TCP_HOST, "dev.i2p.net");
    1310        //System.setProperty(I2PClient.PROP_TCP_PORT, "4101");
  • apps/ministreaming/java/demo/net/i2p/client/streaming/StreamSinkTestStandalone.java

    rbb00e91 rfccd0da  
    1 package net.i2p.client.streaming.impl;
     1package net.i2p.client.streaming;
    22
    3 import net.i2p.client.streaming.I2PSocketManagerFactory;
    43import net.i2p.client.streaming.StreamSinkClient;
    54import net.i2p.client.streaming.StreamSinkSend;
    65import net.i2p.client.streaming.StreamSinkServer;
    7 import net.i2p.client.streaming.impl.I2PSocketManagerFull;
    86/**
    97 * Usage: StreamSinkTest [(old|new) [#hops [#kb]]]
     
    2725   
    2826    public static void main(String args[]) {
    29         boolean old = false;
    3027        int hops = 0;
    3128        int kb = 32*1024;
    3229        if (args.length > 0) {
    33             if ("old".equals(args[0]))
    34                 old = true;
    35         }
    36         if (args.length > 1) {
    3730            try {
    38                 hops = Integer.parseInt(args[1]);
     31                hops = Integer.parseInt(args[0]);
    3932            } catch (NumberFormatException nfe) {
    4033                hops = 0;
    4134            }
    4235        }
    43         if (args.length > 2) {
     36        if (args.length > 1) {
    4437            try {
    45                 kb = Integer.parseInt(args[2]);
     38                kb = Integer.parseInt(args[1]);
    4639            } catch (NumberFormatException nfe) {
    4740                kb = 32*1024;
     
    4942        }
    5043       
    51         if (!old)
    52             System.setProperty(I2PSocketManagerFactory.PROP_MANAGER, I2PSocketManagerFull.class.getName());
    5344        System.setProperty("tunnels.depthInbound", ""+hops);
    5445       
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PServerSocket.java

    rbb00e91 rfccd0da  
    77
    88/**
    9  * Defines how to listen for streaming peer connections
    10  *
     9 *  Streaming server socket returned by {@link I2PSocketManager#getServerSocket()}.
     10 *  Defines how to listen for streaming peer connections.
     11 *<p>
     12 *  Note that this is not a standard Java {@link java.net.ServerSocket},
     13 *  if you need one of those, use {@link I2PSocketManager#getStandardServerSocket()} instead.
    1114 */
    1215public interface I2PServerSocket {
     
    2124     * connection and the local application wasn't .accept()ing new connections,
    2225     * they should get refused (if .accept() doesnt occur in some small period).
    23      * Warning - unlike regular ServerSocket, may return null.
     26     * Warning - unlike regular ServerSocket, may return null (through 0.9.16 only).
    2427     *
    25      * @return a connected I2PSocket OR NULL
     28     * @return a connected I2PSocket OR NULL through 0.9.16; never null as of 0.9.17
    2629     *
    2730     * @throws I2PException if there is a problem with reading a new socket
    28      *         from the data available (aka the I2PSession closed, etc)
    29      * @throws ConnectException if the I2PServerSocket is closed
    30      * @throws SocketTimeoutException
     31     *         from the data available (e.g. the I2PSession is closed)
     32     * @throws ConnectException if the I2PServerSocket is closed, or if interrupted.
     33     *         Not actually thrown through 0.9.16; thrown as of 0.9.17
     34     * @throws SocketTimeoutException if a timeout was previously set with setSoTimeout and the timeout has been reached.
    3135     */
    3236    public I2PSocket accept() throws I2PException, ConnectException, SocketTimeoutException;
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocket.java

    rbb00e91 rfccd0da  
    1010
    1111/**
    12  * Minimalistic adapter between the socket api and I2PTunnel's way.
    13  * Note that this interface is a "subinterface" of the interface
    14  * defined in the "official" streaming api.
     12 *  Streaming socket returned by {@link I2PSocketManager#connect(Destination)}.
     13 *<p>
     14 *  Note that this is not a standard Java {@link java.net.Socket},
     15 *  if you need one of those, use {@link I2PSocketManager#connectToSocket(Destination)} instead.
    1516 */
    1617public interface I2PSocket extends Closeable {
     
    2829     *  As of 0.9.9 will throw an IOE if socket is closed.
    2930     *  Prior to that would return null instead of throwing IOE.
     31     *<p>
     32     *  Note that operations on the returned stream may return an
     33     *  {@link IOException} whose <i>cause</i> as returned by
     34     *  {@link IOException#getCause()} is an {@link I2PSocketException}.
     35     *  If so, the client may retrieve a status code via
     36     *  {@link I2PSocketException#getStatus()} to provide specific feedback to the user.
    3037     *
    3138     * @return an InputStream to read from the socket. Non-null since 0.9.9.
     
    3744     *  As of 0.9.9 will throw an IOE if socket is closed.
    3845     *  Prior to that would return null instead of throwing IOE.
     46     *<p>
     47     *  Note that operations on the returned stream may return an
     48     *  {@link IOException} whose <i>cause</i> as returned by
     49     *  {@link IOException#getCause()} is an {@link I2PSocketException}.
     50     *  If so, the client may retrieve a status code via
     51     *  {@link I2PSocketException#getStatus()} to provide specific feedback to the user.
    3952     *
    4053     * @return an OutputStream to write into the socket. Non-null since 0.9.9.
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketEepGet.java

    rbb00e91 rfccd0da  
    66import java.net.MalformedURLException;
    77import java.net.UnknownHostException;
    8 import java.net.URL;
     8import java.net.URI;
     9import java.net.URISyntaxException;
    910import java.util.Locale;
    1011import java.util.Properties;
     
    1213import net.i2p.I2PAppContext;
    1314import net.i2p.I2PException;
     15import net.i2p.client.I2PSession;
     16import net.i2p.client.I2PSessionException;
     17import net.i2p.data.Base32;
    1418import net.i2p.data.DataHelper;
    1519import net.i2p.data.Destination;
     20import net.i2p.data.Hash;
    1621import net.i2p.util.EepGet;
    1722import net.i2p.util.SocketTimeout;
     
    109114
    110115        try {
    111             URL url = new URL(_actualURL);
    112             if ("http".equals(url.getProtocol())) {
     116            URI url = new URI(_actualURL);
     117            if ("http".equals(url.getScheme())) {
    113118                String host = url.getHost();
     119                if (host == null)
     120                    throw new MalformedURLException("no hostname: " + _actualURL);
    114121                int port = url.getPort();
    115122                if (port <= 0 || port > 65535)
     
    120127                // as the naming service accepts B64KEY (but not B64KEY.i2p atm)
    121128                if ("i2p".equals(host)) {
    122                     String file = url.getFile();
     129                    String file = url.getRawPath();
    123130                    try {
    124131                        int slash = 1 + file.substring(1).indexOf("/");
    125132                        host = file.substring(1, slash);
    126133                        _actualURL = "http://" + host + file.substring(slash);
     134                        String query = url.getRawQuery();
     135                        if (query != null)
     136                            _actualURL = _actualURL + '?' + query;
    127137                    } catch (IndexOutOfBoundsException ioobe) {
    128                         throw new IOException("Bad /i2p/ format: " + _actualURL);
     138                        throw new MalformedURLException("Bad /i2p/ format: " + _actualURL);
    129139                    }
    130140                }
    131141
    132                 Destination dest = _context.namingService().lookup(host);
     142                // Use existing I2PSession for lookups.
     143                // This is much more efficient than using the naming service
     144                Destination dest;
     145                I2PSession sess = _socketManager.getSession();
     146                if (sess != null && !sess.isClosed()) {
     147                    try {
     148                        if (host.length() == 60 && host.endsWith(".b32.i2p")) {
     149                            byte[] b = Base32.decode(host.substring(0, 52));
     150                            if (b != null) {
     151                                Hash h = Hash.create(b);
     152                                dest = sess.lookupDest(h, 20*1000);
     153                            } else {
     154                                dest = null;
     155                            }
     156                        } else {
     157                            dest = sess.lookupDest(host, 20*1000);
     158                        }
     159                    } catch (I2PSessionException ise) {
     160                        dest = null;
     161                    }
     162                } else {
     163                    dest = _context.namingService().lookup(host);
     164                }
    133165                if (dest == null)
    134                     throw new UnknownHostException("Unknown or non-i2p host");
     166                    throw new UnknownHostException("Unknown or non-i2p host: " + host);
    135167
    136168                // Set the timeouts, using the other existing options in the socket manager
     
    148180                _socket = _socketManager.connect(dest, opts);
    149181            } else {
    150                 throw new IOException("Unsupported protocol: " + _actualURL);
     182                throw new MalformedURLException("Unsupported protocol: " + _actualURL);
    151183            }
    152         } catch (MalformedURLException mue) {
    153             throw new IOException("Request URL is invalid: " + _actualURL);
     184        } catch (URISyntaxException use) {
     185            IOException ioe = new MalformedURLException("Bad URL");
     186            ioe.initCause(use);
     187            throw ioe;
    154188        } catch (I2PException ie) {
    155             throw new IOException(ie.toString());
     189            throw new IOException("I2P error", ie);
    156190        }
    157191
     
    177211    protected String getRequest() throws IOException {
    178212        StringBuilder buf = new StringBuilder(2048);
    179         URL url = new URL(_actualURL);
     213        URI url;
     214        try {
     215            url = new URI(_actualURL);
     216        } catch (URISyntaxException use) {
     217            IOException ioe = new MalformedURLException("Bad URL");
     218            ioe.initCause(use);
     219            throw ioe;
     220        }
    180221        //String host = url.getHost();
    181         String path = url.getPath();
    182         String query = url.getQuery();
     222        String path = url.getRawPath();
     223        String query = url.getRawQuery();
    183224        if (query != null)
    184225            path = path + '?' + query;
     
    207248            buf.append("User-Agent: " + USER_AGENT + "\r\n");
    208249        buf.append("\r\n");
     250        if (_log.shouldDebug())
     251            _log.debug("Request: [" + buf.toString() + "]");
    209252        return buf.toString();
    210253    }
     
    239282                }
    240283            }
    241         } catch (Exception e) {
     284        } catch (RuntimeException e) {
    242285            e.printStackTrace();
    243286            usage();
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketException.java

    rbb00e91 rfccd0da  
    2121
    2222    /**
    23      *  Use canned message for this status code
     23     *  Router and I2CP status codes are 0 - 511. Start ours at 512.
     24     *  @since 0.9.19
     25     */
     26    public static final int STATUS_CONNECTION_RESET = 512;
     27
     28    /**
     29     *  Use canned message for this status code.
     30     *
     31     *  Standard codes from the router are 0-255, defined in MessageStatusMessage.
     32     *  Standard codes from client-side I2CP are 256-511, defined in SendMessageStatusListener.
     33     *  Standard codes from streaming are 512-767, defined here.
     34     *
    2435     *  @param status >= 0 from MessageStatusMessage or SendMessageStatusListener
    2536     */
     
    106117                return _x("Local destination shutdown");
    107118
     119            case STATUS_CONNECTION_RESET:
     120                return _x("Connection was reset");
     121
    108122            case CUSTOM:
    109123                return super.getMessage();
     
    111125            default:
    112126                // Translate this one here, can't do it later
    113                 return _("Failure code") + ": " + _status;
     127                return _t("Failure code") + ": " + _status;
    114128        }
    115129    }
     
    123137        if (s == null)
    124138            return null;
    125         return _(s);
     139        return _t(s);
    126140    }
    127141
     
    129143     *  Translate
    130144     */
    131     private static String _(String s) {
     145    private static String _t(String s) {
    132146        return Translate.getString(s, I2PAppContext.getGlobalContext(), BUNDLE_NAME);
    133147    }
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketManager.java

    rbb00e91 rfccd0da  
    66
    77import java.io.IOException;
     8import java.io.InputStream;
    89import java.io.InterruptedIOException;
    910import java.net.ConnectException;
     
    1112import java.net.ServerSocket;
    1213import java.net.Socket;
     14import java.util.List;
    1315import java.util.Properties;
    1416import java.util.Set;
     
    1719import net.i2p.I2PException;
    1820import net.i2p.client.I2PSession;
     21import net.i2p.client.I2PSessionException;
    1922import net.i2p.data.Destination;
    2023
     
    3639   
    3740    /**
     41     *  @return a new subsession, non-null
     42     *  @param privateKeyStream null for transient, if non-null must have same encryption keys as primary session
     43     *                          and different signing keys
     44     *  @param opts subsession options if any, may be null
     45     *  @since 0.9.21
     46     */
     47    public I2PSession addSubsession(InputStream privateKeyStream, Properties opts) throws I2PSessionException;
     48   
     49    /**
     50     *  @since 0.9.21
     51     */
     52    public void removeSubsession(I2PSession session);
     53   
     54    /**
     55     *  @return a list of subsessions, non-null, does not include the primary session
     56     *  @since 0.9.21
     57     */
     58    public List<I2PSession> getSubsessions();
     59
     60    /**
    3861     * How long should we wait for the client to .accept() a socket before
    3962     * sending back a NACK/Close? 
     
    5881    public I2PSocketOptions getDefaultOptions();
    5982
     83    /**
     84     *  Returns non-null socket.
     85     *  This method does not throw exceptions, but methods on the returned socket
     86     *  may throw exceptions if the socket or socket manager is closed.
     87     *
     88     *  @return non-null
     89     */
    6090    public I2PServerSocket getServerSocket();
    6191   
     
    6797    /**
    6898     *  Create a modified copy of the current options, to be used in a setDefaultOptions() call.
     99     *
     100     *  As of 0.9.19, defaults in opts are honored.
     101     *
    69102     *  @param opts The new options, may be null
    70103     */
     
    152185    public boolean ping(Destination peer, int localPort, int remotePort, long timeoutMs);
    153186
     187    /**
     188     * Ping the specified peer, returning true if they replied to the ping within
     189     * the timeout specified, false otherwise.  This call blocks.
     190     *
     191     * Uses the ports specified.
     192     *
     193     * @param peer Destination to ping
     194     * @param localPort 0 - 65535
     195     * @param remotePort 0 - 65535
     196     * @param timeoutMs timeout in ms, greater than zero
     197     * @param payload to include in the ping
     198     * @return the payload received in the pong, zero-length if none, null on failure or timeout
     199     * @throws IllegalArgumentException
     200     * @since 0.9.18
     201     */
     202    public byte[] ping(Destination peer, int localPort, int remotePort, long timeoutMs, byte[] payload);
     203
     204    /**
     205     *  For logging / diagnostics only
     206     */
    154207    public String getName();
     208
     209    /**
     210     *  For logging / diagnostics only
     211     */
    155212    public void setName(String name);
    156213
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketManagerFactory.java

    rbb00e91 rfccd0da  
    2121 * Simplify the creation of I2PSession and transient I2P Destination objects if
    2222 * necessary to create a socket manager.  This class is most likely how classes
    23  * will begin their use of the socket library
     23 * will begin their use of the socket library.
     24 *
     25 * For new applications, createDisconnectedManager() is the preferred method.
     26 * It is non-blocking and throws on all errors.
     27 * All createManager() methods are blocking and return null on error.
     28 *
     29 * Note that for all methods, host and port arguments are ignored if in RouterContext;
     30 * it will connect internally to the router in the JVM.
     31 * You cannot connect out from a router JVM to another router.
    2432 *
    2533 */
    2634public class I2PSocketManagerFactory {
    2735
     36    /**
     37     *  Ignored since 0.9.12, cannot be changed via properties.
     38     *  @deprecated
     39     */
    2840    public static final String PROP_MANAGER = "i2p.streaming.manager";
     41
     42    /**
     43     *  The one and only manager.
     44     */
    2945    public static final String DEFAULT_MANAGER = "net.i2p.client.streaming.impl.I2PSocketManagerFull";
    3046
     
    3450     *
    3551     * Blocks for a long time while the router builds tunnels.
     52     * The nonblocking createDisconnectedManager() is preferred.
    3653     *
    3754     * @return the newly created socket manager, or null if there were errors
     
    4663     *
    4764     * Blocks for a long time while the router builds tunnels.
     65     * The nonblocking createDisconnectedManager() is preferred.
    4866     *
    4967     * @param opts Streaming and I2CP options, may be null
     
    5977     *
    6078     * Blocks for a long time while the router builds tunnels.
    61      *
    62      * @param host I2CP host null to use default
    63      * @param port I2CP port <= 0 to use default
     79     * The nonblocking createDisconnectedManager() is preferred.
     80     *
     81     * @param host I2CP host null to use default, ignored if in router context
     82     * @param port I2CP port <= 0 to use default, ignored if in router context
    6483     * @return the newly created socket manager, or null if there were errors
    6584     */
     
    7392     *
    7493     * Blocks for a long time while the router builds tunnels.
    75      *
    76      * @param i2cpHost I2CP host null to use default
    77      * @param i2cpPort I2CP port <= 0 to use default
     94     * The nonblocking createDisconnectedManager() is preferred.
     95     *
     96     * @param i2cpHost I2CP host null to use default, ignored if in router context
     97     * @param i2cpPort I2CP port <= 0 to use default, ignored if in router context
    7898     * @param opts Streaming and I2CP options, may be null
    7999     * @return the newly created socket manager, or null if there were errors
     
    100120     *
    101121     * Blocks for a long time while the router builds tunnels.
     122     * The nonblocking createDisconnectedManager() is preferred.
    102123     *
    103124     * @param myPrivateKeyStream private key stream, format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile}
     
    114135     *
    115136     * Blocks for a long time while the router builds tunnels.
     137     * The nonblocking createDisconnectedManager() is preferred.
    116138     *
    117139     * @param myPrivateKeyStream private key stream, format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile}
     
    130152     *
    131153     * Blocks for a long time while the router builds tunnels.
     154     * The nonblocking createDisconnectedManager() is preferred.
    132155     *
    133156     * @param myPrivateKeyStream private key stream, format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile}
    134157     *                           or null for a transient destination. Caller must close.
    135      * @param i2cpHost I2CP host null to use default
    136      * @param i2cpPort I2CP port <= 0 to use default
     158     * @param i2cpHost I2CP host null to use default, ignored if in router context
     159     * @param i2cpPort I2CP port <= 0 to use default, ignored if in router context
    137160     * @param opts Streaming and I2CP options, may be null
    138161     * @return the newly created socket manager, or null if there were errors
     
    160183     * @param myPrivateKeyStream private key stream, format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile}
    161184     *                           or null for a transient destination. Caller must close.
    162      * @param i2cpHost I2CP host null to use default
    163      * @param i2cpPort I2CP port <= 0 to use default
     185     * @param i2cpHost I2CP host null to use default, ignored if in router context
     186     * @param i2cpPort I2CP port <= 0 to use default, ignored if in router context
    164187     * @param opts Streaming and I2CP options, may be null
    165188     * @return the newly created socket manager, non-null (throws on error)
     
    173196            try {
    174197                client.createDestination(keyStream, getSigType(opts));
    175             } catch (Exception e) {
     198            } catch (I2PException e) {
     199                throw new I2PSessionException("Error creating keys", e);
     200            } catch (IOException e) {
    176201                throw new I2PSessionException("Error creating keys", e);
    177202            }
     
    190215     * @param myPrivateKeyStream private key stream, format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile}
    191216     *                           non-null. Caller must close.
    192      * @param i2cpHost I2CP host null to use default
    193      * @param i2cpPort I2CP port <= 0 to use default
     217     * @param i2cpHost I2CP host null to use default, ignored if in router context
     218     * @param i2cpPort I2CP port <= 0 to use default, ignored if in router context
    194219     * @param opts Streaming and I2CP options, may be null
    195220     * @param connect true to connect (blocking)
     
    205230        for (Map.Entry<Object, Object> e : syscopy.entrySet()) {
    206231            String name = (String) e.getKey();
    207             if (!opts.containsKey(name))
     232            if (opts.getProperty(name) == null)
    208233                opts.setProperty(name, (String) e.getValue());
    209234        }
    210235        // as of 0.8.1 (I2CP default is BestEffort)
    211         if (!opts.containsKey(I2PClient.PROP_RELIABILITY))
     236        if (opts.getProperty(I2PClient.PROP_RELIABILITY) == null)
    212237            opts.setProperty(I2PClient.PROP_RELIABILITY, I2PClient.PROP_RELIABILITY_NONE);
    213238
     
    234259            if (!I2PSocketManager.class.isAssignableFrom(cls))
    235260                throw new IllegalArgumentException(classname + " is not an I2PSocketManager");
    236             Constructor<I2PSocketManager> con = (Constructor<I2PSocketManager>)
    237                   cls.getConstructor(new Class[] {I2PAppContext.class, I2PSession.class, Properties.class, String.class});
    238             I2PSocketManager mgr = con.newInstance(new Object[] {context, session, opts, name});
     261            Constructor<?> con =
     262                  cls.getConstructor(I2PAppContext.class, I2PSession.class, Properties.class, String.class);
     263            I2PSocketManager mgr = (I2PSocketManager) con.newInstance(new Object[] {context, session, opts, name});
    239264            return mgr;
    240265        } catch (Throwable t) {
     
    271296            if (st != null) {
    272297                SigType rv = SigType.parseSigType(st);
     298                if (rv != null && rv.isAvailable())
     299                    return rv;
    273300                if (rv != null)
    274                     return rv;
    275                 getLog().error("Unsupported sig type " + st);
     301                    st = rv.toString();
     302                getLog().logAlways(Log.WARN, "Unsupported sig type " + st +
     303                                             ", reverting to " + I2PClient.DEFAULT_SIGTYPE);
    276304            }
    277305        }
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketOptions.java

    rbb00e91 rfccd0da  
    3838     * What is the longest we'll block on the input stream while waiting
    3939     * for more data.  If this value is exceeded, the read() throws
    40      * InterruptedIOException
     40     * InterruptedIOException - FIXME doesn't really, returns -1 or 0 instead.
    4141     *
    4242     * WARNING: Default -1 (unlimited), which is probably not what you want.
    4343     *
    44      * @return timeout in ms
     44     * @return timeout in ms, 0 for nonblocking, -1 for forever
    4545     */
    4646    public long getReadTimeout();
     
    4949     * What is the longest we'll block on the input stream while waiting
    5050     * for more data.  If this value is exceeded, the read() throws
    51      * InterruptedIOException
     51     * InterruptedIOException - FIXME doesn't really, returns -1 or 0 instead.
    5252     *
    5353     * WARNING: Default -1 (unlimited), which is probably not what you want.
    5454     *
    55      * @param ms timeout in ms
     55     * @param ms timeout in ms, 0 for nonblocking, -1 for forever
    5656     */
    5757    public void setReadTimeout(long ms);
  • apps/ministreaming/locale/messages_en.po

    rbb00e91 rfccd0da  
    88"Project-Id-Version: I2P streaming\n"
    99"Report-Msgid-Bugs-To: \n"
    10 "POT-Creation-Date: 2014-06-23 17:55+0000\n"
     10"POT-Creation-Date: 2015-03-29 14:30+0000\n"
    1111"Language: en\n"
    1212"MIME-Version: 1.0\n"
     
    1515"Plural-Forms: nplurals=2; plural=(n != 1)\n"
    1616
    17 #: ../java/src/net/i2p/client/streaming/I2PSocketException.java:58
     17#: ../java/src/net/i2p/client/streaming/I2PSocketException.java:69
    1818msgid "Message timeout"
    1919msgstr ""
    2020
    21 #: ../java/src/net/i2p/client/streaming/I2PSocketException.java:61
     21#: ../java/src/net/i2p/client/streaming/I2PSocketException.java:72
    2222msgid "Failed delivery to local destination"
    2323msgstr ""
    2424
    25 #: ../java/src/net/i2p/client/streaming/I2PSocketException.java:64
    26 #: ../java/src/net/i2p/client/streaming/I2PSocketException.java:97
     25#: ../java/src/net/i2p/client/streaming/I2PSocketException.java:75
     26#: ../java/src/net/i2p/client/streaming/I2PSocketException.java:108
    2727msgid "Local router failure"
    2828msgstr ""
    2929
    30 #: ../java/src/net/i2p/client/streaming/I2PSocketException.java:67
     30#: ../java/src/net/i2p/client/streaming/I2PSocketException.java:78
    3131msgid "Local network failure"
    3232msgstr ""
    3333
    34 #: ../java/src/net/i2p/client/streaming/I2PSocketException.java:70
     34#: ../java/src/net/i2p/client/streaming/I2PSocketException.java:81
    3535msgid "Session closed"
    3636msgstr ""
    3737
    38 #: ../java/src/net/i2p/client/streaming/I2PSocketException.java:73
     38#: ../java/src/net/i2p/client/streaming/I2PSocketException.java:84
    3939msgid "Invalid message"
    4040msgstr ""
    4141
    42 #: ../java/src/net/i2p/client/streaming/I2PSocketException.java:76
     42#: ../java/src/net/i2p/client/streaming/I2PSocketException.java:87
    4343msgid "Invalid message options"
    4444msgstr ""
    4545
    46 #: ../java/src/net/i2p/client/streaming/I2PSocketException.java:79
     46#: ../java/src/net/i2p/client/streaming/I2PSocketException.java:90
    4747msgid "Buffer overflow"
    4848msgstr ""
    4949
    50 #: ../java/src/net/i2p/client/streaming/I2PSocketException.java:82
     50#: ../java/src/net/i2p/client/streaming/I2PSocketException.java:93
    5151msgid "Message expired"
    5252msgstr ""
    5353
    54 #: ../java/src/net/i2p/client/streaming/I2PSocketException.java:85
     54#: ../java/src/net/i2p/client/streaming/I2PSocketException.java:96
    5555msgid "Local lease set invalid"
    5656msgstr ""
    5757
    58 #: ../java/src/net/i2p/client/streaming/I2PSocketException.java:88
     58#: ../java/src/net/i2p/client/streaming/I2PSocketException.java:99
    5959msgid "No local tunnels"
    6060msgstr ""
    6161
    62 #: ../java/src/net/i2p/client/streaming/I2PSocketException.java:91
     62#: ../java/src/net/i2p/client/streaming/I2PSocketException.java:102
    6363msgid "Unsupported encryption options"
    6464msgstr ""
    6565
    66 #: ../java/src/net/i2p/client/streaming/I2PSocketException.java:94
     66#: ../java/src/net/i2p/client/streaming/I2PSocketException.java:105
    6767msgid "Invalid destination"
    6868msgstr ""
    6969
    70 #: ../java/src/net/i2p/client/streaming/I2PSocketException.java:100
     70#: ../java/src/net/i2p/client/streaming/I2PSocketException.java:111
    7171msgid "Destination lease set expired"
    7272msgstr ""
    7373
    74 #: ../java/src/net/i2p/client/streaming/I2PSocketException.java:103
     74#: ../java/src/net/i2p/client/streaming/I2PSocketException.java:114
    7575msgid "Destination lease set not found"
    7676msgstr ""
    7777
    78 #: ../java/src/net/i2p/client/streaming/I2PSocketException.java:106
     78#: ../java/src/net/i2p/client/streaming/I2PSocketException.java:117
    7979msgid "Local destination shutdown"
    8080msgstr ""
    8181
     82#: ../java/src/net/i2p/client/streaming/I2PSocketException.java:120
     83msgid "Connection was reset"
     84msgstr ""
     85
    8286#. Translate this one here, can't do it later
    83 #: ../java/src/net/i2p/client/streaming/I2PSocketException.java:113
     87#: ../java/src/net/i2p/client/streaming/I2PSocketException.java:127
    8488msgid "Failure code"
    8589msgstr ""
Note: See TracChangeset for help on using the changeset viewer.