mirror of https://github.com/oxen-io/lokinet
add bootstrap list functionality and utility
This commit is contained in:
parent
51fae100ee
commit
0afb3b320b
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
echo -n 'l'
|
||||
for arg in $@ ; do cat "$arg" ; done
|
||||
echo -n 'e'
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -49,7 +49,7 @@ namespace llarp
|
|||
, inbound_link_msg_parser(this)
|
||||
, _hiddenServiceContext(this)
|
||||
{
|
||||
m_keyManager = std::make_shared<KeyManager>();
|
||||
m_keyManager = std::make_shared< KeyManager >();
|
||||
|
||||
// set rational defaults
|
||||
this->ip4addr.sin_family = AF_INET;
|
||||
|
@ -195,7 +195,6 @@ namespace llarp
|
|||
bool
|
||||
Router::EnsureIdentity()
|
||||
{
|
||||
|
||||
if(whitelistRouters)
|
||||
{
|
||||
#if defined(ANDROID) || defined(IOS)
|
||||
|
@ -209,12 +208,12 @@ namespace llarp
|
|||
#endif
|
||||
}
|
||||
|
||||
_identity = m_keyManager->getIdentityKey();
|
||||
_identity = m_keyManager->getIdentityKey();
|
||||
_encryption = m_keyManager->getEncryptionKey();
|
||||
|
||||
if (_identity.IsZero())
|
||||
if(_identity.IsZero())
|
||||
return false;
|
||||
if (_encryption.IsZero())
|
||||
if(_encryption.IsZero())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
@ -231,7 +230,7 @@ namespace llarp
|
|||
}
|
||||
_nodedb = nodedb;
|
||||
|
||||
if (not m_keyManager->initialize(*conf, true))
|
||||
if(not m_keyManager->initialize(*conf, true))
|
||||
return false;
|
||||
|
||||
if(!FromConfig(conf))
|
||||
|
@ -446,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,
|
||||
|
@ -524,8 +536,7 @@ namespace llarp
|
|||
util::memFn(&IOutboundSessionMaker::OnConnectTimeout,
|
||||
&_outboundSessionMaker),
|
||||
util::memFn(&AbstractRouter::SessionClosed, this),
|
||||
util::memFn(&AbstractRouter::PumpLL, this)
|
||||
);
|
||||
util::memFn(&AbstractRouter::PumpLL, this));
|
||||
|
||||
const auto &key = std::get< LinksConfig::Interface >(serverConfig);
|
||||
int af = std::get< LinksConfig::AddressFamily >(serverConfig);
|
||||
|
@ -1161,8 +1172,7 @@ namespace llarp
|
|||
util::memFn(&IOutboundSessionMaker::OnConnectTimeout,
|
||||
&_outboundSessionMaker),
|
||||
util::memFn(&AbstractRouter::SessionClosed, this),
|
||||
util::memFn(&AbstractRouter::PumpLL, this)
|
||||
);
|
||||
util::memFn(&AbstractRouter::PumpLL, this));
|
||||
|
||||
if(!link)
|
||||
return false;
|
||||
|
|
|
@ -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>
|
||||
|
@ -221,7 +222,7 @@ namespace llarp
|
|||
NetConfig_t netConfig;
|
||||
|
||||
/// bootstrap RCs
|
||||
std::set< RouterContact > bootstrapRCList;
|
||||
BootstrapList bootstrapRCList;
|
||||
|
||||
bool
|
||||
ExitEnabled() const
|
||||
|
@ -461,7 +462,7 @@ namespace llarp
|
|||
|
||||
llarp_time_t m_LastStatsReport = 0;
|
||||
|
||||
std::shared_ptr<llarp::KeyManager> m_keyManager;
|
||||
std::shared_ptr< llarp::KeyManager > m_keyManager;
|
||||
|
||||
bool
|
||||
ShouldReportStats(llarp_time_t now) const;
|
||||
|
|
|
@ -104,8 +104,8 @@ namespace llarp
|
|||
template < typename Item_t >
|
||||
bool
|
||||
BEncodeMaybeVerifyVersion(const char* k, Item_t& item, uint64_t expect,
|
||||
bool& read, const llarp_buffer_t& key,
|
||||
llarp_buffer_t* buf)
|
||||
bool& read, const llarp_buffer_t& key,
|
||||
llarp_buffer_t* buf)
|
||||
{
|
||||
if(key == k)
|
||||
{
|
||||
|
@ -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 New Issue