1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00
lokinet/pybind/llarp/context.cpp

36 lines
1.5 KiB
C++
Raw Normal View History

2020-01-17 14:22:08 +01:00
#include "common.hpp"
#include <llarp.hpp>
2020-02-26 22:54:16 +01:00
#include <router/router.cpp>
2020-02-28 19:44:27 +01:00
#include "llarp/handlers/pyhandler.hpp"
2020-01-17 14:22:08 +01:00
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 isRelay) { self->Setup(isRelay); })
.def("Run", [](Context_ptr self) -> int { return self->Run(RuntimeOptions{}); })
2020-03-07 02:20:11 +01:00
.def("Stop", [](Context_ptr self) { self->CloseAsync(); })
2020-01-17 14:22:08 +01:00
.def("IsUp", &Context::IsUp)
.def("IsRelay", [](Context_ptr self) -> bool { return self->router->IsServiceNode(); })
2020-01-17 14:22:08 +01:00
.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);
})
2020-01-17 14:22:08 +01:00
.def("CallSafe", &Context::CallSafe);
}
} // namespace llarp