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

@ -31,7 +31,7 @@
#include <limits.h>
#include <sys/time.h>
#include <time.h>
#include "util/rstime.h"
/* Debugging for STATE change, and Startup SYNs */
#include "util/rsdebug.h"
@ -2597,7 +2597,7 @@ bool TcpStream::isOldSequence(uint32 tst, uint32 curr)
}
#ifdef WINDOWS_SYS
#include <time.h>
#include "util/rstime.h"
#include <sys/timeb.h>
#endif

View file

@ -25,7 +25,7 @@ static const int kInitStreamTable = 5;
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "util/rstime.h"
#include "udp/udpstack.h"
#include "pqi/pqinetwork.h"

View file

@ -21,7 +21,7 @@
*******************************************************************************/
#include "udprelay.h"
#include <iostream>
#include <time.h>
#include "util/rstime.h"
#include <util/rsmemory.h>
/*
@ -232,7 +232,7 @@ int UdpRelayReceiver::checkRelays()
std::list<UdpRelayAddrSet> eraseList;
std::map<UdpRelayAddrSet, UdpRelayProxy>::iterator rit;
time_t now = time(NULL);
rstime_t now = time(NULL);
#define BANDWIDTH_FILTER_K (0.8)
@ -1088,7 +1088,7 @@ std::ostream &operator<<(std::ostream &out, const UdpRelayAddrSet &uras)
std::ostream &operator<<(std::ostream &out, const UdpRelayProxy &urp)
{
time_t now = time(NULL);
rstime_t now = time(NULL);
out << "UdpRelayProxy for " << urp.mAddrs;
out << std::endl;
out << "\tRelayClass: " << urp.mRelayClass;

View file

@ -51,10 +51,10 @@ class UdpRelayProxy
UdpRelayAddrSet mAddrs;
double mBandwidth;
uint32_t mDataSize;
time_t mLastBandwidthTS;
time_t mLastTS;
rstime_t mLastBandwidthTS;
rstime_t mLastTS;
time_t mStartTS;
rstime_t mStartTS;
double mBandwidthLimit;
int mRelayClass;

View file

@ -21,7 +21,7 @@
*******************************************************************************/
#include "tcponudp/udpstunner.h"
#include <iostream>
#include <time.h>
#include "util/rstime.h"
#include "util/rsrandom.h"
#include "util/rsprint.h"
@ -111,7 +111,7 @@ void UdpStunner::SimSymmetricNat()
int UdpStunner::grabExclusiveMode(std::string holder) /* returns seconds since last send/recv */
{
RsStackMutex stack(stunMtx); /********** LOCK MUTEX *********/
time_t now = time(NULL);
rstime_t now = time(NULL);
#ifdef DEBUG_UDP_STUNNER_FILTER
@ -187,7 +187,7 @@ int UdpStunner::releaseExclusiveMode(std::string holder, bool forceStun)
return 0;
}
time_t now = time(NULL);
rstime_t now = time(NULL);
mExclusiveMode = false;
if (forceStun)
{
@ -330,7 +330,7 @@ bool UdpStunner::locked_handleStunPkt(void *data, int size, struct sockaddr_in &
if (!pkt)
return false;
time_t now = time(NULL);
rstime_t now = time(NULL);
mStunLastSendAny = now;
int sentlen = sendPkt(pkt, len, from, STUN_TTL);
free(pkt);
@ -456,7 +456,7 @@ int UdpStunner::doStun(struct sockaddr_in stun_addr)
{
RsStackMutex stack(stunMtx); /********** LOCK MUTEX *********/
time_t now = time(NULL);
rstime_t now = time(NULL);
mStunLastSendStun = now;
mStunLastSendAny = now;
}
@ -750,7 +750,7 @@ bool UdpStunner::checkStunDesired()
std::cerr << std::endl;
#endif
time_t now;
rstime_t now;
{
RsStackMutex stack(stunMtx); /********** LOCK MUTEX *********/
@ -800,7 +800,7 @@ bool UdpStunner::checkStunDesired()
#define RATE_SCALE (3.0)
double stunPeriod = (mTargetStunPeriod / (RATE_SCALE)) * (1.0 + mSuccessRate * (RATE_SCALE - 1.0));
time_t nextStun = mStunLastRecvResp + (int) stunPeriod;
rstime_t nextStun = mStunLastRecvResp + (int) stunPeriod;
#ifdef DEBUG_UDP_STUNNER
std::cerr << "UdpStunner::checkStunDesired() TargetStunPeriod: " << mTargetStunPeriod;
@ -834,7 +834,7 @@ bool UdpStunner::attemptStun()
{
bool found = false;
TouStunPeer peer;
time_t now = time(NULL);
rstime_t now = time(NULL);
#ifdef DEBUG_UDP_STUNNER
std::cerr << "UdpStunner::attemptStun()";
@ -1000,7 +1000,7 @@ bool UdpStunner::locked_recvdStun(const struct sockaddr_in &remote, const str
mSuccessRate += (1.0-TOU_SUCCESS_LPF_FACTOR);
time_t now = time(NULL);
rstime_t now = time(NULL);
mStunLastRecvResp = now;
mStunLastRecvAny = now;
@ -1025,7 +1025,7 @@ bool UdpStunner::locked_checkExternalAddress()
bool found1 = false;
bool found2 = false;
time_t now = time(NULL);
rstime_t now = time(NULL);
/* iterator backwards - as these are the most recent */
/********
@ -1048,7 +1048,7 @@ bool UdpStunner::locked_checkExternalAddress()
4) recent age.
*/
time_t age = (now - it->lastsend);
rstime_t age = (now - it->lastsend);
if (it->response &&
#ifdef UDPSTUN_ALLOW_LOCALNET
( mAcceptLocalNet || isExternalNet(&(it->eaddr.sin_addr))) &&
@ -1132,7 +1132,7 @@ bool UdpStunner::locked_printStunList()
#ifdef DEBUG_UDP_STUNNER
std::string out = "locked_printStunList()\n";
time_t now = time(NULL);
rstime_t now = time(NULL);
rs_sprintf_append(out, "\tLastSendStun: %ld\n", now - mStunLastSendStun);
rs_sprintf_append(out, "\tLastSendAny: %ld\n", now - mStunLastSendAny);
rs_sprintf_append(out, "\tLastRecvResp: %ld\n", now - mStunLastRecvResp);
@ -1157,7 +1157,7 @@ bool UdpStunner::locked_printStunList()
bool UdpStunner::getStunPeer(int idx, std::string &id,
struct sockaddr_in &remote, struct sockaddr_in &eaddr,
uint32_t &failCount, time_t &lastSend)
uint32_t &failCount, rstime_t &lastSend)
{
RsStackMutex stack(stunMtx); /********** LOCK MUTEX *********/

View file

@ -56,7 +56,7 @@ class TouStunPeer
std::string id;
struct sockaddr_in remote, eaddr;
bool response;
time_t lastsend;
rstime_t lastsend;
uint32_t failCount;
};
@ -89,7 +89,7 @@ bool dropStunPeer(const struct sockaddr_in &remote);
bool getStunPeer(int idx, std::string &id,
struct sockaddr_in &remote, struct sockaddr_in &eaddr,
uint32_t &failCount, time_t &lastSend);
uint32_t &failCount, rstime_t &lastSend);
bool needStunPeers();
@ -125,12 +125,12 @@ bool locked_checkExternalAddress();
bool eaddrKnown;
bool eaddrStable; /* if true then usable. if false -> Symmettric NAT */
time_t eaddrTime;
rstime_t eaddrTime;
time_t mStunLastRecvResp;
time_t mStunLastRecvAny;
time_t mStunLastSendStun;
time_t mStunLastSendAny;
rstime_t mStunLastRecvResp;
rstime_t mStunLastRecvAny;
rstime_t mStunLastSendStun;
rstime_t mStunLastSendAny;
std::list<TouStunPeer> mStunList; /* potentials */
@ -148,7 +148,7 @@ bool locked_checkExternalAddress();
double mSuccessRate;
bool mExclusiveMode; /* when this is switched on, the stunner stays silent (and extAddr is maintained) */
time_t mExclusiveModeTS;
rstime_t mExclusiveModeTS;
std::string mExclusiveHolder;
bool mForceRestun;