mirror of https://github.com/oxen-io/lokinet
initial pybind11 introspection code
parent
8d03e6dd3c
commit
1fdb8b4c94
@ -0,0 +1,38 @@
|
||||
#include <simulation/sim_context.hpp>
|
||||
#include <llarp.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace simulate
|
||||
{
|
||||
Simulation::Simulation() : m_CryptoManager(new sodium::CryptoLibSodium())
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
Simulation::NodeUp(llarp::Context *)
|
||||
{
|
||||
}
|
||||
|
||||
Node_ptr
|
||||
Simulation::AddNode(const std::string &name)
|
||||
{
|
||||
auto itr = m_Nodes.find(name);
|
||||
if(itr == m_Nodes.end())
|
||||
{
|
||||
itr =
|
||||
m_Nodes
|
||||
.emplace(name,
|
||||
std::make_shared< llarp::Context >(shared_from_this()))
|
||||
.first;
|
||||
}
|
||||
return itr->second;
|
||||
}
|
||||
|
||||
void
|
||||
Simulation::DelNode(const std::string &name)
|
||||
{
|
||||
m_Nodes.erase(name);
|
||||
}
|
||||
} // namespace simulate
|
||||
} // namespace llarp
|
@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include <crypto/crypto_libsodium.hpp>
|
||||
#include <ev/ev.h>
|
||||
#include <constants/features.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
// forward declair
|
||||
struct Context;
|
||||
using Node_ptr = std::shared_ptr< llarp::Context >;
|
||||
|
||||
namespace simulate
|
||||
{
|
||||
struct Simulation : public std::enable_shared_from_this< Simulation >
|
||||
{
|
||||
Simulation();
|
||||
|
||||
llarp::CryptoManager m_CryptoManager;
|
||||
llarp_ev_loop_ptr m_NetLoop;
|
||||
|
||||
std::unordered_map< std::string, Node_ptr > m_Nodes;
|
||||
|
||||
void
|
||||
NodeUp(llarp::Context* node);
|
||||
|
||||
Node_ptr
|
||||
AddNode(const std::string& name);
|
||||
|
||||
void
|
||||
DelNode(const std::string& name);
|
||||
};
|
||||
|
||||
using Sim_ptr = std::shared_ptr< Simulation >;
|
||||
} // namespace simulate
|
||||
} // namespace llarp
|
@ -0,0 +1,12 @@
|
||||
|
||||
set(PYTHON_EXECUTABLE "python3")
|
||||
find_package(pybind11 REQUIRED)
|
||||
set(LLARP_PYBIND_SRC
|
||||
module.cpp
|
||||
llarp/router_contact.cpp
|
||||
llarp/simulation/sim_context.cpp)
|
||||
|
||||
pybind11_add_module(pyllarp MODULE ${LLARP_PYBIND_SRC})
|
||||
target_include_directories(pyllarp PRIVATE ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/crypto/libntrup/include ${CMAKE_SOURCE_DIR}/llarp ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_link_libraries(pyllarp PUBLIC ${EXE_LIBS})
|
||||
|
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include <pybind11/pybind11.h>
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
void
|
||||
Context_Init(py::module &mod);
|
||||
|
||||
void
|
||||
RouterContact_Init(py::module &mod);
|
||||
|
||||
namespace simulate
|
||||
{
|
||||
void
|
||||
SimContext_Init(py::module &mod);
|
||||
}
|
||||
} // namespace llarp
|
@ -0,0 +1,23 @@
|
||||
#include "common.hpp"
|
||||
#include <llarp.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
void
|
||||
Context_Init(py::module& mod)
|
||||
{
|
||||
using Context_ptr = std::shared_ptr< Context >;
|
||||
py::class_< Context, Context_ptr >(mod, "Context")
|
||||
.def(py::init< simulate::Sim_ptr >())
|
||||
.def("Setup",
|
||||
[](Context_ptr self) -> bool { return self->Setup() == 0; })
|
||||
.def("Run",
|
||||
[](Context_ptr self) -> int {
|
||||
return self->Run(llarp_main_runtime_opts{});
|
||||
})
|
||||
.def("IsUp", &Context::IsUp)
|
||||
.def("LooksAlive", &Context::LooksAlive)
|
||||
.def("Configure", &Context::Configure)
|
||||
.def("CallSafe", &Context::CallSafe);
|
||||
}
|
||||
} // namespace llarp
|
@ -0,0 +1,18 @@
|
||||
#include <router_contact.hpp>
|
||||
#include "common.hpp"
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
void
|
||||
RouterContact_Init(py::module& mod)
|
||||
{
|
||||
py::class_< RouterContact >(mod, "RouterContact")
|
||||
.def(py::init<>())
|
||||
.def("ReadFile", &RouterContact::Read)
|
||||
.def("WriteFile", &RouterContact::Write)
|
||||
.def("Verify", [](const RouterContact rc) -> bool {
|
||||
const llarp_time_t now = llarp::time_now_ms();
|
||||
return rc.Verify(now);
|
||||
});
|
||||
}
|
||||
} // namespace llarp
|
@ -0,0 +1,20 @@
|
||||
#include "common.hpp"
|
||||
#include <llarp.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace simulate
|
||||
{
|
||||
void
|
||||
SimContext_Init(py::module& mod)
|
||||
{
|
||||
py::class_< Simulation, Sim_ptr >(mod, "Simulation")
|
||||
.def(py::init<>())
|
||||
.def("AddNode", &Simulation::AddNode)
|
||||
.def("DelNode", &Simulation::DelNode);
|
||||
py::object context = py::cast(std::make_shared< Simulation >());
|
||||
mod.attr("context") = context;
|
||||
}
|
||||
|
||||
} // namespace simulate
|
||||
} // namespace llarp
|
@ -0,0 +1,8 @@
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
PYBIND11_MODULE(pyllarp, m)
|
||||
{
|
||||
llarp::simulate::SimContext_Init(m);
|
||||
llarp::RouterContact_Init(m);
|
||||
}
|
Loading…
Reference in New Issue