mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Factory and unit test for the Tor plugin; moved slow tests into their
own ant target.
This commit is contained in:
@@ -48,7 +48,8 @@ class PluginManagerImpl implements PluginManager {
|
||||
|
||||
private static final String[] DUPLEX_PLUGIN_FACTORIES = new String[] {
|
||||
"net.sf.briar.plugins.bluetooth.BluetoothPluginFactory",
|
||||
"net.sf.briar.plugins.socket.SimpleSocketPluginFactory"
|
||||
"net.sf.briar.plugins.socket.SimpleSocketPluginFactory",
|
||||
"net.sf.briar.plugins.tor.TorPluginFactory"
|
||||
};
|
||||
|
||||
private final ExecutorService pluginExecutor;
|
||||
|
||||
@@ -45,7 +45,8 @@ class TorPlugin implements DuplexPlugin {
|
||||
private final long pollingInterval;
|
||||
|
||||
private boolean running = false; // Locking: this
|
||||
private TorNetServerSocket socket = null; // Locking: this
|
||||
private NetServerSocket socket = null; // Locking: this
|
||||
private NetLayer netLayer = null; // Locking: this
|
||||
|
||||
TorPlugin(@PluginExecutor Executor pluginExecutor,
|
||||
DuplexPluginCallback callback, long pollingInterval) {
|
||||
@@ -90,13 +91,12 @@ class TorPlugin implements DuplexPlugin {
|
||||
new TorHiddenServicePortPrivateNetAddress(addr, 80);
|
||||
// Connect to Tor
|
||||
NetFactory netFactory = NetFactory.getInstance();
|
||||
NetLayer netLayer = netFactory.getNetLayerById(NetLayerIDs.TOR);
|
||||
netLayer.waitUntilReady();
|
||||
NetLayer nl = netFactory.getNetLayerById(NetLayerIDs.TOR);
|
||||
nl.waitUntilReady();
|
||||
// Publish the hidden service
|
||||
TorNetServerSocket ss;
|
||||
try {
|
||||
ss = (TorNetServerSocket) netLayer.createNetServerSocket(null,
|
||||
addrPort);
|
||||
ss = (TorNetServerSocket) nl.createNetServerSocket(null, addrPort);
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString());
|
||||
return;
|
||||
@@ -107,6 +107,7 @@ class TorPlugin implements DuplexPlugin {
|
||||
return;
|
||||
}
|
||||
socket = ss;
|
||||
netLayer = nl;
|
||||
}
|
||||
String onion = addr.getPublicOnionHostname();
|
||||
if(LOG.isLoggable(Level.INFO)) LOG.info("Listening on " + onion);
|
||||
@@ -161,6 +162,10 @@ class TorPlugin implements DuplexPlugin {
|
||||
tryToClose(socket);
|
||||
socket = null;
|
||||
}
|
||||
if(netLayer != null) {
|
||||
netLayer.clear();
|
||||
netLayer = null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean shouldPoll() {
|
||||
@@ -203,11 +208,9 @@ class TorPlugin implements DuplexPlugin {
|
||||
TransportProperties p = callback.getRemoteProperties().get(c);
|
||||
if(p == null) return null;
|
||||
String onion = p.get("onion");
|
||||
String portString = p.get("port");
|
||||
if(onion == null || portString == null) return null;
|
||||
if(onion == null) return null;
|
||||
try {
|
||||
int port = Integer.parseInt(portString);
|
||||
TcpipNetAddress addr = new TcpipNetAddress(onion, port);
|
||||
TcpipNetAddress addr = new TcpipNetAddress(onion, 80);
|
||||
NetFactory netFactory = NetFactory.getInstance();
|
||||
NetLayer netLayer = netFactory.getNetLayerById(NetLayerIDs.TOR);
|
||||
netLayer.waitUntilReady();
|
||||
|
||||
18
components/net/sf/briar/plugins/tor/TorPluginFactory.java
Normal file
18
components/net/sf/briar/plugins/tor/TorPluginFactory.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package net.sf.briar.plugins.tor;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import net.sf.briar.api.plugins.PluginExecutor;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexPlugin;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexPluginCallback;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexPluginFactory;
|
||||
|
||||
public class TorPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
private static final long POLLING_INTERVAL = 15L * 60L * 1000L; // 15 mins
|
||||
|
||||
public DuplexPlugin createPlugin(@PluginExecutor Executor pluginExecutor,
|
||||
DuplexPluginCallback callback) {
|
||||
return new TorPlugin(pluginExecutor, callback, POLLING_INTERVAL);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user