Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
interferometer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
akwizgran
interferometer
Commits
37112a72
Commit
37112a72
authored
Jan 30, 2020
by
akwizgran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test for a fixed duration rather than fixed amount of traffic.
parent
344cfac8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
14 deletions
+17
-14
app/src/main/java/org/briarproject/interferometer/MainViewModel.java
...n/java/org/briarproject/interferometer/MainViewModel.java
+17
-14
No files found.
app/src/main/java/org/briarproject/interferometer/MainViewModel.java
View file @
37112a72
...
...
@@ -59,7 +59,7 @@ public class MainViewModel extends AndroidViewModel {
private
static
final
int
BUFFER_SIZE
=
4096
;
private
static
final
int
MS_PER_UPDATE
=
250
;
private
static
final
int
BYTES_TO_TRANSFER
=
10_000
_000
;
private
static
final
int
MS_PER_TRANSFER
=
5
_000
;
private
static
final
int
TRANSFERS_PER_CONDITION
=
10
;
private
static
final
String
TAG
=
"Interferometer"
;
...
...
@@ -121,7 +121,7 @@ public class MainViewModel extends AndroidViewModel {
Future
<?>
discoveryTask
=
startDiscovery
(
adapter
);
try
{
testPhase
.
postValue
(
DISCOVERY
);
Log
.
i
(
TAG
,
"Testing throughput with Bluetooth
enabled
"
);
Log
.
i
(
TAG
,
"Testing throughput with Bluetooth
discovery
"
);
List
<
Long
>
downloadDiscovery
=
new
ArrayList
<>();
List
<
Long
>
uploadDiscovery
=
new
ArrayList
<>();
if
(!
testThroughput
(
hostPort
,
downloadDiscovery
,
uploadDiscovery
))
return
;
...
...
@@ -265,24 +265,26 @@ public class MainViewModel extends AndroidViewModel {
Log
.
i
(
TAG
,
"Connected, requesting upload"
);
OutputStream
out
=
s
.
getOutputStream
();
out
.
write
(
CONNECTION_TYPE_UPLOAD
);
out
.
flush
();
byte
[]
buf
=
new
byte
[
BUFFER_SIZE
];
new
Random
().
nextBytes
(
buf
);
long
start
=
System
.
nanoTime
();
long
now
=
start
;
long
end
=
start
+
MS_PER_TRANSFER
*
1_000_000L
;
long
lastUpdate
=
0
;
int
bytesSinceLastUpdate
=
0
;
int
bytesTotal
=
0
;
while
(
bytesTotal
<
BYTES_TO_TRANSFER
)
{
int
len
=
Math
.
min
(
BUFFER_SIZE
,
BYTES_TO_TRANSFER
-
bytesTotal
);
out
.
write
(
buf
,
0
,
len
);
while
(
now
<
end
)
{
out
.
write
(
buf
);
if
(
Thread
.
currentThread
().
isInterrupted
())
{
Log
.
i
(
TAG
,
"Upload to "
+
hostPort
+
" interrupted"
);
return
-
1
;
}
bytesSinceLastUpdate
+=
len
;
bytesTotal
+=
len
;
long
now
=
System
.
nanoTime
();
bytesSinceLastUpdate
+=
BUFFER_SIZE
;
bytesTotal
+=
BUFFER_SIZE
;
now
=
System
.
nanoTime
();
long
msSinceLastUpdate
=
(
now
-
lastUpdate
)
/
1_000_000
;
if
(
msSinceLastUpdate
>=
MS_PER_UPDATE
)
{
long
bytesPerSecond
=
bytesSinceLastUpdate
*
1000L
/
msSinceLastUpdate
;
...
...
@@ -292,7 +294,6 @@ public class MainViewModel extends AndroidViewModel {
}
}
Log
.
i
(
TAG
,
"Upload to "
+
hostPort
+
" finished"
);
long
now
=
System
.
nanoTime
();
long
msSinceStart
=
(
now
-
start
)
/
1_000_000
;
return
bytesTotal
*
1000L
/
msSinceStart
;
}
catch
(
IOException
e
)
{
...
...
@@ -315,17 +316,19 @@ public class MainViewModel extends AndroidViewModel {
Log
.
i
(
TAG
,
"Connected, requesting download"
);
OutputStream
out
=
s
.
getOutputStream
();
out
.
write
(
CONNECTION_TYPE_DOWNLOAD
);
out
.
flush
();
InputStream
in
=
s
.
getInputStream
();
byte
[]
buf
=
new
byte
[
BUFFER_SIZE
];
long
start
=
System
.
nanoTime
();
long
now
=
start
;
long
end
=
start
+
MS_PER_TRANSFER
*
1_000_000L
;
long
lastUpdate
=
0
;
int
bytesSinceLastUpdate
=
0
;
int
bytesTotal
=
0
;
while
(
bytesTotal
<
BYTES_TO_TRANSFER
)
{
int
len
=
Math
.
min
(
BUFFER_SIZE
,
BYTES_TO_TRANSFER
-
bytesTotal
);
int
read
=
in
.
read
(
buf
,
0
,
len
);
while
(
now
<
end
)
{
int
read
=
in
.
read
(
buf
);
if
(
read
==
-
1
)
{
Log
.
w
(
TAG
,
"Download from "
+
hostPort
+
" finished early"
);
return
-
1
;
...
...
@@ -336,7 +339,7 @@ public class MainViewModel extends AndroidViewModel {
}
bytesSinceLastUpdate
+=
read
;
bytesTotal
+=
read
;
long
now
=
System
.
nanoTime
();
now
=
System
.
nanoTime
();
long
msSinceLastUpdate
=
(
now
-
lastUpdate
)
/
1_000_000
;
if
(
msSinceLastUpdate
>=
MS_PER_UPDATE
)
{
long
bytesPerSecond
=
bytesSinceLastUpdate
*
1000L
/
msSinceLastUpdate
;
...
...
@@ -346,7 +349,7 @@ public class MainViewModel extends AndroidViewModel {
}
}
Log
.
i
(
TAG
,
"Download from "
+
hostPort
+
" finished"
);
long
now
=
System
.
nanoTime
();
now
=
System
.
nanoTime
();
long
msSinceStart
=
(
now
-
start
)
/
1_000_000
;
return
bytesTotal
*
1000L
/
msSinceStart
;
}
catch
(
IOException
e
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment