2018-09-13 18:41:53 +02:00
|
|
|
#ifndef LLARP_PROFILING_HPP
|
|
|
|
#define LLARP_PROFILING_HPP
|
2018-12-12 03:52:51 +01:00
|
|
|
|
2019-01-11 02:19:36 +01:00
|
|
|
#include <path/path.hpp>
|
2019-01-10 20:41:51 +01:00
|
|
|
#include <router_id.hpp>
|
|
|
|
#include <util/bencode.hpp>
|
2019-09-01 15:26:16 +02:00
|
|
|
#include <util/thread/threading.hpp>
|
2018-09-13 18:41:53 +02:00
|
|
|
|
2019-03-03 21:51:47 +01:00
|
|
|
#include <absl/base/thread_annotations.h>
|
2018-09-13 18:41:53 +02:00
|
|
|
#include <map>
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
2019-05-24 04:01:36 +02:00
|
|
|
struct RouterProfile
|
2018-09-13 18:41:53 +02:00
|
|
|
{
|
2018-09-14 16:50:37 +02:00
|
|
|
static constexpr size_t MaxSize = 256;
|
2018-09-13 18:41:53 +02:00
|
|
|
uint64_t connectTimeoutCount = 0;
|
|
|
|
uint64_t connectGoodCount = 0;
|
2018-09-14 16:50:37 +02:00
|
|
|
uint64_t pathSuccessCount = 0;
|
|
|
|
uint64_t pathFailCount = 0;
|
2019-03-04 18:03:18 +01:00
|
|
|
llarp_time_t lastUpdated = 0;
|
2019-04-16 19:30:07 +02:00
|
|
|
llarp_time_t lastDecay = 0;
|
2019-05-24 04:01:36 +02:00
|
|
|
uint64_t version = LLARP_PROTO_VERSION;
|
2018-09-13 18:41:53 +02:00
|
|
|
|
|
|
|
bool
|
2019-05-24 04:01:36 +02:00
|
|
|
BEncode(llarp_buffer_t* buf) const;
|
2018-09-13 18:41:53 +02:00
|
|
|
|
|
|
|
bool
|
2019-05-24 04:01:36 +02:00
|
|
|
DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf);
|
2018-09-13 18:41:53 +02:00
|
|
|
|
|
|
|
bool
|
2018-09-14 16:50:37 +02:00
|
|
|
IsGood(uint64_t chances) const;
|
2019-03-04 18:03:18 +01:00
|
|
|
|
2019-04-16 13:44:55 +02:00
|
|
|
bool
|
|
|
|
IsGoodForConnect(uint64_t chances) const;
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsGoodForPath(uint64_t chances) const;
|
|
|
|
|
2019-03-05 14:38:50 +01:00
|
|
|
/// decay stats
|
2019-03-04 18:03:18 +01:00
|
|
|
void
|
2019-03-05 14:38:50 +01:00
|
|
|
Decay();
|
2019-03-04 18:03:18 +01:00
|
|
|
|
|
|
|
// rotate stats if timeout reached
|
|
|
|
void
|
|
|
|
Tick();
|
2018-09-13 18:41:53 +02:00
|
|
|
};
|
|
|
|
|
2019-05-24 04:01:36 +02:00
|
|
|
struct Profiling
|
2018-09-13 18:41:53 +02:00
|
|
|
{
|
2019-04-25 13:00:18 +02:00
|
|
|
Profiling();
|
2018-09-13 18:41:53 +02:00
|
|
|
|
2019-04-16 13:44:55 +02:00
|
|
|
/// generic variant
|
2018-09-13 18:41:53 +02:00
|
|
|
bool
|
2019-03-22 15:48:53 +01:00
|
|
|
IsBad(const RouterID& r, uint64_t chances = 8)
|
2019-03-03 21:51:47 +01:00
|
|
|
LOCKS_EXCLUDED(m_ProfilesMutex);
|
2018-09-13 18:41:53 +02:00
|
|
|
|
2019-05-24 04:01:36 +02:00
|
|
|
/// check if this router should have paths built over it
|
2019-04-16 15:20:48 +02:00
|
|
|
bool
|
|
|
|
IsBadForPath(const RouterID& r, uint64_t chances = 8)
|
2019-04-16 13:44:55 +02:00
|
|
|
LOCK_RETURNED(m_ProfilesMutex);
|
|
|
|
|
|
|
|
/// check if this router should be connected directly to
|
2019-04-16 15:20:48 +02:00
|
|
|
bool
|
|
|
|
IsBadForConnect(const RouterID& r, uint64_t chances = 8)
|
2019-04-16 13:44:55 +02:00
|
|
|
LOCKS_EXCLUDED(m_ProfilesMutex);
|
|
|
|
|
2018-09-13 18:41:53 +02:00
|
|
|
void
|
2019-04-17 16:46:00 +02:00
|
|
|
MarkConnectTimeout(const RouterID& r) LOCKS_EXCLUDED(m_ProfilesMutex);
|
2018-09-13 18:41:53 +02:00
|
|
|
|
|
|
|
void
|
2019-04-17 16:46:00 +02:00
|
|
|
MarkConnectSuccess(const RouterID& r) LOCKS_EXCLUDED(m_ProfilesMutex);
|
2019-03-03 21:51:47 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
MarkPathFail(path::Path* p) LOCKS_EXCLUDED(m_ProfilesMutex);
|
|
|
|
|
|
|
|
void
|
|
|
|
MarkPathSuccess(path::Path* p) LOCKS_EXCLUDED(m_ProfilesMutex);
|
2018-09-13 18:41:53 +02:00
|
|
|
|
2020-01-03 13:52:19 +01:00
|
|
|
void
|
|
|
|
MarkHopFail(const RouterID& r) LOCKS_EXCLUDED(m_ProfilesMutex);
|
|
|
|
|
2019-03-31 17:25:13 +02:00
|
|
|
void
|
|
|
|
ClearProfile(const RouterID& r) LOCKS_EXCLUDED(m_ProfilesMutex);
|
|
|
|
|
2019-03-04 18:03:18 +01:00
|
|
|
void
|
2019-03-14 01:20:37 +01:00
|
|
|
Tick() LOCKS_EXCLUDED(m_ProfilesMutex);
|
2019-03-04 18:03:18 +01:00
|
|
|
|
2018-09-13 18:41:53 +02:00
|
|
|
bool
|
2019-05-24 04:01:36 +02:00
|
|
|
BEncode(llarp_buffer_t* buf) const LOCKS_EXCLUDED(m_ProfilesMutex);
|
2018-09-13 18:41:53 +02:00
|
|
|
|
|
|
|
bool
|
2019-05-24 04:01:36 +02:00
|
|
|
DecodeKey(const llarp_buffer_t& k,
|
|
|
|
llarp_buffer_t* buf) NO_THREAD_SAFETY_ANALYSIS;
|
|
|
|
// disabled because we do load -> bencode::BDecodeReadFromFile -> DecodeKey
|
2018-09-13 18:41:53 +02:00
|
|
|
|
|
|
|
bool
|
2019-03-03 21:51:47 +01:00
|
|
|
Load(const char* fname) LOCKS_EXCLUDED(m_ProfilesMutex);
|
2018-09-13 18:41:53 +02:00
|
|
|
|
|
|
|
bool
|
2019-03-03 21:51:47 +01:00
|
|
|
Save(const char* fname) LOCKS_EXCLUDED(m_ProfilesMutex);
|
2018-09-14 16:50:37 +02:00
|
|
|
|
2019-03-25 16:41:37 +01:00
|
|
|
bool
|
|
|
|
ShouldSave(llarp_time_t now) const;
|
|
|
|
|
2019-04-25 13:00:18 +02:00
|
|
|
void
|
|
|
|
Disable();
|
|
|
|
|
|
|
|
void
|
|
|
|
Enable();
|
|
|
|
|
2018-09-13 18:41:53 +02:00
|
|
|
private:
|
2019-03-03 21:51:47 +01:00
|
|
|
bool
|
|
|
|
BEncodeNoLock(llarp_buffer_t* buf) const
|
|
|
|
SHARED_LOCKS_REQUIRED(m_ProfilesMutex);
|
|
|
|
using lock_t = util::Lock;
|
|
|
|
mutable util::Mutex m_ProfilesMutex; // protects m_Profiles
|
|
|
|
std::map< RouterID, RouterProfile > m_Profiles GUARDED_BY(m_ProfilesMutex);
|
2019-03-25 16:41:37 +01:00
|
|
|
llarp_time_t m_LastSave = 0;
|
2019-04-25 13:00:18 +02:00
|
|
|
std::atomic< bool > m_DisableProfiling;
|
2018-09-13 18:41:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace llarp
|
|
|
|
|
|
|
|
#endif
|