Search in sources :

Example 1 with I2PThread

use of net.i2p.util.I2PThread in project i2p.i2p by i2p.

the class TestSwarm method connectWithPeers.

private void connectWithPeers() {
    if (_peerDestFiles != null) {
        for (int i = 0; i < _peerDestFiles.length; i++) {
            try {
                FileInputStream fin = new FileInputStream(_peerDestFiles[i]);
                byte[] dest = new byte[1024];
                int read = DataHelper.read(fin, dest);
                String remDest = new String(dest, 0, read);
                int con = 0;
                Flooder flooder = null;
                synchronized (_remotePeers) {
                    con = _remotePeers.size() + 1;
                    flooder = new Flooder(con, remDest);
                    _remotePeers.put(new Integer(con), flooder);
                }
                byte[] msg = (DataHelper.getUTF8("STREAM CONNECT ID=" + con + " DESTINATION=" + remDest + "\n"));
                synchronized (_samOut) {
                    _samOut.write(msg);
                    _samOut.flush();
                }
                I2PThread flood = new I2PThread(flooder, "Flood " + con);
                flood.start();
                _log.debug("Starting flooder with peer from " + _peerDestFiles[i] + ": " + con);
            } catch (IOException ioe) {
                _log.error("Unable to read the peer from " + _peerDestFiles[i]);
            }
        }
    }
}
Also used : I2PThread(net.i2p.util.I2PThread) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 2 with I2PThread

use of net.i2p.util.I2PThread in project i2p.i2p by i2p.

the class TestStreamTransfer method startAlice.

private static void startAlice(String host, int port, String conOptions) {
    _log.info("\n\nStarting up Alice");
    try {
        Socket s = new Socket(host, port);
        OutputStream out = s.getOutputStream();
        out.write(DataHelper.getASCII("HELLO VERSION MIN=1.0 MAX=1.0\n"));
        BufferedReader reader = new BufferedReader(new InputStreamReader(s.getInputStream()));
        String line = reader.readLine();
        _log.debug("line read for valid version: " + line);
        String req = "SESSION CREATE STYLE=STREAM DESTINATION=Alice " + conOptions + "\n";
        out.write(DataHelper.getASCII(req));
        line = reader.readLine();
        _log.info("Response to creating the session with destination Alice: " + line);
        req = "NAMING LOOKUP NAME=ME\n";
        out.write(DataHelper.getASCII(req));
        line = reader.readLine();
        Properties props = SAMUtils.parseParams(line);
        String value = props.getProperty("VALUE");
        if (value == null) {
            _log.error("No value for ME found!  [" + line + "]");
            return;
        } else {
            _log.info("Alice is located at " + value);
        }
        _alice = value;
        I2PThread aliceThread = new I2PThread(new AliceRunner(reader, out, s));
        aliceThread.setName("Alice");
        aliceThread.start();
    } catch (Exception e) {
        _log.error("Error testing for valid version", e);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) OutputStream(java.io.OutputStream) I2PThread(net.i2p.util.I2PThread) BufferedReader(java.io.BufferedReader) Properties(java.util.Properties) Socket(java.net.Socket) IOException(java.io.IOException)

Example 3 with I2PThread

use of net.i2p.util.I2PThread in project i2p.i2p by i2p.

the class TestStreamTransfer method testBob.

private static void testBob(String sessionName, String host, int port, String conOptions) {
    I2PThread t = new I2PThread(new TestBob(sessionName, host, port, conOptions), sessionName);
    t.start();
}
Also used : I2PThread(net.i2p.util.I2PThread)

Example 4 with I2PThread

use of net.i2p.util.I2PThread in project i2p.i2p by i2p.

the class StreamSinkServer method startup.

public void startup(I2PServerSocket sock) {
    for (int i = 0; i < _handlers; i++) {
        I2PThread t = new I2PThread(new ClientRunner(sock));
        t.setName("Handler " + i);
        t.setDaemon(false);
        t.start();
    }
}
Also used : I2PThread(net.i2p.util.I2PThread)

Example 5 with I2PThread

use of net.i2p.util.I2PThread in project i2p.i2p by i2p.

the class TestSwarm method startup.

public void startup() {
    _log.debug("Starting up");
    File keys = new File(_destFile);
    if (!keys.exists()) {
        try {
            I2PClientFactory.createClient().createDestination(new FileOutputStream(keys));
        } catch (Exception e) {
            _log.error("Error creating a new destination on " + keys, e);
            return;
        }
    }
    try {
        _manager = I2PSocketManagerFactory.createManager(new FileInputStream(_destFile), null, -1, null);
    } catch (Exception e) {
        _log.error("Error creatign the manager", e);
        return;
    }
    I2PThread listener = new I2PThread(new Listener(), "Listener");
    listener.start();
    connectWithPeers();
}
Also used : FileOutputStream(java.io.FileOutputStream) I2PThread(net.i2p.util.I2PThread) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

I2PThread (net.i2p.util.I2PThread)35 FileInputStream (java.io.FileInputStream)3 IOException (java.io.IOException)3 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 OutputStream (java.io.OutputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Socket (java.net.Socket)1 SocketException (java.net.SocketException)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 Destination (net.i2p.data.Destination)1 I2CPMessageReader (net.i2p.data.i2cp.I2CPMessageReader)1 I2PAppThread (net.i2p.util.I2PAppThread)1 ForwardPort (org.freenetproject.ForwardPort)1 ForwardPortStatus (org.freenetproject.ForwardPortStatus)1