mirror of https://github.com/oxen-io/lokinet
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
1.5 KiB
C++
82 lines
1.5 KiB
C++
6 years ago
|
#ifndef LLARP_PROFILING_HPP
|
||
|
#define LLARP_PROFILING_HPP
|
||
6 years ago
|
|
||
|
#include <bencode.hpp>
|
||
|
#include <threading.hpp>
|
||
|
#include <router_id.hpp>
|
||
|
#include <path.hpp>
|
||
6 years ago
|
|
||
|
#include <map>
|
||
|
|
||
|
namespace llarp
|
||
|
{
|
||
6 years ago
|
struct RouterProfile final : public IBEncodeMessage
|
||
6 years ago
|
{
|
||
6 years ago
|
static constexpr size_t MaxSize = 256;
|
||
6 years ago
|
uint64_t connectTimeoutCount = 0;
|
||
|
uint64_t connectGoodCount = 0;
|
||
6 years ago
|
uint64_t pathSuccessCount = 0;
|
||
|
uint64_t pathFailCount = 0;
|
||
6 years ago
|
|
||
|
RouterProfile() : IBEncodeMessage(){};
|
||
6 years ago
|
|
||
6 years ago
|
~RouterProfile(){};
|
||
|
|
||
|
bool
|
||
6 years ago
|
BEncode(llarp_buffer_t* buf) const override;
|
||
6 years ago
|
|
||
|
bool
|
||
6 years ago
|
DecodeKey(llarp_buffer_t k, llarp_buffer_t* buf) override;
|
||
6 years ago
|
|
||
|
bool
|
||
6 years ago
|
IsGood(uint64_t chances) const;
|
||
6 years ago
|
};
|
||
|
|
||
6 years ago
|
struct Profiling final : public IBEncodeMessage
|
||
6 years ago
|
{
|
||
6 years ago
|
Profiling() : IBEncodeMessage()
|
||
|
{
|
||
|
}
|
||
|
|
||
6 years ago
|
~Profiling()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
bool
|
||
6 years ago
|
IsBad(const RouterID& r, uint64_t chances = 2);
|
||
6 years ago
|
|
||
|
void
|
||
|
MarkSuccess(const RouterID& r);
|
||
|
|
||
|
void
|
||
|
MarkTimeout(const RouterID& r);
|
||
|
|
||
|
bool
|
||
6 years ago
|
BEncode(llarp_buffer_t* buf) const override;
|
||
6 years ago
|
|
||
|
bool
|
||
6 years ago
|
DecodeKey(llarp_buffer_t k, llarp_buffer_t* buf) override;
|
||
6 years ago
|
|
||
|
bool
|
||
|
Load(const char* fname);
|
||
|
|
||
|
bool
|
||
|
Save(const char* fname);
|
||
|
|
||
6 years ago
|
void
|
||
|
MarkPathFail(path::Path* p);
|
||
|
|
||
|
void
|
||
|
MarkPathSuccess(path::Path* p);
|
||
|
|
||
6 years ago
|
private:
|
||
6 years ago
|
using lock_t = llarp::util::Lock;
|
||
|
using mtx_t = llarp::util::Mutex;
|
||
6 years ago
|
mtx_t m_ProfilesMutex;
|
||
|
std::map< RouterID, RouterProfile > m_Profiles;
|
||
|
};
|
||
|
|
||
|
} // namespace llarp
|
||
|
|
||
|
#endif
|