Use safer rstime_t instead of time_t

Avoid problems to serialization on different platforms, without breaking
nested STL containers serialization.

The conversion have been made with sed, and checked with grep, plus
kdiff3 visual ispection, plus rutime tests, so it should be fine.
This commit is contained in:
Gioacchino Mazzurco 2018-10-07 01:34:05 +02:00
parent 41aa675a9b
commit 329050a9c2
No known key found for this signature in database
GPG key ID: A1FBCA3872E87051
223 changed files with 930 additions and 911 deletions

View file

@ -80,7 +80,7 @@
PeerConnectStateBox::PeerConnectStateBox()
{
//mPeerId = id;
time_t now = time(NULL);
rstime_t now = time(NULL);
mState = CSB_START;
mNetState = CSB_NETSTATE_UNKNOWN;
mStateTS = now;
@ -241,7 +241,7 @@ void PeerConnectStateBox::stateMsg(std::ostream &out, std::string msg, uint32_t
std::string PeerConnectStateBox::connectState() const
{
std::string str = StateAsString(mState);
time_t now = time(NULL);
rstime_t now = time(NULL);
std::string out;
rs_sprintf(out, "%s(%lu/%lu) for %ld secs", str.c_str(), mNoAttempts, mNoFailedAttempts, now - mStateTS);
if ( (mState == CSB_CONNECTED) || (mState == CSB_DIRECT_ATTEMPT) ||
@ -358,7 +358,7 @@ uint32_t PeerConnectStateBox::connectCb(uint32_t cbtype, uint32_t netmode, uint3
uint32_t PeerConnectStateBox::connectCb_direct()
{
uint32_t retval = 0;
time_t now = time(NULL);
rstime_t now = time(NULL);
switch(mState)
{
@ -497,7 +497,7 @@ uint32_t PeerConnectStateBox::connectCb_unreachable()
proxyPortMode = CSB_ACTION_DHT_PORT;
}
time_t now = time(NULL);
rstime_t now = time(NULL);
switch(mState)
{
@ -782,7 +782,7 @@ uint32_t PeerConnectStateBox::updateCb(uint32_t update)
*/
/* DO Connect / Disconnect Updates ... very specific! */
time_t now = time(NULL);
rstime_t now = time(NULL);
switch(update)
{
case CSB_UPDATE_CONNECTED:
@ -1035,7 +1035,7 @@ bool PeerConnectStateBox::storeProxyPortChoice(uint32_t flags, bool useProxyPort
bool PeerConnectStateBox::getProxyPortChoice()
{
#ifdef DEBUG_CONNECTBOX
time_t now = time(NULL);
rstime_t now = time(NULL);
std::cerr << "PeerConnectStateBox::getProxyPortChoice() Using ConnectLogic Info from: ";
std::cerr << now-mProxyPortTS << " ago. Flags: " << mProxyPortFlags;

View file

@ -72,7 +72,7 @@
#include <string>
#include <stdlib.h>
#include <time.h>
#include "util/rstime.h"
#include <inttypes.h>
class PeerConnectStateBox
@ -104,16 +104,16 @@ class PeerConnectStateBox
uint32_t mState;
uint32_t mNetState;
time_t mStateTS;
rstime_t mStateTS;
uint32_t mNoAttempts;
uint32_t mNoFailedAttempts;
time_t mNextAttemptTS;
time_t mAttemptLength;
rstime_t mNextAttemptTS;
rstime_t mAttemptLength;
// ProxyPort Storage.
uint32_t mProxyPortFlags;
bool mProxyPortChoice;
time_t mProxyPortTS;
rstime_t mProxyPortTS;
};

View file

@ -52,7 +52,7 @@ class DhtPeerDetails
/* direct from the DHT! */
uint32_t mDhtState; // One of RSDHT_PEERDHT_[...]
time_t mDhtUpdateTS;
rstime_t mDhtUpdateTS;
/* internal state */
PeerConnectStateBox mConnectLogic;
@ -66,9 +66,9 @@ class DhtPeerDetails
struct sockaddr_in mPeerConnectAddr;
uint32_t mPeerConnectPoint;
time_t mPeerConnectUdpTS;
time_t mPeerConnectTS;
time_t mPeerConnectClosedTS;
rstime_t mPeerConnectUdpTS;
rstime_t mPeerConnectTS;
rstime_t mPeerConnectClosedTS;
bool mExclusiveProxyLock;
@ -80,7 +80,7 @@ class DhtPeerDetails
uint32_t mPeerReqState;
uint32_t mPeerReqMode;
bdId mPeerReqProxyId;
time_t mPeerReqTS;
rstime_t mPeerReqTS;
/* Callback Info */
std::string mPeerCbMsg;
@ -88,7 +88,7 @@ class DhtPeerDetails
uint32_t mPeerCbPoint;
bdId mPeerCbProxyId;
bdId mPeerCbDestId;
time_t mPeerCbTS;
rstime_t mPeerCbTS;
};
@ -331,7 +331,7 @@ private:
float mDhtReadRate;
float mDhtWriteRate;
time_t mLastDataRateUpdate;
rstime_t mLastDataRateUpdate;
/***********************************************************************************************
@ -380,7 +380,7 @@ private:
RsPeerId mOwnRsId;
bdNodeId mOwnDhtId;
time_t mMinuteTS;
rstime_t mMinuteTS;
/* translation maps */
std::map<RsPeerId, bdNodeId> mTransToNodeId;

View file

@ -204,7 +204,7 @@ void p3BitDht::updateDataRates()
RsStackMutex stack(dhtMtx); /********* LOCKED *********/
time_t now = time(NULL);
rstime_t now = time(NULL);
float period = now - mLastDataRateUpdate;
#define RATE_FACTOR (0.75)
@ -380,7 +380,7 @@ RsDhtRelayProxy::RsDhtRelayProxy()
mCreateTS = 0;
//uint32_t mDataSize;
//time_t mLastBandwidthTS;
//rstime_t mLastBandwidthTS;
}

View file

@ -249,7 +249,7 @@ int p3BitDht::PeerCallback(const bdId *id, uint32_t status)
}
time_t now = time(NULL);
rstime_t now = time(NULL);
dpd->mDhtUpdateTS = now;
return 1;
@ -510,7 +510,7 @@ int p3BitDht::ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId
*/
bdId peerId;
time_t now = time(NULL);
rstime_t now = time(NULL);
switch(point)
{
@ -1101,7 +1101,7 @@ int p3BitDht::tick()
minuteTick();
#ifdef DEBUG_PEERNET_COMMON
time_t now = time(NULL);
rstime_t now = time(NULL);
std::cerr << "p3BitDht::tick() TIME: " << ctime(&now) << std::endl;
std::cerr.flush();
#endif
@ -1114,7 +1114,7 @@ int p3BitDht::tick()
int p3BitDht::minuteTick()
{
time_t now = time(NULL);
rstime_t now = time(NULL);
int deltaT = 0;
{
@ -1164,7 +1164,7 @@ int p3BitDht::doActions()
std::cerr << "p3BitDht::doActions()" << std::endl;
#endif
time_t now = time(NULL);
rstime_t now = time(NULL);
while(mActions.size() > 0)
{
@ -1727,7 +1727,7 @@ int p3BitDht::checkConnectionAllowed(const bdId *peerId, int mode)
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
time_t now = time(NULL);
rstime_t now = time(NULL);
/* check if they are in our friend list */
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId->id), RSDHT_PEERTYPE_FRIEND);
@ -2171,7 +2171,7 @@ int p3BitDht::removeRelayConnection(const bdId *srcId, const bdId *destId)
void p3BitDht::monitorConnections()
{
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
time_t now = time(NULL);
rstime_t now = time(NULL);
std::map<bdNodeId, DhtPeerDetails>::iterator it;