mirror of https://github.com/oxen-io/oxen-core.git
Remove epee/time_helper
It's included in a bunch of places, but only actually half-used in one, which is easily replaced with `<chrono>` and tools::friendly_duration.
This commit is contained in:
parent
9dc312b0d9
commit
aaebf9d9d7
|
@ -1,35 +0,0 @@
|
|||
// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the Andrey N. Sabelnikov nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
|
||||
namespace epee::misc_utils
|
||||
{
|
||||
std::string get_internet_time_str(const time_t& time_);
|
||||
std::string get_time_interval_string(time_t seconds);
|
||||
}
|
|
@ -38,7 +38,6 @@ add_library(epee
|
|||
parserse_base_utils.cpp
|
||||
portable_storage.cpp
|
||||
string_tools.cpp
|
||||
time_helper.cpp
|
||||
wipeable_string.cpp
|
||||
)
|
||||
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
#include "epee/time_helper.h"
|
||||
#include "epee/pragma_comp_defs.h"
|
||||
|
||||
namespace epee::misc_utils
|
||||
{
|
||||
std::string get_internet_time_str(const time_t& time_)
|
||||
{
|
||||
char tmpbuf[200] = {0};
|
||||
tm* pt = NULL;
|
||||
PRAGMA_WARNING_PUSH
|
||||
PRAGMA_WARNING_DISABLE_VS(4996)
|
||||
pt = gmtime(&time_);
|
||||
PRAGMA_WARNING_POP
|
||||
strftime( tmpbuf, 199, "%a, %d %b %Y %H:%M:%S GMT", pt );
|
||||
return tmpbuf;
|
||||
}
|
||||
|
||||
std::string get_time_interval_string(time_t seconds)
|
||||
{
|
||||
PRAGMA_WARNING_PUSH
|
||||
PRAGMA_WARNING_DISABLE_VS(4244)
|
||||
int days = seconds/(60*60*24);
|
||||
seconds %= 60*60*24;
|
||||
int hours = seconds /(60*60);
|
||||
seconds %= (60*60);
|
||||
int minutes = seconds/60;
|
||||
seconds %= 60;
|
||||
PRAGMA_WARNING_POP
|
||||
return "d" + std::to_string(days) + ".h" + std::to_string(hours) + ".m" + std::to_string(minutes) + ".s" + std::to_string(seconds);
|
||||
}
|
||||
}
|
|
@ -55,7 +55,6 @@
|
|||
#include "cryptonote_config.h"
|
||||
#include "cryptonote_basic/miner.h"
|
||||
#include "epee/int-util.h"
|
||||
#include "epee/time_helper.h"
|
||||
#include "common/threadpool.h"
|
||||
#include "common/boost_serialization_helper.h"
|
||||
#include "epee/warnings.h"
|
||||
|
@ -512,11 +511,9 @@ bool Blockchain::init(BlockchainDB* db, sqlite3 *ons_db, std::shared_ptr<crypton
|
|||
|
||||
// check how far behind we are
|
||||
uint64_t top_block_timestamp = m_db->get_top_block_timestamp();
|
||||
uint64_t timestamp_diff = time(NULL) - top_block_timestamp;
|
||||
|
||||
// genesis block has no timestamp, could probably change it to have timestamp of 1341378000...
|
||||
if(!top_block_timestamp)
|
||||
timestamp_diff = time(NULL) - 1341378000;
|
||||
// genesis block has no timestamp, so use block 1's timestamp if we get that:
|
||||
if (!top_block_timestamp)
|
||||
top_block_timestamp = 1525306361;
|
||||
|
||||
// create general purpose async service queue
|
||||
|
||||
|
@ -528,7 +525,8 @@ bool Blockchain::init(BlockchainDB* db, sqlite3 *ons_db, std::shared_ptr<crypton
|
|||
load_compiled_in_block_hashes(get_checkpoints);
|
||||
#endif
|
||||
|
||||
log::info(logcat, "Blockchain initialized. last block: {}, {} time ago", m_db->height() - 1, epee::misc_utils::get_time_interval_string(timestamp_diff));
|
||||
log::info(logcat, "Blockchain initialized. last block: {}, {} time ago", m_db->height() - 1,
|
||||
tools::friendly_duration(std::chrono::system_clock::now() - std::chrono::system_clock::from_time_t(top_block_timestamp)));
|
||||
rtxn_guard.stop();
|
||||
|
||||
uint64_t num_popped_blocks = 0;
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
// IP blocking adapted from Boolberry
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <optional>
|
||||
#include <boost/uuid/uuid_io.hpp>
|
||||
#include <atomic>
|
||||
|
@ -42,10 +43,10 @@
|
|||
#include <vector>
|
||||
#include <fmt/color.h>
|
||||
|
||||
#include "common/string_util.h"
|
||||
#include "cryptonote_config.h"
|
||||
#include "version.h"
|
||||
#include "epee/string_tools.h"
|
||||
#include "epee/time_helper.h"
|
||||
#include "common/file.h"
|
||||
#include "common/fs-format.h"
|
||||
#include "common/pruning.h"
|
||||
|
@ -1072,6 +1073,12 @@ namespace nodetool
|
|||
return connected;
|
||||
}
|
||||
|
||||
static std::string format_stamp_ago(int64_t stamp) {
|
||||
if (stamp)
|
||||
return tools::friendly_duration(std::chrono::system_clock::now() - std::chrono::system_clock::from_time_t(stamp));
|
||||
return "never"s;
|
||||
}
|
||||
|
||||
template<class t_payload_net_handler>
|
||||
bool node_server<t_payload_net_handler>::try_to_connect_and_handshake_with_new_peer(const epee::net_utils::network_address& na, bool just_take_peerlist, uint64_t last_seen_stamp, PeerType peer_type, uint64_t first_seen_stamp)
|
||||
{
|
||||
|
@ -1091,7 +1098,8 @@ namespace nodetool
|
|||
}
|
||||
|
||||
|
||||
log::debug(logcat, "Connecting to {}(peer_type={}, last_seen: {})...", na.str(), peer_type, (last_seen_stamp ? epee::misc_utils::get_time_interval_string(time(NULL) - last_seen_stamp):"never"));
|
||||
log::debug(logcat, "Connecting to {}(peer_type={}, last_seen: {})...",
|
||||
na.str(), peer_type, format_stamp_ago(last_seen_stamp));
|
||||
|
||||
auto con = zone.m_connect(zone, na);
|
||||
if(!con)
|
||||
|
@ -1155,7 +1163,7 @@ namespace nodetool
|
|||
if (zone.m_connect == nullptr)
|
||||
return false;
|
||||
|
||||
log::info(logcat, "Connecting to {}(last_seen: {})...", na.str(), (last_seen_stamp ? epee::misc_utils::get_time_interval_string(time(NULL) - last_seen_stamp):"never"));
|
||||
log::info(logcat, "Connecting to {}(last_seen: {})...", na.str(), format_stamp_ago(last_seen_stamp));
|
||||
|
||||
auto con = zone.m_connect(zone, na);
|
||||
if (!con) {
|
||||
|
@ -1232,7 +1240,8 @@ namespace nodetool
|
|||
continue;
|
||||
}
|
||||
|
||||
log::debug(logcat, "Selected peer: {} {} first_seen: {}", peerid_to_string(pe.id), pe.adr.str(), epee::misc_utils::get_time_interval_string(time(NULL) - pe.first_seen));
|
||||
log::debug(logcat, "Selected peer: {} {} first_seen: {}",
|
||||
peerid_to_string(pe.id), pe.adr.str(), format_stamp_ago(pe.first_seen));
|
||||
|
||||
if(!try_to_connect_and_handshake_with_new_peer(pe.adr, false, 0, anchor, pe.first_seen)) {
|
||||
log::debug(logcat, "Handshake failed");
|
||||
|
@ -1364,7 +1373,12 @@ namespace nodetool
|
|||
if(is_addr_recently_failed(pe.adr))
|
||||
continue;
|
||||
|
||||
log::debug(logcat, "Selected peer: {} {}, pruning seed {} [peer_list={}] last_seen: {}", peerid_to_string(pe.id), pe.adr.str(), epee::string_tools::to_string_hex(pe.pruning_seed), (use_white_list ? white : gray), (pe.last_seen ? epee::misc_utils::get_time_interval_string(time(NULL) - pe.last_seen) : "never"));
|
||||
log::debug(logcat, "Selected peer: {} {}, pruning seed {} [peer_list={}] last_seen: {}",
|
||||
peerid_to_string(pe.id),
|
||||
pe.adr.str(),
|
||||
epee::string_tools::to_string_hex(pe.pruning_seed),
|
||||
(use_white_list ? white : gray),
|
||||
format_stamp_ago(pe.last_seen));
|
||||
|
||||
if(!try_to_connect_and_handshake_with_new_peer(pe.adr, false, pe.last_seen, use_white_list ? white : gray)) {
|
||||
log::debug(logcat, "Handshake failed");
|
||||
|
|
|
@ -1,20 +1,22 @@
|
|||
#include "p2p_protocol_defs.h"
|
||||
#include "common/string_util.h"
|
||||
#include "epee/string_tools.h"
|
||||
#include "epee/time_helper.h"
|
||||
#include "net/tor_address.h" // needed for serialization
|
||||
#include "net/i2p_address.h" // needed for serialization
|
||||
#include <fmt/core.h>
|
||||
#include <chrono>
|
||||
|
||||
namespace nodetool {
|
||||
|
||||
std::string print_peerlist_to_string(const std::vector<peerlist_entry>& pl)
|
||||
{
|
||||
time_t now = time(nullptr);
|
||||
auto now = std::chrono::system_clock::now();
|
||||
std::string result;
|
||||
for (const auto& pe : pl) {
|
||||
result += "{:016x}\t{}\tpruning seed {}\tlast_seen {}"_format(
|
||||
pe.id, pe.adr.str(), pe.pruning_seed,
|
||||
(pe.last_seen == 0 ? std::string("never") : epee::misc_utils::get_time_interval_string(now - pe.last_seen)));
|
||||
pe.last_seen == 0 ? "never"s : tools::friendly_duration(now - std::chrono::system_clock::from_time_t(pe.last_seen))
|
||||
);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
#include "net/tor_address.h" // needed for serialization
|
||||
#include "net/i2p_address.h" // needed for serialization
|
||||
#include "epee/string_tools.h"
|
||||
#include "epee/time_helper.h"
|
||||
#include "cryptonote_config.h"
|
||||
#include "crypto/crypto.h"
|
||||
|
||||
|
|
Loading…
Reference in New Issue