mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-04 11:15:56 +00:00
Migrate off of posix_time and most uses of C time_t.
This commit is contained in:
committed by
Vinnie Falco
parent
2e2a7509cd
commit
5d9e53a37d
@@ -1467,8 +1467,6 @@
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\ripple\basics\ThreadName.h">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple\basics\Time.h">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple\basics\ToString.h">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple\basics\UnorderedContainers.h">
|
||||
|
||||
@@ -1935,9 +1935,6 @@
|
||||
<ClInclude Include="..\..\src\ripple\basics\ThreadName.h">
|
||||
<Filter>ripple\basics</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple\basics\Time.h">
|
||||
<Filter>ripple\basics</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple\basics\ToString.h">
|
||||
<Filter>ripple\basics</Filter>
|
||||
</ClInclude>
|
||||
|
||||
@@ -21,12 +21,10 @@
|
||||
#define RIPPLE_APP_LEDGER_LEDGERTOJSON_H_INCLUDED
|
||||
|
||||
#include <ripple/app/ledger/Ledger.h>
|
||||
#include <ripple/basics/Time.h>
|
||||
#include <ripple/basics/StringUtilities.h>
|
||||
#include <ripple/protocol/JsonFields.h>
|
||||
#include <ripple/protocol/STTx.h>
|
||||
#include <ripple/json/Object.h>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
enum
|
||||
{
|
||||
// Number of peers to start with
|
||||
@@ -45,9 +47,6 @@ enum
|
||||
// Number of peers to add on a timeout
|
||||
,peerCountAdd = 2
|
||||
|
||||
// millisecond for each ledger timeout
|
||||
,ledgerAcquireTimeoutMillis = 2500
|
||||
|
||||
// how many timeouts before we giveup
|
||||
,ledgerTimeoutRetriesMax = 10
|
||||
|
||||
@@ -64,9 +63,12 @@ enum
|
||||
,reqNodes = 8
|
||||
};
|
||||
|
||||
// millisecond for each ledger timeout
|
||||
auto constexpr ledgerAcquireTimeout = 2500ms;
|
||||
|
||||
InboundLedger::InboundLedger (
|
||||
Application& app, uint256 const& hash, std::uint32_t seq, fcReason reason, clock_type& clock)
|
||||
: PeerSet (app, hash, ledgerAcquireTimeoutMillis, false, clock,
|
||||
: PeerSet (app, hash, ledgerAcquireTimeout, false, clock,
|
||||
app.journal("InboundLedger"))
|
||||
, mHaveHeader (false)
|
||||
, mHaveState (false)
|
||||
|
||||
@@ -74,8 +74,7 @@ void fillJson(Object& json, bool closed, LedgerInfo const& info, bool bFull)
|
||||
|
||||
if (info.closeTime != NetClock::time_point{})
|
||||
{
|
||||
json[jss::close_time_human] = boost::posix_time::to_simple_string (
|
||||
ptFromSeconds (info.closeTime.time_since_epoch().count()));
|
||||
json[jss::close_time_human] = to_string(info.closeTime);
|
||||
if (! getCloseAgree(info))
|
||||
json[jss::close_time_estimated] = true;
|
||||
}
|
||||
|
||||
@@ -30,11 +30,13 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
// Timeout interval in milliseconds
|
||||
auto constexpr TX_ACQUIRE_TIMEOUT = 250ms;
|
||||
|
||||
enum
|
||||
{
|
||||
// Timeout interval in milliseconds
|
||||
TX_ACQUIRE_TIMEOUT = 250,
|
||||
|
||||
NORM_TIMEOUTS = 4,
|
||||
MAX_TIMEOUTS = 20,
|
||||
};
|
||||
|
||||
@@ -45,7 +45,6 @@
|
||||
#include <ripple/basics/contract.h>
|
||||
#include <ripple/basics/Log.h>
|
||||
#include <ripple/basics/random.h>
|
||||
#include <ripple/basics/Time.h>
|
||||
#include <ripple/protocol/digest.h>
|
||||
#include <ripple/basics/StringUtilities.h>
|
||||
#include <ripple/basics/UptimeTimer.h>
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include <ripple/net/InfoSub.h>
|
||||
#include <memory>
|
||||
#include <ripple/core/Stoppable.h>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
#include <deque>
|
||||
#include <tuple>
|
||||
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef RIPPLE_BASICS_TIME_H_INCLUDED
|
||||
#define RIPPLE_BASICS_TIME_H_INCLUDED
|
||||
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
// VFALCO TODO Roll this into some utilities header
|
||||
int iToSeconds (boost::posix_time::ptime ptWhen);
|
||||
boost::posix_time::ptime ptFromSeconds (int iSeconds);
|
||||
uint64_t utFromSeconds (int iSeconds);
|
||||
|
||||
} // ripple
|
||||
|
||||
#endif
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <ripple/beast/clock/manual_clock.h>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
@@ -55,6 +56,9 @@ public:
|
||||
static bool const is_steady = false;
|
||||
};
|
||||
|
||||
std::string to_string(NetClock::time_point tp);
|
||||
std::string to_string(std::chrono::system_clock::time_point tp);
|
||||
|
||||
/** A clock for measuring elapsed time.
|
||||
|
||||
The epoch is unspecified.
|
||||
|
||||
@@ -18,11 +18,11 @@
|
||||
//==============================================================================
|
||||
|
||||
#include <BeastConfig.h>
|
||||
#include <ripple/basics/chrono.h>
|
||||
#include <ripple/basics/Log.h>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
// VFALCO TODO Use std::chrono
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
namespace ripple {
|
||||
@@ -311,8 +311,7 @@ Logs::format (std::string& output, std::string const& message,
|
||||
{
|
||||
output.reserve (message.size() + partition.size() + 100);
|
||||
|
||||
output = boost::posix_time::to_simple_string (
|
||||
boost::posix_time::second_clock::universal_time ());
|
||||
output = to_string(std::chrono::system_clock::now());
|
||||
|
||||
output += " ";
|
||||
if (! partition.empty ())
|
||||
|
||||
@@ -18,47 +18,66 @@
|
||||
//==============================================================================
|
||||
|
||||
#include <BeastConfig.h>
|
||||
#include <ripple/basics/Time.h>
|
||||
#include <ripple/beast/clock/chrono_util.h>
|
||||
#include <ripple/basics/chrono.h>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <tuple>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
// VFALCO TODO Tidy this up into a RippleTime object
|
||||
|
||||
//
|
||||
// Time support
|
||||
// We have our own epoch.
|
||||
//
|
||||
|
||||
boost::posix_time::ptime ptEpoch ()
|
||||
static
|
||||
std::tuple<int, unsigned, unsigned>
|
||||
civil_from_days(int z) noexcept
|
||||
{
|
||||
return boost::posix_time::ptime (boost::gregorian::date (2000, boost::gregorian::Jan, 1));
|
||||
z += 719468;
|
||||
const int era = (z >= 0 ? z : z - 146096) / 146097;
|
||||
const unsigned doe = static_cast<unsigned>(z - era * 146097); // [0, 146096]
|
||||
const unsigned yoe = (doe - doe/1460 + doe/36524 - doe/146096) / 365; // [0, 399]
|
||||
const int y = static_cast<int>(yoe) + era * 400;
|
||||
const unsigned doy = doe - (365*yoe + yoe/4 - yoe/100); // [0, 365]
|
||||
const unsigned mp = (5*doy + 2)/153; // [0, 11]
|
||||
const unsigned d = doy - (153*mp+2)/5 + 1; // [1, 31]
|
||||
const unsigned m = mp + (mp < 10 ? 3 : -9); // [1, 12]
|
||||
return std::tuple<int, unsigned, unsigned>(y + (m <= 2), m, d);
|
||||
}
|
||||
|
||||
int iToSeconds (boost::posix_time::ptime ptWhen)
|
||||
std::string
|
||||
to_string(std::chrono::system_clock::time_point tp)
|
||||
{
|
||||
return ptWhen.is_not_a_date_time ()
|
||||
? -1
|
||||
: (ptWhen - ptEpoch ()).total_seconds ();
|
||||
const char* months[] =
|
||||
{
|
||||
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
||||
};
|
||||
using namespace std::chrono;
|
||||
auto s = floor<seconds>(tp.time_since_epoch());
|
||||
auto sd = floor<days>(s); // number of days
|
||||
s -= sd; // time of day in seconds
|
||||
auto h = floor<hours>(s);
|
||||
s -= h;
|
||||
auto m = floor<minutes>(s);
|
||||
s -= m;
|
||||
int y;
|
||||
unsigned mn, d;
|
||||
std::tie(y, mn, d) = civil_from_days(static_cast<int>(sd.count()));
|
||||
// Date-time in y/mn/d h:m:s
|
||||
std::ostringstream str;
|
||||
str.fill('0');
|
||||
str.flags(std::ios::dec | std::ios::right);
|
||||
using std::setw;
|
||||
str << y << '-' << months[mn-1] << '-' << setw(2) << d << ' '
|
||||
<< setw(2) << h.count() << ':'
|
||||
<< setw(2) << m.count() << ':'
|
||||
<< setw(2) << s.count();
|
||||
return str.str();
|
||||
}
|
||||
|
||||
// Convert our time in seconds to a ptime.
|
||||
boost::posix_time::ptime ptFromSeconds (int iSeconds)
|
||||
std::string
|
||||
to_string(NetClock::time_point tp)
|
||||
{
|
||||
return iSeconds < 0
|
||||
? boost::posix_time::ptime (boost::posix_time::not_a_date_time)
|
||||
: ptEpoch () + boost::posix_time::seconds (iSeconds);
|
||||
}
|
||||
|
||||
// Convert from our time to UNIX time in seconds.
|
||||
uint64_t utFromSeconds (int iSeconds)
|
||||
{
|
||||
boost::posix_time::time_duration tdDelta =
|
||||
boost::posix_time::ptime (boost::gregorian::date (2000, boost::gregorian::Jan, 1))
|
||||
- boost::posix_time::ptime (boost::gregorian::date (1970, boost::gregorian::Jan, 1))
|
||||
+ boost::posix_time::seconds (iSeconds)
|
||||
;
|
||||
|
||||
return tdDelta.total_seconds ();
|
||||
using namespace std::chrono;
|
||||
return to_string(system_clock::time_point{tp.time_since_epoch() + 946684800s});
|
||||
}
|
||||
|
||||
} // ripple
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#ifndef BEAST_ASIO_IO_LATENCY_PROBE_H_INCLUDED
|
||||
#define BEAST_ASIO_IO_LATENCY_PROBE_H_INCLUDED
|
||||
|
||||
#include <boost/asio/deadline_timer.hpp>
|
||||
#include <boost/asio/basic_waitable_timer.hpp>
|
||||
#include <boost/asio/io_service.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <chrono>
|
||||
@@ -43,7 +43,7 @@ private:
|
||||
std::size_t m_count;
|
||||
duration const m_period;
|
||||
boost::asio::io_service& m_ios;
|
||||
boost::asio::deadline_timer m_timer;
|
||||
boost::asio::basic_waitable_timer<std::chrono::steady_clock> m_timer;
|
||||
bool m_cancel;
|
||||
|
||||
public:
|
||||
@@ -219,11 +219,7 @@ private:
|
||||
}
|
||||
else
|
||||
{
|
||||
boost::posix_time::microseconds mms (
|
||||
std::chrono::duration_cast <
|
||||
std::chrono::microseconds> (
|
||||
when - now).count ());
|
||||
m_probe->m_timer.expires_from_now (mms);
|
||||
m_probe->m_timer.expires_from_now(when - now);
|
||||
m_probe->m_timer.async_wait (sample_op <Handler> (
|
||||
m_handler, now, m_repeat, m_probe));
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
#ifndef BEAST_CHRONO_CHRONO_UTIL_H_INCLUDED
|
||||
#define BEAST_CHRONO_CHRONO_UTIL_H_INCLUDED
|
||||
|
||||
#include <chrono>
|
||||
|
||||
// From Howard Hinnant
|
||||
// http://home.roadrunner.com/~hinnant/duration_io/chrono_util.html
|
||||
|
||||
|
||||
@@ -204,7 +204,7 @@ private:
|
||||
boost::asio::io_service m_io_service;
|
||||
boost::optional <boost::asio::io_service::work> m_work;
|
||||
boost::asio::io_service::strand m_strand;
|
||||
boost::asio::deadline_timer m_timer;
|
||||
boost::asio::basic_waitable_timer<std::chrono::steady_clock> m_timer;
|
||||
boost::asio::ip::udp::socket m_socket;
|
||||
std::deque <std::string> m_data;
|
||||
std::recursive_mutex metricsLock_;
|
||||
@@ -407,7 +407,8 @@ public:
|
||||
|
||||
void set_timer ()
|
||||
{
|
||||
m_timer.expires_from_now (boost::posix_time::seconds (1));
|
||||
using namespace std::chrono_literals;
|
||||
m_timer.expires_from_now(1s);
|
||||
m_timer.async_wait (std::bind (
|
||||
&StatsDCollectorImp::on_timer, this,
|
||||
beast::asio::placeholders::error));
|
||||
|
||||
@@ -42,6 +42,8 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
class Rules;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -144,7 +146,7 @@ public:
|
||||
bool PEER_PRIVATE = false; // True to ask peers not to relay current IP.
|
||||
int PEERS_MAX = 0;
|
||||
|
||||
int WEBSOCKET_PING_FREQ = 5 * 60;
|
||||
std::chrono::seconds WEBSOCKET_PING_FREQ = 5min;
|
||||
|
||||
// RPC parameters
|
||||
Json::Value RPC_STARTUP;
|
||||
|
||||
@@ -351,7 +351,7 @@ void Config::loadFromString (std::string const& fileContents)
|
||||
ELB_SUPPORT = beast::lexicalCastThrow <bool> (strTemp);
|
||||
|
||||
if (getSingleSection (secConfig, SECTION_WEBSOCKET_PING_FREQ, strTemp, j_))
|
||||
WEBSOCKET_PING_FREQ = beast::lexicalCastThrow <int> (strTemp);
|
||||
WEBSOCKET_PING_FREQ = std::chrono::seconds{beast::lexicalCastThrow <int>(strTemp)};
|
||||
|
||||
getSingleSection (secConfig, SECTION_SSL_VERIFY_FILE, SSL_VERIFY_FILE, j_);
|
||||
getSingleSection (secConfig, SECTION_SSL_VERIFY_DIR, SSL_VERIFY_DIR, j_);
|
||||
|
||||
@@ -40,20 +40,21 @@ namespace ripple {
|
||||
static uint8_t SNTPQueryData[48] =
|
||||
{ 0x1B, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
// NTP query frequency - 4 minutes
|
||||
#define NTP_QUERY_FREQUENCY (4 * 60)
|
||||
auto constexpr NTP_QUERY_FREQUENCY = 4min;
|
||||
|
||||
// NTP minimum interval to query same servers - 3 minutes
|
||||
#define NTP_MIN_QUERY (3 * 60)
|
||||
auto constexpr NTP_MIN_QUERY = 3min;
|
||||
|
||||
// NTP sample window (should be odd)
|
||||
#define NTP_SAMPLE_WINDOW 9
|
||||
|
||||
// NTP timestamp constant
|
||||
#define NTP_UNIX_OFFSET 0x83AA7E80
|
||||
auto constexpr NTP_UNIX_OFFSET = 0x83AA7E80s;
|
||||
|
||||
// NTP timestamp validity
|
||||
#define NTP_TIMESTAMP_VALID ((NTP_QUERY_FREQUENCY + NTP_MIN_QUERY) * 2)
|
||||
auto constexpr NTP_TIMESTAMP_VALID = (NTP_QUERY_FREQUENCY + NTP_MIN_QUERY) * 2;
|
||||
|
||||
// SNTP packet offsets
|
||||
#define NTP_OFF_INFO 0
|
||||
@@ -73,13 +74,18 @@ class SNTPClientImp
|
||||
: public SNTPClock
|
||||
{
|
||||
private:
|
||||
template <class Duration>
|
||||
using sys_time = std::chrono::time_point<clock_type, Duration>;
|
||||
|
||||
using sys_seconds = sys_time<std::chrono::seconds>;
|
||||
|
||||
struct Query
|
||||
{
|
||||
bool replied;
|
||||
time_t sent; // VFALCO time_t, really?
|
||||
sys_seconds sent;
|
||||
std::uint32_t nonce;
|
||||
|
||||
Query (time_t j = time_t(-1))
|
||||
Query (sys_seconds j = sys_seconds::max())
|
||||
: replied (false)
|
||||
, sent (j)
|
||||
{
|
||||
@@ -95,12 +101,12 @@ private:
|
||||
|
||||
std::map <boost::asio::ip::udp::endpoint, Query> queries_;
|
||||
boost::asio::ip::udp::socket socket_;
|
||||
boost::asio::deadline_timer timer_;
|
||||
boost::asio::basic_waitable_timer<std::chrono::system_clock> timer_;
|
||||
boost::asio::ip::udp::resolver resolver_;
|
||||
std::vector<std::pair<std::string, time_t>> servers_;
|
||||
int offset_;
|
||||
time_t lastUpdate_;
|
||||
std::deque<int> offsets_;
|
||||
std::vector<std::pair<std::string, sys_seconds>> servers_;
|
||||
std::chrono::seconds offset_;
|
||||
sys_seconds lastUpdate_;
|
||||
std::deque<std::chrono::seconds> offsets_;
|
||||
std::vector<uint8_t> buf_;
|
||||
boost::asio::ip::udp::endpoint ep_;
|
||||
|
||||
@@ -115,7 +121,7 @@ public:
|
||||
, timer_ (io_service_)
|
||||
, resolver_ (io_service_)
|
||||
, offset_ (0)
|
||||
, lastUpdate_ (time_t(-1))
|
||||
, lastUpdate_ (sys_seconds::max())
|
||||
, buf_ (256)
|
||||
{
|
||||
}
|
||||
@@ -150,7 +156,7 @@ public:
|
||||
std::lock_guard<std::mutex> lock (mutex_);
|
||||
for (auto const& item : servers)
|
||||
servers_.emplace_back(
|
||||
item, time_t(-1));
|
||||
item, sys_seconds::max());
|
||||
}
|
||||
queryAll();
|
||||
|
||||
@@ -161,8 +167,7 @@ public:
|
||||
&SNTPClientImp::onRead, this,
|
||||
beast::asio::placeholders::error,
|
||||
beast::asio::placeholders::bytes_transferred));
|
||||
timer_.expires_from_now(
|
||||
boost::posix_time::seconds(NTP_QUERY_FREQUENCY));
|
||||
timer_.expires_from_now(NTP_QUERY_FREQUENCY);
|
||||
timer_.async_wait(std::bind(
|
||||
&SNTPClientImp::onTimer, this,
|
||||
beast::asio::placeholders::error));
|
||||
@@ -177,18 +182,20 @@ public:
|
||||
now() const override
|
||||
{
|
||||
std::lock_guard<std::mutex> lock (mutex_);
|
||||
auto const when = clock_type::now();
|
||||
if ((lastUpdate_ == (time_t)-1) ||
|
||||
((lastUpdate_ + NTP_TIMESTAMP_VALID) < time(nullptr)))
|
||||
using namespace std::chrono;
|
||||
auto const when = time_point_cast<seconds>(clock_type::now());
|
||||
if ((lastUpdate_ == sys_seconds::max()) ||
|
||||
((lastUpdate_ + NTP_TIMESTAMP_VALID) <
|
||||
time_point_cast<seconds>(clock_type::now())))
|
||||
return when;
|
||||
return when + std::chrono::seconds(offset_);
|
||||
return when + offset_;
|
||||
}
|
||||
|
||||
duration
|
||||
offset() const override
|
||||
{
|
||||
std::lock_guard<std::mutex> lock (mutex_);
|
||||
return std::chrono::seconds(offset_);
|
||||
return offset_;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -213,8 +220,7 @@ public:
|
||||
}
|
||||
|
||||
doQuery ();
|
||||
timer_.expires_from_now(
|
||||
boost::posix_time::seconds (NTP_QUERY_FREQUENCY));
|
||||
timer_.expires_from_now(NTP_QUERY_FREQUENCY);
|
||||
timer_.async_wait(std::bind(
|
||||
&SNTPClientImp::onTimer, this,
|
||||
beast::asio::placeholders::error));
|
||||
@@ -224,6 +230,7 @@ public:
|
||||
onRead (error_code const& ec, std::size_t bytes_xferd)
|
||||
{
|
||||
using namespace boost::asio;
|
||||
using namespace std::chrono;
|
||||
if (ec == error::operation_aborted)
|
||||
return;
|
||||
|
||||
@@ -253,7 +260,7 @@ public:
|
||||
{
|
||||
query->second.replied = true;
|
||||
|
||||
if (time (nullptr) > (query->second.sent + 1))
|
||||
if (time_point_cast<seconds>(clock_type::now()) > (query->second.sent + 1s))
|
||||
{
|
||||
JLOG(j_.warn()) <<
|
||||
"SNTP: Late response from " << ep_;
|
||||
@@ -289,7 +296,7 @@ public:
|
||||
void addServer (std::string const& server)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock (mutex_);
|
||||
servers_.push_back (std::make_pair (server, time_t(-1)));
|
||||
servers_.push_back (std::make_pair (server, sys_seconds::max()));
|
||||
}
|
||||
|
||||
void queryAll ()
|
||||
@@ -302,11 +309,12 @@ public:
|
||||
bool doQuery ()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock (mutex_);
|
||||
std::vector< std::pair<std::string, time_t> >::iterator best = servers_.end ();
|
||||
auto best = servers_.end ();
|
||||
|
||||
for (auto iter = servers_.begin (), end = best;
|
||||
iter != end; ++iter)
|
||||
if ((best == end) || (iter->second == time_t(-1)) || (iter->second < best->second))
|
||||
if ((best == end) || (iter->second == sys_seconds::max()) ||
|
||||
(iter->second < best->second))
|
||||
best = iter;
|
||||
|
||||
if (best == servers_.end ())
|
||||
@@ -316,9 +324,10 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
time_t now = time (nullptr);
|
||||
using namespace std::chrono;
|
||||
auto now = time_point_cast<seconds>(clock_type::now());
|
||||
|
||||
if ((best->second != time_t(-1)) && ((best->second + NTP_MIN_QUERY) >= now))
|
||||
if ((best->second != sys_seconds::max()) && ((best->second + NTP_MIN_QUERY) >= now))
|
||||
{
|
||||
JLOG(j_.trace()) <<
|
||||
"SNTP: All servers recently queried";
|
||||
@@ -366,9 +375,10 @@ public:
|
||||
{
|
||||
std::lock_guard<std::mutex> lock (mutex_);
|
||||
Query& query = queries_[*sel];
|
||||
time_t now = time (nullptr);
|
||||
using namespace std::chrono;
|
||||
auto now = time_point_cast<seconds>(clock_type::now());
|
||||
|
||||
if ((query.sent == now) || ((query.sent + 1) == now))
|
||||
if ((query.sent == now) || ((query.sent + 1s) == now))
|
||||
{
|
||||
// This can happen if the same IP address is reached through multiple names
|
||||
JLOG(j_.trace()) <<
|
||||
@@ -379,7 +389,11 @@ public:
|
||||
query.replied = false;
|
||||
query.sent = now;
|
||||
query.nonce = rand_int<std::uint32_t>();
|
||||
reinterpret_cast<std::uint32_t*> (SNTPQueryData)[NTP_OFF_XMITTS_INT] = static_cast<std::uint32_t> (time (nullptr)) + NTP_UNIX_OFFSET;
|
||||
// The following line of code will overflow at 2036-02-07 06:28:16 UTC
|
||||
// due to the 32 bit cast.
|
||||
reinterpret_cast<std::uint32_t*> (SNTPQueryData)[NTP_OFF_XMITTS_INT] =
|
||||
static_cast<std::uint32_t>((time_point_cast<seconds>(clock_type::now()) +
|
||||
NTP_UNIX_OFFSET).time_since_epoch().count());
|
||||
reinterpret_cast<std::uint32_t*> (SNTPQueryData)[NTP_OFF_XMITTS_FRAC] = query.nonce;
|
||||
socket_.async_send_to(buffer(SNTPQueryData, 48),
|
||||
*sel, std::bind (&SNTPClientImp::onSend, this,
|
||||
@@ -403,11 +417,12 @@ public:
|
||||
|
||||
void processReply ()
|
||||
{
|
||||
using namespace std::chrono;
|
||||
assert (buf_.size () >= 48);
|
||||
std::uint32_t* recvBuffer = reinterpret_cast<std::uint32_t*> (&buf_.front ());
|
||||
|
||||
unsigned info = ntohl (recvBuffer[NTP_OFF_INFO]);
|
||||
int64_t timev = ntohl (recvBuffer[NTP_OFF_RECVTS_INT]);
|
||||
auto timev = seconds{ntohl(recvBuffer[NTP_OFF_RECVTS_INT])};
|
||||
unsigned stratum = (info >> 16) & 0xff;
|
||||
|
||||
if ((info >> 30) == 3)
|
||||
@@ -424,8 +439,9 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
std::int64_t now = static_cast<int> (time (nullptr));
|
||||
timev -= now;
|
||||
using namespace std::chrono;
|
||||
auto now = time_point_cast<seconds>(clock_type::now());
|
||||
timev -= now.time_since_epoch();
|
||||
timev -= NTP_UNIX_OFFSET;
|
||||
|
||||
// add offset to list, replacing oldest one if appropriate
|
||||
@@ -448,13 +464,13 @@ public:
|
||||
|
||||
// debounce: small corrections likely
|
||||
// do more harm than good
|
||||
if ((offset_ == -1) || (offset_ == 1))
|
||||
offset_ = 0;
|
||||
if ((offset_ == -1s) || (offset_ == 1s))
|
||||
offset_ = 0s;
|
||||
|
||||
if (timev || offset_)
|
||||
if (timev != 0s || offset_ != 0s)
|
||||
{
|
||||
JLOG(j_.trace()) << "SNTP: Offset is " << timev <<
|
||||
", new system offset is " << offset_;
|
||||
JLOG(j_.trace()) << "SNTP: Offset is " << timev.count() <<
|
||||
", new system offset is " << offset_.count();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include <ripple/core/Config.h>
|
||||
#include <boost/asio/io_service.hpp>
|
||||
#include <boost/asio/streambuf.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time_types.hpp>
|
||||
#include <chrono>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
const unsigned short port,
|
||||
std::string const& strPath,
|
||||
std::size_t responseMax,
|
||||
boost::posix_time::time_duration timeout,
|
||||
std::chrono::seconds timeout,
|
||||
std::function <bool (const boost::system::error_code& ecResult, int iStatus, std::string const& strData)> complete,
|
||||
Logs& l);
|
||||
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
const unsigned short port,
|
||||
std::string const& strPath,
|
||||
std::size_t responseMax,
|
||||
boost::posix_time::time_duration timeout,
|
||||
std::chrono::seconds timeout,
|
||||
std::function <bool (const boost::system::error_code& ecResult, int iStatus, std::string const& strData)> complete,
|
||||
Logs& l);
|
||||
|
||||
@@ -68,7 +68,7 @@ public:
|
||||
const unsigned short port,
|
||||
std::function <void (boost::asio::streambuf& sb, std::string const& strHost)> build,
|
||||
std::size_t responseMax,
|
||||
boost::posix_time::time_duration timeout,
|
||||
std::chrono::seconds timeout,
|
||||
std::function <bool (const boost::system::error_code& ecResult, int iStatus, std::string const& strData)> complete,
|
||||
Logs& l);
|
||||
};
|
||||
|
||||
@@ -138,7 +138,7 @@ public:
|
||||
bool bSSL,
|
||||
std::deque<std::string> deqSites,
|
||||
std::function<void (boost::asio::streambuf& sb, std::string const& strHost)> build,
|
||||
boost::posix_time::time_duration timeout,
|
||||
std::chrono::seconds timeout,
|
||||
std::function<bool (const boost::system::error_code& ecResult,
|
||||
int iStatus, std::string const& strData)> complete)
|
||||
{
|
||||
@@ -157,7 +157,7 @@ public:
|
||||
bool bSSL,
|
||||
std::deque<std::string> deqSites,
|
||||
std::string const& strPath,
|
||||
boost::posix_time::time_duration timeout,
|
||||
std::chrono::seconds timeout,
|
||||
std::function<bool (const boost::system::error_code& ecResult, int iStatus,
|
||||
std::string const& strData)> complete)
|
||||
{
|
||||
@@ -518,13 +518,13 @@ private:
|
||||
std::function<void (boost::asio::streambuf& sb, std::string const& strHost)> mBuild;
|
||||
std::function<bool (const boost::system::error_code& ecResult, int iStatus, std::string const& strData)> mComplete;
|
||||
|
||||
boost::asio::deadline_timer mDeadline;
|
||||
boost::asio::basic_waitable_timer<std::chrono::steady_clock> mDeadline;
|
||||
|
||||
// If not success, we are shutting down.
|
||||
boost::system::error_code mShutdown;
|
||||
|
||||
std::deque<std::string> mDeqSites;
|
||||
boost::posix_time::time_duration mTimeout;
|
||||
std::chrono::seconds mTimeout;
|
||||
beast::Journal j_;
|
||||
};
|
||||
|
||||
@@ -537,7 +537,7 @@ void HTTPClient::get (
|
||||
const unsigned short port,
|
||||
std::string const& strPath,
|
||||
std::size_t responseMax,
|
||||
boost::posix_time::time_duration timeout,
|
||||
std::chrono::seconds timeout,
|
||||
std::function<bool (const boost::system::error_code& ecResult, int iStatus,
|
||||
std::string const& strData)> complete,
|
||||
Logs& l)
|
||||
@@ -554,7 +554,7 @@ void HTTPClient::get (
|
||||
const unsigned short port,
|
||||
std::string const& strPath,
|
||||
std::size_t responseMax,
|
||||
boost::posix_time::time_duration timeout,
|
||||
std::chrono::seconds timeout,
|
||||
std::function<bool (const boost::system::error_code& ecResult, int iStatus,
|
||||
std::string const& strData)> complete,
|
||||
Logs& l)
|
||||
@@ -573,7 +573,7 @@ void HTTPClient::request (
|
||||
const unsigned short port,
|
||||
std::function<void (boost::asio::streambuf& sb, std::string const& strHost)> setRequest,
|
||||
std::size_t responseMax,
|
||||
boost::posix_time::time_duration timeout,
|
||||
std::chrono::seconds timeout,
|
||||
std::function<bool (const boost::system::error_code& ecResult, int iStatus,
|
||||
std::string const& strData)> complete,
|
||||
Logs& l)
|
||||
|
||||
@@ -1307,7 +1307,8 @@ void fromNetwork (
|
||||
// Send request
|
||||
|
||||
const int RPC_REPLY_MAX_BYTES (256*1024*1024);
|
||||
const int RPC_NOTIFY_SECONDS (600);
|
||||
using namespace std::chrono_literals;
|
||||
auto constexpr RPC_NOTIFY = 10min;
|
||||
|
||||
auto j = logs.journal ("HTTPClient");
|
||||
|
||||
@@ -1323,7 +1324,7 @@ void fromNetwork (
|
||||
mapRequestHeaders,
|
||||
strPath, std::placeholders::_1, std::placeholders::_2, j),
|
||||
RPC_REPLY_MAX_BYTES,
|
||||
boost::posix_time::seconds (RPC_NOTIFY_SECONDS),
|
||||
RPC_NOTIFY,
|
||||
std::bind (&RPCCallImp::onResponse, callbackFuncP,
|
||||
std::placeholders::_1, std::placeholders::_2,
|
||||
std::placeholders::_3, j),
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <ripple/overlay/Peer.h>
|
||||
#include <ripple/beast/clock/abstract_clock.h>
|
||||
#include <ripple/beast/utility/Journal.h>
|
||||
#include <boost/asio/deadline_timer.hpp>
|
||||
#include <boost/asio/basic_waitable_timer.hpp>
|
||||
#include <mutex>
|
||||
|
||||
namespace ripple {
|
||||
@@ -119,8 +119,8 @@ private:
|
||||
protected:
|
||||
using ScopedLockType = std::unique_lock <std::recursive_mutex>;
|
||||
|
||||
PeerSet (Application& app, uint256 const& hash, int interval, bool txnData,
|
||||
clock_type& clock, beast::Journal journal);
|
||||
PeerSet (Application& app, uint256 const& hash, std::chrono::milliseconds interval,
|
||||
bool txnData, clock_type& clock, beast::Journal journal);
|
||||
|
||||
virtual ~PeerSet() = 0;
|
||||
|
||||
@@ -162,7 +162,7 @@ protected:
|
||||
std::recursive_mutex mLock;
|
||||
|
||||
uint256 mHash;
|
||||
int mTimerInterval;
|
||||
std::chrono::milliseconds mTimerInterval;
|
||||
int mTimeouts;
|
||||
bool mComplete;
|
||||
bool mFailed;
|
||||
@@ -171,7 +171,7 @@ protected:
|
||||
bool mProgress;
|
||||
|
||||
// VFALCO TODO move the responsibility for the timer to a higher level
|
||||
boost::asio::deadline_timer mTimer;
|
||||
boost::asio::basic_waitable_timer<std::chrono::steady_clock> mTimer;
|
||||
|
||||
// VFALCO TODO Verify that these are used in the way that the names suggest.
|
||||
using PeerIdentifier = Peer::id_t;
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
class InboundLedger;
|
||||
|
||||
// VFALCO NOTE The txnData constructor parameter is a code smell.
|
||||
@@ -35,7 +37,8 @@ class InboundLedger;
|
||||
// derived class. Why not just make the timer callback
|
||||
// function pure virtual?
|
||||
//
|
||||
PeerSet::PeerSet (Application& app, uint256 const& hash, int interval, bool txnData,
|
||||
PeerSet::PeerSet (Application& app, uint256 const& hash,
|
||||
std::chrono::milliseconds interval, bool txnData,
|
||||
clock_type& clock, beast::Journal journal)
|
||||
: app_ (app)
|
||||
, m_journal (journal)
|
||||
@@ -50,7 +53,7 @@ PeerSet::PeerSet (Application& app, uint256 const& hash, int interval, bool txnD
|
||||
, mTimer (app_.getIOService ())
|
||||
{
|
||||
mLastAction = m_clock.now();
|
||||
assert ((mTimerInterval > 10) && (mTimerInterval < 30000));
|
||||
assert ((mTimerInterval > 10ms) && (mTimerInterval < 30s));
|
||||
}
|
||||
|
||||
PeerSet::~PeerSet ()
|
||||
@@ -70,7 +73,7 @@ bool PeerSet::insert (Peer::ptr const& ptr)
|
||||
|
||||
void PeerSet::setTimer ()
|
||||
{
|
||||
mTimer.expires_from_now (boost::posix_time::milliseconds (mTimerInterval));
|
||||
mTimer.expires_from_now(mTimerInterval);
|
||||
mTimer.async_wait (std::bind (&PeerSet::timerEntry, pmDowncast (),
|
||||
beast::asio::placeholders::error, m_journal));
|
||||
}
|
||||
|
||||
@@ -36,10 +36,15 @@ std::string getHTTPHeaderTimestamp ()
|
||||
char buffer[96];
|
||||
time_t now;
|
||||
time (&now);
|
||||
struct tm* now_gmt = gmtime (&now);
|
||||
struct tm now_gmt{};
|
||||
#ifndef _MSC_VER
|
||||
gmtime_r(&now, &now_gmt);
|
||||
#else
|
||||
gmtime_s(&now_gmt, &now);
|
||||
#endif
|
||||
strftime (buffer, sizeof (buffer),
|
||||
"Date: %a, %d %b %Y %H:%M:%S +0000\r\n",
|
||||
now_gmt);
|
||||
&now_gmt);
|
||||
return std::string (buffer);
|
||||
}
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ private:
|
||||
std::deque <std::string> m_receiveQueue;
|
||||
NetworkOPs& m_netOPs;
|
||||
boost::asio::io_service& m_io_service;
|
||||
boost::asio::deadline_timer m_pingTimer;
|
||||
boost::asio::basic_waitable_timer<std::chrono::system_clock> m_pingTimer;
|
||||
|
||||
bool m_sentPing = false;
|
||||
bool m_receiveQueueRunning = false;
|
||||
@@ -122,7 +122,7 @@ private:
|
||||
handler_type& m_handler;
|
||||
weak_connection_ptr m_connection;
|
||||
|
||||
int pingFreq_;
|
||||
std::chrono::seconds pingFreq_;
|
||||
beast::Journal j_;
|
||||
};
|
||||
|
||||
@@ -155,7 +155,7 @@ ConnectionImpl <WebSocket>::ConnectionImpl (
|
||||
, j_ (app.journal ("ConnectionImpl"))
|
||||
{
|
||||
// VFALCO Disabled since it might cause hangs
|
||||
pingFreq_ = 0;
|
||||
pingFreq_ = std::chrono::seconds{0};
|
||||
|
||||
if (! m_forwardedFor.empty() || ! m_user.empty())
|
||||
{
|
||||
|
||||
@@ -74,13 +74,13 @@ boost::asio::io_service::strand& WebSocket02::getStrand (Connection& con)
|
||||
template <>
|
||||
void ConnectionImpl <WebSocket02>::setPingTimer ()
|
||||
{
|
||||
if (pingFreq_ <= 0)
|
||||
using namespace std::chrono_literals;
|
||||
if (pingFreq_ <= 0s)
|
||||
return;
|
||||
connection_ptr ptr = m_connection.lock ();
|
||||
if (ptr)
|
||||
{
|
||||
this->m_pingTimer.expires_from_now (
|
||||
boost::posix_time::seconds (pingFreq_));
|
||||
this->m_pingTimer.expires_from_now(pingFreq_);
|
||||
|
||||
this->m_pingTimer.async_wait (
|
||||
ptr->get_strand ().wrap (
|
||||
|
||||
Reference in New Issue
Block a user