1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00
lokinet/llarp/bootstrap.hpp

72 lines
1.2 KiB
C++
Raw Normal View History

#pragma once
#include "router_contact.hpp"
#include <llarp/crypto/crypto.hpp>
#include <llarp/util/fs.hpp>
#include <set>
#include <unordered_map>
2023-10-19 23:59:57 +02:00
namespace llarp
{
struct BootstrapList final : public std::set<RemoteRC>
{
2023-12-12 16:45:38 +01:00
std::set<RemoteRC>::iterator _curr = begin();
2023-12-08 02:07:32 +01:00
const RemoteRC&
current()
{
return *_curr;
}
bool
bt_decode(std::string_view buf);
std::string_view
bt_encode() const;
void
read_from_file(const fs::path& fpath);
bool
2023-12-12 16:45:38 +01:00
contains(const RouterID& rid) const;
// returns a reference to the next index and a boolean that equals true if
// this is the front of the set
const RemoteRC&
next()
{
2023-12-12 18:01:02 +01:00
if (size() < 2)
return *_curr;
2023-12-08 02:07:32 +01:00
++_curr;
2023-12-08 02:07:32 +01:00
if (_curr == this->end())
_curr = this->begin();
2023-12-08 02:07:32 +01:00
return *_curr;
}
bool
2023-12-12 16:45:38 +01:00
contains(const RemoteRC& rc) const;
void
randomize()
{
2023-12-08 02:07:32 +01:00
if (size() > 1)
_curr = std::next(begin(), std::uniform_int_distribution<size_t>{0, size() - 1}(csrng));
}
void
clear_list()
{
clear();
}
};
std::unordered_map<std::string, BootstrapList>
load_bootstrap_fallbacks();
} // namespace llarp