mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-10-31 09:20:21 +00:00
Merge pull request #1302 from majestrate/pybind11-log-silencer-2020-06-08
add pybind to CI
This commit is contained in:
commit
e25500f091
@ -158,6 +158,10 @@ local mac_builder(name, build_type='Release', werror=true, cmake_extra='', extra
|
|||||||
'../contrib/ci/drone-static-upload.sh'
|
'../contrib/ci/drone-static-upload.sh'
|
||||||
]),
|
]),
|
||||||
|
|
||||||
|
// integration tests
|
||||||
|
debian_pipeline("Router Hive", "ubuntu:focal", deps='python3-dev python3-pytest python3-pybind11 ' + default_deps,
|
||||||
|
cmake_extra='-DWITH_HIVE=ON', extra_cmds=['../contrib/ci/drone-run-router-hive.sh']),
|
||||||
|
|
||||||
// Deb builds:
|
// Deb builds:
|
||||||
deb_builder("debian:sid", "sid", "debian/sid"),
|
deb_builder("debian:sid", "sid", "debian/sid"),
|
||||||
deb_builder("debian:buster", "buster", "debian/buster", imaginary_repo=true),
|
deb_builder("debian:buster", "buster", "debian/buster", imaginary_repo=true),
|
||||||
|
2
contrib/ci/drone-run-router-hive.sh
Executable file
2
contrib/ci/drone-run-router-hive.sh
Executable file
@ -0,0 +1,2 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
PYTHONPATH=pybind pytest-3 ../test/
|
@ -18,7 +18,7 @@ namespace tooling
|
|||||||
const std::shared_ptr<llarp::Config>& config, std::vector<llarp_main*>* routers, bool isRelay)
|
const std::shared_ptr<llarp::Config>& config, std::vector<llarp_main*>* routers, bool isRelay)
|
||||||
{
|
{
|
||||||
llarp_main* ctx = llarp_main_init_from_config(config->Copy(), isRelay);
|
llarp_main* ctx = llarp_main_init_from_config(config->Copy(), isRelay);
|
||||||
auto result = llarp_main_setup(ctx);
|
auto result = llarp_main_setup(ctx, isRelay);
|
||||||
if (result == 0)
|
if (result == 0)
|
||||||
{
|
{
|
||||||
llarp::Context::Get(ctx)->InjectHive(this);
|
llarp::Context::Get(ctx)->InjectHive(this);
|
||||||
|
@ -82,21 +82,14 @@ namespace llarp
|
|||||||
/** internal */
|
/** internal */
|
||||||
template <typename... TArgs>
|
template <typename... TArgs>
|
||||||
inline static void
|
inline static void
|
||||||
#ifndef LOKINET_HIVE
|
|
||||||
_Log(LogLevel lvl, const char* fname, int lineno, TArgs&&... args) noexcept
|
_Log(LogLevel lvl, const char* fname, int lineno, TArgs&&... args) noexcept
|
||||||
#else
|
|
||||||
_Log(LogLevel, const char*, int, TArgs&&...) noexcept
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
/* nop out logging for hive mode for now */
|
|
||||||
#ifndef LOKINET_HIVE
|
|
||||||
auto& log = LogContext::Instance();
|
auto& log = LogContext::Instance();
|
||||||
if (log.curLevel > lvl || log.logStream == nullptr)
|
if (log.curLevel > lvl || log.logStream == nullptr)
|
||||||
return;
|
return;
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
LogAppend(ss, std::forward<TArgs>(args)...);
|
LogAppend(ss, std::forward<TArgs>(args)...);
|
||||||
log.logStream->AppendLog(lvl, fname, lineno, log.nodeName, ss.str());
|
log.logStream->AppendLog(lvl, fname, lineno, log.nodeName, ss.str());
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
} // namespace llarp
|
} // namespace llarp
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ pybind11_add_module(pyllarp MODULE
|
|||||||
llarp/router_contact.cpp
|
llarp/router_contact.cpp
|
||||||
llarp/crypto/types.cpp
|
llarp/crypto/types.cpp
|
||||||
llarp/config.cpp
|
llarp/config.cpp
|
||||||
|
llarp/logger.cpp
|
||||||
llarp/dht/dht_types.cpp
|
llarp/dht/dht_types.cpp
|
||||||
llarp/path/path_types.cpp
|
llarp/path/path_types.cpp
|
||||||
llarp/path/path_hop_config.cpp
|
llarp/path/path_hop_config.cpp
|
||||||
|
@ -5,10 +5,15 @@
|
|||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
|
#include <util/fs.hpp>
|
||||||
|
|
||||||
namespace py = pybind11;
|
namespace py = pybind11;
|
||||||
|
|
||||||
namespace llarp
|
namespace llarp
|
||||||
{
|
{
|
||||||
|
void
|
||||||
|
Logger_Init(py::module& mod);
|
||||||
|
|
||||||
void
|
void
|
||||||
Context_Init(py::module& mod);
|
Context_Init(py::module& mod);
|
||||||
|
|
||||||
|
@ -41,19 +41,10 @@ namespace llarp
|
|||||||
[](RouterConfig& self) { return self.m_dataDir.c_str(); },
|
[](RouterConfig& self) { return self.m_dataDir.c_str(); },
|
||||||
[](RouterConfig& self, std::string dir) { self.m_dataDir = dir; })
|
[](RouterConfig& self, std::string dir) { self.m_dataDir = dir; })
|
||||||
.def_readwrite("blockBogons", &RouterConfig::m_blockBogons)
|
.def_readwrite("blockBogons", &RouterConfig::m_blockBogons)
|
||||||
.def_readwrite("publicOverride", &RouterConfig::m_publicOverride)
|
|
||||||
.def_readwrite("ip4addr", &RouterConfig::m_ip4addr)
|
|
||||||
.def(
|
.def(
|
||||||
"overrideAddress",
|
"overrideAddress",
|
||||||
[](RouterConfig& self, std::string ip, std::string port) {
|
[](RouterConfig& self, std::string addr) {
|
||||||
llarp::Addr addr(ip);
|
self.m_publicAddress = llarp::IpAddress(addr);
|
||||||
self.m_addrInfo.ip = *addr.addr6();
|
|
||||||
|
|
||||||
int portInt = stoi(port);
|
|
||||||
self.m_ip4addr.sin_port = portInt;
|
|
||||||
self.m_addrInfo.port = portInt;
|
|
||||||
|
|
||||||
self.m_publicOverride = true;
|
|
||||||
})
|
})
|
||||||
.def_readwrite("workerThreads", &RouterConfig::m_workerThreads)
|
.def_readwrite("workerThreads", &RouterConfig::m_workerThreads)
|
||||||
.def_readwrite("numNetThreads", &RouterConfig::m_numNetThreads)
|
.def_readwrite("numNetThreads", &RouterConfig::m_numNetThreads)
|
||||||
@ -67,10 +58,10 @@ namespace llarp
|
|||||||
.def_readwrite("keyfile", &NetworkConfig::m_keyfile)
|
.def_readwrite("keyfile", &NetworkConfig::m_keyfile)
|
||||||
.def_readwrite("endpointType", &NetworkConfig::m_endpointType)
|
.def_readwrite("endpointType", &NetworkConfig::m_endpointType)
|
||||||
.def_readwrite("reachable", &NetworkConfig::m_reachable)
|
.def_readwrite("reachable", &NetworkConfig::m_reachable)
|
||||||
.def_readwrite("hops", &NetworkConfig::m_hops)
|
.def_readwrite("hops", &NetworkConfig::m_Hops)
|
||||||
.def_readwrite("paths", &NetworkConfig::m_paths)
|
.def_readwrite("paths", &NetworkConfig::m_Paths)
|
||||||
.def_readwrite("snodeBlacklist", &NetworkConfig::m_snodeBlacklist)
|
.def_readwrite("snodeBlacklist", &NetworkConfig::m_snodeBlacklist)
|
||||||
.def_readwrite("mapAddr", &NetworkConfig::m_mapAddr)
|
.def_readwrite("mapAddr", &NetworkConfig::m_mapAddrs)
|
||||||
.def_readwrite("strictConnect", &NetworkConfig::m_strictConnect);
|
.def_readwrite("strictConnect", &NetworkConfig::m_strictConnect);
|
||||||
|
|
||||||
py::class_<ConnectConfig>(mod, "ConnectConfig")
|
py::class_<ConnectConfig>(mod, "ConnectConfig")
|
||||||
@ -116,7 +107,21 @@ namespace llarp
|
|||||||
|
|
||||||
py::class_<BootstrapConfig>(mod, "BootstrapConfig")
|
py::class_<BootstrapConfig>(mod, "BootstrapConfig")
|
||||||
.def(py::init<>())
|
.def(py::init<>())
|
||||||
.def_readwrite("routers", &BootstrapConfig::routers);
|
.def_property(
|
||||||
|
"routers",
|
||||||
|
[](BootstrapConfig& self) {
|
||||||
|
std::vector<std::string> args;
|
||||||
|
for (const auto& arg : self.routers)
|
||||||
|
args.emplace_back(arg.string());
|
||||||
|
return args;
|
||||||
|
},
|
||||||
|
[](BootstrapConfig& self, std::vector<std::string> args) {
|
||||||
|
self.routers.clear();
|
||||||
|
for (const auto& arg : args)
|
||||||
|
{
|
||||||
|
self.routers.emplace_back(arg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
py::class_<LoggingConfig>(mod, "LoggingConfig")
|
py::class_<LoggingConfig>(mod, "LoggingConfig")
|
||||||
.def(py::init<>())
|
.def(py::init<>())
|
||||||
|
@ -9,7 +9,9 @@ namespace llarp
|
|||||||
{
|
{
|
||||||
using Context_ptr = std::shared_ptr<Context>;
|
using Context_ptr = std::shared_ptr<Context>;
|
||||||
py::class_<Context, Context_ptr>(mod, "Context")
|
py::class_<Context, Context_ptr>(mod, "Context")
|
||||||
.def("Setup", [](Context_ptr self) -> bool { return self->Setup() == 0; })
|
.def(
|
||||||
|
"Setup",
|
||||||
|
[](Context_ptr self, bool isRelay) -> bool { return self->Setup(isRelay) == 0; })
|
||||||
.def("Run", [](Context_ptr self) -> int { return self->Run(llarp_main_runtime_opts{}); })
|
.def("Run", [](Context_ptr self) -> int { return self->Run(llarp_main_runtime_opts{}); })
|
||||||
.def("Stop", [](Context_ptr self) { self->CloseAsync(); })
|
.def("Stop", [](Context_ptr self) { self->CloseAsync(); })
|
||||||
.def("IsUp", &Context::IsUp)
|
.def("IsUp", &Context::IsUp)
|
||||||
|
@ -69,6 +69,9 @@ namespace llarp
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SendPacketToRemote(const llarp_buffer_t&) override{};
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
GetOurAddress() const
|
GetOurAddress() const
|
||||||
{
|
{
|
||||||
|
31
pybind/llarp/logger.cpp
Normal file
31
pybind/llarp/logger.cpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include "common.hpp"
|
||||||
|
#include <memory>
|
||||||
|
#include <util/logging/logger.hpp>
|
||||||
|
|
||||||
|
namespace llarp
|
||||||
|
{
|
||||||
|
struct PyLogger
|
||||||
|
{
|
||||||
|
std::unique_ptr<LogSilencer> shutup;
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
Logger_Init(py::module& mod)
|
||||||
|
{
|
||||||
|
py::class_<PyLogger>(mod, "LogContext")
|
||||||
|
.def(py::init<>())
|
||||||
|
.def_property(
|
||||||
|
"shutup",
|
||||||
|
[](PyLogger& self) { return self.shutup != nullptr; },
|
||||||
|
[](PyLogger& self, bool shutup) {
|
||||||
|
if (self.shutup == nullptr && shutup)
|
||||||
|
{
|
||||||
|
self.shutup = std::make_unique<LogSilencer>();
|
||||||
|
}
|
||||||
|
else if (self.shutup != nullptr && shutup == false)
|
||||||
|
{
|
||||||
|
self.shutup.reset();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} // namespace llarp
|
@ -16,4 +16,5 @@ PYBIND11_MODULE(pyllarp, m)
|
|||||||
llarp::handlers::PyHandler_Init(m);
|
llarp::handlers::PyHandler_Init(m);
|
||||||
llarp::service::Address_Init(m);
|
llarp::service::Address_Init(m);
|
||||||
m.def("EnableDebug", []() { llarp::SetLogLevel(llarp::eLogDebug); });
|
m.def("EnableDebug", []() { llarp::SetLogLevel(llarp::eLogDebug); });
|
||||||
|
llarp::Logger_Init(m);
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,9 @@ import traceback
|
|||||||
|
|
||||||
class RouterHive(object):
|
class RouterHive(object):
|
||||||
|
|
||||||
def __init__(self, n_relays=10, n_clients=10, netid="hive"):
|
def __init__(self, n_relays=10, n_clients=10, netid="hive", shutup=True):
|
||||||
|
self._log = pyllarp.LogContext()
|
||||||
|
self._log.shutup = shutup
|
||||||
try:
|
try:
|
||||||
|
|
||||||
self.endpointName = "pyllarp"
|
self.endpointName = "pyllarp"
|
||||||
@ -61,13 +63,7 @@ class RouterHive(object):
|
|||||||
config.router.dataDir = dirname
|
config.router.dataDir = dirname
|
||||||
config.router.netid = self.netid
|
config.router.netid = self.netid
|
||||||
config.router.nickname = "Router%d" % index
|
config.router.nickname = "Router%d" % index
|
||||||
config.router.publicOverride = True
|
config.router.overrideAddress('127.0.0.1:{}'.format(port))
|
||||||
config.router.overrideAddress("127.0.0.1", '{}'.format(port))
|
|
||||||
"""
|
|
||||||
config.router.ip4addr.sin_family = AF_INET
|
|
||||||
config.router.ip4addr.sin_port = htons(port)
|
|
||||||
config.router.ip4addr.sin_addr.set("127.0.0.1")
|
|
||||||
"""
|
|
||||||
config.router.blockBogons = False
|
config.router.blockBogons = False
|
||||||
|
|
||||||
config.network.enableProfiling = False
|
config.network.enableProfiling = False
|
||||||
@ -176,7 +172,7 @@ class RouterHive(object):
|
|||||||
return rcs
|
return rcs
|
||||||
|
|
||||||
|
|
||||||
def main(n_relays=10, n_clients=10, print_each_event=True):
|
def main(n_relays=10, n_clients=10, print_each_event=True, verbose=False):
|
||||||
|
|
||||||
running = True
|
running = True
|
||||||
|
|
||||||
@ -188,7 +184,7 @@ def main(n_relays=10, n_clients=10, print_each_event=True):
|
|||||||
signal(SIGINT, handle_sigint)
|
signal(SIGINT, handle_sigint)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
hive = RouterHive(n_relays, n_clients)
|
hive = RouterHive(n_relays, n_clients, shutup=not verbose)
|
||||||
hive.Start()
|
hive.Start()
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
@ -239,7 +235,8 @@ def main(n_relays=10, n_clients=10, print_each_event=True):
|
|||||||
pprint(event_counts)
|
pprint(event_counts)
|
||||||
|
|
||||||
hive.events = []
|
hive.events = []
|
||||||
sleep(1)
|
for _ in range(100):
|
||||||
|
sleep(1.0 / 100)
|
||||||
|
|
||||||
print('stopping')
|
print('stopping')
|
||||||
hive.Stop()
|
hive.Stop()
|
||||||
@ -254,5 +251,6 @@ if __name__ == '__main__':
|
|||||||
parser.add_argument('--print-events', dest="print_events", action='store_true')
|
parser.add_argument('--print-events', dest="print_events", action='store_true')
|
||||||
parser.add_argument('--relay-count', dest="relay_count", type=int, default=10)
|
parser.add_argument('--relay-count', dest="relay_count", type=int, default=10)
|
||||||
parser.add_argument('--client-count', dest="client_count", type=int, default=10)
|
parser.add_argument('--client-count', dest="client_count", type=int, default=10)
|
||||||
|
parser.add_argument('--verbose', action='store_true', dest='verbose')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
main(n_relays=args.relay_count, n_clients=args.client_count, print_each_event = args.print_events)
|
main(n_relays=args.relay_count, n_clients=args.client_count, print_each_event = args.print_events, verbose=args.verbose)
|
||||||
|
Loading…
Reference in New Issue
Block a user