mirror of https://github.com/oxen-io/lokinet
update profiles on path build
This commit is contained in:
parent
b245453ef6
commit
8331449ab9
|
@ -210,7 +210,7 @@ namespace llarp
|
|||
return router->NumberOfConnectedRouters()
|
||||
&& router->GetRandomConnectedRouter(cur);
|
||||
|
||||
size_t tries = 5;
|
||||
size_t tries = 10;
|
||||
do
|
||||
{
|
||||
--tries;
|
||||
|
@ -326,6 +326,7 @@ namespace llarp
|
|||
Builder::HandlePathBuilt(Path* p)
|
||||
{
|
||||
buildIntervalLimit = MIN_PATH_BUILD_INTERVAL;
|
||||
router->routerProfiling().MarkPathSuccess(p);
|
||||
PathSet::HandlePathBuilt(p);
|
||||
}
|
||||
|
||||
|
@ -336,6 +337,7 @@ namespace llarp
|
|||
static constexpr llarp_time_t MaxBuildInterval = 30 * 1000;
|
||||
buildIntervalLimit =
|
||||
std::max(1000 + buildIntervalLimit, MaxBuildInterval);
|
||||
router->routerProfiling().MarkPathFail(p);
|
||||
PathSet::HandlePathBuildTimeout(p);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@ namespace llarp
|
|||
return false;
|
||||
if(!BEncodeWriteDictInt("t", connectTimeoutCount, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("u", lastUpdated, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("v", version, buf))
|
||||
return false;
|
||||
|
||||
|
@ -32,6 +34,8 @@ namespace llarp
|
|||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("t", connectTimeoutCount, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("u", lastUpdated, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("v", version, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("s", pathFailCount, read, k, buf))
|
||||
|
@ -41,6 +45,28 @@ namespace llarp
|
|||
return read;
|
||||
}
|
||||
|
||||
void
|
||||
RouterProfile::Clear()
|
||||
{
|
||||
connectGoodCount = 0;
|
||||
connectTimeoutCount = 0;
|
||||
pathSuccessCount = 0;
|
||||
pathFailCount = 0;
|
||||
lastUpdated = llarp::time_now_ms();
|
||||
}
|
||||
|
||||
void
|
||||
RouterProfile::Tick()
|
||||
{
|
||||
// 10 minutes
|
||||
static constexpr llarp_time_t updateInterval = DEFAULT_PATH_LIFETIME;
|
||||
auto now = llarp::time_now_ms();
|
||||
if(lastUpdated < now && now - lastUpdated > updateInterval)
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
RouterProfile::IsGood(uint64_t chances) const
|
||||
{
|
||||
|
@ -59,11 +85,20 @@ namespace llarp
|
|||
return !itr->second.IsGood(chances);
|
||||
}
|
||||
|
||||
void
|
||||
Profiling::Tick()
|
||||
{
|
||||
lock_t lock(m_ProfilesMutex);
|
||||
std::for_each(m_Profiles.begin(), m_Profiles.end(),
|
||||
[](auto& item) { item.second.Tick(); });
|
||||
}
|
||||
|
||||
void
|
||||
Profiling::MarkTimeout(const RouterID& r)
|
||||
{
|
||||
lock_t lock(m_ProfilesMutex);
|
||||
m_Profiles[r].connectTimeoutCount += 1;
|
||||
m_Profiles[r].lastUpdated = llarp::time_now_ms();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -71,6 +106,7 @@ namespace llarp
|
|||
{
|
||||
lock_t lock(m_ProfilesMutex);
|
||||
m_Profiles[r].connectGoodCount += 1;
|
||||
m_Profiles[r].lastUpdated = llarp::time_now_ms();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -81,6 +117,7 @@ namespace llarp
|
|||
{
|
||||
// TODO: also mark bad?
|
||||
m_Profiles[hop.rc.pubkey].pathFailCount += 1;
|
||||
m_Profiles[hop.rc.pubkey].lastUpdated = llarp::time_now_ms();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,6 +128,7 @@ namespace llarp
|
|||
for(const auto& hop : p->hops)
|
||||
{
|
||||
m_Profiles[hop.rc.pubkey].pathSuccessCount += 1;
|
||||
m_Profiles[hop.rc.pubkey].lastUpdated = llarp::time_now_ms();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace llarp
|
|||
uint64_t connectGoodCount = 0;
|
||||
uint64_t pathSuccessCount = 0;
|
||||
uint64_t pathFailCount = 0;
|
||||
llarp_time_t lastUpdated = 0;
|
||||
|
||||
RouterProfile() : IBEncodeMessage(){};
|
||||
|
||||
|
@ -30,6 +31,14 @@ namespace llarp
|
|||
|
||||
bool
|
||||
IsGood(uint64_t chances) const;
|
||||
|
||||
/// clear stats
|
||||
void
|
||||
Clear();
|
||||
|
||||
// rotate stats if timeout reached
|
||||
void
|
||||
Tick();
|
||||
};
|
||||
|
||||
struct Profiling final : public IBEncodeMessage
|
||||
|
@ -51,6 +60,9 @@ namespace llarp
|
|||
void
|
||||
MarkTimeout(const RouterID& r);
|
||||
|
||||
void
|
||||
Tick();
|
||||
|
||||
bool
|
||||
BEncode(llarp_buffer_t* buf) const override;
|
||||
|
||||
|
|
|
@ -1021,6 +1021,8 @@ namespace llarp
|
|||
// LogDebug("tick router");
|
||||
auto now = Now();
|
||||
|
||||
routerProfiling().Tick();
|
||||
|
||||
if(_rc.ExpiresSoon(now, randint() % 10000))
|
||||
{
|
||||
LogInfo("regenerating RC");
|
||||
|
|
Loading…
Reference in New Issue