lokinet/llarp/link/contacts.hpp
dr7ana 5ccec24470 callsafe
- Added call_get to ev.hpp to queue event loop operations w/ a return value
- de-mutexed NodeDB and made all operations via event loop. Some calls to NodeDB methods (like ::put_if_newer) were wrapped in call->get's, but some weren't. All function bodies were using mutex locks
2023-10-12 06:43:18 -07:00

77 lines
1.8 KiB
C++

#pragma once
#include <llarp/dht/bucket.hpp>
#include <llarp/dht/node.hpp>
namespace llarp
{
struct Router;
/// This class mediates storage, retrieval, and functionality for the various types
/// of contact information that needs to be stored locally by the link manager and
/// router, like RouterContacts and introsets for example
struct Contacts
{
private:
// TODO: why was this a shared ptr in the original implementation? revisit this
std::shared_ptr<int> timer_keepalive;
const dht::Key_t& _local_key;
Router& _router;
std::atomic<bool> transit_allowed{false};
// holds router contacts
std::unique_ptr<dht::Bucket<dht::RCNode>> _rc_nodes;
// holds introsets for remote services
std::unique_ptr<dht::Bucket<dht::ISNode>> _introset_nodes;
public:
Contacts(const dht::Key_t& local, Router& r);
/// Sets the value of transit_allowed to the value of `b`. Returns false if the
/// value was already b, true otherwise
bool
set_transit_allowed(bool b)
{
return not transit_allowed.exchange(b) == b;
}
void
on_clean_contacts();
std::optional<service::EncryptedIntroSet>
get_introset_by_location(const dht::Key_t& key) const;
// TODO: rename every ExtractStatus function to be uniformly snake cased
util::StatusObject
ExtractStatus() const;
bool
lookup_router(const RouterID&, std::function<void(oxen::quic::message)> = nullptr);
void
put_rc_node_async(const dht::RCNode& val);
void
delete_rc_node_async(const dht::Key_t& val);
dht::Bucket<dht::RCNode>*
rc_nodes() const
{
return _rc_nodes.get();
}
dht::Bucket<dht::ISNode>*
services() const
{
return _introset_nodes.get();
}
Router*
router() const
{
return &_router;
}
};
} // namespace llarp