[mihi]
This commit is contained in:
mihi
2004-04-14 23:26:59 +00:00
committed by zzz
parent 7b03c95cfd
commit 24c69a26ea
3 changed files with 100 additions and 100 deletions

View File

@ -12,33 +12,33 @@ import java.net.*;
public class EchoServer extends Thread { public class EchoServer extends Thread {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
ServerSocket ss = new ServerSocket(Integer.parseInt(args[0])); ServerSocket ss = new ServerSocket(Integer.parseInt(args[0]));
while (true) { while (true) {
Socket s = ss.accept(); Socket s = ss.accept();
new EchoServer(s); new EchoServer(s);
} }
} }
private Socket s; private Socket s;
public EchoServer(Socket s) { public EchoServer(Socket s) {
this.s=s; this.s=s;
start(); start();
} }
public void run() { public void run() {
try { try {
InputStream in = s.getInputStream(); InputStream in = s.getInputStream();
OutputStream out = s.getOutputStream(); OutputStream out = s.getOutputStream();
byte[] b = new byte[4096]; byte[] b = new byte[4096];
int len; int len;
while ((len = in.read(b)) != -1) { while ((len = in.read(b)) != -1) {
out.write(b, 0, len); out.write(b, 0, len);
} }
} catch (SocketException ex) { } catch (SocketException ex) {
// nothing // nothing
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
} }

View File

@ -10,97 +10,97 @@ public class GuaranteedBug {
public void reproduce() { public void reproduce() {
try { try {
Destination d1 = null; Destination d1 = null;
// first client (receiver) // first client (receiver)
if (true) { // smaller scope for variables ... if (true) { // smaller scope for variables ...
I2PClient client = I2PClientFactory.createClient(); I2PClient client = I2PClientFactory.createClient();
ByteArrayOutputStream keyStream = ByteArrayOutputStream keyStream =
new ByteArrayOutputStream(512); new ByteArrayOutputStream(512);
d1 = client.createDestination(keyStream); d1 = client.createDestination(keyStream);
ByteArrayInputStream in = ByteArrayInputStream in =
new ByteArrayInputStream(keyStream.toByteArray()); new ByteArrayInputStream(keyStream.toByteArray());
Properties opts = new Properties(); Properties opts = new Properties();
opts.setProperty(I2PClient.PROP_RELIABILITY, opts.setProperty(I2PClient.PROP_RELIABILITY,
I2PClient.PROP_RELIABILITY_GUARANTEED); I2PClient.PROP_RELIABILITY_GUARANTEED);
opts.setProperty(I2PClient.PROP_TCP_HOST, "127.0.0.1"); opts.setProperty(I2PClient.PROP_TCP_HOST, "127.0.0.1");
opts.setProperty(I2PClient.PROP_TCP_PORT, "7654"); opts.setProperty(I2PClient.PROP_TCP_PORT, "7654");
I2PSession session = client.createSession(in, opts); I2PSession session = client.createSession(in, opts);
session.connect(); session.connect();
session.setSessionListener(new PacketCounter()); session.setSessionListener(new PacketCounter());
} }
// second client (sender) // second client (sender)
I2PClient client = I2PClientFactory.createClient(); I2PClient client = I2PClientFactory.createClient();
ByteArrayOutputStream keyStream = new ByteArrayOutputStream(512); ByteArrayOutputStream keyStream = new ByteArrayOutputStream(512);
Destination d2 = client.createDestination(keyStream); Destination d2 = client.createDestination(keyStream);
ByteArrayInputStream in = ByteArrayInputStream in =
new ByteArrayInputStream(keyStream.toByteArray()); new ByteArrayInputStream(keyStream.toByteArray());
Properties opts = new Properties(); Properties opts = new Properties();
opts.setProperty(I2PClient.PROP_RELIABILITY, opts.setProperty(I2PClient.PROP_RELIABILITY,
I2PClient.PROP_RELIABILITY_GUARANTEED); I2PClient.PROP_RELIABILITY_GUARANTEED);
opts.setProperty(I2PClient.PROP_TCP_HOST, "127.0.0.1"); opts.setProperty(I2PClient.PROP_TCP_HOST, "127.0.0.1");
opts.setProperty(I2PClient.PROP_TCP_PORT, "7654"); opts.setProperty(I2PClient.PROP_TCP_PORT, "7654");
I2PSession session = client.createSession(in, opts); I2PSession session = client.createSession(in, opts);
session.connect(); session.connect();
session.setSessionListener(new DummyListener()); session.setSessionListener(new DummyListener());
for (int i=0;i<1000; i++) { for (int i=0;i<1000; i++) {
byte[] msg = (""+i).getBytes("ISO-8859-1"); byte[] msg = (""+i).getBytes("ISO-8859-1");
session.sendMessage(d1,msg); session.sendMessage(d1,msg);
System.out.println(">>"+i); System.out.println(">>"+i);
} }
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); ex.printStackTrace();
} catch (I2PException ex) { } catch (I2PException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
public static void main(String[] args) { public static void main(String[] args) {
new GuaranteedBug().reproduce(); new GuaranteedBug().reproduce();
} }
// ------------------------------------------------------- // -------------------------------------------------------
public class DummyListener implements I2PSessionListener { public class DummyListener implements I2PSessionListener {
public void disconnected(I2PSession session) { public void disconnected(I2PSession session) {
System.err.println("Disconnected: "+session); System.err.println("Disconnected: "+session);
} }
public void errorOccurred(I2PSession session, String message, public void errorOccurred(I2PSession session, String message,
Throwable error) { Throwable error) {
System.err.println("Error: "+session+"/"+message); System.err.println("Error: "+session+"/"+message);
error.printStackTrace(); error.printStackTrace();
} }
public void messageAvailable(I2PSession session, int msgId, public void messageAvailable(I2PSession session, int msgId,
long size) { long size) {
System.err.println("Message here? "+session); System.err.println("Message here? "+session);
} }
public void reportAbuse(I2PSession session, int severity) { public void reportAbuse(I2PSession session, int severity) {
System.err.println("Abuse: "+severity+"/"+session); System.err.println("Abuse: "+severity+"/"+session);
} }
} }
public class PacketCounter extends DummyListener { public class PacketCounter extends DummyListener {
private int lastPacket = -1; private int lastPacket = -1;
public void messageAvailable(I2PSession session, int msgId, public void messageAvailable(I2PSession session, int msgId,
long size) { long size) {
try { try {
byte msg[] = session.receiveMessage(msgId); byte msg[] = session.receiveMessage(msgId);
String m = new String(msg, "ISO-8859-1"); String m = new String(msg, "ISO-8859-1");
int no = Integer.parseInt(m); int no = Integer.parseInt(m);
if (no != ++lastPacket) { if (no != ++lastPacket) {
System.out.println("ERROR: <<"+no); System.out.println("ERROR: <<"+no);
} else { } else {
System.out.println("<<"+no); System.out.println("<<"+no);
} }
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
ex.printStackTrace(); ex.printStackTrace();
} catch (I2PException ex) { } catch (I2PException ex) {
ex.printStackTrace(); ex.printStackTrace();
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
} }
} }