working toward full testnet of routers (not clients yet) in hive/pybind setup

Not working yet -- some sort of RC issue.  Checkout the commit prior to this if you want something that 'works' that you can play with.
This commit is contained in:
Thomas Winget 2020-02-28 04:50:33 -05:00
parent d8d0338575
commit 931ff521d1
6 changed files with 104 additions and 6 deletions

View File

@ -2,10 +2,65 @@
import pyllarp
from time import sleep
from signal import signal, SIGINT
from shutil import rmtree
from os import makedirs
from socket import AF_INET, htons, inet_aton
from pprint import pprint
tmpdir = "/tmp/lokinet_hive"
def RemoveTmpDir(dirname):
if dirname.startswith("/tmp/") and len(dirname) > 5:
print("calling rmdir -r %s" % dirname)
if (input("Is this ok? (y/n): ").lower().strip()[:1] == "y"):
rmtree(dirname, ignore_errors=True)
else:
print("not removing dir %s because it doesn't start with /tmp/" % dirname)
def AddRouter(hive, index, netid="hive"):
dirname = "%s/routers/%d" % (tmpdir, index)
makedirs("%s/netdb" % dirname, exist_ok=True)
config = pyllarp.Config()
port = index + 30000
tunname = "lokihive%d" % index
config.router.encryptionKeyfile = "%s/encryption.key" % dirname
config.router.transportKeyfile = "%s/transport.key" % dirname
config.router.identKeyfile = "%s/identity.key" % dirname
config.router.ourRcFile = "%s/rc.signed" % dirname
config.router.netid = netid
config.router.nickname = "Router%d" % index
config.router.publicOverride = True
"""
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.network.enableProfiling = False
config.network.routerProfilesFile = "%s/profiles.dat" % dirname
config.network.netConfig = {"type": "null"}
config.netdb.nodedbDir = "%s/netdb" % dirname
config.links.InboundLinks = [("lo", AF_INET, port, set())]
config.system.pidfile = "%s/lokinet.pid" % dirname
config.dns.netConfig = {"local-dns": ("127.3.2.1:%d" % port)}
if index != 1:
config.bootstrap.routers = ["%s/routers/1/rc.signed" % tmpdir]
hive.AddRouter(config)
def main():
running = True
RemoveTmpDir(tmpdir)
def handle_sigint(sig, frame):
nonlocal running
@ -15,10 +70,21 @@ def main():
signal(SIGINT, handle_sigint)
hive = pyllarp.RouterHive()
config = pyllarp.Config()
config.router.netid = "gamma"
config.netdb.nodedbDir = "/home/tom/.lokinet/netdb"
hive.AddRouter(config)
AddRouter(hive, 1)
hive.StartAll()
sleep(5)
hive.StopAll()
r = pyllarp.RouterContact()
r.ReadFile("/tmp/lokinet_hive/routers/1/rc.signed")
print(r.ToString())
hive = pyllarp.RouterHive()
for i in range(1, 11):
AddRouter(hive, i)
hive.StartAll()
while running:

View File

@ -478,6 +478,7 @@ namespace llarp
llarp::LogError("invalid key for strict-connect: ", val);
}
llarp::LogWarn("Bootstrap routers list size: ", conf->bootstrap.routers.size());
std::vector< std::string > configRouters = conf->connect.routers;
configRouters.insert(configRouters.end(), conf->bootstrap.routers.begin(),
conf->bootstrap.routers.end());
@ -578,6 +579,7 @@ namespace llarp
const auto &key = std::get< LinksConfig::Interface >(serverConfig);
int af = std::get< LinksConfig::AddressFamily >(serverConfig);
uint16_t port = std::get< LinksConfig::Port >(serverConfig);
llarp::LogWarn("tun: ", key, " -- af: ", af, " -- port: ", port);
if(!server->Configure(netloop(), key, af, port))
{
LogError("failed to bind inbound link on ", key, " port ", port);

View File

@ -35,6 +35,7 @@ namespace tooling
for (llarp_main* ctx : routers)
{
routerMainThreads.emplace_back([=](){ llarp_main_run(ctx, opts); });
std::this_thread::sleep_for(20ms);
}
}

View File

@ -2,24 +2,34 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <nonstd/optional.hpp>
#include <unordered_map>
namespace py = pybind11;
/*
namespace pybind11
{
namespace detail
{
template <typename Key, typename Value, typename Hash, typename Equal, typename Alloc> struct type_caster<std::unordered_multimap<Key, Value, Hash, Equal, Alloc>>
: map_caster<std::unordered_multimap<Key, Value, Hash, Equal, Alloc>, Key, Value> { };
template<typename T>
struct type_caster<nonstd::optional<T>>
: public optional_caster<nonstd::optional<T>> {};
/*
template <typename CharT, class Traits>
struct type_caster<simple_string_view>
: string_caster<simple_string_view, true> {};
*/
} // namespace pybind11::detail
} // namespace pybind11
*/
namespace llarp
{

View File

@ -1,7 +1,16 @@
#include "common.hpp"
#include "config/config.hpp"
#include <netinet/in.h>
namespace llarp
{
void
in_addr_set(in_addr *addr, const char *str)
{
inet_aton(str, addr);
}
void
Config_Init(py::module & mod)
{
@ -96,5 +105,12 @@ namespace llarp
.def_readwrite("LogJSON", &LoggingConfig::m_LogJSON)
.def_readwrite("LogFile", &LoggingConfig::m_LogFile);
py::class_<sockaddr_in>(mod, "sockaddr_in")
.def_readwrite("sin_family", &sockaddr_in::sin_family)
.def_readwrite("sin_port", &sockaddr_in::sin_port)
.def_readwrite("sin_addr", &sockaddr_in::sin_addr);
py::class_<in_addr>(mod, "in_addr")
.def("set", &in_addr_set);
}
}

View File

@ -10,6 +10,9 @@ namespace llarp
.def(py::init<>())
.def("ReadFile", &RouterContact::Read)
.def("WriteFile", &RouterContact::Write)
.def("ToString", [](const RouterContact rc) -> std::string {
return rc.ToJson().dump();
})
.def("Verify", [](const RouterContact rc) -> bool {
const llarp_time_t now = llarp::time_now_ms();
return rc.Verify(now);