mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-03 23:15:52 +00:00
4c630e0437
- Previous android java and jni code updated to work, but with much love still needed to make it work nicely, e.g. handling when the VPN is turned off. - DNS handling refactored to allow android to intercept and handle DNS requests as we can't set the system DNS to use a high port (and apparently Chrome ignores system DNS settings anyway) - add packet router structure to allow separate handling of specific intercepted traffic, e.g. UDP traffic to port 53 gets handled by our DNS handler rather than being naively forwarded as exit traffic. - For now, android lokinet is exit-only and hard-coded to use exit.loki as its exit. The exit will be configurable before release, but allowing to not use exit-only mode is more of a challenge. - some old gitignore remnants which were matching to things we don't want them to (and are no longer relevant) removed - some minor changes to CI configuration
75 lines
1.9 KiB
C++
75 lines
1.9 KiB
C++
#include "network_loki_lokinet_LokinetConfig.h"
|
|
#include <llarp.hpp>
|
|
#include <config/config.hpp>
|
|
#include "lokinet_jni_common.hpp"
|
|
|
|
extern "C"
|
|
{
|
|
JNIEXPORT jobject JNICALL
|
|
Java_network_loki_lokinet_LokinetConfig_Obtain(JNIEnv* env, jclass, jstring dataDir)
|
|
{
|
|
auto conf = VisitStringAsStringView<llarp::Config*>(
|
|
env, dataDir, [](std::string_view val) -> llarp::Config* {
|
|
return new llarp::Config{val};
|
|
});
|
|
|
|
if (conf == nullptr)
|
|
return nullptr;
|
|
return env->NewDirectByteBuffer(conf, sizeof(llarp::Config));
|
|
}
|
|
|
|
JNIEXPORT void JNICALL
|
|
Java_network_loki_lokinet_LokinetConfig_Free(JNIEnv* env, jclass, jobject buf)
|
|
{
|
|
auto ptr = FromBuffer<llarp::Config>(env, buf);
|
|
delete ptr;
|
|
}
|
|
|
|
JNIEXPORT jboolean JNICALL
|
|
Java_network_loki_lokinet_LokinetConfig_Load(JNIEnv* env, jobject self)
|
|
{
|
|
auto conf = GetImpl<llarp::Config>(env, self);
|
|
if (conf == nullptr)
|
|
return JNI_FALSE;
|
|
if (conf->Load())
|
|
{
|
|
return JNI_TRUE;
|
|
}
|
|
return JNI_FALSE;
|
|
}
|
|
|
|
JNIEXPORT jboolean JNICALL
|
|
Java_network_loki_lokinet_LokinetConfig_Save(JNIEnv* env, jobject self)
|
|
{
|
|
auto conf = GetImpl<llarp::Config>(env, self);
|
|
if (conf == nullptr)
|
|
return JNI_FALSE;
|
|
try
|
|
{
|
|
conf->Save();
|
|
}
|
|
catch (...)
|
|
{
|
|
return JNI_FALSE;
|
|
}
|
|
return JNI_TRUE;
|
|
}
|
|
|
|
JNIEXPORT void JNICALL
|
|
Java_network_loki_lokinet_LokinetConfig_AddDefaultValue(
|
|
JNIEnv* env, jobject self, jstring section, jstring key, jstring value)
|
|
{
|
|
auto convert = [](std::string_view str) -> std::string { return std::string{str}; };
|
|
|
|
const auto sect = VisitStringAsStringView<std::string>(env, section, convert);
|
|
const auto k = VisitStringAsStringView<std::string>(env, key, convert);
|
|
const auto v = VisitStringAsStringView<std::string>(env, value, convert);
|
|
|
|
auto conf = GetImpl<llarp::Config>(env, self);
|
|
if (conf)
|
|
{
|
|
conf->AddDefault(sect, k, v);
|
|
}
|
|
}
|
|
}
|