|
|
@ -97,10 +97,10 @@ struct AndroidMain
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
SetVPN_FD(int fd)
|
|
|
|
SetVPN_FD(int rfd, int wfd)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(m_impl)
|
|
|
|
if(m_impl)
|
|
|
|
llarp_main_inject_vpn_fd(m_impl, fd);
|
|
|
|
llarp_main_inject_vpn_fd(m_impl, rfd, wfd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// stop daemon thread
|
|
|
|
/// stop daemon thread
|
|
|
@ -120,7 +120,7 @@ struct AndroidMain
|
|
|
|
typedef std::unique_ptr< AndroidMain > Ptr;
|
|
|
|
typedef std::unique_ptr< AndroidMain > Ptr;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static AndroidMain::Ptr daemon(new AndroidMain());
|
|
|
|
static AndroidMain::Ptr daemon_ptr(new AndroidMain());
|
|
|
|
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -135,7 +135,7 @@ extern "C"
|
|
|
|
Java_network_loki_lokinet_Lokinet_1JNI_startLokinet(JNIEnv* env, jclass,
|
|
|
|
Java_network_loki_lokinet_Lokinet_1JNI_startLokinet(JNIEnv* env, jclass,
|
|
|
|
jstring configfile)
|
|
|
|
jstring configfile)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(daemon->Running())
|
|
|
|
if(daemon_ptr->Running())
|
|
|
|
return env->NewStringUTF("already running");
|
|
|
|
return env->NewStringUTF("already running");
|
|
|
|
std::string conf;
|
|
|
|
std::string conf;
|
|
|
|
fs::path basepath;
|
|
|
|
fs::path basepath;
|
|
|
@ -145,9 +145,9 @@ extern "C"
|
|
|
|
env->ReleaseStringUTFChars(configfile, nativeString);
|
|
|
|
env->ReleaseStringUTFChars(configfile, nativeString);
|
|
|
|
basepath = fs::path(conf).parent_path();
|
|
|
|
basepath = fs::path(conf).parent_path();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(daemon->Configure(conf.c_str(), basepath.string().c_str()))
|
|
|
|
if(daemon_ptr->Configure(conf.c_str(), basepath.string().c_str()))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(daemon->Start())
|
|
|
|
if(daemon_ptr->Start())
|
|
|
|
return env->NewStringUTF("ok");
|
|
|
|
return env->NewStringUTF("ok");
|
|
|
|
else
|
|
|
|
else
|
|
|
|
return env->NewStringUTF("failed to start daemon");
|
|
|
|
return env->NewStringUTF("failed to start daemon");
|
|
|
@ -159,24 +159,25 @@ extern "C"
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_network_loki_lokinet_Lokinet_1JNI_stopLokinet(JNIEnv*, jclass)
|
|
|
|
Java_network_loki_lokinet_Lokinet_1JNI_stopLokinet(JNIEnv*, jclass)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(daemon->Running())
|
|
|
|
if(daemon_ptr->Running())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
daemon->Stop();
|
|
|
|
daemon_ptr->Stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_network_loki_lokinet_Lokinet_1JNI_setVPNFileDescriptor(JNIEnv*, jclass,
|
|
|
|
Java_network_loki_lokinet_Lokinet_1JNI_setVPNFileDescriptor(JNIEnv*, jclass,
|
|
|
|
jint fd)
|
|
|
|
jint rfd,
|
|
|
|
|
|
|
|
jint wfd)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
daemon->SetVPN_FD(fd);
|
|
|
|
daemon_ptr->SetVPN_FD(rfd, wfd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
JNIEXPORT jstring JNICALL
|
|
|
|
JNIEXPORT jstring JNICALL
|
|
|
|
Java_network_loki_lokinet_Lokinet_1JNI_getIfAddr(JNIEnv* env, jclass)
|
|
|
|
Java_network_loki_lokinet_Lokinet_1JNI_getIfAddr(JNIEnv* env, jclass)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(daemon)
|
|
|
|
if(daemon_ptr)
|
|
|
|
return env->NewStringUTF(daemon->GetIfAddr());
|
|
|
|
return env->NewStringUTF(daemon_ptr->GetIfAddr());
|
|
|
|
else
|
|
|
|
else
|
|
|
|
return env->NewStringUTF("");
|
|
|
|
return env->NewStringUTF("");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -184,8 +185,8 @@ extern "C"
|
|
|
|
JNIEXPORT jint JNICALL
|
|
|
|
JNIEXPORT jint JNICALL
|
|
|
|
Java_network_loki_lokinet_Lokinet_1JNI_getIfRange(JNIEnv*, jclass)
|
|
|
|
Java_network_loki_lokinet_Lokinet_1JNI_getIfRange(JNIEnv*, jclass)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(daemon)
|
|
|
|
if(daemon_ptr)
|
|
|
|
return daemon->GetIfRange();
|
|
|
|
return daemon_ptr->GetIfRange();
|
|
|
|
else
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -196,17 +197,17 @@ extern "C"
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(isConnected)
|
|
|
|
if(isConnected)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!daemon->Running())
|
|
|
|
if(!daemon_ptr->Running())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!daemon->Start())
|
|
|
|
if(!daemon_ptr->Start())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// TODO: do some kind of callback here
|
|
|
|
// TODO: do some kind of callback here
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(daemon->Running())
|
|
|
|
else if(daemon_ptr->Running())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
daemon->Stop();
|
|
|
|
daemon_ptr->Stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|