2018-09-13 16:41:53 +00:00
|
|
|
#ifndef LLARP_PROFILING_HPP
|
|
|
|
#define LLARP_PROFILING_HPP
|
2018-12-12 02:52:51 +00:00
|
|
|
|
2019-01-11 01:19:36 +00:00
|
|
|
#include <path/path.hpp>
|
2019-01-10 19:41:51 +00:00
|
|
|
#include <router_id.hpp>
|
|
|
|
#include <util/bencode.hpp>
|
|
|
|
#include <util/threading.hpp>
|
2018-09-13 16:41:53 +00:00
|
|
|
|
2019-03-03 20:51:47 +00:00
|
|
|
#include <absl/base/thread_annotations.h>
|
2018-09-13 16:41:53 +00:00
|
|
|
#include <map>
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
2018-11-05 11:27:12 +00:00
|
|
|
struct RouterProfile final : public IBEncodeMessage
|
2018-09-13 16:41:53 +00:00
|
|
|
{
|
2018-09-14 14:50:37 +00:00
|
|
|
static constexpr size_t MaxSize = 256;
|
2018-09-13 16:41:53 +00:00
|
|
|
uint64_t connectTimeoutCount = 0;
|
|
|
|
uint64_t connectGoodCount = 0;
|
2018-09-14 14:50:37 +00:00
|
|
|
uint64_t pathSuccessCount = 0;
|
|
|
|
uint64_t pathFailCount = 0;
|
2019-03-04 17:03:18 +00:00
|
|
|
llarp_time_t lastUpdated = 0;
|
2018-09-13 16:41:53 +00:00
|
|
|
|
|
|
|
RouterProfile() : IBEncodeMessage(){};
|
2018-11-05 11:27:12 +00:00
|
|
|
|
2018-09-13 16:41:53 +00:00
|
|
|
~RouterProfile(){};
|
|
|
|
|
|
|
|
bool
|
2018-11-05 11:27:12 +00:00
|
|
|
BEncode(llarp_buffer_t* buf) const override;
|
2018-09-13 16:41:53 +00:00
|
|
|
|
|
|
|
bool
|
2019-02-05 00:41:33 +00:00
|
|
|
DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf) override;
|
2018-09-13 16:41:53 +00:00
|
|
|
|
|
|
|
bool
|
2018-09-14 14:50:37 +00:00
|
|
|
IsGood(uint64_t chances) const;
|
2019-03-04 17:03:18 +00:00
|
|
|
|
2019-03-05 13:38:50 +00:00
|
|
|
/// decay stats
|
2019-03-04 17:03:18 +00:00
|
|
|
void
|
2019-03-05 13:38:50 +00:00
|
|
|
Decay();
|
2019-03-04 17:03:18 +00:00
|
|
|
|
|
|
|
// rotate stats if timeout reached
|
|
|
|
void
|
|
|
|
Tick();
|
2018-09-13 16:41:53 +00:00
|
|
|
};
|
|
|
|
|
2018-11-05 11:27:12 +00:00
|
|
|
struct Profiling final : public IBEncodeMessage
|
2018-09-13 16:41:53 +00:00
|
|
|
{
|
2018-11-05 11:27:12 +00:00
|
|
|
Profiling() : IBEncodeMessage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-09-13 16:41:53 +00:00
|
|
|
~Profiling()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2019-03-03 20:51:47 +00:00
|
|
|
IsBad(const RouterID& r, uint64_t chances = 2)
|
|
|
|
LOCKS_EXCLUDED(m_ProfilesMutex);
|
2018-09-13 16:41:53 +00:00
|
|
|
|
|
|
|
void
|
2019-03-03 20:51:47 +00:00
|
|
|
MarkTimeout(const RouterID& r) LOCKS_EXCLUDED(m_ProfilesMutex);
|
2018-09-13 16:41:53 +00:00
|
|
|
|
|
|
|
void
|
2019-03-03 20:51:47 +00:00
|
|
|
MarkSuccess(const RouterID& r) LOCKS_EXCLUDED(m_ProfilesMutex);
|
|
|
|
|
|
|
|
void
|
|
|
|
MarkPathFail(path::Path* p) LOCKS_EXCLUDED(m_ProfilesMutex);
|
|
|
|
|
|
|
|
void
|
|
|
|
MarkPathSuccess(path::Path* p) LOCKS_EXCLUDED(m_ProfilesMutex);
|
2018-09-13 16:41:53 +00:00
|
|
|
|
2019-03-04 17:03:18 +00:00
|
|
|
void
|
2019-03-14 00:20:37 +00:00
|
|
|
Tick() LOCKS_EXCLUDED(m_ProfilesMutex);
|
2019-03-04 17:03:18 +00:00
|
|
|
|
2018-09-13 16:41:53 +00:00
|
|
|
bool
|
2019-03-03 20:51:47 +00:00
|
|
|
BEncode(llarp_buffer_t* buf) const override LOCKS_EXCLUDED(m_ProfilesMutex);
|
2018-09-13 16:41:53 +00:00
|
|
|
|
|
|
|
bool
|
2019-03-14 00:20:37 +00:00
|
|
|
DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf) override
|
|
|
|
SHARED_LOCKS_REQUIRED(m_ProfilesMutex);
|
2018-09-13 16:41:53 +00:00
|
|
|
|
|
|
|
bool
|
2019-03-03 20:51:47 +00:00
|
|
|
Load(const char* fname) LOCKS_EXCLUDED(m_ProfilesMutex);
|
2018-09-13 16:41:53 +00:00
|
|
|
|
|
|
|
bool
|
2019-03-03 20:51:47 +00:00
|
|
|
Save(const char* fname) LOCKS_EXCLUDED(m_ProfilesMutex);
|
2018-09-14 14:50:37 +00:00
|
|
|
|
2018-09-13 16:41:53 +00:00
|
|
|
private:
|
2019-03-03 20:51:47 +00: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);
|
2018-09-13 16:41:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace llarp
|
|
|
|
|
|
|
|
#endif
|