Skip to content

Commit

Permalink
Merge pull request #2170 from getlantern/issue-2164
Browse files Browse the repository at this point in the history
Issue 2164
  • Loading branch information
oxtoacart committed Jan 14, 2015
2 parents 61ce9fe + 78a053a commit f65d62c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ protected BasePluggableTransport(boolean copyToConfigFolder,
path += ".exe";
}
try {
this.exe = LanternUtils.extractExecutableFromJar(path,
LanternClientConstants.DATA_DIR);
synchronized(this.getClass()) {
this.exe = LanternUtils.extractExecutableFromJar(path,
LanternClientConstants.DATA_DIR);
}
} catch (final IOException e) {
throw new Error(String.format("Could not extract jar file from '%s': %s", path, e.getMessage()), e);
}
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/org/lantern/proxy/pt/FlashlightServerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,26 @@ synchronized private void update(boolean inGiveMode, boolean isConnected) {

private void startFlashlight() {
LOGGER.debug("Starting flashlight");
heartbeat = Threads
.newSingleThreadScheduledExecutor("FlashlightServerManager-Heartbeat");
heartbeat.scheduleAtFixedRate(peerRegistrar,
10,
HEARTBEAT_PERIOD_MINUTES * 60,
TimeUnit.SECONDS);
try {
// Note if this call succeeds it blocks indefinitely.
runFlashlight(true);
} catch (RuntimeException re) {
final String msg = re.getMessage();
if (msg != null && msg.contains("Exit value: 50")) {
LOGGER.info("Unable to start flashlight with automatically mapped external port, try without mapping");
// Note if this call succeeds it blocks indefinitely.
runFlashlight(false);
} else {
LOGGER.error("Unexpected runtime exception", re);
throw re;
}
}

heartbeat = Threads
.newSingleThreadScheduledExecutor("FlashlightServerManager-Heartbeat");
heartbeat.scheduleAtFixedRate(peerRegistrar,
0,
HEARTBEAT_PERIOD_MINUTES,
TimeUnit.MINUTES);
}

private void stopFlashlight(boolean unregister) {
Expand Down Expand Up @@ -161,6 +162,7 @@ private void runFlashlight(boolean mapExternalPort) {
int localPort = LanternUtils
.findFreePort(PREFERRED_FLASHLIGHT_INTERNAL_PORT);
flashlight.startServer(localPort, null);
LOGGER.info("Finished starting server...");
}

private Runnable peerRegistrar = new Runnable() {
Expand Down Expand Up @@ -202,6 +204,7 @@ private boolean shouldShowPortMappingFailure() {
}

private boolean registerPeer() {
LOGGER.info("Registering peer...");
Response response = null;
try {
response = Request
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/log4j.properties
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ log4j.logger.org.littleshoot.proxy=INFO
#log4j.logger.org.lastbamboo.common.ice=all
#log4j.logger.org.lastbamboo.common.stun=all
#log4j.logger.org.lastbamboo.jni=all
log4j.logger.org.lantern.proxy.pt.BasePluggableTransport=DEBUG

0 comments on commit f65d62c

Please sign in to comment.