mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-15 12:13:24 +00:00
7caa87862e
All #ifndef guards on headers have been removed, I think, in favor of #pragma once Headers are now included as `#include "filename"` if the included file resides in the same directory as the file including it, or any subdirectory therein. Otherwise they are included as `#include <project/top/dir/relative/path/filename>` The above does not include system/os headers.
56 lines
2.0 KiB
C++
56 lines
2.0 KiB
C++
#include <common.hpp>
|
|
#include <llarp.hpp>
|
|
#include <llarp/tooling/hive_context.hpp>
|
|
#include <llarp/router/router.cpp>
|
|
#include <llarp/handlers/pyhandler.hpp>
|
|
namespace llarp
|
|
{
|
|
void
|
|
Context_Init(py::module& mod)
|
|
{
|
|
using Context_ptr = std::shared_ptr<Context>;
|
|
py::class_<Context, Context_ptr>(mod, "Context")
|
|
.def(
|
|
"Setup",
|
|
[](Context_ptr self, bool isRouter) {
|
|
self->Setup({false, false, isRouter});
|
|
})
|
|
.def("Run", [](Context_ptr self) -> int { return self->Run(RuntimeOptions{}); })
|
|
.def("Stop", [](Context_ptr self) { self->CloseAsync(); })
|
|
.def("IsUp", &Context::IsUp)
|
|
.def("IsRelay", [](Context_ptr self) -> bool { return self->router->IsServiceNode(); })
|
|
.def("LooksAlive", &Context::LooksAlive)
|
|
.def("Configure", &Context::Configure)
|
|
.def(
|
|
"TrySendPacket",
|
|
[](Context_ptr self, std::string from, service::Address to, std::string pkt) {
|
|
auto ep = self->router->hiddenServiceContext().GetEndpointByName(from);
|
|
std::vector<byte_t> buf;
|
|
buf.resize(pkt.size());
|
|
std::copy_n(pkt.c_str(), pkt.size(), buf.data());
|
|
return ep and ep->SendToServiceOrQueue(to, std::move(buf), service::eProtocolControl);
|
|
})
|
|
.def(
|
|
"AddEndpoint",
|
|
[](Context_ptr self, handlers::PythonEndpoint_ptr ep) {
|
|
self->router->hiddenServiceContext().InjectEndpoint(ep->OurName, ep);
|
|
})
|
|
.def("CallSafe", &Context::CallSafe);
|
|
}
|
|
|
|
} // namespace llarp
|
|
|
|
namespace tooling
|
|
{
|
|
void
|
|
HiveContext_Init(py::module& mod)
|
|
{
|
|
using HiveContext_ptr = std::shared_ptr<HiveContext>;
|
|
py::class_<tooling::HiveContext, HiveContext_ptr, llarp::Context>(mod, "HiveContext")
|
|
.def(
|
|
"getRouterAsHiveRouter",
|
|
&tooling::HiveContext::getRouterAsHiveRouter,
|
|
py::return_value_policy::reference);
|
|
}
|
|
} // namespace tooling
|