2018-09-13 16:41:53 +00:00
|
|
|
#ifndef LLARP_PROFILING_HPP
|
|
|
|
#define LLARP_PROFILING_HPP
|
|
|
|
#include <llarp/bencode.hpp>
|
|
|
|
#include <llarp/threading.hpp>
|
|
|
|
#include <llarp/router_id.hpp>
|
2018-09-14 14:50:37 +00:00
|
|
|
#include <llarp/path.hpp>
|
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;
|
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
|
2018-11-05 11:27:12 +00:00
|
|
|
DecodeKey(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;
|
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
|
2018-10-04 16:48:26 +00:00
|
|
|
IsBad(const RouterID& r, uint64_t chances = 2);
|
2018-09-13 16:41:53 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
MarkSuccess(const RouterID& r);
|
|
|
|
|
|
|
|
void
|
|
|
|
MarkTimeout(const RouterID& r);
|
|
|
|
|
|
|
|
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
|
2018-11-05 11:27:12 +00:00
|
|
|
DecodeKey(llarp_buffer_t k, llarp_buffer_t* buf) override;
|
2018-09-13 16:41:53 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
Load(const char* fname);
|
|
|
|
|
|
|
|
bool
|
|
|
|
Save(const char* fname);
|
|
|
|
|
2018-09-14 14:50:37 +00:00
|
|
|
void
|
|
|
|
MarkPathFail(path::Path* p);
|
|
|
|
|
|
|
|
void
|
|
|
|
MarkPathSuccess(path::Path* p);
|
|
|
|
|
2018-09-13 16:41:53 +00:00
|
|
|
private:
|
|
|
|
typedef llarp::util::Lock lock_t;
|
|
|
|
typedef llarp::util::Mutex mtx_t;
|
|
|
|
mtx_t m_ProfilesMutex;
|
|
|
|
std::map< RouterID, RouterProfile > m_Profiles;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace llarp
|
|
|
|
|
|
|
|
#endif
|