forked from I2P_Developers/i2p.i2p
Fix bug receiving datagrams on v3 sessions with UTF-8 IDs
Add test for tag options
This commit is contained in:
@@ -137,6 +137,7 @@ class SAMv3DatagramServer implements Handler {
|
|||||||
|
|
||||||
private static class MessageDispatcher implements Runnable {
|
private static class MessageDispatcher implements Runnable {
|
||||||
private final ByteArrayInputStream is;
|
private final ByteArrayInputStream is;
|
||||||
|
private static final int MAX_LINE_LENGTH = 2*1024;
|
||||||
|
|
||||||
public MessageDispatcher(byte[] buf) {
|
public MessageDispatcher(byte[] buf) {
|
||||||
this.is = new ByteArrayInputStream(buf) ;
|
this.is = new ByteArrayInputStream(buf) ;
|
||||||
@@ -144,8 +145,21 @@ class SAMv3DatagramServer implements Handler {
|
|||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
String header = DataHelper.readLine(is).trim();
|
// not UTF-8
|
||||||
|
//String header = DataHelper.readLine(is).trim();
|
||||||
// we cannot use SAMUtils.parseParams() here
|
// we cannot use SAMUtils.parseParams() here
|
||||||
|
final UTF8Reader reader = new UTF8Reader(is);
|
||||||
|
final StringBuilder buf = new StringBuilder(MAX_LINE_LENGTH);
|
||||||
|
int c;
|
||||||
|
int i = 0;
|
||||||
|
while ((c = reader.read()) != -1) {
|
||||||
|
if (++i > MAX_LINE_LENGTH)
|
||||||
|
throw new IOException("Line too long - max " + MAX_LINE_LENGTH);
|
||||||
|
if (c == '\n')
|
||||||
|
break;
|
||||||
|
buf.append((char)c);
|
||||||
|
}
|
||||||
|
String header = buf.toString();
|
||||||
StringTokenizer tok = new StringTokenizer(header, " ");
|
StringTokenizer tok = new StringTokenizer(header, " ");
|
||||||
if (tok.countTokens() < 3) {
|
if (tok.countTokens() < 3) {
|
||||||
// This is not a correct message, for sure
|
// This is not a correct message, for sure
|
||||||
|
@@ -513,6 +513,7 @@ public class SAMStreamSend {
|
|||||||
baos.write(DataHelper.getUTF8(" PROTOCOL=123 TO_PORT=5678"));
|
baos.write(DataHelper.getUTF8(" PROTOCOL=123 TO_PORT=5678"));
|
||||||
else
|
else
|
||||||
baos.write(DataHelper.getUTF8(" TO_PORT=5678"));
|
baos.write(DataHelper.getUTF8(" TO_PORT=5678"));
|
||||||
|
baos.write(DataHelper.getUTF8(" SEND_TAGS=19 TAG_THRESHOLD=13 EXPIRES=33 SEND_LEASESET=true"));
|
||||||
}
|
}
|
||||||
baos.write((byte) '\n');
|
baos.write((byte) '\n');
|
||||||
baos.write(data, 0, read);
|
baos.write(data, 0, read);
|
||||||
|
Reference in New Issue
Block a user