2018-09-02 18:25:42 +00:00
|
|
|
#ifndef LLARP_LINK_SERVER_HPP
|
|
|
|
#define LLARP_LINK_SERVER_HPP
|
2018-12-12 02:52:51 +00:00
|
|
|
|
2019-01-13 16:30:07 +00:00
|
|
|
#include <crypto/types.hpp>
|
2019-01-11 01:19:36 +00:00
|
|
|
#include <ev/ev.h>
|
2018-12-12 01:32:10 +00:00
|
|
|
#include <link/session.hpp>
|
2020-05-06 20:38:44 +00:00
|
|
|
#include <net/sock_addr.hpp>
|
2018-12-12 01:55:30 +00:00
|
|
|
#include <router_contact.hpp>
|
2019-02-15 22:19:19 +00:00
|
|
|
#include <util/status.hpp>
|
2019-09-01 13:26:16 +00:00
|
|
|
#include <util/thread/logic.hpp>
|
|
|
|
#include <util/thread/threading.hpp>
|
2019-12-03 17:58:53 +00:00
|
|
|
#include <config/key_manager.hpp>
|
2018-12-12 01:32:10 +00:00
|
|
|
|
2018-09-07 20:36:06 +00:00
|
|
|
#include <list>
|
2019-04-02 09:03:53 +00:00
|
|
|
#include <memory>
|
2018-12-12 01:32:10 +00:00
|
|
|
#include <unordered_map>
|
2018-09-03 12:08:02 +00:00
|
|
|
|
2018-09-02 18:25:42 +00:00
|
|
|
namespace llarp
|
|
|
|
{
|
2020-06-05 20:16:51 +00:00
|
|
|
/// handle a link layer message. this allows for the message to be handled by "upper layers"
|
|
|
|
///
|
|
|
|
/// currently called from iwp::Session when messages are sent or received.
|
2020-04-07 18:38:56 +00:00
|
|
|
using LinkMessageHandler = std::function<bool(ILinkSession*, const llarp_buffer_t&)>;
|
2018-12-17 20:46:08 +00:00
|
|
|
|
2020-06-05 20:16:51 +00:00
|
|
|
/// sign a buffer with identity key. this function should take the given `llarp_buffer_t` and
|
|
|
|
/// sign it, prividing the signature in the out variable `Signature&`.
|
|
|
|
///
|
|
|
|
/// currently called from iwp::Session for signing LIMs (link introduction messages)
|
2020-04-07 18:38:56 +00:00
|
|
|
using SignBufferFunc = std::function<bool(Signature&, const llarp_buffer_t&)>;
|
2018-12-17 20:46:08 +00:00
|
|
|
|
|
|
|
/// handle connection timeout
|
2020-06-05 20:16:51 +00:00
|
|
|
///
|
|
|
|
/// currently called from ILinkLayer::Pump() when an unestablished session times out
|
2020-04-07 18:38:56 +00:00
|
|
|
using TimeoutHandler = std::function<void(ILinkSession*)>;
|
2018-12-17 20:46:08 +00:00
|
|
|
|
|
|
|
/// get our RC
|
2020-06-05 20:16:51 +00:00
|
|
|
///
|
|
|
|
/// currently called by iwp::Session to include as part of a LIM (link introduction message)
|
2020-04-07 18:38:56 +00:00
|
|
|
using GetRCFunc = std::function<const llarp::RouterContact&(void)>;
|
2018-12-17 20:46:08 +00:00
|
|
|
|
|
|
|
/// handler of session established
|
2019-02-27 12:55:26 +00:00
|
|
|
/// return false to reject
|
|
|
|
/// return true to accept
|
2020-06-05 20:16:51 +00:00
|
|
|
///
|
|
|
|
/// currently called in iwp::Session when a valid LIM is received.
|
2020-06-11 19:02:34 +00:00
|
|
|
using SessionEstablishedHandler = std::function<bool(ILinkSession*, bool)>;
|
2018-12-17 20:46:08 +00:00
|
|
|
|
2018-12-19 16:17:41 +00:00
|
|
|
/// f(new, old)
|
|
|
|
/// handler of session renegotiation
|
|
|
|
/// returns true if the new rc is valid
|
|
|
|
/// returns false otherwise and the session is terminated
|
2020-06-05 20:16:51 +00:00
|
|
|
///
|
|
|
|
/// currently called from iwp::Session when we receive a renegotiation LIM
|
2020-04-07 18:38:56 +00:00
|
|
|
using SessionRenegotiateHandler = std::function<bool(llarp::RouterContact, llarp::RouterContact)>;
|
2018-12-19 16:17:41 +00:00
|
|
|
|
2018-12-17 20:46:08 +00:00
|
|
|
/// handles close of all sessions with pubkey
|
2020-06-05 20:16:51 +00:00
|
|
|
///
|
|
|
|
/// Note that this handler is called while m_AuthedLinksMutex is held
|
|
|
|
///
|
|
|
|
/// currently called from iwp::ILinkSession when a previously established session times out
|
2020-04-07 18:38:56 +00:00
|
|
|
using SessionClosedHandler = std::function<void(llarp::RouterID)>;
|
2018-12-10 16:26:46 +00:00
|
|
|
|
2019-11-04 18:49:08 +00:00
|
|
|
/// notifies router that a link session has ended its pump and we should flush
|
|
|
|
/// messages to upper layers
|
2020-06-05 20:16:51 +00:00
|
|
|
///
|
|
|
|
/// currently called at the end of every iwp::Session::Pump() call
|
2020-04-07 18:38:56 +00:00
|
|
|
using PumpDoneHandler = std::function<void(void)>;
|
2019-11-04 18:49:08 +00:00
|
|
|
|
2020-06-11 11:44:02 +00:00
|
|
|
using Work_t = std::function<void(void)>;
|
|
|
|
/// queue work to worker thread
|
|
|
|
using WorkerFunc_t = std::function<void(Work_t)>;
|
|
|
|
|
2020-09-01 21:22:22 +00:00
|
|
|
/// before connection hook, called before we try connecting via outbound link
|
|
|
|
using BeforeConnectFunc_t = std::function<void(llarp::RouterContact)>;
|
|
|
|
|
2019-04-19 15:10:26 +00:00
|
|
|
struct ILinkLayer
|
2018-09-02 18:25:42 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
ILinkLayer(
|
|
|
|
std::shared_ptr<KeyManager> keyManager,
|
|
|
|
GetRCFunc getrc,
|
|
|
|
LinkMessageHandler handler,
|
|
|
|
SignBufferFunc signFunc,
|
2020-09-01 21:22:22 +00:00
|
|
|
BeforeConnectFunc_t before,
|
2020-04-07 18:38:56 +00:00
|
|
|
SessionEstablishedHandler sessionEstablish,
|
|
|
|
SessionRenegotiateHandler renegotiate,
|
|
|
|
TimeoutHandler timeout,
|
|
|
|
SessionClosedHandler closed,
|
2020-06-11 11:44:02 +00:00
|
|
|
PumpDoneHandler pumpDone,
|
|
|
|
WorkerFunc_t doWork);
|
2018-09-03 13:10:56 +00:00
|
|
|
virtual ~ILinkLayer();
|
2018-12-17 20:46:08 +00:00
|
|
|
|
2018-10-29 16:48:36 +00:00
|
|
|
/// get current time via event loop
|
|
|
|
llarp_time_t
|
2018-12-17 20:46:08 +00:00
|
|
|
Now() const
|
2018-10-29 16:48:36 +00:00
|
|
|
{
|
|
|
|
return llarp_ev_loop_time_now_ms(m_Loop);
|
|
|
|
}
|
2018-12-17 20:46:08 +00:00
|
|
|
|
2018-09-02 18:25:42 +00:00
|
|
|
bool
|
2019-01-02 01:03:53 +00:00
|
|
|
HasSessionTo(const RouterID& pk);
|
2018-09-02 18:25:42 +00:00
|
|
|
|
2018-10-25 18:18:12 +00:00
|
|
|
void
|
2020-04-07 18:38:56 +00:00
|
|
|
ForEachSession(std::function<void(const ILinkSession*)> visit, bool randomize = false) const
|
|
|
|
EXCLUDES(m_AuthedLinksMutex);
|
2018-10-25 18:18:12 +00:00
|
|
|
|
2018-12-19 16:17:41 +00:00
|
|
|
void
|
2020-04-07 18:38:56 +00:00
|
|
|
ForEachSession(std::function<void(ILinkSession*)> visit) EXCLUDES(m_AuthedLinksMutex);
|
2018-12-19 16:17:41 +00:00
|
|
|
|
2018-09-02 18:25:42 +00:00
|
|
|
static void
|
2019-09-12 18:19:25 +00:00
|
|
|
udp_tick(llarp_udp_io* udp);
|
2018-09-02 18:25:42 +00:00
|
|
|
|
2019-01-03 21:10:40 +00:00
|
|
|
void
|
2020-05-06 20:38:44 +00:00
|
|
|
SendTo_LL(const SockAddr& to, const llarp_buffer_t& pkt)
|
2019-01-03 21:10:40 +00:00
|
|
|
{
|
|
|
|
llarp_ev_udp_sendto(&m_udp, to, pkt);
|
|
|
|
}
|
|
|
|
|
2019-08-07 16:33:29 +00:00
|
|
|
virtual bool
|
2020-04-07 18:38:56 +00:00
|
|
|
Configure(llarp_ev_loop_ptr loop, const std::string& ifname, int af, uint16_t port);
|
2018-09-02 18:25:42 +00:00
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
virtual std::shared_ptr<ILinkSession>
|
2018-09-04 12:41:25 +00:00
|
|
|
NewOutboundSession(const RouterContact& rc, const AddressInfo& ai) = 0;
|
2018-09-02 18:25:42 +00:00
|
|
|
|
2018-09-04 12:41:25 +00:00
|
|
|
virtual void
|
2018-09-03 13:10:56 +00:00
|
|
|
Pump();
|
2018-09-02 18:25:42 +00:00
|
|
|
|
2018-09-04 12:41:25 +00:00
|
|
|
virtual void
|
2020-05-06 20:38:44 +00:00
|
|
|
RecvFrom(const SockAddr& from, ILinkSession::Packet_t pkt) = 0;
|
2018-09-02 18:25:42 +00:00
|
|
|
|
2018-09-03 13:10:56 +00:00
|
|
|
bool
|
2018-09-04 12:41:25 +00:00
|
|
|
PickAddress(const RouterContact& rc, AddressInfo& picked) const;
|
2018-09-02 18:25:42 +00:00
|
|
|
|
2018-11-21 14:56:12 +00:00
|
|
|
bool
|
2018-12-19 17:48:29 +00:00
|
|
|
TryEstablishTo(RouterContact rc);
|
2018-09-02 18:25:42 +00:00
|
|
|
|
2019-09-05 17:39:09 +00:00
|
|
|
bool
|
2020-06-11 11:44:02 +00:00
|
|
|
Start(std::shared_ptr<llarp::Logic> l);
|
2018-09-02 18:25:42 +00:00
|
|
|
|
2019-08-07 16:33:29 +00:00
|
|
|
virtual void
|
2018-09-03 13:10:56 +00:00
|
|
|
Stop();
|
2018-09-02 18:25:42 +00:00
|
|
|
|
|
|
|
virtual const char*
|
|
|
|
Name() const = 0;
|
|
|
|
|
2019-02-18 19:44:41 +00:00
|
|
|
util::StatusObject
|
De-abseil, part 2: mutex, locks, (most) time
- util::Mutex is now a std::shared_timed_mutex, which is capable of
exclusive and shared locks.
- util::Lock is still present as a std::lock_guard<util::Mutex>.
- the locking annotations are preserved, but updated to the latest
supported by clang rather than using abseil's older/deprecated ones.
- ACQUIRE_LOCK macro is gone since we don't pass mutexes by pointer into
locks anymore (WTF abseil).
- ReleasableLock is gone. Instead there are now some llarp::util helper
methods to obtain unique and/or shared locks:
- `auto lock = util::unique_lock(mutex);` gets an RAII-but-also
unlockable object (std::unique_lock<T>, with T inferred from
`mutex`).
- `auto lock = util::shared_lock(mutex);` gets an RAII shared (i.e.
"reader") lock of the mutex.
- `auto lock = util::unique_locks(mutex1, mutex2, mutex3);` can be
used to atomically lock multiple mutexes at once (returning a
tuple of the locks).
This are templated on the mutex which makes them a bit more flexible
than using a concrete type: they can be used for any type of lockable
mutex, not only util::Mutex. (Some of the code here uses them for
getting locks around a std::mutex). Until C++17, using the RAII types
is painfully verbose:
```C++
// pre-C++17 - needing to figure out the mutex type here is annoying:
std::unique_lock<util::Mutex> lock(mutex);
// pre-C++17 and even more verbose (but at least the type isn't needed):
std::unique_lock<decltype(mutex)> lock(mutex);
// our compromise:
auto lock = util::unique_lock(mutex);
// C++17:
std::unique_lock lock(mutex);
```
All of these functions will also warn (under gcc or clang) if you
discard the return value. You can also do fancy things like
`auto l = util::unique_lock(mutex, std::adopt_lock)` (which lets a
lock take over an already-locked mutex).
- metrics code is gone, which also removes a big pile of code that was
only used by metrics:
- llarp::util::Scheduler
- llarp::thread::TimerQueue
- llarp::util::Stopwatch
2020-02-21 17:21:11 +00:00
|
|
|
ExtractStatus() const EXCLUDES(m_AuthedLinksMutex);
|
2019-02-15 22:19:19 +00:00
|
|
|
|
2018-09-02 18:25:42 +00:00
|
|
|
void
|
2019-01-02 01:04:04 +00:00
|
|
|
CloseSessionTo(const RouterID& remote);
|
2018-09-02 18:25:42 +00:00
|
|
|
|
|
|
|
void
|
2019-01-02 01:04:04 +00:00
|
|
|
KeepAliveSessionTo(const RouterID& remote);
|
2018-09-03 13:10:56 +00:00
|
|
|
|
2019-08-07 16:33:29 +00:00
|
|
|
virtual bool
|
2020-04-07 18:38:56 +00:00
|
|
|
SendTo(
|
|
|
|
const RouterID& remote,
|
|
|
|
const llarp_buffer_t& buf,
|
|
|
|
ILinkSession::CompletionHandler completed);
|
2018-09-03 13:10:56 +00:00
|
|
|
|
2019-08-07 16:33:29 +00:00
|
|
|
virtual bool
|
2018-09-04 12:41:25 +00:00
|
|
|
GetOurAddressInfo(AddressInfo& addr) const;
|
2018-09-03 13:10:56 +00:00
|
|
|
|
2018-12-19 16:17:41 +00:00
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
VisitSessionByPubkey(const RouterID& pk, std::function<bool(ILinkSession*)> visit)
|
De-abseil, part 2: mutex, locks, (most) time
- util::Mutex is now a std::shared_timed_mutex, which is capable of
exclusive and shared locks.
- util::Lock is still present as a std::lock_guard<util::Mutex>.
- the locking annotations are preserved, but updated to the latest
supported by clang rather than using abseil's older/deprecated ones.
- ACQUIRE_LOCK macro is gone since we don't pass mutexes by pointer into
locks anymore (WTF abseil).
- ReleasableLock is gone. Instead there are now some llarp::util helper
methods to obtain unique and/or shared locks:
- `auto lock = util::unique_lock(mutex);` gets an RAII-but-also
unlockable object (std::unique_lock<T>, with T inferred from
`mutex`).
- `auto lock = util::shared_lock(mutex);` gets an RAII shared (i.e.
"reader") lock of the mutex.
- `auto lock = util::unique_locks(mutex1, mutex2, mutex3);` can be
used to atomically lock multiple mutexes at once (returning a
tuple of the locks).
This are templated on the mutex which makes them a bit more flexible
than using a concrete type: they can be used for any type of lockable
mutex, not only util::Mutex. (Some of the code here uses them for
getting locks around a std::mutex). Until C++17, using the RAII types
is painfully verbose:
```C++
// pre-C++17 - needing to figure out the mutex type here is annoying:
std::unique_lock<util::Mutex> lock(mutex);
// pre-C++17 and even more verbose (but at least the type isn't needed):
std::unique_lock<decltype(mutex)> lock(mutex);
// our compromise:
auto lock = util::unique_lock(mutex);
// C++17:
std::unique_lock lock(mutex);
```
All of these functions will also warn (under gcc or clang) if you
discard the return value. You can also do fancy things like
`auto l = util::unique_lock(mutex, std::adopt_lock)` (which lets a
lock take over an already-locked mutex).
- metrics code is gone, which also removes a big pile of code that was
only used by metrics:
- llarp::util::Scheduler
- llarp::thread::TimerQueue
- llarp::util::Stopwatch
2020-02-21 17:21:11 +00:00
|
|
|
EXCLUDES(m_AuthedLinksMutex);
|
2018-12-19 16:17:41 +00:00
|
|
|
|
2018-09-03 13:10:56 +00:00
|
|
|
virtual uint16_t
|
|
|
|
Rank() const = 0;
|
|
|
|
|
|
|
|
const byte_t*
|
|
|
|
TransportPubKey() const;
|
2018-09-02 18:25:42 +00:00
|
|
|
|
2019-01-02 01:04:04 +00:00
|
|
|
const SecretKey&
|
2018-12-17 20:46:08 +00:00
|
|
|
RouterEncryptionSecret() const
|
|
|
|
{
|
|
|
|
return m_RouterEncSecret;
|
|
|
|
}
|
|
|
|
|
2019-01-02 01:04:04 +00:00
|
|
|
const SecretKey&
|
2018-09-04 12:41:25 +00:00
|
|
|
TransportSecretKey() const;
|
|
|
|
|
2019-01-05 13:45:05 +00:00
|
|
|
bool
|
|
|
|
IsCompatable(const llarp::RouterContact& other) const
|
|
|
|
{
|
|
|
|
const std::string us = Name();
|
2020-04-07 18:38:56 +00:00
|
|
|
for (const auto& ai : other.addrs)
|
|
|
|
if (ai.dialect == us)
|
2019-01-05 13:45:05 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-08-23 11:32:52 +00:00
|
|
|
virtual bool
|
2019-01-02 01:03:53 +00:00
|
|
|
MapAddr(const RouterID& pk, ILinkSession* s);
|
2018-09-04 19:15:06 +00:00
|
|
|
|
2019-02-18 19:44:41 +00:00
|
|
|
void
|
|
|
|
Tick(llarp_time_t now);
|
2018-09-06 20:31:58 +00:00
|
|
|
|
2018-12-17 20:46:08 +00:00
|
|
|
LinkMessageHandler HandleMessage;
|
|
|
|
TimeoutHandler HandleTimeout;
|
|
|
|
SignBufferFunc Sign;
|
|
|
|
GetRCFunc GetOurRC;
|
2020-09-01 21:22:22 +00:00
|
|
|
BeforeConnectFunc_t BeforeConnect;
|
2018-12-17 20:46:08 +00:00
|
|
|
SessionEstablishedHandler SessionEstablished;
|
|
|
|
SessionClosedHandler SessionClosed;
|
2018-12-19 16:17:41 +00:00
|
|
|
SessionRenegotiateHandler SessionRenegotiate;
|
2019-11-04 18:49:08 +00:00
|
|
|
PumpDoneHandler PumpDone;
|
2020-04-07 18:38:56 +00:00
|
|
|
std::shared_ptr<KeyManager> keyManager;
|
2020-06-11 11:44:02 +00:00
|
|
|
WorkerFunc_t QueueWork;
|
2018-12-17 20:46:08 +00:00
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
std::shared_ptr<Logic>
|
2019-08-07 16:33:29 +00:00
|
|
|
logic()
|
|
|
|
{
|
|
|
|
return m_Logic;
|
|
|
|
}
|
|
|
|
|
2019-05-07 12:31:34 +00:00
|
|
|
bool
|
|
|
|
operator<(const ILinkLayer& other) const
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
return Rank() < other.Rank() || Name() < other.Name() || m_ourAddr < other.m_ourAddr;
|
2019-05-07 12:31:34 +00:00
|
|
|
}
|
|
|
|
|
2019-01-07 16:35:25 +00:00
|
|
|
/// called by link session to remove a pending session who is timed out
|
2019-03-11 13:01:43 +00:00
|
|
|
// void
|
De-abseil, part 2: mutex, locks, (most) time
- util::Mutex is now a std::shared_timed_mutex, which is capable of
exclusive and shared locks.
- util::Lock is still present as a std::lock_guard<util::Mutex>.
- the locking annotations are preserved, but updated to the latest
supported by clang rather than using abseil's older/deprecated ones.
- ACQUIRE_LOCK macro is gone since we don't pass mutexes by pointer into
locks anymore (WTF abseil).
- ReleasableLock is gone. Instead there are now some llarp::util helper
methods to obtain unique and/or shared locks:
- `auto lock = util::unique_lock(mutex);` gets an RAII-but-also
unlockable object (std::unique_lock<T>, with T inferred from
`mutex`).
- `auto lock = util::shared_lock(mutex);` gets an RAII shared (i.e.
"reader") lock of the mutex.
- `auto lock = util::unique_locks(mutex1, mutex2, mutex3);` can be
used to atomically lock multiple mutexes at once (returning a
tuple of the locks).
This are templated on the mutex which makes them a bit more flexible
than using a concrete type: they can be used for any type of lockable
mutex, not only util::Mutex. (Some of the code here uses them for
getting locks around a std::mutex). Until C++17, using the RAII types
is painfully verbose:
```C++
// pre-C++17 - needing to figure out the mutex type here is annoying:
std::unique_lock<util::Mutex> lock(mutex);
// pre-C++17 and even more verbose (but at least the type isn't needed):
std::unique_lock<decltype(mutex)> lock(mutex);
// our compromise:
auto lock = util::unique_lock(mutex);
// C++17:
std::unique_lock lock(mutex);
```
All of these functions will also warn (under gcc or clang) if you
discard the return value. You can also do fancy things like
`auto l = util::unique_lock(mutex, std::adopt_lock)` (which lets a
lock take over an already-locked mutex).
- metrics code is gone, which also removes a big pile of code that was
only used by metrics:
- llarp::util::Scheduler
- llarp::thread::TimerQueue
- llarp::util::Stopwatch
2020-02-21 17:21:11 +00:00
|
|
|
// RemovePending(ILinkSession* s) EXCLUDES(m_PendingMutex);
|
2019-01-07 16:35:25 +00:00
|
|
|
|
2019-12-03 17:03:19 +00:00
|
|
|
/// count the number of sessions that are yet to be fully connected
|
|
|
|
size_t
|
|
|
|
NumberOfPendingSessions() const
|
|
|
|
{
|
De-abseil, part 2: mutex, locks, (most) time
- util::Mutex is now a std::shared_timed_mutex, which is capable of
exclusive and shared locks.
- util::Lock is still present as a std::lock_guard<util::Mutex>.
- the locking annotations are preserved, but updated to the latest
supported by clang rather than using abseil's older/deprecated ones.
- ACQUIRE_LOCK macro is gone since we don't pass mutexes by pointer into
locks anymore (WTF abseil).
- ReleasableLock is gone. Instead there are now some llarp::util helper
methods to obtain unique and/or shared locks:
- `auto lock = util::unique_lock(mutex);` gets an RAII-but-also
unlockable object (std::unique_lock<T>, with T inferred from
`mutex`).
- `auto lock = util::shared_lock(mutex);` gets an RAII shared (i.e.
"reader") lock of the mutex.
- `auto lock = util::unique_locks(mutex1, mutex2, mutex3);` can be
used to atomically lock multiple mutexes at once (returning a
tuple of the locks).
This are templated on the mutex which makes them a bit more flexible
than using a concrete type: they can be used for any type of lockable
mutex, not only util::Mutex. (Some of the code here uses them for
getting locks around a std::mutex). Until C++17, using the RAII types
is painfully verbose:
```C++
// pre-C++17 - needing to figure out the mutex type here is annoying:
std::unique_lock<util::Mutex> lock(mutex);
// pre-C++17 and even more verbose (but at least the type isn't needed):
std::unique_lock<decltype(mutex)> lock(mutex);
// our compromise:
auto lock = util::unique_lock(mutex);
// C++17:
std::unique_lock lock(mutex);
```
All of these functions will also warn (under gcc or clang) if you
discard the return value. You can also do fancy things like
`auto l = util::unique_lock(mutex, std::adopt_lock)` (which lets a
lock take over an already-locked mutex).
- metrics code is gone, which also removes a big pile of code that was
only used by metrics:
- llarp::util::Scheduler
- llarp::thread::TimerQueue
- llarp::util::Stopwatch
2020-02-21 17:21:11 +00:00
|
|
|
Lock_t lock(m_PendingMutex);
|
2019-12-03 17:03:19 +00:00
|
|
|
return m_Pending.size();
|
|
|
|
}
|
|
|
|
|
2018-09-03 13:10:56 +00:00
|
|
|
private:
|
|
|
|
void
|
2019-11-23 05:05:07 +00:00
|
|
|
OnTick();
|
2018-09-03 13:10:56 +00:00
|
|
|
|
|
|
|
void
|
2020-02-24 19:40:45 +00:00
|
|
|
ScheduleTick(llarp_time_t interval);
|
2018-09-03 13:10:56 +00:00
|
|
|
|
|
|
|
uint32_t tick_id;
|
2019-01-02 01:04:04 +00:00
|
|
|
const SecretKey& m_RouterEncSecret;
|
2018-09-02 18:25:42 +00:00
|
|
|
|
|
|
|
protected:
|
2019-09-03 15:56:56 +00:00
|
|
|
#ifdef TRACY_ENABLE
|
2020-04-07 18:38:56 +00:00
|
|
|
using Lock_t = std::lock_guard<LockableBase(std::mutex)>;
|
2019-09-03 15:56:56 +00:00
|
|
|
using Mutex_t = std::mutex;
|
|
|
|
#else
|
2020-04-07 18:38:56 +00:00
|
|
|
using Lock_t = util::NullLock;
|
2019-09-03 15:56:56 +00:00
|
|
|
using Mutex_t = util::NullMutex;
|
|
|
|
#endif
|
2019-01-07 12:47:57 +00:00
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
PutSession(const std::shared_ptr<ILinkSession>& s);
|
2018-09-04 12:41:25 +00:00
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
std::shared_ptr<llarp::Logic> m_Logic = nullptr;
|
2019-04-08 12:01:52 +00:00
|
|
|
llarp_ev_loop_ptr m_Loop;
|
2020-05-06 20:38:44 +00:00
|
|
|
IpAddress m_ourAddr;
|
2018-09-02 18:25:42 +00:00
|
|
|
llarp_udp_io m_udp;
|
2018-09-03 13:10:56 +00:00
|
|
|
SecretKey m_SecretKey;
|
2018-09-07 20:36:06 +00:00
|
|
|
|
2019-03-29 14:03:07 +00:00
|
|
|
using AuthedLinks =
|
2020-04-07 18:38:56 +00:00
|
|
|
std::unordered_multimap<RouterID, std::shared_ptr<ILinkSession>, RouterID::Hash>;
|
2019-03-29 14:03:07 +00:00
|
|
|
using Pending =
|
2020-05-06 20:38:44 +00:00
|
|
|
std::unordered_multimap<IpAddress, std::shared_ptr<ILinkSession>, IpAddress::Hash>;
|
2020-04-07 18:38:56 +00:00
|
|
|
mutable DECLARE_LOCK(Mutex_t, m_AuthedLinksMutex, ACQUIRED_BEFORE(m_PendingMutex));
|
2019-03-29 14:03:07 +00:00
|
|
|
AuthedLinks m_AuthedLinks GUARDED_BY(m_AuthedLinksMutex);
|
2020-04-07 18:38:56 +00:00
|
|
|
mutable DECLARE_LOCK(Mutex_t, m_PendingMutex, ACQUIRED_AFTER(m_AuthedLinksMutex));
|
2019-03-29 14:03:07 +00:00
|
|
|
Pending m_Pending GUARDED_BY(m_PendingMutex);
|
2019-09-12 18:19:25 +00:00
|
|
|
|
2020-05-06 20:38:44 +00:00
|
|
|
std::unordered_map<IpAddress, llarp_time_t, IpAddress::Hash> m_RecentlyClosed;
|
2018-09-02 18:25:42 +00:00
|
|
|
};
|
2019-05-15 15:54:26 +00:00
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
using LinkLayer_ptr = std::shared_ptr<ILinkLayer>;
|
2018-09-02 18:25:42 +00:00
|
|
|
} // namespace llarp
|
|
|
|
|
|
|
|
#endif
|