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

40 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 { return self->Setup() == 0; })
.def("Run",
[](Context_ptr self) -> int {
return self->Run(llarp_main_runtime_opts{});
})
2020-02-28 19:44:27 +01:00
.def("Stop", [](Context_ptr self) {
self->CloseAsync();
})
2020-01-17 14:22:08 +01:00
.def("IsUp", &Context::IsUp)
2020-02-28 19:44:27 +01:00
.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)
2020-02-28 19:44:27 +01:00
.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-02-28 17:29:15 +01:00
})
2020-01-17 14:22:08 +01:00
.def("CallSafe", &Context::CallSafe);
}
} // namespace llarp