mirror of
https://github.com/oxen-io/lokinet
synced 2023-12-14 06:53:00 +01:00
Merge pull request #949 from majestrate/bootstrap-list-2019-12-06
add bootstrap list functionality and utility
This commit is contained in:
commit
f9dd3ea794
8 changed files with 99 additions and 26 deletions
4
contrib/bootstrap/make-bootstrap-list.sh
Executable file
4
contrib/bootstrap/make-bootstrap-list.sh
Executable file
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
echo -n 'l'
|
||||
for arg in $@ ; do cat "$arg" ; done
|
||||
echo -n 'e'
|
3
contrib/bootstrap/readme.txt
Normal file
3
contrib/bootstrap/readme.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
usage:
|
||||
|
||||
./make-bootstrap-list.sh $(find $HOME/.lokinet/netdb | grep \\.signed$) > bootstrap.signed
|
|
@ -134,6 +134,7 @@ set(DNSLIB_SRC
|
|||
|
||||
set(LIB_SRC
|
||||
${DNSLIB_SRC}
|
||||
bootstrap.cpp
|
||||
context.cpp
|
||||
crypto/constants.cpp
|
||||
crypto/crypto_libsodium.cpp
|
||||
|
|
34
llarp/bootstrap.cpp
Normal file
34
llarp/bootstrap.cpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
#include <bootstrap.hpp>
|
||||
#include <util/bencode.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
void
|
||||
BootstrapList::Clear()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
bool
|
||||
BootstrapList::BDecode(llarp_buffer_t* buf)
|
||||
{
|
||||
return bencode_read_list(
|
||||
[&](llarp_buffer_t* b, bool more) -> bool {
|
||||
if(more)
|
||||
{
|
||||
RouterContact rc;
|
||||
if(not rc.BDecode(b))
|
||||
return false;
|
||||
emplace(std::move(rc));
|
||||
}
|
||||
return true;
|
||||
},
|
||||
buf);
|
||||
}
|
||||
|
||||
bool
|
||||
BootstrapList::BEncode(llarp_buffer_t* buf) const
|
||||
{
|
||||
return BEncodeWriteList(begin(), end(), buf);
|
||||
}
|
||||
} // namespace llarp
|
22
llarp/bootstrap.hpp
Normal file
22
llarp/bootstrap.hpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
#ifndef LLARP_BOOTSTRAP_HPP
|
||||
#define LLARP_BOOTSTRAP_HPP
|
||||
|
||||
#include <router_contact.hpp>
|
||||
#include <set>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
struct BootstrapList final : public std::set< RouterContact >
|
||||
{
|
||||
bool
|
||||
BDecode(llarp_buffer_t* buf);
|
||||
|
||||
bool
|
||||
BEncode(llarp_buffer_t* buf) const;
|
||||
|
||||
void
|
||||
Clear();
|
||||
};
|
||||
} // namespace llarp
|
||||
|
||||
#endif
|
|
@ -445,38 +445,51 @@ namespace llarp
|
|||
std::vector< std::string > configRouters = conf->connect.routers;
|
||||
configRouters.insert(configRouters.end(), conf->bootstrap.routers.begin(),
|
||||
conf->bootstrap.routers.end());
|
||||
BootstrapList b_list;
|
||||
for(const auto &router : configRouters)
|
||||
{
|
||||
// llarp::LogDebug("connect section has ", key, "=", val);
|
||||
RouterContact rc;
|
||||
if(!rc.Read(router.c_str()))
|
||||
bool isListFile = false;
|
||||
{
|
||||
llarp::LogWarn("failed to decode bootstrap RC, file='", router,
|
||||
"' rc=", rc);
|
||||
return false;
|
||||
std::ifstream inf(router, std::ios::binary);
|
||||
if(inf.is_open())
|
||||
{
|
||||
const char ch = inf.get();
|
||||
isListFile = ch == 'l';
|
||||
}
|
||||
}
|
||||
if(rc.Verify(Now()))
|
||||
if(isListFile)
|
||||
{
|
||||
const auto result = bootstrapRCList.insert(rc);
|
||||
if(result.second)
|
||||
llarp::LogInfo("Added bootstrap node ", RouterID(rc.pubkey));
|
||||
else
|
||||
llarp::LogWarn("Duplicate bootstrap node ", RouterID(rc.pubkey));
|
||||
if(not BDecodeReadFile(router.c_str(), b_list))
|
||||
{
|
||||
LogWarn("failed to read bootstrap list file '", router, "'");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(rc.IsExpired(Now()))
|
||||
RouterContact rc;
|
||||
if(not rc.Read(router.c_str()))
|
||||
{
|
||||
llarp::LogWarn("Bootstrap node ", RouterID(rc.pubkey),
|
||||
" is too old and needs to be refreshed");
|
||||
}
|
||||
else
|
||||
{
|
||||
llarp::LogError("malformed rc file='", router, "' rc=", rc);
|
||||
llarp::LogWarn("failed to decode bootstrap RC, file='", router,
|
||||
"' rc=", rc);
|
||||
return false;
|
||||
}
|
||||
b_list.insert(rc);
|
||||
}
|
||||
}
|
||||
|
||||
for(auto &rc : b_list)
|
||||
{
|
||||
if(not rc.Verify(Now()))
|
||||
{
|
||||
LogWarn("ignoring invalid RC: ", RouterID(rc.pubkey));
|
||||
continue;
|
||||
}
|
||||
bootstrapRCList.emplace(std::move(rc));
|
||||
}
|
||||
|
||||
LogInfo("Loaded ", bootstrapRCList.size(), " bootstrap routers");
|
||||
|
||||
// Init components after relevant config settings loaded
|
||||
_outboundMessageHandler.Init(&_linkManager, _logic);
|
||||
_outboundSessionMaker.Init(&_linkManager, &_rcLookupHandler, _logic,
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <router/abstractrouter.hpp>
|
||||
|
||||
#include <bootstrap.hpp>
|
||||
#include <config/key_manager.hpp>
|
||||
#include <constants/link_layer.hpp>
|
||||
#include <crypto/types.hpp>
|
||||
|
@ -227,7 +228,7 @@ namespace llarp
|
|||
NetConfig_t netConfig;
|
||||
|
||||
/// bootstrap RCs
|
||||
std::set< RouterContact > bootstrapRCList;
|
||||
BootstrapList bootstrapRCList;
|
||||
|
||||
bool
|
||||
ExitEnabled() const
|
||||
|
|
|
@ -312,12 +312,7 @@ namespace llarp
|
|||
f.read((char*)ptr.data(), sz);
|
||||
}
|
||||
llarp_buffer_t buf(ptr);
|
||||
auto result = t.BDecode(&buf);
|
||||
if(!result)
|
||||
{
|
||||
DumpBuffer(buf);
|
||||
}
|
||||
return result;
|
||||
return t.BDecode(&buf);
|
||||
}
|
||||
|
||||
/// read entire file and decode its contents into t
|
||||
|
|
Loading…
Reference in a new issue