mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 06:09:55 +01:00
Extract latest Tor binary before starting Tor process. Dev task #81.
This commit is contained in:
@@ -139,9 +139,14 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
|||||||
startProcess = true;
|
startProcess = true;
|
||||||
}
|
}
|
||||||
if(startProcess) {
|
if(startProcess) {
|
||||||
// Install the binary, GeoIP database and config file if necessary
|
// Install the binary, possibly overwriting an older version
|
||||||
if(!isInstalled() && !install()) {
|
if(!installBinary()) {
|
||||||
LOG.info("Could not install Tor");
|
LOG.warning("Could not install Tor binary");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Install the GeoIP database and config file if necessary
|
||||||
|
if(!isConfigInstalled() && !installConfig()) {
|
||||||
|
LOG.info("Could not install Tor config");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
LOG.info("Starting Tor");
|
LOG.info("Starting Tor");
|
||||||
@@ -219,11 +224,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isInstalled() {
|
private boolean installBinary() {
|
||||||
return doneFile.exists();
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean install() {
|
|
||||||
InputStream in = null;
|
InputStream in = null;
|
||||||
OutputStream out = null;
|
OutputStream out = null;
|
||||||
try {
|
try {
|
||||||
@@ -231,6 +232,30 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
|||||||
in = getTorInputStream();
|
in = getTorInputStream();
|
||||||
out = new FileOutputStream(torFile);
|
out = new FileOutputStream(torFile);
|
||||||
copy(in, out);
|
copy(in, out);
|
||||||
|
// Make the Tor binary executable
|
||||||
|
if(!setExecutable(torFile)) {
|
||||||
|
LOG.warning("Could not make Tor executable");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Create a file to indicate that installation succeeded
|
||||||
|
doneFile.createNewFile();
|
||||||
|
return true;
|
||||||
|
} catch(IOException e) {
|
||||||
|
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
|
tryToClose(in);
|
||||||
|
tryToClose(out);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isConfigInstalled() {
|
||||||
|
return doneFile.exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean installConfig() {
|
||||||
|
InputStream in = null;
|
||||||
|
OutputStream out = null;
|
||||||
|
try {
|
||||||
// Unzip the GeoIP database to the filesystem
|
// Unzip the GeoIP database to the filesystem
|
||||||
in = getGeoIpInputStream();
|
in = getGeoIpInputStream();
|
||||||
out = new FileOutputStream(geoIpFile);
|
out = new FileOutputStream(geoIpFile);
|
||||||
@@ -239,11 +264,6 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
|||||||
in = getConfigInputStream();
|
in = getConfigInputStream();
|
||||||
out = new FileOutputStream(configFile);
|
out = new FileOutputStream(configFile);
|
||||||
copy(in, out);
|
copy(in, out);
|
||||||
// Make the Tor binary executable
|
|
||||||
if(!setExecutable(torFile)) {
|
|
||||||
LOG.warning("Could not make Tor executable");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Create a file to indicate that installation succeeded
|
// Create a file to indicate that installation succeeded
|
||||||
doneFile.createNewFile();
|
doneFile.createNewFile();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user