Unit tests for ConnectionWriterImpl.

This commit is contained in:
akwizgran
2012-09-06 16:38:24 +01:00
parent 164166481e
commit 67eb9d6f93
4 changed files with 119 additions and 8 deletions

View File

@@ -2,7 +2,6 @@ package net.sf.briar.transport;
import static net.sf.briar.api.transport.TransportConstants.HEADER_LENGTH;
import static net.sf.briar.api.transport.TransportConstants.MAC_LENGTH;
import static net.sf.briar.util.ByteUtils.MAX_32_BIT_UNSIGNED;
import java.io.IOException;
import java.io.OutputStream;
@@ -22,7 +21,6 @@ class ConnectionWriterImpl extends OutputStream implements ConnectionWriter {
private final int frameLength;
private int length = 0;
private long frameNumber = 0L;
ConnectionWriterImpl(FrameWriter out, int frameLength) {
this.out = out;
@@ -80,9 +78,7 @@ class ConnectionWriterImpl extends OutputStream implements ConnectionWriter {
}
private void writeFrame(boolean finalFrame) throws IOException {
if(frameNumber > MAX_32_BIT_UNSIGNED) throw new IllegalStateException();
out.writeFrame(frame, length, finalFrame);
length = 0;
frameNumber++;
}
}

View File

@@ -69,6 +69,7 @@ class OutgoingEncryptionLayer implements FrameWriter {
public void writeFrame(byte[] frame, int payloadLength, boolean finalFrame)
throws IOException {
if(frameNumber > MAX_32_BIT_UNSIGNED) throw new IllegalStateException();
// If the initiator's side of the connection is closed without writing
// any data, don't write anything to the underlying transport
if(writeTag && finalFrame && payloadLength == 0) return;