Distinguish between recoverable and unrecoverable errors.

This commit is contained in:
akwizgran
2012-01-19 19:27:04 +00:00
parent 7eaa1f176f
commit 1f39bfef78
11 changed files with 73 additions and 34 deletions

View File

@@ -35,7 +35,8 @@ public class ConnectionReaderImplTest extends TransportTest {
IncomingEncryptionLayer decrypter = new NullIncomingEncryptionLayer(in);
IncomingErrorCorrectionLayer correcter =
new NullIncomingErrorCorrectionLayer(decrypter);
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey);
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey,
false);
// There should be no bytes available before EOF
assertEquals(-1, r.getInputStream().read());
}
@@ -55,7 +56,8 @@ public class ConnectionReaderImplTest extends TransportTest {
IncomingEncryptionLayer decrypter = new NullIncomingEncryptionLayer(in);
IncomingErrorCorrectionLayer correcter =
new NullIncomingErrorCorrectionLayer(decrypter);
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey);
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey,
false);
// There should be one byte available before EOF
assertEquals(0, r.getInputStream().read());
assertEquals(-1, r.getInputStream().read());
@@ -83,7 +85,8 @@ public class ConnectionReaderImplTest extends TransportTest {
IncomingEncryptionLayer decrypter = new NullIncomingEncryptionLayer(in);
IncomingErrorCorrectionLayer correcter =
new NullIncomingErrorCorrectionLayer(decrypter);
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey);
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey,
false);
byte[] read = new byte[MAX_PAYLOAD_LENGTH];
TestUtils.readFully(r.getInputStream(), read);
// Try to read the second frame
@@ -119,7 +122,8 @@ public class ConnectionReaderImplTest extends TransportTest {
IncomingEncryptionLayer decrypter = new NullIncomingEncryptionLayer(in);
IncomingErrorCorrectionLayer correcter =
new NullIncomingErrorCorrectionLayer(decrypter);
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey);
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey,
false);
byte[] read = new byte[MAX_PAYLOAD_LENGTH - paddingLength];
TestUtils.readFully(r.getInputStream(), read);
// Try to read the second frame
@@ -147,7 +151,8 @@ public class ConnectionReaderImplTest extends TransportTest {
IncomingEncryptionLayer decrypter = new NullIncomingEncryptionLayer(in);
IncomingErrorCorrectionLayer correcter =
new NullIncomingErrorCorrectionLayer(decrypter);
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey);
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey,
false);
// The non-zero padding should be rejected
try {
r.getInputStream().read();
@@ -181,7 +186,8 @@ public class ConnectionReaderImplTest extends TransportTest {
IncomingEncryptionLayer decrypter = new NullIncomingEncryptionLayer(in);
IncomingErrorCorrectionLayer correcter =
new NullIncomingErrorCorrectionLayer(decrypter);
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey);
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey,
false);
byte[] read = new byte[payloadLength];
TestUtils.readFully(r.getInputStream(), read);
assertArrayEquals(new byte[payloadLength], read);
@@ -207,7 +213,8 @@ public class ConnectionReaderImplTest extends TransportTest {
IncomingEncryptionLayer decrypter = new NullIncomingEncryptionLayer(in);
IncomingErrorCorrectionLayer correcter =
new NullIncomingErrorCorrectionLayer(decrypter);
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey);
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey,
false);
try {
r.getInputStream().read();
fail();
@@ -231,7 +238,8 @@ public class ConnectionReaderImplTest extends TransportTest {
IncomingEncryptionLayer decrypter = new NullIncomingEncryptionLayer(in);
IncomingErrorCorrectionLayer correcter =
new NullIncomingErrorCorrectionLayer(decrypter);
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey);
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey,
false);
try {
r.getInputStream().read();
fail();

View File

@@ -98,7 +98,7 @@ public class FrameReadWriteTest extends BriarTestCase {
IncomingErrorCorrectionLayer correcter1 =
new NullIncomingErrorCorrectionLayer(decrypter);
ConnectionReader reader = new ConnectionReaderImpl(correcter1, mac,
macKey);
macKey, false);
InputStream in1 = reader.getInputStream();
byte[] recovered = new byte[frame.length];
int offset = 0;

View File

@@ -39,7 +39,7 @@ class NullIncomingEncryptionLayer implements IncomingEncryptionLayer {
int padding = HeaderEncoder.getPaddingLength(buf);
length = FRAME_HEADER_LENGTH + payload + padding + MAC_LENGTH;
if(length > MAX_FRAME_LENGTH) throw new FormatException();
// Read the remainder of the frame/segment
// Read the remainder of the frame
while(offset < length) {
int read = in.read(buf, offset, length - offset);
if(read == -1) throw new EOFException();