| 82 | } |
| 83 | |
| 84 | void RouterProfile::Load (const IdentHash& identHash) |
| 85 | { |
| 86 | m_IsUpdated = false; |
| 87 | std::string ident = identHash.ToBase64 (); |
| 88 | std::string path = g_ProfilesStorage.Path(ident); |
| 89 | boost::property_tree::ptree pt; |
| 90 | |
| 91 | if (!i2p::fs::Exists(path)) |
| 92 | { |
| 93 | LogPrint(eLogWarning, "Profiling: No profile yet for ", ident); |
| 94 | return; |
| 95 | } |
| 96 | |
| 97 | try |
| 98 | { |
| 99 | boost::property_tree::read_ini (path, pt); |
| 100 | } catch (std::exception& ex) |
| 101 | { |
| 102 | /* boost exception verbose enough */ |
| 103 | LogPrint (eLogError, "Profiling: ", ex.what ()); |
| 104 | return; |
| 105 | } |
| 106 | |
| 107 | try |
| 108 | { |
| 109 | auto ts = pt.get (PEER_PROFILE_LAST_UPDATE_TIMESTAMP, 0); |
| 110 | if (ts) |
| 111 | m_LastUpdateTime = ts; |
| 112 | else |
| 113 | { |
| 114 | // try old lastupdatetime |
| 115 | auto ut = pt.get (PEER_PROFILE_LAST_UPDATE_TIME, ""); |
| 116 | if (ut.length () > 0) |
| 117 | { |
| 118 | std::istringstream ss (ut); std::tm t; |
| 119 | ss >> std::get_time(&t, "%Y-%b-%d %H:%M:%S"); |
| 120 | if (!ss.fail()) |
| 121 | m_LastUpdateTime = mktime (&t); // t is local time |
| 122 | } |
| 123 | } |
| 124 | if (i2p::util::GetSecondsSinceEpoch () - m_LastUpdateTime < PEER_PROFILE_EXPIRATION_TIMEOUT) |
| 125 | { |
| 126 | m_LastUnreachableTime = pt.get (PEER_PROFILE_LAST_UNREACHABLE_TIME, 0); |
| 127 | try |
| 128 | { |
| 129 | // read participations |
| 130 | auto participations = pt.get_child (PEER_PROFILE_SECTION_PARTICIPATION); |
| 131 | m_NumTunnelsAgreed = participations.get (PEER_PROFILE_PARTICIPATION_AGREED, 0); |
| 132 | m_NumTunnelsDeclined = participations.get (PEER_PROFILE_PARTICIPATION_DECLINED, 0); |
| 133 | m_NumTunnelsNonReplied = participations.get (PEER_PROFILE_PARTICIPATION_NON_REPLIED, 0.0f); |
| 134 | } |
| 135 | catch (boost::property_tree::ptree_bad_path& ex) |
| 136 | { |
| 137 | LogPrint (eLogWarning, "Profiling: Missing section ", PEER_PROFILE_SECTION_PARTICIPATION, " in profile for ", ident); |
| 138 | } |
| 139 | try |
| 140 | { |
| 141 | // read usage |
no test coverage detected