Browse Source

[android] stop immediatly if no transit tunnels available while graceful shutdown

Signed-off-by: R4SAS <r4sas@i2pmail.org>
pull/1515/head
R4SAS 5 years ago
parent
commit
c0de9455bb
  1. 6
      android/jni/i2pd_android.cpp
  2. 3
      android/jni/org_purplei2p_i2pd_I2PD_JNI.h
  3. 4
      android/src/org/purplei2p/i2pd/DaemonSingleton.java
  4. 11
      android/src/org/purplei2p/i2pd/I2PDActivity.java
  5. 2
      android/src/org/purplei2p/i2pd/I2PD_JNI.java

6
android/jni/i2pd_android.cpp

@ -4,6 +4,7 @@
#include "RouterContext.h" #include "RouterContext.h"
#include "ClientContext.h" #include "ClientContext.h"
#include "Transports.h" #include "Transports.h"
#include "Tunnel.h"
JNIEXPORT jstring JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_getABICompiledWith JNIEXPORT jstring JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_getABICompiledWith
(JNIEnv *env, jclass clazz) { (JNIEnv *env, jclass clazz) {
@ -98,3 +99,8 @@ JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_setDataDir
// Set DataDir // Set DataDir
i2p::android::SetDataDir(dataDir); i2p::android::SetDataDir(dataDir);
} }
JNIEXPORT jint JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_GetTransitTunnelsCount
(JNIEnv *env, jclass clazz) {
return i2p::tunnel::tunnels.CountTransitTunnels();
}

3
android/jni/org_purplei2p_i2pd_I2PD_JNI.h

@ -36,6 +36,9 @@ JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_onNetworkStateChanged
JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_setDataDir JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_setDataDir
(JNIEnv *env, jclass clazz, jstring jdataDir); (JNIEnv *env, jclass clazz, jstring jdataDir);
JNIEXPORT jint JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_GetTransitTunnelsCount
(JNIEnv *, jclass);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

4
android/src/org/purplei2p/i2pd/DaemonSingleton.java

@ -65,6 +65,10 @@ public class DaemonSingleton {
} }
} }
public synchronized int GetTransitTunnelsCount() {
return I2PD_JNI.GetTransitTunnelsCount();
}
private volatile boolean startedOkay; private volatile boolean startedOkay;
public enum State { public enum State {

11
android/src/org/purplei2p/i2pd/I2PDActivity.java

@ -74,7 +74,7 @@ public class I2PDActivity extends Activity {
processAssets(); processAssets();
runOnUiThread(() -> { runOnUiThread(() -> {
try { try {
if (textView==null) if (textView == null)
return; return;
Throwable tr = daemon.getLastThrowable(); Throwable tr = daemon.getLastThrowable();
if (tr!=null) { if (tr!=null) {
@ -128,7 +128,7 @@ public class I2PDActivity extends Activity {
doBindService(); doBindService();
final Timer gracefulQuitTimer = getGracefulQuitTimer(); final Timer gracefulQuitTimer = getGracefulQuitTimer();
if (gracefulQuitTimer!=null) { if (gracefulQuitTimer != null) {
long gracefulStopAtMillis; long gracefulStopAtMillis;
synchronized (graceStartedMillis_LOCK) { synchronized (graceStartedMillis_LOCK) {
gracefulStopAtMillis = graceStartedMillis + GRACEFUL_DELAY_MILLIS; gracefulStopAtMillis = graceStartedMillis + GRACEFUL_DELAY_MILLIS;
@ -373,6 +373,11 @@ public class I2PDActivity extends Activity {
if (gracefulQuitTimerOld != null) if (gracefulQuitTimerOld != null)
gracefulQuitTimerOld.cancel(); gracefulQuitTimerOld.cancel();
if(daemon.GetTransitTunnelsCount() <= 0) { // no tunnels left
Log.d(TAG, "no transit tunnels left, stopping");
i2pdStop();
}
final Timer gracefulQuitTimer = new Timer(true); final Timer gracefulQuitTimer = new Timer(true);
setGracefulQuitTimer(gracefulQuitTimer); setGracefulQuitTimer(gracefulQuitTimer);
gracefulQuitTimer.schedule(new TimerTask() { gracefulQuitTimer.schedule(new TimerTask() {
@ -480,7 +485,7 @@ public class I2PDActivity extends Activity {
private void deleteRecursive(File fileOrDirectory) { private void deleteRecursive(File fileOrDirectory) {
if (fileOrDirectory.isDirectory()) { if (fileOrDirectory.isDirectory()) {
File[] files = fileOrDirectory.listFiles(); File[] files = fileOrDirectory.listFiles();
if (files!=null) { if (files != null) {
for (File child : files) { for (File child : files) {
deleteRecursive(child); deleteRecursive(child);
} }

2
android/src/org/purplei2p/i2pd/I2PD_JNI.java

@ -22,6 +22,8 @@ public class I2PD_JNI {
public static native void setDataDir(String jdataDir); public static native void setDataDir(String jdataDir);
public static native int GetTransitTunnelsCount();
public static void loadLibraries() { public static void loadLibraries() {
//System.loadLibrary("c++_shared"); //System.loadLibrary("c++_shared");
System.loadLibrary("i2pd"); System.loadLibrary("i2pd");

Loading…
Cancel
Save