more fixes, implemenmt missing functions

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

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

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

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

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

@ -240,10 +240,34 @@ __ ___ ____ _ _ ___ _ _ ____
// run net io thread
llarp::LogInfo("running mainloop");
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;
}
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
Context::WritePIDFile() const
{
@ -433,6 +457,14 @@ extern "C"
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
llarp_config_load_file(const char *fname, struct llarp_config **conf)
{
@ -565,6 +597,31 @@ extern "C"
{
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)

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

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

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

Loading…
Cancel
Save