add new JNI function: LokinetDaemon DumpStatus

This commit is contained in:
Jeff Becker 2021-06-20 05:55:33 -04:00
parent 13af82474c
commit 6992d98c6a
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05
3 changed files with 31 additions and 0 deletions

View File

@ -26,6 +26,9 @@ public class LokinetDaemon extends VpnService
private static native String DetectFreeRange();
public native String DumpStatus();
public static final String LOG_TAG = "LokinetDaemon";
ByteBuffer impl = null;

View File

@ -2,6 +2,7 @@
#include "lokinet_jni_common.hpp"
#include <llarp.hpp>
#include <llarp/config/config.hpp>
#include <llarp/router/abstractrouter.hpp>
extern "C"
{
@ -99,4 +100,23 @@ extern "C"
}
return env->NewStringUTF(rangestr.c_str());
}
JNIEXPORT jstring JNICALL
Java_network_loki_lokinet_LokinetDaemon_DumpStatus(JNIEnv* env, jobject self)
{
std::string status{};
if (auto ptr = GetImpl<llarp::Context>(env, self))
{
if (ptr->IsUp())
{
std::promise<std::string> result;
ptr->CallSafe([&result, router = ptr->router]() {
const auto status = router->ExtractStatus();
result.set_value(status.dump());
});
status = result.get_future().get();
}
}
return env->NewStringUTF(status.c_str());
}
}

View File

@ -80,6 +80,14 @@ extern "C"
JNIEXPORT jstring JNICALL
Java_network_loki_lokinet_LokinetDaemon_DetectFreeRange(JNIEnv*, jclass);
/*
* Class: network_loki_lokinet_LokinetDaemon
* Method: DumpStatus
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL
Java_network_loki_lokinet_LokinetDaemon_DumpStatus(JNIEnv*, jobject);
#ifdef __cplusplus
}
#endif