mirror of
https://github.com/bisq-network/bisq.git
synced 2025-03-12 02:08:11 +01:00
TorHiddenServiceStartupTime Metric available
This commit is contained in:
parent
295cb6c2b8
commit
d46813c866
5 changed files with 197 additions and 0 deletions
|
@ -330,6 +330,9 @@ configure(project(':monitor')) {
|
||||||
compile('com.github.JesusMcCloud.netlayer:tor.native:0.6.2') {
|
compile('com.github.JesusMcCloud.netlayer:tor.native:0.6.2') {
|
||||||
exclude(module: 'slf4j-api')
|
exclude(module: 'slf4j-api')
|
||||||
}
|
}
|
||||||
|
compile('com.github.JesusMcCloud.netlayer:tor.external:0.6') {
|
||||||
|
exclude(module: 'slf4j-api')
|
||||||
|
}
|
||||||
|
|
||||||
testCompile 'org.junit.jupiter:junit-jupiter-api:5.3.2'
|
testCompile 'org.junit.jupiter:junit-jupiter-api:5.3.2'
|
||||||
testCompile 'org.junit.jupiter:junit-jupiter-params:5.3.2'
|
testCompile 'org.junit.jupiter:junit-jupiter-params:5.3.2'
|
||||||
|
|
|
@ -29,6 +29,7 @@ import org.berndpruenster.netlayer.tor.Tor;
|
||||||
import bisq.monitor.metric.TorStartupTime;
|
import bisq.monitor.metric.TorStartupTime;
|
||||||
import bisq.monitor.metric.Metric;
|
import bisq.monitor.metric.Metric;
|
||||||
import bisq.monitor.metric.TorRoundtripTime;
|
import bisq.monitor.metric.TorRoundtripTime;
|
||||||
|
import bisq.monitor.metric.TorHiddenServiceStartupTime;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import sun.misc.Signal;
|
import sun.misc.Signal;
|
||||||
|
|
||||||
|
@ -64,6 +65,7 @@ public class Monitor {
|
||||||
// assemble Metrics
|
// assemble Metrics
|
||||||
metrics.add(new TorStartupTime());
|
metrics.add(new TorStartupTime());
|
||||||
metrics.add(new TorRoundtripTime());
|
metrics.add(new TorRoundtripTime());
|
||||||
|
metrics.add(new TorHiddenServiceStartupTime());
|
||||||
|
|
||||||
// configure Metrics
|
// configure Metrics
|
||||||
Properties properties = getProperties();
|
Properties properties = getProperties();
|
||||||
|
|
|
@ -0,0 +1,95 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Bisq.
|
||||||
|
*
|
||||||
|
* Bisq is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Bisq is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||||
|
* License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package bisq.monitor.metric;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.berndpruenster.netlayer.tor.HiddenServiceSocket;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Metric to measure the startup time of a Tor Hidden Service on a already
|
||||||
|
* running Tor.
|
||||||
|
*
|
||||||
|
* @author Florian Reimair
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class TorHiddenServiceStartupTime extends Metric {
|
||||||
|
|
||||||
|
private static final String SERVICE_PORT = "run.servicePort";
|
||||||
|
private static final String LOCAL_PORT = "run.localPort";
|
||||||
|
private final String hiddenServiceDirectory = "metric_" + getName();
|
||||||
|
|
||||||
|
public TorHiddenServiceStartupTime() throws IOException {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* synchronization helper. Required because directly closing the
|
||||||
|
* HiddenServiceSocket in its ReadyListener causes a deadlock
|
||||||
|
*/
|
||||||
|
private void await() {
|
||||||
|
synchronized (hiddenServiceDirectory) {
|
||||||
|
try {
|
||||||
|
hiddenServiceDirectory.wait();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void proceed() {
|
||||||
|
synchronized (hiddenServiceDirectory) {
|
||||||
|
hiddenServiceDirectory.notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void execute() {
|
||||||
|
// prepare settings. Fetch them everytime we run the Metric so we do not have to
|
||||||
|
// restart on a config update
|
||||||
|
int localPort = Integer.parseInt(configuration.getProperty(LOCAL_PORT, "9998"));
|
||||||
|
int servicePort = Integer.parseInt(configuration.getProperty(SERVICE_PORT, "9999"));
|
||||||
|
|
||||||
|
// clear directory so we get a new onion address everytime
|
||||||
|
new File(hiddenServiceDirectory).delete();
|
||||||
|
|
||||||
|
log.debug("creating the hidden service");
|
||||||
|
// start timer - we do not need System.nanoTime as we expect our result to be in
|
||||||
|
// the range of tenth of seconds.
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
|
||||||
|
HiddenServiceSocket hiddenServiceSocket = new HiddenServiceSocket(localPort, hiddenServiceDirectory,
|
||||||
|
servicePort);
|
||||||
|
hiddenServiceSocket.addReadyListener(socket -> {
|
||||||
|
// stop the timer and report
|
||||||
|
report(System.currentTimeMillis() - start);
|
||||||
|
log.debug("the hidden service is ready");
|
||||||
|
proceed();
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
await();
|
||||||
|
log.debug("going to unpublish the hidden service...");
|
||||||
|
hiddenServiceSocket.close();
|
||||||
|
log.debug("[going to unpublish the hidden service...] done");
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,5 +18,11 @@ TorRoundtripTime.run.sampleSize=3
|
||||||
# torproject.org hidden service
|
# torproject.org hidden service
|
||||||
TorRoundtripTime.run.hosts=http://expyuzz4wqqyqhjn.onion:80
|
TorRoundtripTime.run.hosts=http://expyuzz4wqqyqhjn.onion:80
|
||||||
|
|
||||||
|
#TorHiddenServiceStartupTime Metric
|
||||||
|
TorHiddenServiceStartupTime.enabled=true
|
||||||
|
TorHiddenServiceStartupTime.run.interval=2
|
||||||
|
TorHiddenServiceStartupTime.run.localPort=90501
|
||||||
|
TorHiddenServiceStartupTime.run.servicePort=90511
|
||||||
|
|
||||||
#Another Metric
|
#Another Metric
|
||||||
Another.run.interval=5
|
Another.run.interval=5
|
|
@ -0,0 +1,91 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Bisq.
|
||||||
|
*
|
||||||
|
* Bisq is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Bisq is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||||
|
* License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package bisq.monitor;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.berndpruenster.netlayer.tor.NativeTor;
|
||||||
|
import org.berndpruenster.netlayer.tor.Tor;
|
||||||
|
import org.berndpruenster.netlayer.tor.TorCtlException;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.jupiter.api.AfterAll;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import bisq.monitor.metric.TorHiddenServiceStartupTime;
|
||||||
|
|
||||||
|
public class TorHiddenServiceStartupTimeTests {
|
||||||
|
|
||||||
|
private class Dut extends TorHiddenServiceStartupTime {
|
||||||
|
|
||||||
|
private long result;
|
||||||
|
|
||||||
|
public Dut() throws IOException {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void report(long value) {
|
||||||
|
super.report(value);
|
||||||
|
|
||||||
|
result = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long results() {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final static File torWorkingDirectory = new File(TorHiddenServiceStartupTimeTests.class.getSimpleName());
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
public static void setup() throws TorCtlException {
|
||||||
|
Tor.setDefault(new NativeTor(torWorkingDirectory));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void run() throws Exception {
|
||||||
|
|
||||||
|
// configure
|
||||||
|
Properties configuration = new Properties();
|
||||||
|
configuration.put("Dut.enabled", "true");
|
||||||
|
configuration.put("Dut.run.interval", "5");
|
||||||
|
|
||||||
|
Dut DUT = new Dut();
|
||||||
|
DUT.configure(configuration);
|
||||||
|
|
||||||
|
// start
|
||||||
|
DUT.start();
|
||||||
|
|
||||||
|
// give it some time and then stop
|
||||||
|
Thread.sleep(180 * 1000);
|
||||||
|
DUT.shutdown();
|
||||||
|
|
||||||
|
// observe results
|
||||||
|
Assert.assertTrue(DUT.results() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterAll
|
||||||
|
public static void cleanup() {
|
||||||
|
Tor.getDefault().shutdown();
|
||||||
|
torWorkingDirectory.delete();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue