forked from I2P_Developers/i2p.i2p
untabify
[mihi]
This commit is contained in:
@ -12,33 +12,33 @@ import java.net.*;
|
||||
public class EchoServer extends Thread {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
ServerSocket ss = new ServerSocket(Integer.parseInt(args[0]));
|
||||
while (true) {
|
||||
Socket s = ss.accept();
|
||||
new EchoServer(s);
|
||||
}
|
||||
ServerSocket ss = new ServerSocket(Integer.parseInt(args[0]));
|
||||
while (true) {
|
||||
Socket s = ss.accept();
|
||||
new EchoServer(s);
|
||||
}
|
||||
}
|
||||
|
||||
private Socket s;
|
||||
|
||||
public EchoServer(Socket s) {
|
||||
this.s=s;
|
||||
start();
|
||||
this.s=s;
|
||||
start();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
InputStream in = s.getInputStream();
|
||||
OutputStream out = s.getOutputStream();
|
||||
byte[] b = new byte[4096];
|
||||
int len;
|
||||
while ((len = in.read(b)) != -1) {
|
||||
out.write(b, 0, len);
|
||||
}
|
||||
} catch (SocketException ex) {
|
||||
// nothing
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
try {
|
||||
InputStream in = s.getInputStream();
|
||||
OutputStream out = s.getOutputStream();
|
||||
byte[] b = new byte[4096];
|
||||
int len;
|
||||
while ((len = in.read(b)) != -1) {
|
||||
out.write(b, 0, len);
|
||||
}
|
||||
} catch (SocketException ex) {
|
||||
// nothing
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,97 +10,97 @@ public class GuaranteedBug {
|
||||
|
||||
|
||||
public void reproduce() {
|
||||
try {
|
||||
Destination d1 = null;
|
||||
// first client (receiver)
|
||||
if (true) { // smaller scope for variables ...
|
||||
I2PClient client = I2PClientFactory.createClient();
|
||||
ByteArrayOutputStream keyStream =
|
||||
new ByteArrayOutputStream(512);
|
||||
d1 = client.createDestination(keyStream);
|
||||
ByteArrayInputStream in =
|
||||
new ByteArrayInputStream(keyStream.toByteArray());
|
||||
Properties opts = new Properties();
|
||||
opts.setProperty(I2PClient.PROP_RELIABILITY,
|
||||
I2PClient.PROP_RELIABILITY_GUARANTEED);
|
||||
opts.setProperty(I2PClient.PROP_TCP_HOST, "127.0.0.1");
|
||||
opts.setProperty(I2PClient.PROP_TCP_PORT, "7654");
|
||||
I2PSession session = client.createSession(in, opts);
|
||||
session.connect();
|
||||
session.setSessionListener(new PacketCounter());
|
||||
}
|
||||
// second client (sender)
|
||||
I2PClient client = I2PClientFactory.createClient();
|
||||
ByteArrayOutputStream keyStream = new ByteArrayOutputStream(512);
|
||||
Destination d2 = client.createDestination(keyStream);
|
||||
ByteArrayInputStream in =
|
||||
new ByteArrayInputStream(keyStream.toByteArray());
|
||||
Properties opts = new Properties();
|
||||
opts.setProperty(I2PClient.PROP_RELIABILITY,
|
||||
I2PClient.PROP_RELIABILITY_GUARANTEED);
|
||||
opts.setProperty(I2PClient.PROP_TCP_HOST, "127.0.0.1");
|
||||
opts.setProperty(I2PClient.PROP_TCP_PORT, "7654");
|
||||
I2PSession session = client.createSession(in, opts);
|
||||
session.connect();
|
||||
session.setSessionListener(new DummyListener());
|
||||
for (int i=0;i<1000; i++) {
|
||||
byte[] msg = (""+i).getBytes("ISO-8859-1");
|
||||
session.sendMessage(d1,msg);
|
||||
System.out.println(">>"+i);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
} catch (I2PException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
try {
|
||||
Destination d1 = null;
|
||||
// first client (receiver)
|
||||
if (true) { // smaller scope for variables ...
|
||||
I2PClient client = I2PClientFactory.createClient();
|
||||
ByteArrayOutputStream keyStream =
|
||||
new ByteArrayOutputStream(512);
|
||||
d1 = client.createDestination(keyStream);
|
||||
ByteArrayInputStream in =
|
||||
new ByteArrayInputStream(keyStream.toByteArray());
|
||||
Properties opts = new Properties();
|
||||
opts.setProperty(I2PClient.PROP_RELIABILITY,
|
||||
I2PClient.PROP_RELIABILITY_GUARANTEED);
|
||||
opts.setProperty(I2PClient.PROP_TCP_HOST, "127.0.0.1");
|
||||
opts.setProperty(I2PClient.PROP_TCP_PORT, "7654");
|
||||
I2PSession session = client.createSession(in, opts);
|
||||
session.connect();
|
||||
session.setSessionListener(new PacketCounter());
|
||||
}
|
||||
// second client (sender)
|
||||
I2PClient client = I2PClientFactory.createClient();
|
||||
ByteArrayOutputStream keyStream = new ByteArrayOutputStream(512);
|
||||
Destination d2 = client.createDestination(keyStream);
|
||||
ByteArrayInputStream in =
|
||||
new ByteArrayInputStream(keyStream.toByteArray());
|
||||
Properties opts = new Properties();
|
||||
opts.setProperty(I2PClient.PROP_RELIABILITY,
|
||||
I2PClient.PROP_RELIABILITY_GUARANTEED);
|
||||
opts.setProperty(I2PClient.PROP_TCP_HOST, "127.0.0.1");
|
||||
opts.setProperty(I2PClient.PROP_TCP_PORT, "7654");
|
||||
I2PSession session = client.createSession(in, opts);
|
||||
session.connect();
|
||||
session.setSessionListener(new DummyListener());
|
||||
for (int i=0;i<1000; i++) {
|
||||
byte[] msg = (""+i).getBytes("ISO-8859-1");
|
||||
session.sendMessage(d1,msg);
|
||||
System.out.println(">>"+i);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
} catch (I2PException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new GuaranteedBug().reproduce();
|
||||
new GuaranteedBug().reproduce();
|
||||
}
|
||||
|
||||
// -------------------------------------------------------
|
||||
public class DummyListener implements I2PSessionListener {
|
||||
public void disconnected(I2PSession session) {
|
||||
System.err.println("Disconnected: "+session);
|
||||
}
|
||||
public void disconnected(I2PSession session) {
|
||||
System.err.println("Disconnected: "+session);
|
||||
}
|
||||
|
||||
public void errorOccurred(I2PSession session, String message,
|
||||
Throwable error) {
|
||||
System.err.println("Error: "+session+"/"+message);
|
||||
error.printStackTrace();
|
||||
}
|
||||
public void errorOccurred(I2PSession session, String message,
|
||||
Throwable error) {
|
||||
System.err.println("Error: "+session+"/"+message);
|
||||
error.printStackTrace();
|
||||
}
|
||||
|
||||
public void messageAvailable(I2PSession session, int msgId,
|
||||
long size) {
|
||||
System.err.println("Message here? "+session);
|
||||
}
|
||||
public void messageAvailable(I2PSession session, int msgId,
|
||||
long size) {
|
||||
System.err.println("Message here? "+session);
|
||||
}
|
||||
|
||||
public void reportAbuse(I2PSession session, int severity) {
|
||||
System.err.println("Abuse: "+severity+"/"+session);
|
||||
}
|
||||
public void reportAbuse(I2PSession session, int severity) {
|
||||
System.err.println("Abuse: "+severity+"/"+session);
|
||||
}
|
||||
}
|
||||
|
||||
public class PacketCounter extends DummyListener {
|
||||
private int lastPacket = -1;
|
||||
public void messageAvailable(I2PSession session, int msgId,
|
||||
long size) {
|
||||
try {
|
||||
byte msg[] = session.receiveMessage(msgId);
|
||||
String m = new String(msg, "ISO-8859-1");
|
||||
int no = Integer.parseInt(m);
|
||||
if (no != ++lastPacket) {
|
||||
System.out.println("ERROR: <<"+no);
|
||||
} else {
|
||||
System.out.println("<<"+no);
|
||||
}
|
||||
} catch (NumberFormatException ex) {
|
||||
ex.printStackTrace();
|
||||
} catch (I2PException ex) {
|
||||
ex.printStackTrace();
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
private int lastPacket = -1;
|
||||
public void messageAvailable(I2PSession session, int msgId,
|
||||
long size) {
|
||||
try {
|
||||
byte msg[] = session.receiveMessage(msgId);
|
||||
String m = new String(msg, "ISO-8859-1");
|
||||
int no = Integer.parseInt(m);
|
||||
if (no != ++lastPacket) {
|
||||
System.out.println("ERROR: <<"+no);
|
||||
} else {
|
||||
System.out.println("<<"+no);
|
||||
}
|
||||
} catch (NumberFormatException ex) {
|
||||
ex.printStackTrace();
|
||||
} catch (I2PException ex) {
|
||||
ex.printStackTrace();
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ public class EchoTester extends Thread {
|
||||
}
|
||||
} catch (InterruptedException ex) {
|
||||
ex.printStackTrace();
|
||||
System.exit(1); // treat these errors as fatal
|
||||
System.exit(1); // treat these errors as fatal
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
System.exit(1); // treat these errors as fatal
|
||||
|
Reference in New Issue
Block a user