more fixes, implemenmt missing functions

pull/869/head
jeff 5 years ago
parent d80633a975
commit 58a25602f5

@ -87,6 +87,14 @@ namespace llarp
bool bool
Configure(); Configure();
/// close async
void
Close();
/// wait until closed and done
void
Wait();
/// call a function in logic thread /// call a function in logic thread
/// return true if queued for calling /// return true if queued for calling
/// return false if not queued for calling /// return false if not queued for calling
@ -117,6 +125,7 @@ namespace llarp
std::string configfile; std::string configfile;
std::string pidfile; std::string pidfile;
std::unique_ptr< std::promise< void > > closeWaiter;
}; };
} // namespace llarp } // namespace llarp

@ -14,8 +14,7 @@ extern "C"
} }
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_network_loki_lokinet_LokinetConfig_Free(JNIEnv* env, jclass, Java_network_loki_lokinet_LokinetConfig_Free(JNIEnv* env, jclass, jobject buf)
jobject buf)
{ {
llarp_config_free(FromBuffer< llarp_config >(env, buf)); llarp_config_free(FromBuffer< llarp_config >(env, buf));
} }

@ -31,7 +31,7 @@ extern "C"
return JNI_FALSE; return JNI_FALSE;
if(llarp_main_configure(ptr, config)) if(llarp_main_configure(ptr, config))
return JNI_TRUE; return JNI_TRUE;
return JNI_FALSE; return llarp_main_setup(ptr) == 0 ? JNI_TRUE : JNI_FALSE;
} }
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL

@ -23,8 +23,7 @@ VisitStringAsStringView(JNIEnv* env, jobject str, V visit)
const size_t length = env->GetArrayLength(stringJbytes); const size_t length = env->GetArrayLength(stringJbytes);
jbyte* pBytes = env->GetByteArrayElements(stringJbytes, NULL); jbyte* pBytes = env->GetByteArrayElements(stringJbytes, NULL);
T result = T result = visit(llarp::string_view((const char*)pBytes, length));
visit(llarp::string_view((const char*)pBytes, length));
env->ReleaseByteArrayElements(stringJbytes, pBytes, JNI_ABORT); env->ReleaseByteArrayElements(stringJbytes, pBytes, JNI_ABORT);
env->DeleteLocalRef(stringJbytes); env->DeleteLocalRef(stringJbytes);

@ -240,10 +240,34 @@ __ ___ ____ _ _ ___ _ _ ____
// run net io thread // run net io thread
llarp::LogInfo("running mainloop"); llarp::LogInfo("running mainloop");
llarp_ev_loop_run_single_process(mainloop, logic); llarp_ev_loop_run_single_process(mainloop, logic);
// waits for router graceful stop if(closeWaiter)
{
// inform promise if called by Stop
closeWaiter->set_value();
}
return 0; return 0;
} }
void
Context::Close()
{
/// already closing
if(closeWaiter)
return;
if(CallSafe(std::bind(&Context::HandleSignal, this, SIGINT)))
closeWaiter = std::make_unique< std::promise< void > >();
}
void
Context::Wait()
{
if(closeWaiter)
{
closeWaiter->get_future().wait();
closeWaiter.reset();
}
}
bool bool
Context::WritePIDFile() const Context::WritePIDFile() const
{ {
@ -433,6 +457,14 @@ extern "C"
return nullptr; return nullptr;
} }
bool
llarp_config_read_file(struct llarp_config *conf, const char *fname)
{
if(conf == nullptr)
return false;
return conf->impl.Load(fname);
}
bool bool
llarp_config_load_file(const char *fname, struct llarp_config **conf) llarp_config_load_file(const char *fname, struct llarp_config **conf)
{ {
@ -565,6 +597,31 @@ extern "C"
{ {
return "default"; return "default";
} }
void
llarp_main_stop(struct llarp_main *ptr)
{
if(ptr == nullptr)
return;
ptr->ctx->Close();
ptr->ctx->Wait();
}
bool
llarp_main_configure(struct llarp_main *ptr, struct llarp_config *conf)
{
if(ptr == nullptr || conf == nullptr)
return false;
// give new config
ptr->ctx->config.reset(new llarp::Config(conf->impl));
return ptr->ctx->Configure();
}
bool
llarp_main_is_running(struct llarp_main *ptr)
{
return ptr && ptr->ctx->router && ptr->ctx->router->IsRunning();
}
} }
llarp_main::llarp_main(llarp_config *conf) llarp_main::llarp_main(llarp_config *conf)

@ -132,6 +132,9 @@ namespace llarp
virtual bool virtual bool
Run() = 0; Run() = 0;
virtual bool
IsRunning() const = 0;
/// stop running the router logic gracefully /// stop running the router logic gracefully
virtual void virtual void
Stop() = 0; Stop() = 0;

@ -1036,6 +1036,12 @@ namespace llarp
return _running; return _running;
} }
bool
Router::IsRunning() const
{
return _running;
}
llarp_time_t llarp_time_t
Router::Uptime() const Router::Uptime() const
{ {

@ -310,6 +310,9 @@ namespace llarp
bool bool
InitServiceNode(); InitServiceNode();
bool
IsRunning() const override;
/// return true if we are running in service node mode /// return true if we are running in service node mode
bool bool
IsServiceNode() const; IsServiceNode() const;

Loading…
Cancel
Save