Skip to content

Commit

Permalink
save last update time
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Mar 31, 2015
1 parent 92bd29e commit d9911f4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Profiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ namespace i2p
namespace data
{
RouterProfile::RouterProfile (const IdentHash& identHash):
m_IdentHash (identHash), m_NumTunnelsAgreed (0), m_NumTunnelsDeclined (0),
m_IdentHash (identHash), m_LastUpdateTime (boost::posix_time::second_clock::local_time()),
m_NumTunnelsAgreed (0), m_NumTunnelsDeclined (0),
m_NumTunnelsNonReplied (0)
{
}

void RouterProfile::UpdateTime ()
{
m_LastUpdateTime = boost::posix_time::second_clock::local_time();
}

void RouterProfile::Save ()
{
Expand All @@ -24,6 +30,7 @@ namespace data
participation.put (PEER_PROFILE_PARTICIPATION_NON_REPLIED, m_NumTunnelsNonReplied);
// fill property tree
boost::property_tree::ptree pt;
pt.put (PEER_PROFILE_LAST_UPDATE_TIME, boost::posix_time::to_simple_string (m_LastUpdateTime));
pt.put_child (PEER_PROFILE_SECTION_PARTICIPATION, participation);

// save to file
Expand Down Expand Up @@ -80,6 +87,9 @@ namespace data
}
try
{
auto t = pt.get (PEER_PROFILE_LAST_UPDATE_TIME, "");
if (t.length () > 0)
m_LastUpdateTime = boost::posix_time::time_from_string (t);
// read participations
auto participations = pt.get_child (PEER_PROFILE_SECTION_PARTICIPATION);
m_NumTunnelsAgreed = participations.get (PEER_PROFILE_PARTICIPATION_AGREED, 0);
Expand All @@ -99,11 +109,13 @@ namespace data
m_NumTunnelsDeclined++;
else
m_NumTunnelsAgreed++;
UpdateTime ();
}

void RouterProfile::TunnelNonReplied ()
{
m_NumTunnelsNonReplied++;
UpdateTime ();
}

std::shared_ptr<RouterProfile> GetRouterProfile (const IdentHash& identHash)
Expand Down
7 changes: 7 additions & 0 deletions Profiling.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define PROFILING_H__

#include <memory>
#include <boost/date_time/posix_time/posix_time.hpp>
#include "Identity.h"

namespace i2p
Expand All @@ -13,6 +14,7 @@ namespace data
// sections
const char PEER_PROFILE_SECTION_PARTICIPATION[] = "participation";
// params
const char PEER_PROFILE_LAST_UPDATE_TIME[] = "lastupdatetime";
const char PEER_PROFILE_PARTICIPATION_AGREED[] = "agreed";
const char PEER_PROFILE_PARTICIPATION_DECLINED[] = "declined";
const char PEER_PROFILE_PARTICIPATION_NON_REPLIED[] = "nonreplied";
Expand All @@ -30,10 +32,15 @@ namespace data

void TunnelBuildResponse (uint8_t ret);
void TunnelNonReplied ();

private:

void UpdateTime ();

private:

IdentHash m_IdentHash;
boost::posix_time::ptime m_LastUpdateTime;
// participation
uint32_t m_NumTunnelsAgreed;
uint32_t m_NumTunnelsDeclined;
Expand Down

0 comments on commit d9911f4

Please sign in to comment.