mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 05:39:53 +01:00
Write the tag immediately even if there are no packets to send. Bug #27.
This commit is contained in:
@@ -223,6 +223,8 @@ abstract class DuplexConnection implements EventListener {
|
|||||||
OutputStream out = createConnectionWriter().getOutputStream();
|
OutputStream out = createConnectionWriter().getOutputStream();
|
||||||
writer = packetWriterFactory.createPacketWriter(out, true);
|
writer = packetWriterFactory.createPacketWriter(out, true);
|
||||||
LOG.info("Starting to write");
|
LOG.info("Starting to write");
|
||||||
|
// Ensure the tag is sent
|
||||||
|
out.flush();
|
||||||
// Send the initial packets
|
// Send the initial packets
|
||||||
dbExecutor.execute(new GenerateTransportAcks());
|
dbExecutor.execute(new GenerateTransportAcks());
|
||||||
dbExecutor.execute(new GenerateTransportUpdates());
|
dbExecutor.execute(new GenerateTransportUpdates());
|
||||||
|
|||||||
@@ -63,9 +63,6 @@ class OutgoingEncryptionLayer implements FrameWriter {
|
|||||||
public void writeFrame(byte[] frame, int payloadLength, boolean finalFrame)
|
public void writeFrame(byte[] frame, int payloadLength, boolean finalFrame)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
if(frameNumber > MAX_32_BIT_UNSIGNED) throw new IllegalStateException();
|
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;
|
|
||||||
// Write the tag if required
|
// Write the tag if required
|
||||||
if(writeTag) {
|
if(writeTag) {
|
||||||
try {
|
try {
|
||||||
@@ -115,6 +112,17 @@ class OutgoingEncryptionLayer implements FrameWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void flush() throws IOException {
|
public void flush() throws IOException {
|
||||||
|
// Write the tag if required
|
||||||
|
if(writeTag) {
|
||||||
|
try {
|
||||||
|
out.write(tag, 0, tag.length);
|
||||||
|
} catch(IOException e) {
|
||||||
|
frameKey.erase();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
capacity -= tag.length;
|
||||||
|
writeTag = false;
|
||||||
|
}
|
||||||
out.flush();
|
out.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -140,8 +140,8 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
|
|||||||
will(returnValue(null));
|
will(returnValue(null));
|
||||||
}});
|
}});
|
||||||
connection.write();
|
connection.write();
|
||||||
// Nothing should have been written
|
// Only the tag and an empty final frame should have been written
|
||||||
assertEquals(0, out.size());
|
assertEquals(TAG_LENGTH + HEADER_LENGTH + MAC_LENGTH, out.size());
|
||||||
// The transport should have been disposed with exception == false
|
// The transport should have been disposed with exception == false
|
||||||
assertTrue(transport.getDisposed());
|
assertTrue(transport.getDisposed());
|
||||||
assertFalse(transport.getException());
|
assertFalse(transport.getException());
|
||||||
|
|||||||
@@ -75,8 +75,8 @@ public class OutgoingEncryptionLayerTest extends BriarTestCase {
|
|||||||
FRAME_LENGTH, tag);
|
FRAME_LENGTH, tag);
|
||||||
// Write an empty final frame without having written any other frames
|
// Write an empty final frame without having written any other frames
|
||||||
o.writeFrame(new byte[FRAME_LENGTH - MAC_LENGTH], 0, true);
|
o.writeFrame(new byte[FRAME_LENGTH - MAC_LENGTH], 0, true);
|
||||||
// Nothing should be written to the output stream
|
// The tag and the empty frame should be written to the output stream
|
||||||
assertEquals(0, out.size());
|
assertEquals(TAG_LENGTH + HEADER_LENGTH + MAC_LENGTH, out.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user