2021-03-09 22:24:35 +00:00
|
|
|
#include <common.hpp>
|
2020-01-17 13:22:08 +00:00
|
|
|
#include <llarp.hpp>
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/tooling/hive_context.hpp>
|
2021-03-08 20:48:11 +00:00
|
|
|
#include <llarp/router/router.hpp>
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/handlers/pyhandler.hpp>
|
2021-03-08 20:48:11 +00:00
|
|
|
#include "service/protocol_type.hpp"
|
2020-01-17 13:22:08 +00:00
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
void
|
|
|
|
Context_Init(py::module& mod)
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
using Context_ptr = std::shared_ptr<Context>;
|
|
|
|
py::class_<Context, Context_ptr>(mod, "Context")
|
2020-07-01 19:46:52 +00:00
|
|
|
.def(
|
|
|
|
"Setup",
|
|
|
|
[](Context_ptr self, bool isRouter) {
|
|
|
|
self->Setup({false, false, isRouter});
|
|
|
|
})
|
2020-06-30 15:45:26 +00:00
|
|
|
.def("Run", [](Context_ptr self) -> int { return self->Run(RuntimeOptions{}); })
|
2020-03-07 01:20:11 +00:00
|
|
|
.def("Stop", [](Context_ptr self) { self->CloseAsync(); })
|
2020-01-17 13:22:08 +00:00
|
|
|
.def("IsUp", &Context::IsUp)
|
2020-04-07 18:38:56 +00:00
|
|
|
.def("IsRelay", [](Context_ptr self) -> bool { return self->router->IsServiceNode(); })
|
2020-01-17 13:22:08 +00:00
|
|
|
.def("LooksAlive", &Context::LooksAlive)
|
|
|
|
.def("Configure", &Context::Configure)
|
2020-04-07 18:38:56 +00: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());
|
2021-03-23 18:18:21 +00:00
|
|
|
return ep and ep->SendToOrQueue(to, std::move(buf), service::ProtocolType::Control);
|
2020-04-07 18:38:56 +00:00
|
|
|
})
|
|
|
|
.def(
|
|
|
|
"AddEndpoint",
|
|
|
|
[](Context_ptr self, handlers::PythonEndpoint_ptr ep) {
|
|
|
|
self->router->hiddenServiceContext().InjectEndpoint(ep->OurName, ep);
|
|
|
|
})
|
2020-01-17 13:22:08 +00:00
|
|
|
.def("CallSafe", &Context::CallSafe);
|
|
|
|
}
|
2020-07-02 15:40:38 +00:00
|
|
|
|
2020-01-17 13:22:08 +00:00
|
|
|
} // namespace llarp
|
2020-07-02 15:40:38 +00:00
|
|
|
|
|
|
|
namespace tooling
|
|
|
|
{
|
|
|
|
void
|
|
|
|
HiveContext_Init(py::module& mod)
|
|
|
|
{
|
2020-07-06 22:10:42 +00:00
|
|
|
using HiveContext_ptr = std::shared_ptr<HiveContext>;
|
|
|
|
py::class_<tooling::HiveContext, HiveContext_ptr, llarp::Context>(mod, "HiveContext")
|
2020-07-06 23:39:22 +00:00
|
|
|
.def(
|
|
|
|
"getRouterAsHiveRouter",
|
|
|
|
&tooling::HiveContext::getRouterAsHiveRouter,
|
|
|
|
py::return_value_policy::reference);
|
2020-07-02 15:40:38 +00:00
|
|
|
}
|
|
|
|
} // namespace tooling
|