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
294a8853
Commit
294a8853
authored
10 years ago
by
akwizgran
Browse files
Options
Downloads
Patches
Plain Diff
Consider Tor to have started when it's bootstrapped and built a circuit.
parent
8dc0cf2c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
briar-android/src/org/briarproject/plugins/tor/TorPlugin.java
+18
-9
18 additions, 9 deletions
...r-android/src/org/briarproject/plugins/tor/TorPlugin.java
with
18 additions
and
9 deletions
briar-android/src/org/briarproject/plugins/tor/TorPlugin.java
+
18
−
9
View file @
294a8853
...
...
@@ -61,7 +61,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
static
final
TransportId
ID
=
new
TransportId
(
"tor"
);
private
static
final
String
[]
EVENTS
=
{
private
static
final
String
[]
EVENTS
=
{
"CIRC"
,
"ORCONN"
,
"NOTICE"
,
"WARN"
,
"ERR"
};
private
static
final
int
SOCKS_PORT
=
59050
,
CONTROL_PORT
=
59051
;
...
...
@@ -81,9 +81,10 @@ class TorPlugin implements DuplexPlugin, EventHandler {
private
final
long
maxLatency
,
pollingInterval
;
private
final
File
torDirectory
,
torFile
,
geoIpFile
,
configFile
,
doneFile
;
private
final
File
cookieFile
,
pidFile
,
hostnameFile
;
private
final
AtomicBoolean
firstCircui
t
;
private
final
AtomicBoolean
circuitBuil
t
;
private
volatile
boolean
running
=
false
,
networkEnabled
=
false
;
private
volatile
boolean
bootstrapped
=
false
;
private
volatile
Process
tor
=
null
;
private
volatile
int
pid
=
-
1
;
private
volatile
ServerSocket
socket
=
null
;
...
...
@@ -111,7 +112,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
cookieFile
=
new
File
(
torDirectory
,
".tor/control_auth_cookie"
);
pidFile
=
new
File
(
torDirectory
,
".tor/pid"
);
hostnameFile
=
new
File
(
torDirectory
,
"hostname"
);
firstCircui
t
=
new
AtomicBoolean
(
tru
e
);
circuitBuil
t
=
new
AtomicBoolean
(
fals
e
);
}
public
TransportId
getId
()
{
...
...
@@ -133,9 +134,12 @@ class TorPlugin implements DuplexPlugin, EventHandler {
controlSocket
=
new
Socket
(
"127.0.0.1"
,
CONTROL_PORT
);
LOG
.
info
(
"Tor is already running"
);
if
(
readPidFile
()
==
-
1
)
{
LOG
.
info
(
"Could not read PID of Tor process"
);
controlSocket
.
close
();
killZombieProcess
();
startProcess
=
true
;
}
else
{
bootstrapped
=
true
;
}
}
catch
(
IOException
e
)
{
LOG
.
info
(
"Tor is not running"
);
...
...
@@ -548,9 +552,9 @@ class TorPlugin implements DuplexPlugin, EventHandler {
private
void
enableNetwork
(
boolean
enable
)
throws
IOException
{
if
(!
running
)
return
;
if
(
LOG
.
isLoggable
(
INFO
))
LOG
.
info
(
"Enabling network: "
+
enable
);
if
(!
enable
)
firstCircuit
.
set
(
true
);
controlConnection
.
setConf
(
"DisableNetwork"
,
enable
?
"0"
:
"1"
);
if
(!
enable
)
circuitBuilt
.
set
(
false
);
networkEnabled
=
enable
;
controlConnection
.
setConf
(
"DisableNetwork"
,
enable
?
"0"
:
"1"
);
}
public
void
stop
()
throws
IOException
{
...
...
@@ -577,7 +581,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
}
public
boolean
isRunning
()
{
return
running
&&
networkEnabled
;
return
running
&&
networkEnabled
&&
bootstrapped
&&
circuitBuilt
.
get
()
;
}
public
boolean
shouldPoll
()
{
...
...
@@ -648,9 +652,9 @@ class TorPlugin implements DuplexPlugin, EventHandler {
if
(!
path
.
isEmpty
())
msg
+=
", path: "
+
shortenPath
(
path
);
LOG
.
info
(
msg
);
}
if
(
"BUILT"
.
equals
(
status
)
&&
firstCirc
uit
.
getAndSet
(
fals
e
))
{
if
(
status
.
equals
(
"BUILT"
)
&&
!
circuitB
ui
l
t
.
getAndSet
(
tru
e
))
{
LOG
.
info
(
"First circuit built"
);
callback
.
pollNow
();
if
(
isRunning
())
callback
.
pollNow
();
}
}
...
...
@@ -674,7 +678,11 @@ class TorPlugin implements DuplexPlugin, EventHandler {
public
void
newDescriptors
(
List
<
String
>
orList
)
{}
public
void
message
(
String
severity
,
String
msg
)
{
if
(
LOG
.
isLoggable
(
INFO
))
LOG
.
info
(
severity
+
" "
+
msg
);
if
(
LOG
.
isLoggable
(
INFO
))
LOG
.
info
(
severity
+
" "
+
msg
);
if
(
severity
.
equals
(
"NOTICE"
)
&&
msg
.
startsWith
(
"Bootstrapped 100%"
))
{
bootstrapped
=
true
;
if
(
isRunning
())
callback
.
pollNow
();
}
}
public
void
unrecognized
(
String
type
,
String
msg
)
{
...
...
@@ -690,6 +698,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
this
.
latch
=
latch
;
}
@Override
public
void
onEvent
(
int
event
,
String
path
)
{
stopWatching
();
latch
.
countDown
();
...
...
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