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

@ -50,7 +50,7 @@ class GRouterCacheInfo
{
public:
GRouterCacheInfoFlags flags ;
time_t last_activity ;
rstime_t last_activity ;
};
class GRouterCache

View file

@ -144,10 +144,10 @@ void RsGRouterRoutingInfoItem::serial_process(RsGenericSerializer::SerializeJob
RsTypeSerializer::serial_process (j,ctx,peerId,"peerId") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,data_status,"data_status") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,tunnel_status,"tunnel_status") ;
RsTypeSerializer::serial_process<time_t> (j,ctx,received_time_TS,"received_time_TS") ;
RsTypeSerializer::serial_process<time_t> (j,ctx,last_sent_TS,"last_sent_TS") ;
RsTypeSerializer::serial_process<rstime_t> (j,ctx,received_time_TS,"received_time_TS") ;
RsTypeSerializer::serial_process<rstime_t> (j,ctx,last_sent_TS,"last_sent_TS") ;
RsTypeSerializer::serial_process<time_t> (j,ctx,last_tunnel_request_TS,"last_tunnel_request_TS") ;
RsTypeSerializer::serial_process<rstime_t> (j,ctx,last_tunnel_request_TS,"last_tunnel_request_TS") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,sending_attempts,"sending_attempts") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,client_id,"client_id") ;
@ -215,7 +215,7 @@ void RsGRouterMatrixTrackItem::serial_process(RsGenericSerializer::SerializeJob
{
RsTypeSerializer::serial_process(j,ctx,provider_id,"provider_id") ;
RsTypeSerializer::serial_process(j,ctx,message_id,"message_id") ;
RsTypeSerializer::serial_process<time_t>(j,ctx,time_stamp,"time_stamp") ;
RsTypeSerializer::serial_process<rstime_t>(j,ctx,time_stamp,"time_stamp") ;
}
void RsGRouterMatrixCluesItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
@ -228,7 +228,7 @@ template<> void RsTypeSerializer::serial_process(RsGenericSerializer::SerializeJ
{
RsTypeSerializer::serial_process<uint32_t>(j,ctx,s.friend_id,name+":friend_id") ;
RsTypeSerializer::serial_process<float> (j,ctx,s.weight,name+":weight") ;
RsTypeSerializer::serial_process<time_t> (j,ctx,s.time_stamp,name+":time_stamp") ;
RsTypeSerializer::serial_process<rstime_t> (j,ctx,s.time_stamp,name+":time_stamp") ;
}
RsGRouterGenericDataItem *RsGRouterGenericDataItem::duplicate() const

View file

@ -224,7 +224,7 @@ class RsGRouterMatrixTrackItem: public RsGRouterItem
//
RsGxsMessageId message_id ;
RsPeerId provider_id ;
time_t time_stamp ;
rstime_t time_stamp ;
};
class RsGRouterMatrixFriendListItem: public RsGRouterItem
{

View file

@ -36,7 +36,7 @@ GRouterMatrix::GRouterMatrix()
bool GRouterMatrix::addTrackingInfo(const RsGxsMessageId& mid,const RsPeerId& source_friend)
{
time_t now = time(NULL) ;
rstime_t now = time(NULL) ;
RoutingTrackEntry rte ;
@ -57,7 +57,7 @@ bool GRouterMatrix::cleanUp()
#ifdef ROUTING_MATRIX_DEBUG
std::cerr << "GRouterMatrix::cleanup()" << std::endl;
#endif
time_t now = time(NULL) ;
rstime_t now = time(NULL) ;
for(std::map<RsGxsMessageId,RoutingTrackEntry>::iterator it(_tracking_clues.begin());it!=_tracking_clues.end();)
if(it->second.time_stamp + RS_GROUTER_MAX_KEEP_TRACKING_CLUES < now)
@ -84,7 +84,7 @@ bool GRouterMatrix::addRoutingClue(const GRouterKeyId& key_id,const RsPeerId& so
// 2 - get the Key map, and add the routing clue.
//
time_t now = time(NULL) ;
rstime_t now = time(NULL) ;
RoutingMatrixHitEntry rc ;
rc.weight = weight ;
@ -179,7 +179,7 @@ void GRouterMatrix::debugDump() const
std::cerr << " Proba needs up: " << _proba_need_updating << std::endl;
std::cerr << " Known keys: " << _time_combined_hits.size() << std::endl;
std::cerr << " Routing events: " << std::endl;
time_t now = time(NULL) ;
rstime_t now = time(NULL) ;
for(std::map<GRouterKeyId, std::list<RoutingMatrixHitEntry> >::const_iterator it(_routing_clues.begin());it!=_routing_clues.end();++it)
{
@ -209,7 +209,7 @@ bool GRouterMatrix::computeRoutingProbabilities(const GRouterKeyId& key_id, cons
{
// Routing probabilities are computed according to routing clues
//
// For a given key, each friend has a known set of routing clues (time_t, weight)
// For a given key, each friend has a known set of routing clues (rstime_t, weight)
// We combine these to compute a static weight for each friend/key pair.
// This is performed in updateRoutingProbabilities()
//
@ -271,7 +271,7 @@ bool GRouterMatrix::updateRoutingProbabilities()
if(!_proba_need_updating)
return false ;
time_t now = time(NULL) ;
rstime_t now = time(NULL) ;
for(std::map<GRouterKeyId, std::list<RoutingMatrixHitEntry> >::const_iterator it(_routing_clues.begin());it!=_routing_clues.end();++it)
{

View file

@ -39,13 +39,13 @@ struct RoutingMatrixHitEntry
{
uint32_t friend_id ; // not the full key. Gets too big otherwise!
float weight ;
time_t time_stamp ;
rstime_t time_stamp ;
};
struct RoutingTrackEntry
{
RsPeerId friend_id ; // not the full key. Gets too big otherwise!
time_t time_stamp ;
rstime_t time_stamp ;
};
class GRouterMatrix

View file

@ -22,7 +22,7 @@
#pragma once
#include <stdint.h>
#include <time.h>
#include "util/rstime.h"
#include <list>
#include "pgp/rscertificate.h"
#include "turtle/p3turtle.h"
@ -56,9 +56,9 @@ static const uint32_t MAX_INACTIVE_DATA_PIPE_DELAY = 300 ; // cl
static const uint32_t GROUTER_MAX_DUPLICATION_FACTOR = 10 ; // max number of duplicates for a given message to keep in the network
static const uint32_t GROUTER_MAX_BRANCHING_FACTOR = 3 ; // max number of branches, for locally forwarding items
static const time_t RS_GROUTER_DEBUG_OUTPUT_PERIOD = 10 ; // Output everything
static const time_t RS_GROUTER_AUTOWASH_PERIOD = 10 ; // Autowash every minute. Not a costly operation.
static const time_t RS_GROUTER_MATRIX_UPDATE_PERIOD = 60*10 ; // Check for key advertising every 10 minutes
static const rstime_t RS_GROUTER_DEBUG_OUTPUT_PERIOD = 10 ; // Output everything
static const rstime_t RS_GROUTER_AUTOWASH_PERIOD = 10 ; // Autowash every minute. Not a costly operation.
static const rstime_t RS_GROUTER_MATRIX_UPDATE_PERIOD = 60*10 ; // Check for key advertising every 10 minutes
static const uint32_t GROUTER_ITEM_MAX_CACHE_KEEP_TIME = 2*86400 ; // Cached items are kept for 48 hours at most.
static const uint32_t RS_GROUTER_DATA_STATUS_UNKNOWN = 0x0000 ; // unknown. Unused.
@ -79,7 +79,7 @@ class FriendTrialRecord
{
public:
RsPeerId friend_id ; // id of the friend
time_t time_stamp ; // time of the last tried
rstime_t time_stamp ; // time of the last tried
float probability ; // probability at which the item was selected
uint32_t nb_friends ; // number of friends at the time of sending the item
@ -108,9 +108,9 @@ public:
uint32_t data_status ; // pending, waiting, etc.
uint32_t tunnel_status ; // status of tunnel handling.
time_t received_time_TS ; // time at which the item was originally received
time_t last_sent_TS ; // last time the item was sent
time_t last_tunnel_request_TS ; // last time tunnels have been asked for this item.
rstime_t received_time_TS ; // time at which the item was originally received
rstime_t last_sent_TS ; // last time the item was sent
rstime_t last_tunnel_request_TS ; // last time tunnels have been asked for this item.
uint32_t sending_attempts ; // number of times tunnels have been asked for this peer without success
GRouterServiceId client_id ; // service ID of the client. Only valid when origin==OwnId
@ -125,7 +125,7 @@ public:
// non serialised data
time_t data_transaction_TS ;
rstime_t data_transaction_TS ;
static const uint32_t ROUTING_FLAGS_ALLOW_TUNNELS = 0x0001;
static const uint32_t ROUTING_FLAGS_ALLOW_FRIENDS = 0x0002;

View file

@ -218,7 +218,7 @@ p3GRouter::p3GRouter(p3ServiceControl *sc, RsGixs *is)
int p3GRouter::tick()
{
time_t now = time(NULL) ;
rstime_t now = time(NULL) ;
// Sort incoming service data
//
@ -555,7 +555,7 @@ void GRouterTunnelInfo::addVirtualPeer(const TurtleVirtualPeerId& vpid)
virtual_peers.insert(vpid) ;
time_t now = time(NULL) ;
rstime_t now = time(NULL) ;
if(first_tunnel_ok_TS == 0) first_tunnel_ok_TS = now ;
last_tunnel_ok_TS = now ;
@ -760,7 +760,7 @@ void p3GRouter::handleTunnels()
}
#endif
time_t now = time(NULL) ;
rstime_t now = time(NULL) ;
std::vector<std::pair<int,GRouterRoutingInfo*> > priority_list ;
for(std::map<GRouterMsgPropagationId, GRouterRoutingInfo>::iterator it=_pending_messages.begin();it!=_pending_messages.end();++it)
@ -893,7 +893,7 @@ void p3GRouter::routePendingObjects()
// Which tunnels are available is handled by handleTunnels()
//
time_t now = time(NULL) ;
rstime_t now = time(NULL) ;
RS_STACK_MUTEX(grMtx) ;
#ifdef GROUTER_DEBUG
@ -1220,7 +1220,7 @@ void p3GRouter::locked_collectAvailableFriends(const GRouterKeyId& gxs_id,const
void p3GRouter::locked_collectAvailableTunnels(const TurtleFileHash& hash,uint32_t total_duplication,std::map<RsPeerId,uint32_t>& tunnel_peers_and_duplication_factors)
{
time_t now = time(NULL) ;
rstime_t now = time(NULL) ;
// Now go through available virtual peers. Select the ones that are interesting, and set them as potential destinations.
@ -1304,7 +1304,7 @@ bool p3GRouter::locked_sendTransactionData(const RsPeerId& pid,const RsGRouterTr
void p3GRouter::autoWash()
{
bool items_deleted = false ;
time_t now = time(NULL) ;
rstime_t now = time(NULL) ;
std::map<GRouterMsgPropagationId,std::pair<GRouterClientService *,RsGxsId> > failed_msgs ;
@ -2158,7 +2158,7 @@ bool p3GRouter::sendData(const RsGxsId& destination,const GRouterServiceId& clie
//
GRouterRoutingInfo info ;
time_t now = time(NULL) ;
rstime_t now = time(NULL) ;
info.data_item = data_item ;
info.receipt_item = NULL ;
@ -2368,7 +2368,7 @@ void p3GRouter::debugDump()
{
RS_STACK_MUTEX(grMtx) ;
time_t now = time(NULL) ;
rstime_t now = time(NULL) ;
grouter_debug() << "Full dump of Global Router state: " << std::endl;
grouter_debug() << " Owned keys : " << std::endl;

View file

@ -68,8 +68,8 @@ public:
std::set<TurtleVirtualPeerId> virtual_peers ;
time_t first_tunnel_ok_TS ; // timestamp when 1st tunnel was received.
time_t last_tunnel_ok_TS ; // timestamp when last tunnel was received.
rstime_t first_tunnel_ok_TS ; // timestamp when 1st tunnel was received.
rstime_t last_tunnel_ok_TS ; // timestamp when last tunnel was received.
};
class GRouterDataInfo
{
@ -87,7 +87,7 @@ public:
RsGRouterAbstractMsgItem *addDataChunk(RsGRouterTransactionChunkItem *chunk_item) ;
RsGRouterTransactionChunkItem *incoming_data_buffer ;
time_t last_activity_TS ;
rstime_t last_activity_TS ;
};
class p3GRouter: public RsGRouter, public RsTurtleClientService, public p3Service, public p3Config
@ -346,10 +346,10 @@ private:
bool _changed ;
bool _debug_enabled ;
time_t _last_autowash_time ;
time_t _last_matrix_update_time ;
time_t _last_debug_output_time ;
time_t _last_config_changed ;
rstime_t _last_autowash_time ;
rstime_t _last_matrix_update_time ;
rstime_t _last_debug_output_time ;
rstime_t _last_config_changed ;
uint64_t _random_salt ;
};