Skip to content

Commit

Permalink
add new JNI function: LokinetDaemon DumpStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
majestrate committed Jun 20, 2021
1 parent 13af824 commit 6992d98
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions jni/java/src/network/loki/lokinet/LokinetDaemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions jni/lokinet_daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "lokinet_jni_common.hpp"
#include <llarp.hpp>
#include <llarp/config/config.hpp>
#include <llarp/router/abstractrouter.hpp>

extern "C"
{
Expand Down Expand Up @@ -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());
}
}
8 changes: 8 additions & 0 deletions jni/network_loki_lokinet_LokinetDaemon.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6992d98

Please sign in to comment.