forked from I2P_Developers/i2p.i2p
Moved *streaming and i2ptunnel tests to match convention
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
package net.i2p.client.streaming;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.client.I2PClient;
|
||||
import net.i2p.client.I2PClientFactory;
|
||||
import net.i2p.client.I2PSession;
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
* Have a client connect to a server, where the server waits 5
|
||||
* seconds and closes the socket and the client detect that
|
||||
* EOF.
|
||||
*
|
||||
*/
|
||||
public class ConnectCloseTest {
|
||||
private Log _log;
|
||||
private I2PSession _server;
|
||||
public void test() {
|
||||
try {
|
||||
I2PAppContext context = I2PAppContext.getGlobalContext();
|
||||
_log = context.logManager().getLog(ConnectCloseTest.class);
|
||||
_log.debug("creating server session");
|
||||
_server = createSession();
|
||||
_log.debug("running server");
|
||||
runServer(context, _server);
|
||||
_log.debug("running client");
|
||||
runClient(context, createSession());
|
||||
} catch (Exception e) {
|
||||
_log.error("error running", e);
|
||||
}
|
||||
try { Thread.sleep(10*60*1000); } catch (Exception e) {}
|
||||
}
|
||||
|
||||
private void runClient(I2PAppContext ctx, I2PSession session) {
|
||||
Thread t = new Thread(new ClientRunner(ctx, session));
|
||||
t.setName("client");
|
||||
t.setDaemon(true);
|
||||
t.start();
|
||||
}
|
||||
|
||||
private void runServer(I2PAppContext ctx, I2PSession session) {
|
||||
Thread t = new Thread(new ServerRunner(ctx, session));
|
||||
t.setName("server");
|
||||
t.setDaemon(true);
|
||||
t.start();
|
||||
}
|
||||
|
||||
private class ServerRunner implements Runnable {
|
||||
private I2PAppContext _context;
|
||||
private I2PSession _session;
|
||||
private Log _log;
|
||||
public ServerRunner(I2PAppContext ctx, I2PSession session) {
|
||||
_context = ctx;
|
||||
_session = session;
|
||||
_log = ctx.logManager().getLog(ServerRunner.class);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
Properties opts = new Properties();
|
||||
I2PSocketManager mgr = new I2PSocketManagerFull(_context, _session, opts, "client");
|
||||
_log.debug("* manager created");
|
||||
I2PServerSocket ssocket = mgr.getServerSocket();
|
||||
_log.debug("* server socket created");
|
||||
while (true) {
|
||||
I2PSocket socket = ssocket.accept();
|
||||
_log.debug("* socket accepted: " + socket);
|
||||
try { Thread.sleep(5*1000); } catch (InterruptedException ie) {}
|
||||
socket.close();
|
||||
_log.debug("* socket closed: " + socket);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
_log.error("error running", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class ClientRunner implements Runnable {
|
||||
private I2PAppContext _context;
|
||||
private I2PSession _session;
|
||||
private Log _log;
|
||||
public ClientRunner(I2PAppContext ctx, I2PSession session) {
|
||||
_context = ctx;
|
||||
_session = session;
|
||||
_log = ctx.logManager().getLog(ClientRunner.class);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
Properties opts = new Properties();
|
||||
I2PSocketManager mgr = new I2PSocketManagerFull(_context, _session, opts, "client");
|
||||
_log.debug("* manager created");
|
||||
I2PSocket socket = mgr.connect(_server.getMyDestination());
|
||||
_log.debug("* socket created");
|
||||
InputStream in = socket.getInputStream();
|
||||
int c = in.read();
|
||||
if (c != -1)
|
||||
throw new RuntimeException("hrm, we got data? [" + c + "]");
|
||||
socket.close();
|
||||
_log.debug("* socket closed");
|
||||
mgr.destroySocketManager();
|
||||
mgr = null;
|
||||
socket = null;
|
||||
} catch (Exception e) {
|
||||
_log.error("error running", e);
|
||||
}
|
||||
try { Thread.sleep(5*1000); } catch (InterruptedException ie) {}
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private I2PSession createSession() {
|
||||
try {
|
||||
I2PClient client = I2PClientFactory.createClient();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
|
||||
Destination dest = client.createDestination(baos);
|
||||
I2PSession sess = client.createSession(new ByteArrayInputStream(baos.toByteArray()), System.getProperties());
|
||||
sess.connect();
|
||||
return sess;
|
||||
} catch (Exception e) {
|
||||
_log.error("error running", e);
|
||||
throw new RuntimeException("b0rk b0rk b0rk");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
ConnectCloseTest ct = new ConnectCloseTest();
|
||||
ct.test();
|
||||
}
|
||||
}
|
@@ -0,0 +1,131 @@
|
||||
package net.i2p.client.streaming;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.client.I2PClient;
|
||||
import net.i2p.client.I2PClientFactory;
|
||||
import net.i2p.client.I2PSession;
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class ConnectInactivityTest {
|
||||
private Log _log;
|
||||
private I2PSession _client;
|
||||
private I2PSession _server;
|
||||
public void test() {
|
||||
try {
|
||||
I2PAppContext context = I2PAppContext.getGlobalContext();
|
||||
_log = context.logManager().getLog(ConnectTest.class);
|
||||
_log.debug("creating server session");
|
||||
_server = createSession();
|
||||
_log.debug("running server");
|
||||
runServer(context, _server);
|
||||
_log.debug("creating client session");
|
||||
_client = createSession();
|
||||
_log.debug("running client");
|
||||
runClient(context, _client);
|
||||
} catch (Exception e) {
|
||||
_log.error("error running", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void runClient(I2PAppContext ctx, I2PSession session) {
|
||||
Thread t = new Thread(new ClientRunner(ctx, session));
|
||||
t.setName("client");
|
||||
t.setDaemon(false);
|
||||
t.start();
|
||||
}
|
||||
|
||||
private void runServer(I2PAppContext ctx, I2PSession session) {
|
||||
Thread t = new Thread(new ServerRunner(ctx, session));
|
||||
t.setName("server");
|
||||
t.setDaemon(false);
|
||||
t.start();
|
||||
}
|
||||
|
||||
private class ServerRunner implements Runnable {
|
||||
private I2PAppContext _context;
|
||||
private I2PSession _session;
|
||||
private Log _log;
|
||||
public ServerRunner(I2PAppContext ctx, I2PSession session) {
|
||||
_context = ctx;
|
||||
_session = session;
|
||||
_log = ctx.logManager().getLog(ServerRunner.class);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
Properties opts = new Properties();
|
||||
I2PSocketManager mgr = new I2PSocketManagerFull(_context, _session, opts, "client");
|
||||
_log.debug("manager created");
|
||||
I2PServerSocket ssocket = mgr.getServerSocket();
|
||||
_log.debug("server socket created");
|
||||
I2PSocket socket = ssocket.accept();
|
||||
_log.debug("socket accepted: " + socket);
|
||||
try { Thread.sleep(10*60*1000); } catch (InterruptedException ie) {}
|
||||
socket.close();
|
||||
ssocket.close();
|
||||
_session.destroySession();
|
||||
} catch (Exception e) {
|
||||
_log.error("error running", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class ClientRunner implements Runnable {
|
||||
private I2PAppContext _context;
|
||||
private I2PSession _session;
|
||||
private Log _log;
|
||||
public ClientRunner(I2PAppContext ctx, I2PSession session) {
|
||||
_context = ctx;
|
||||
_session = session;
|
||||
_log = ctx.logManager().getLog(ClientRunner.class);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
Properties opts = new Properties();
|
||||
I2PSocketManager mgr = new I2PSocketManagerFull(_context, _session, opts, "client");
|
||||
_log.debug("manager created");
|
||||
I2PSocket socket = mgr.connect(_server.getMyDestination());
|
||||
_log.debug("socket created");
|
||||
try { Thread.sleep(10*60*1000); } catch (InterruptedException ie) {}
|
||||
socket.close();
|
||||
_log.debug("socket closed");
|
||||
//_session.destroySession();
|
||||
} catch (Exception e) {
|
||||
_log.error("error running", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private I2PSession createSession() {
|
||||
try {
|
||||
I2PClient client = I2PClientFactory.createClient();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
|
||||
Destination dest = client.createDestination(baos);
|
||||
Properties p = new Properties();
|
||||
p.setProperty(I2PClient.PROP_TCP_HOST, "localhost");
|
||||
p.setProperty(I2PClient.PROP_TCP_PORT, "10001");
|
||||
I2PSession sess = client.createSession(new ByteArrayInputStream(baos.toByteArray()), p);
|
||||
sess.connect();
|
||||
return sess;
|
||||
} catch (Exception e) {
|
||||
_log.error("error running", e);
|
||||
throw new RuntimeException("b0rk b0rk b0rk");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
ConnectInactivityTest ct = new ConnectInactivityTest();
|
||||
ct.test();
|
||||
}
|
||||
}
|
@@ -0,0 +1,132 @@
|
||||
package net.i2p.client.streaming;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.client.I2PClient;
|
||||
import net.i2p.client.I2PClientFactory;
|
||||
import net.i2p.client.I2PSession;
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class ConnectTest {
|
||||
private Log _log;
|
||||
private I2PSession _server;
|
||||
public void test() {
|
||||
try {
|
||||
I2PAppContext context = I2PAppContext.getGlobalContext();
|
||||
_log = context.logManager().getLog(ConnectTest.class);
|
||||
_log.debug("creating server session");
|
||||
_server = createSession();
|
||||
_log.debug("running server");
|
||||
runServer(context, _server);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
_log.debug("running client");
|
||||
runClient(context, createSession());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
_log.error("error running", e);
|
||||
}
|
||||
try { Thread.sleep(10*60*1000); } catch (Exception e) {}
|
||||
}
|
||||
|
||||
private void runClient(I2PAppContext ctx, I2PSession session) {
|
||||
Thread t = new Thread(new ClientRunner(ctx, session));
|
||||
t.setName("client");
|
||||
t.setDaemon(true);
|
||||
t.start();
|
||||
}
|
||||
|
||||
private void runServer(I2PAppContext ctx, I2PSession session) {
|
||||
Thread t = new Thread(new ServerRunner(ctx, session));
|
||||
t.setName("server");
|
||||
t.setDaemon(true);
|
||||
t.start();
|
||||
}
|
||||
|
||||
private class ServerRunner implements Runnable {
|
||||
private I2PAppContext _context;
|
||||
private I2PSession _session;
|
||||
private Log _log;
|
||||
public ServerRunner(I2PAppContext ctx, I2PSession session) {
|
||||
_context = ctx;
|
||||
_session = session;
|
||||
_log = ctx.logManager().getLog(ServerRunner.class);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
Properties opts = new Properties();
|
||||
I2PSocketManager mgr = new I2PSocketManagerFull(_context, _session, opts, "client");
|
||||
_log.debug("manager created");
|
||||
I2PServerSocket ssocket = mgr.getServerSocket();
|
||||
_log.debug("server socket created");
|
||||
while (true) {
|
||||
I2PSocket socket = ssocket.accept();
|
||||
_log.debug("socket accepted: " + socket);
|
||||
try { Thread.sleep(5*1000); } catch (InterruptedException ie) {}
|
||||
socket.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
_log.error("error running", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class ClientRunner implements Runnable {
|
||||
private I2PAppContext _context;
|
||||
private I2PSession _session;
|
||||
private Log _log;
|
||||
public ClientRunner(I2PAppContext ctx, I2PSession session) {
|
||||
_context = ctx;
|
||||
_session = session;
|
||||
_log = ctx.logManager().getLog(ClientRunner.class);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
Properties opts = new Properties();
|
||||
I2PSocketManager mgr = new I2PSocketManagerFull(_context, _session, opts, "client");
|
||||
_log.debug("manager created");
|
||||
I2PSocket socket = mgr.connect(_server.getMyDestination());
|
||||
_log.debug("socket created");
|
||||
try { Thread.sleep(5*1000); } catch (InterruptedException ie) {}
|
||||
socket.close();
|
||||
_log.debug("socket closed");
|
||||
mgr.destroySocketManager();
|
||||
mgr = null;
|
||||
socket = null;
|
||||
} catch (Exception e) {
|
||||
_log.error("error running", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private I2PSession createSession() {
|
||||
try {
|
||||
I2PClient client = I2PClientFactory.createClient();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
|
||||
Destination dest = client.createDestination(baos);
|
||||
I2PSession sess = client.createSession(new ByteArrayInputStream(baos.toByteArray()), System.getProperties());
|
||||
sess.connect();
|
||||
return sess;
|
||||
} catch (Exception e) {
|
||||
_log.error("error running", e);
|
||||
throw new RuntimeException("b0rk b0rk b0rk");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
System.setProperty(I2PClient.PROP_TCP_HOST, "localhost");
|
||||
System.setProperty(I2PClient.PROP_TCP_PORT, "11001");
|
||||
ConnectTest ct = new ConnectTest();
|
||||
ct.test();
|
||||
}
|
||||
}
|
@@ -0,0 +1,110 @@
|
||||
package net.i2p.client.streaming;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.client.I2PClient;
|
||||
import net.i2p.client.I2PClientFactory;
|
||||
import net.i2p.client.I2PSession;
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
* Try to connect to a new nonexistant peer and, of course,
|
||||
* timeout.
|
||||
*/
|
||||
public class ConnectTimeoutTest {
|
||||
private Log _log;
|
||||
private I2PSession _client;
|
||||
private I2PSession _server;
|
||||
private Destination _serverDest;
|
||||
|
||||
public void testNonexistant() {
|
||||
try {
|
||||
I2PAppContext context = I2PAppContext.getGlobalContext();
|
||||
_log = context.logManager().getLog(ConnectTest.class);
|
||||
_log.debug("creating server dest");
|
||||
try {
|
||||
_serverDest = I2PClientFactory.createClient().createDestination(new ByteArrayOutputStream());
|
||||
} catch (Exception e) {}
|
||||
_log.debug("creating client session");
|
||||
_client = createSession();
|
||||
_log.debug("running client");
|
||||
runClient(context, _client);
|
||||
} catch (Exception e) {
|
||||
_log.error("error running", e);
|
||||
}
|
||||
while (true) { synchronized (this) { try { wait(); } catch (Exception e) {} } }
|
||||
}
|
||||
|
||||
private void runClient(I2PAppContext ctx, I2PSession session) {
|
||||
Thread t = new Thread(new ClientRunner(ctx, session));
|
||||
t.setName("client");
|
||||
t.setDaemon(true);
|
||||
t.start();
|
||||
}
|
||||
|
||||
private class ClientRunner implements Runnable {
|
||||
private I2PAppContext _context;
|
||||
private I2PSession _session;
|
||||
private Log _log;
|
||||
public ClientRunner(I2PAppContext ctx, I2PSession session) {
|
||||
_context = ctx;
|
||||
_session = session;
|
||||
_log = ctx.logManager().getLog(ClientRunner.class);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
I2PSocketManager mgr = I2PSocketManagerFactory.createManager("localhost", 10001, getProps());
|
||||
_log.debug("manager created");
|
||||
_log.debug("options: " + mgr.getDefaultOptions());
|
||||
I2PSocket socket = mgr.connect(_serverDest);
|
||||
_log.debug("socket created");
|
||||
socket.getOutputStream().write("you smell".getBytes());
|
||||
socket.getOutputStream().flush();
|
||||
_log.error("wtf, shouldn't have flushed");
|
||||
socket.close();
|
||||
_log.debug("socket closed");
|
||||
} catch (Exception e) {
|
||||
_log.error("error running (yay!)", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private I2PSession createSession() {
|
||||
try {
|
||||
I2PClient client = I2PClientFactory.createClient();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
|
||||
Destination dest = client.createDestination(baos);
|
||||
Properties p = getProps();
|
||||
|
||||
I2PSession sess = client.createSession(new ByteArrayInputStream(baos.toByteArray()), p);
|
||||
sess.connect();
|
||||
return sess;
|
||||
} catch (Exception e) {
|
||||
_log.error("error running", e);
|
||||
throw new RuntimeException("b0rk b0rk b0rk");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
ConnectTimeoutTest ct = new ConnectTimeoutTest();
|
||||
ct.testNonexistant();
|
||||
}
|
||||
|
||||
private static Properties getProps() {
|
||||
Properties p = new Properties();
|
||||
p.setProperty(I2PSocketManagerFactory.PROP_MANAGER, I2PSocketManagerFull.class.getName());
|
||||
p.setProperty("tunnels.depthInbound", "0");
|
||||
p.setProperty(I2PClient.PROP_TCP_HOST, "localhost");
|
||||
p.setProperty(I2PClient.PROP_TCP_PORT, "10001");
|
||||
p.setProperty(ConnectionOptions.PROP_CONNECT_TIMEOUT, "30000");
|
||||
//p.setProperty(ConnectionOptions.PROP_CONNECT_DELAY, "10000");
|
||||
p.setProperty(ConnectionOptions.PROP_CONNECT_DELAY, "0");
|
||||
return p;
|
||||
}
|
||||
}
|
@@ -0,0 +1,200 @@
|
||||
package net.i2p.client.streaming;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.client.I2PClient;
|
||||
import net.i2p.client.I2PClientFactory;
|
||||
import net.i2p.client.I2PSession;
|
||||
import net.i2p.data.Base64;
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class EchoLargeTest {
|
||||
private Log _log;
|
||||
private I2PSession _client;
|
||||
private I2PSession _server;
|
||||
|
||||
public void test() {
|
||||
try {
|
||||
I2PAppContext context = I2PAppContext.getGlobalContext();
|
||||
_log = context.logManager().getLog(ConnectTest.class);
|
||||
_log.debug("creating server session");
|
||||
_server = createSession();
|
||||
_log.debug("running server");
|
||||
runServer(context, _server);
|
||||
_log.debug("creating client session");
|
||||
_client = createSession();
|
||||
_log.debug("running client");
|
||||
runClient(context, _client);
|
||||
} catch (Exception e) {
|
||||
_log.error("error running", e);
|
||||
}
|
||||
try { Thread.sleep(300*1000); } catch (Exception e) {}
|
||||
}
|
||||
|
||||
private void runClient(I2PAppContext ctx, I2PSession session) {
|
||||
Thread t = new Thread(new ClientRunner(ctx, session));
|
||||
t.setName("client");
|
||||
t.setDaemon(true);
|
||||
t.start();
|
||||
}
|
||||
|
||||
private void runServer(I2PAppContext ctx, I2PSession session) {
|
||||
Thread t = new Thread(new ServerRunner(ctx, session));
|
||||
t.setName("server");
|
||||
t.setDaemon(true);
|
||||
t.start();
|
||||
}
|
||||
|
||||
private class ServerRunner implements Runnable {
|
||||
private I2PAppContext _context;
|
||||
private I2PSession _session;
|
||||
private Log _log;
|
||||
public ServerRunner(I2PAppContext ctx, I2PSession session) {
|
||||
_context = ctx;
|
||||
_session = session;
|
||||
_log = ctx.logManager().getLog(ServerRunner.class);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
Properties opts = new Properties();
|
||||
I2PSocketManager mgr = new I2PSocketManagerFull(_context, _session, opts, "client");
|
||||
_log.debug("manager created");
|
||||
I2PServerSocket ssocket = mgr.getServerSocket();
|
||||
_log.debug("server socket created");
|
||||
while (true) {
|
||||
I2PSocket socket = ssocket.accept();
|
||||
_log.debug("socket accepted: " + socket);
|
||||
InputStream in = socket.getInputStream();
|
||||
OutputStream out = socket.getOutputStream();
|
||||
_log.debug("server streams built");
|
||||
byte buf[] = new byte[128*1024];
|
||||
while (buf != null) {
|
||||
for (int i = 0; i < buf.length; i++) {
|
||||
int c = in.read();
|
||||
if (c == -1) {
|
||||
buf = null;
|
||||
break;
|
||||
} else {
|
||||
buf[i] = (byte)(c & 0xFF);
|
||||
}
|
||||
}
|
||||
if (buf != null) {
|
||||
_log.debug("* server read the full buffer");
|
||||
out.write(buf);
|
||||
out.flush();
|
||||
}
|
||||
}
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Closing the received server socket");
|
||||
socket.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
_log.error("error running", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class ClientRunner implements Runnable {
|
||||
private I2PAppContext _context;
|
||||
private I2PSession _session;
|
||||
private Log _log;
|
||||
public ClientRunner(I2PAppContext ctx, I2PSession session) {
|
||||
_context = ctx;
|
||||
_session = session;
|
||||
_log = ctx.logManager().getLog(ClientRunner.class);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
Properties opts = new Properties();
|
||||
I2PSocketManager mgr = new I2PSocketManagerFull(_context, _session, opts, "client");
|
||||
_log.debug("manager created");
|
||||
I2PSocket socket = mgr.connect(_server.getMyDestination());
|
||||
_log.debug("socket created");
|
||||
InputStream in = socket.getInputStream();
|
||||
OutputStream out = socket.getOutputStream();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
byte buf[] = new byte[128*1024];
|
||||
_context.random().nextBytes(buf);
|
||||
byte orig[] = new byte[buf.length];
|
||||
System.arraycopy(buf, 0, orig, 0, buf.length);
|
||||
out.write(buf);
|
||||
_log.debug("client wrote a buffer");
|
||||
out.flush();
|
||||
_log.debug("client flushed");
|
||||
|
||||
byte rbuf[] = new byte[buf.length];
|
||||
for (int j = 0; j < buf.length; j++) {
|
||||
int c = in.read();
|
||||
if (c == -1) {
|
||||
buf = null;
|
||||
break;
|
||||
} else {
|
||||
//_log.debug("client read: " + ((char)c));
|
||||
if (c < 0) c += 256;
|
||||
rbuf[j] = (byte)(c & 0xFF);
|
||||
}
|
||||
}
|
||||
if (buf != null) {
|
||||
_log.debug("* client read a full buffer");
|
||||
int firstOff = -1;
|
||||
for (int k = 0; k < orig.length; k++) {
|
||||
if (orig[k] != rbuf[k]) {
|
||||
firstOff = k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (firstOff < 0) {
|
||||
System.out.println("** Read match");
|
||||
} else {
|
||||
System.out.println("** Read does not match: first off = " + firstOff);
|
||||
_log.error("read does not match (first off = " + firstOff + "): \n"
|
||||
+ Base64.encode(orig) + "\n"
|
||||
+ Base64.encode(rbuf));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Closing the client socket");
|
||||
socket.close();
|
||||
_log.debug("socket closed");
|
||||
|
||||
Thread.sleep(5*1000);
|
||||
System.exit(0);
|
||||
} catch (Exception e) {
|
||||
_log.error("error running", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private I2PSession createSession() {
|
||||
try {
|
||||
I2PClient client = I2PClientFactory.createClient();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
|
||||
Destination dest = client.createDestination(baos);
|
||||
I2PSession sess = client.createSession(new ByteArrayInputStream(baos.toByteArray()), new Properties());
|
||||
sess.connect();
|
||||
return sess;
|
||||
} catch (Exception e) {
|
||||
_log.error("error running", e);
|
||||
throw new RuntimeException("b0rk b0rk b0rk");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
EchoLargeTest et = new EchoLargeTest();
|
||||
et.test();
|
||||
}
|
||||
}
|
@@ -0,0 +1,178 @@
|
||||
package net.i2p.client.streaming;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.client.I2PClient;
|
||||
import net.i2p.client.I2PClientFactory;
|
||||
import net.i2p.client.I2PSession;
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class EchoTest {
|
||||
private Log _log;
|
||||
private I2PSession _client;
|
||||
private I2PSession _server;
|
||||
public void test() {
|
||||
try {
|
||||
I2PAppContext context = I2PAppContext.getGlobalContext();
|
||||
_log = context.logManager().getLog(ConnectTest.class);
|
||||
_log.debug("creating server session");
|
||||
_server = createSession();
|
||||
_log.debug("running server");
|
||||
runServer(context, _server);
|
||||
_log.debug("creating client session");
|
||||
_client = createSession();
|
||||
_log.debug("running client");
|
||||
runClient(context, _client);
|
||||
} catch (Exception e) {
|
||||
_log.error("error running", e);
|
||||
}
|
||||
try { Thread.sleep(300*1000); } catch (Exception e) {}
|
||||
}
|
||||
|
||||
private void runClient(I2PAppContext ctx, I2PSession session) {
|
||||
Thread t = new Thread(new ClientRunner(ctx, session));
|
||||
t.setName("client");
|
||||
t.setDaemon(true);
|
||||
t.start();
|
||||
}
|
||||
|
||||
private void runServer(I2PAppContext ctx, I2PSession session) {
|
||||
Thread t = new Thread(new ServerRunner(ctx, session));
|
||||
t.setName("server");
|
||||
t.setDaemon(true);
|
||||
t.start();
|
||||
}
|
||||
|
||||
private class ServerRunner implements Runnable {
|
||||
private I2PAppContext _context;
|
||||
private I2PSession _session;
|
||||
private Log _log;
|
||||
public ServerRunner(I2PAppContext ctx, I2PSession session) {
|
||||
_context = ctx;
|
||||
_session = session;
|
||||
_log = ctx.logManager().getLog(ServerRunner.class);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
Properties opts = new Properties();
|
||||
I2PSocketManager mgr = new I2PSocketManagerFull(_context, _session, opts, "client");
|
||||
_log.debug("manager created");
|
||||
I2PServerSocket ssocket = mgr.getServerSocket();
|
||||
_log.debug("server socket created");
|
||||
while (true) {
|
||||
I2PSocket socket = ssocket.accept();
|
||||
_log.debug("socket accepted: " + socket);
|
||||
InputStream in = socket.getInputStream();
|
||||
OutputStream out = socket.getOutputStream();
|
||||
_log.debug("server streams built");
|
||||
byte buf[] = new byte[5];
|
||||
while (buf != null) {
|
||||
for (int i = 0; i < buf.length; i++) {
|
||||
int c = in.read();
|
||||
if (c == -1) {
|
||||
buf = null;
|
||||
break;
|
||||
} else {
|
||||
buf[i] = (byte)(c & 0xFF);
|
||||
}
|
||||
}
|
||||
if (buf != null) {
|
||||
_log.debug("* server read: " + new String(buf));
|
||||
out.write(buf);
|
||||
out.flush();
|
||||
}
|
||||
}
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Closing the received server socket");
|
||||
socket.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
_log.error("error running", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class ClientRunner implements Runnable {
|
||||
private I2PAppContext _context;
|
||||
private I2PSession _session;
|
||||
private Log _log;
|
||||
public ClientRunner(I2PAppContext ctx, I2PSession session) {
|
||||
_context = ctx;
|
||||
_session = session;
|
||||
_log = ctx.logManager().getLog(ClientRunner.class);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
Properties opts = new Properties();
|
||||
I2PSocketManager mgr = new I2PSocketManagerFull(_context, _session, opts, "client");
|
||||
_log.debug("manager created");
|
||||
I2PSocket socket = mgr.connect(_server.getMyDestination());
|
||||
_log.debug("socket created");
|
||||
InputStream in = socket.getInputStream();
|
||||
OutputStream out = socket.getOutputStream();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
out.write("blah!".getBytes());
|
||||
_log.debug("client wrote a line");
|
||||
out.flush();
|
||||
_log.debug("client flushed");
|
||||
byte buf[] = new byte[5];
|
||||
|
||||
for (int j = 0; j < buf.length; j++) {
|
||||
int c = in.read();
|
||||
if (c == -1) {
|
||||
buf = null;
|
||||
break;
|
||||
} else {
|
||||
//_log.debug("client read: " + ((char)c));
|
||||
buf[j] = (byte)(c & 0xFF);
|
||||
}
|
||||
}
|
||||
if (buf != null) {
|
||||
_log.debug("* client read: " + new String(buf));
|
||||
}
|
||||
}
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Closing the client socket");
|
||||
socket.close();
|
||||
_log.debug("socket closed");
|
||||
|
||||
Thread.sleep(5*1000);
|
||||
System.exit(0);
|
||||
} catch (Exception e) {
|
||||
_log.error("error running", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private I2PSession createSession() {
|
||||
try {
|
||||
I2PClient client = I2PClientFactory.createClient();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
|
||||
Destination dest = client.createDestination(baos);
|
||||
I2PSession sess = client.createSession(new ByteArrayInputStream(baos.toByteArray()), new Properties());
|
||||
sess.connect();
|
||||
return sess;
|
||||
} catch (Exception e) {
|
||||
_log.error("error running", e);
|
||||
throw new RuntimeException("b0rk b0rk b0rk");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
EchoTest et = new EchoTest();
|
||||
et.test();
|
||||
}
|
||||
}
|
@@ -0,0 +1,164 @@
|
||||
package net.i2p.client.streaming;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.ByteArray;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
* Stress test the MessageInputStream
|
||||
*/
|
||||
public class MessageInputStreamTest {
|
||||
private I2PAppContext _context;
|
||||
private Log _log;
|
||||
|
||||
public MessageInputStreamTest() {
|
||||
_context = I2PAppContext.getGlobalContext();
|
||||
_log = _context.logManager().getLog(MessageInputStreamTest.class);
|
||||
}
|
||||
|
||||
public void testInOrder() {
|
||||
byte orig[] = new byte[256*1024];
|
||||
_context.random().nextBytes(orig);
|
||||
|
||||
MessageInputStream in = new MessageInputStream(_context);
|
||||
for (int i = 0; i < orig.length / 1024; i++) {
|
||||
byte msg[] = new byte[1024];
|
||||
System.arraycopy(orig, i*1024, msg, 0, 1024);
|
||||
in.messageReceived(i, new ByteArray(msg));
|
||||
}
|
||||
|
||||
byte read[] = new byte[orig.length];
|
||||
try {
|
||||
int howMany = DataHelper.read(in, read);
|
||||
if (howMany != orig.length)
|
||||
throw new RuntimeException("Failed test: not enough bytes read [" + howMany + "]");
|
||||
if (!DataHelper.eq(orig, read))
|
||||
throw new RuntimeException("Failed test: data read is not equal");
|
||||
|
||||
_log.info("Passed test: in order");
|
||||
} catch (IOException ioe) {
|
||||
throw new RuntimeException("IOError reading: " + ioe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testRandomOrder() {
|
||||
byte orig[] = new byte[256*1024];
|
||||
_context.random().nextBytes(orig);
|
||||
|
||||
MessageInputStream in = new MessageInputStream(_context);
|
||||
ArrayList order = new ArrayList(32);
|
||||
for (int i = 0; i < orig.length / 1024; i++)
|
||||
order.add(new Integer(i));
|
||||
Collections.shuffle(order);
|
||||
for (int i = 0; i < orig.length / 1024; i++) {
|
||||
byte msg[] = new byte[1024];
|
||||
Integer cur = (Integer)order.get(i);
|
||||
System.arraycopy(orig, cur.intValue()*1024, msg, 0, 1024);
|
||||
in.messageReceived(cur.intValue(), new ByteArray(msg));
|
||||
_log.debug("Injecting " + cur);
|
||||
}
|
||||
|
||||
byte read[] = new byte[orig.length];
|
||||
try {
|
||||
int howMany = DataHelper.read(in, read);
|
||||
if (howMany != orig.length)
|
||||
throw new RuntimeException("Failed test: not enough bytes read [" + howMany + "]");
|
||||
if (!DataHelper.eq(orig, read))
|
||||
throw new RuntimeException("Failed test: data read is not equal");
|
||||
|
||||
_log.info("Passed test: random order");
|
||||
} catch (IOException ioe) {
|
||||
throw new RuntimeException("IOError reading: " + ioe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testRandomDups() {
|
||||
byte orig[] = new byte[256*1024];
|
||||
_context.random().nextBytes(orig);
|
||||
|
||||
MessageInputStream in = new MessageInputStream(_context);
|
||||
for (int n = 0; n < 3; n++) {
|
||||
ArrayList order = new ArrayList(32);
|
||||
for (int i = 0; i < orig.length / 1024; i++)
|
||||
order.add(new Integer(i));
|
||||
Collections.shuffle(order);
|
||||
for (int i = 0; i < orig.length / 1024; i++) {
|
||||
byte msg[] = new byte[1024];
|
||||
Integer cur = (Integer)order.get(i);
|
||||
System.arraycopy(orig, cur.intValue()*1024, msg, 0, 1024);
|
||||
in.messageReceived(cur.intValue(), new ByteArray(msg));
|
||||
_log.debug("Injecting " + cur);
|
||||
}
|
||||
}
|
||||
|
||||
byte read[] = new byte[orig.length];
|
||||
try {
|
||||
int howMany = DataHelper.read(in, read);
|
||||
if (howMany != orig.length)
|
||||
throw new RuntimeException("Failed test: not enough bytes read [" + howMany + "]");
|
||||
if (!DataHelper.eq(orig, read))
|
||||
throw new RuntimeException("Failed test: data read is not equal");
|
||||
|
||||
_log.info("Passed test: random dups");
|
||||
} catch (IOException ioe) {
|
||||
throw new RuntimeException("IOError reading: " + ioe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testStaggered() {
|
||||
byte orig[] = new byte[256*1024];
|
||||
byte read[] = new byte[orig.length];
|
||||
_context.random().nextBytes(orig);
|
||||
|
||||
MessageInputStream in = new MessageInputStream(_context);
|
||||
ArrayList order = new ArrayList(32);
|
||||
for (int i = 0; i < orig.length / 1024; i++)
|
||||
order.add(new Integer(i));
|
||||
Collections.shuffle(order);
|
||||
|
||||
int offset = 0;
|
||||
for (int i = 0; i < orig.length / 1024; i++) {
|
||||
byte msg[] = new byte[1024];
|
||||
Integer cur = (Integer)order.get(i);
|
||||
System.arraycopy(orig, cur.intValue()*1024, msg, 0, 1024);
|
||||
in.messageReceived(cur.intValue(), new ByteArray(msg));
|
||||
_log.debug("Injecting " + cur);
|
||||
|
||||
try {
|
||||
if (in.available() > 0) {
|
||||
int curRead = in.read(read, offset, read.length-offset);
|
||||
_log.debug("read " + curRead);
|
||||
if (curRead == -1)
|
||||
throw new RuntimeException("EOF with offset " + offset);
|
||||
else
|
||||
offset += curRead;
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
throw new RuntimeException("IOE: " + ioe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if (!DataHelper.eq(orig, read))
|
||||
throw new RuntimeException("Failed test: data read is not equal");
|
||||
|
||||
_log.info("Passed test: staggered");
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
MessageInputStreamTest t = new MessageInputStreamTest();
|
||||
try {
|
||||
t.testInOrder();
|
||||
t.testRandomOrder();
|
||||
t.testRandomDups();
|
||||
t.testStaggered();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try { Thread.sleep(10*1000); } catch (InterruptedException ie) {}
|
||||
}
|
||||
}
|
@@ -0,0 +1,74 @@
|
||||
package net.i2p.client.streaming;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.Base64;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class MessageOutputStreamTest {
|
||||
private I2PAppContext _context;
|
||||
private Log _log;
|
||||
|
||||
public MessageOutputStreamTest() {
|
||||
_context = I2PAppContext.getGlobalContext();
|
||||
_log = _context.logManager().getLog(MessageOutputStreamTest.class);
|
||||
}
|
||||
|
||||
public void test() {
|
||||
Receiver receiver = new Receiver();
|
||||
MessageOutputStream out = new MessageOutputStream(_context, receiver);
|
||||
byte buf[] = new byte[128*1024];
|
||||
_context.random().nextBytes(buf);
|
||||
try {
|
||||
out.write(buf);
|
||||
out.flush();
|
||||
} catch (IOException ioe) { ioe.printStackTrace(); }
|
||||
byte read[] = receiver.getData();
|
||||
int firstOff = -1;
|
||||
for (int k = 0; k < buf.length; k++) {
|
||||
if (buf[k] != read[k]) {
|
||||
firstOff = k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (firstOff < 0) {
|
||||
System.out.println("** Read match");
|
||||
} else {
|
||||
System.out.println("** Read does not match: first off = " + firstOff);
|
||||
_log.error("read does not match (first off = " + firstOff + "): \n"
|
||||
+ Base64.encode(buf) + "\n"
|
||||
+ Base64.encode(read));
|
||||
}
|
||||
}
|
||||
|
||||
private class Receiver implements MessageOutputStream.DataReceiver {
|
||||
private ByteArrayOutputStream _data;
|
||||
public Receiver() {
|
||||
_data = new ByteArrayOutputStream();
|
||||
}
|
||||
public MessageOutputStream.WriteStatus writeData(byte[] buf, int off, int size) {
|
||||
_data.write(buf, off, size);
|
||||
return new DummyWriteStatus();
|
||||
}
|
||||
public boolean writeInProcess() { return false; }
|
||||
public byte[] getData() { return _data.toByteArray(); }
|
||||
}
|
||||
|
||||
private static class DummyWriteStatus implements MessageOutputStream.WriteStatus {
|
||||
public void waitForAccept(int maxWaitMs) { return; }
|
||||
public void waitForCompletion(int maxWaitMs) { return; }
|
||||
public boolean writeAccepted() { return true; }
|
||||
public boolean writeFailed() { return false; }
|
||||
public boolean writeSuccessful() { return true; }
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
MessageOutputStreamTest t = new MessageOutputStreamTest();
|
||||
t.test();
|
||||
}
|
||||
}
|
@@ -0,0 +1,56 @@
|
||||
package net.i2p.client.streaming;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.client.I2PClient;
|
||||
import net.i2p.client.I2PClientFactory;
|
||||
import net.i2p.client.I2PSession;
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class PingTest {
|
||||
public void test() {
|
||||
try {
|
||||
I2PAppContext context = I2PAppContext.getGlobalContext();
|
||||
I2PSession session = createSession();
|
||||
ConnectionManager mgr = new ConnectionManager(context, session, -1, null);
|
||||
Log log = context.logManager().getLog(PingTest.class);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
log.debug("ping " + i);
|
||||
long before = context.clock().now();
|
||||
boolean ponged = mgr.ping(session.getMyDestination(), 2*1000);
|
||||
long after = context.clock().now();
|
||||
log.debug("ponged? " + ponged + " after " + (after-before) + "ms");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try { Thread.sleep(30*1000); } catch (Exception e) {}
|
||||
|
||||
}
|
||||
|
||||
private I2PSession createSession() {
|
||||
try {
|
||||
I2PClient client = I2PClientFactory.createClient();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
|
||||
Destination dest = client.createDestination(baos);
|
||||
I2PSession sess = client.createSession(new ByteArrayInputStream(baos.toByteArray()), new Properties());
|
||||
sess.connect();
|
||||
return sess;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("b0rk b0rk b0rk");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
PingTest pt = new PingTest();
|
||||
pt.test();
|
||||
}
|
||||
}
|
@@ -0,0 +1,97 @@
|
||||
package net.i2p.client.streaming;
|
||||
|
||||
/**
|
||||
* Usage: StreamSinkTest [(old|new) [#hops [#kb]]]
|
||||
*/
|
||||
public class StreamSinkTest {
|
||||
/* private static String HOST1 = "dev.i2p.net";
|
||||
private static String HOST2 = "dev.i2p.net";
|
||||
private static String PORT1 = "4101";
|
||||
private static String PORT2 = "4501";
|
||||
/*
|
||||
private static String HOST1 = "localhost";
|
||||
private static String HOST2 = "localhost";
|
||||
private static String PORT1 = "7654";
|
||||
private static String PORT2 = "7654";
|
||||
*/
|
||||
private static String HOST1 = "localhost";
|
||||
private static String HOST2 = "localhost";
|
||||
private static String PORT1 = "10001";
|
||||
private static String PORT2 = "11001";
|
||||
/* */
|
||||
|
||||
public static void main(String args[]) {
|
||||
boolean old = false;
|
||||
int hops = 0;
|
||||
int kb = 32*1024;
|
||||
if (args.length > 0) {
|
||||
if ("old".equals(args[0]))
|
||||
old = true;
|
||||
}
|
||||
if (args.length > 1) {
|
||||
try {
|
||||
hops = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException nfe) {
|
||||
hops = 0;
|
||||
}
|
||||
}
|
||||
if (args.length > 2) {
|
||||
try {
|
||||
kb = Integer.parseInt(args[2]);
|
||||
} catch (NumberFormatException nfe) {
|
||||
kb = 32*1024;
|
||||
}
|
||||
}
|
||||
|
||||
if (!old)
|
||||
System.setProperty(I2PSocketManagerFactory.PROP_MANAGER, I2PSocketManagerFull.class.getName());
|
||||
System.setProperty("tunnels.depthInbound", ""+hops);
|
||||
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
StreamSinkServer.main(new String[] { HOST1, PORT1, "streamSinkTestDir", "streamSinkTestServer.key" });
|
||||
}
|
||||
}, "server").start();
|
||||
|
||||
try { Thread.sleep(60*1000); } catch (Exception e) {}
|
||||
|
||||
//run(256, 1);
|
||||
//run(256, 1000);
|
||||
//run(4*1024, 10);
|
||||
run(kb, 1);
|
||||
//run(1*1024, 1);
|
||||
//run("/home/jrandom/streamSinkTestDir/clientSink36766.dat", 1);
|
||||
//run(512*1024, 1);
|
||||
try { Thread.sleep(10*1000); } catch (InterruptedException e) {}
|
||||
System.out.println("Shutting down");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
private static void run(final int kb, final int msBetweenWrites) {
|
||||
Thread t = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
StreamSinkClient.main(new String[] { HOST2, PORT2, kb+"", msBetweenWrites+"", "streamSinkTestServer.key" });
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
|
||||
System.out.println("client and server started: size = " + kb + "KB, delay = " + msBetweenWrites);
|
||||
try {
|
||||
t.join();
|
||||
} catch (InterruptedException ie) {}
|
||||
}
|
||||
|
||||
private static void run(final String filename, final int msBetweenWrites) {
|
||||
Thread t = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
StreamSinkSend.main(new String[] { filename, msBetweenWrites+"", "streamSinkTestServer.key" });
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
|
||||
System.out.println("client and server started: file " + filename + ", delay = " + msBetweenWrites);
|
||||
try {
|
||||
t.join();
|
||||
} catch (InterruptedException ie) {}
|
||||
}
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
package net.i2p.client.streaming;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class StreamSinkTestClient {
|
||||
public static void main(String args[]) {
|
||||
System.setProperty(I2PSocketManagerFactory.PROP_MANAGER, I2PSocketManagerFull.class.getName());
|
||||
//System.setProperty(I2PClient.PROP_TCP_HOST, "dev.i2p.net");
|
||||
//System.setProperty(I2PClient.PROP_TCP_PORT, "4501");
|
||||
System.setProperty("tunnels.depthInbound", "0");
|
||||
|
||||
if (args.length <= 0) {
|
||||
send("/home/jrandom/libjbigi.so");
|
||||
} else {
|
||||
for (int i = 0; i < args.length; i++)
|
||||
send(args[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private static void send(final String filename) {
|
||||
Thread t = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
StreamSinkSend.main(new String[] { filename, "0", "streamSinkTestLiveServer.key" });
|
||||
}
|
||||
}, "client " + filename);
|
||||
t.start();
|
||||
try { t.join(); } catch (Exception e) {}
|
||||
System.err.println("Done sending");
|
||||
try { Thread.sleep(120*1000); } catch (Exception e) {}
|
||||
//System.exit(0);
|
||||
}
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package net.i2p.client.streaming;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class StreamSinkTestServer {
|
||||
public static void main(String args[]) {
|
||||
System.setProperty(I2PSocketManagerFactory.PROP_MANAGER, I2PSocketManagerFull.class.getName());
|
||||
//System.setProperty(I2PClient.PROP_TCP_HOST, "dev.i2p.net");
|
||||
//System.setProperty(I2PClient.PROP_TCP_PORT, "4101");
|
||||
System.setProperty("tunnels.depthInbound", "0");
|
||||
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
StreamSinkServer.main(new String[] { "streamSinkTestLiveDir", "streamSinkTestLiveServer.key" });
|
||||
}
|
||||
}, "server").start();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user