Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
briar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julian Dehm
briar
Commits
3b32aee6
Commit
3b32aee6
authored
13 years ago
by
akwizgran
Browse files
Options
Downloads
Patches
Plain Diff
Slightly modified ConnectionWriterImpl to write a full-size frame as
soon as possible, rather than waiting for the next write.
parent
0132c1ef
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
components/net/sf/briar/transport/ConnectionWriterImpl.java
+6
-2
6 additions, 2 deletions
components/net/sf/briar/transport/ConnectionWriterImpl.java
test/net/sf/briar/transport/ConnectionWriterImplTest.java
+17
-7
17 additions, 7 deletions
test/net/sf/briar/transport/ConnectionWriterImplTest.java
with
23 additions
and
9 deletions
components/net/sf/briar/transport/ConnectionWriterImpl.java
+
6
−
2
View file @
3b32aee6
...
...
@@ -13,6 +13,10 @@ import javax.crypto.Mac;
import
net.sf.briar.api.transport.ConnectionWriter
;
import
net.sf.briar.util.ByteUtils
;
/**
* A ConnectionWriter that buffers its input and writes a frame whenever there
* is a full-size frame to write or the flush() method is called.
*/
class
ConnectionWriterImpl
extends
FilterOutputStream
implements
ConnectionWriter
{
...
...
@@ -45,8 +49,8 @@ implements ConnectionWriter {
@Override
public
void
write
(
int
b
)
throws
IOException
{
if
(
buf
.
size
()
==
maxPayloadLength
)
writeFrame
();
buf
.
write
(
b
);
if
(
buf
.
size
()
==
maxPayloadLength
)
writeFrame
();
}
@Override
...
...
@@ -57,7 +61,7 @@ implements ConnectionWriter {
@Override
public
void
write
(
byte
[]
b
,
int
off
,
int
len
)
throws
IOException
{
int
available
=
maxPayloadLength
-
buf
.
size
();
while
(
available
<
len
)
{
while
(
available
<
=
len
)
{
buf
.
write
(
b
,
off
,
available
);
writeFrame
();
off
+=
available
;
...
...
This diff is collapsed.
Click to expand it.
test/net/sf/briar/transport/ConnectionWriterImplTest.java
+
17
−
7
View file @
3b32aee6
...
...
@@ -45,21 +45,31 @@ public class ConnectionWriterImplTest extends TransportTest {
}
@Test
public
void
test
FrameIsWrittenAtMaxLength
()
throws
Exception
{
public
void
test
WriteByteToMaxLengthWritesFrame
()
throws
Exception
{
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
ConnectionEncrypter
e
=
new
NullConnectionEncrypter
(
out
);
ConnectionWriter
w
=
new
ConnectionWriterImpl
(
e
,
mac
);
OutputStream
out1
=
w
.
getOutputStream
();
// The first maxPayloadLength bytes should be buffered
for
(
int
i
=
0
;
i
<
maxPayloadLength
;
i
++)
out1
.
write
(
0
);
// The first maxPayloadLength
- 1
bytes should be buffered
for
(
int
i
=
0
;
i
<
maxPayloadLength
-
1
;
i
++)
out1
.
write
(
0
);
assertEquals
(
0
,
out
.
size
());
// The next byte should trigger the writing of a frame
out1
.
write
(
0
);
assertEquals
(
MAX_FRAME_LENGTH
,
out
.
size
());
// Flushing the stream should write a single-byte frame
out1
.
flush
();
assertEquals
(
MAX_FRAME_LENGTH
+
headerLength
+
1
+
macLength
,
out
.
size
());
}
@Test
public
void
testWriteArrayToMaxLengthWritesFrame
()
throws
Exception
{
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
ConnectionEncrypter
e
=
new
NullConnectionEncrypter
(
out
);
ConnectionWriter
w
=
new
ConnectionWriterImpl
(
e
,
mac
);
OutputStream
out1
=
w
.
getOutputStream
();
// The first maxPayloadLength - 1 bytes should be buffered
out1
.
write
(
new
byte
[
maxPayloadLength
-
1
]);
assertEquals
(
0
,
out
.
size
());
// The next maxPayloadLength + 1 bytes should trigger two frames
out1
.
write
(
new
byte
[
maxPayloadLength
+
1
]);
assertEquals
(
MAX_FRAME_LENGTH
*
2
,
out
.
size
());
}
@Test
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment