mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-19 09:25:28 +00:00
22879b64ed
- new btdc method used to ensure no junk at the end of our bt data - DRYed out the RC code - check inbound bootstraps against all registered routers, not just whitelist - libquic vbump
61 lines
1.2 KiB
C++
61 lines
1.2 KiB
C++
#include "constants/version.hpp"
|
|
#include "crypto/crypto.hpp"
|
|
#include "net/net.hpp"
|
|
#include "router_contact.hpp"
|
|
#include "util/bencode.hpp"
|
|
#include "util/buffer.hpp"
|
|
#include "util/file.hpp"
|
|
#include "util/time.hpp"
|
|
|
|
#include <oxenc/bt_serialize.h>
|
|
|
|
namespace llarp
|
|
{
|
|
RemoteRC::RemoteRC(oxenc::bt_dict_consumer btdc)
|
|
{
|
|
try
|
|
{
|
|
bt_load(btdc);
|
|
bt_verify(btdc, /*reject_expired=*/true);
|
|
}
|
|
catch (const std::exception& e)
|
|
{
|
|
auto err = "Exception caught parsing RemoteRC: {}"_format(e.what());
|
|
log::warning(logcat, err);
|
|
throw std::runtime_error{err};
|
|
}
|
|
}
|
|
|
|
bool
|
|
RemoteRC::read(const fs::path& fname)
|
|
{
|
|
_payload.resize(MAX_RC_SIZE);
|
|
|
|
try
|
|
{
|
|
auto nread = util::file_to_buffer(fname, _payload.data(), _payload.size());
|
|
_payload.resize(nread);
|
|
|
|
oxenc::bt_dict_consumer btdc{_payload};
|
|
bt_load(btdc);
|
|
bt_verify(btdc);
|
|
}
|
|
catch (const std::exception& e)
|
|
{
|
|
log::warning(logcat, "Failed to read or validate RC from {}: {}", fname, e.what());
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
RemoteRC::verify() const
|
|
{
|
|
oxenc::bt_dict_consumer btdc{_payload};
|
|
bt_verify(btdc);
|
|
return true;
|
|
}
|
|
|
|
} // namespace llarp
|