Merge pull request #1153 from csoler/v0.6-TorOnly

V0.6 tor only
This commit is contained in:
csoler 2018-02-11 20:49:45 +01:00 committed by GitHub
commit 7a2d874863
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
105 changed files with 7078 additions and 258 deletions

View file

@ -38,7 +38,7 @@
#include "crypto/chacha20.h"
#include "util/rsprint.h"
#include "util/rsrandom.h"
#include "util/rsscopetimer.h"
#include "util/rstime.h"
#define rotl(x,n) { x = (x << n) | (x >> (-n & 31)) ;}
@ -1385,27 +1385,27 @@ bool perform_tests()
uint8_t received_tag[16] ;
{
RsScopeTimer s("AEAD1") ;
rstime::RsScopeTimer s("AEAD1") ;
chacha20_encrypt_rs(key, 1, nonce, ten_megabyte_data,SIZE) ;
std::cerr << " Chacha20 encryption speed : " << SIZE / (1024.0*1024.0) / s.duration() << " MB/s" << std::endl;
}
{
RsScopeTimer s("AEAD2") ;
rstime::RsScopeTimer s("AEAD2") ;
AEAD_chacha20_poly1305_rs(key,nonce,ten_megabyte_data,SIZE,aad,12,received_tag,true) ;
std::cerr << " AEAD/poly1305 own encryption speed : " << SIZE / (1024.0*1024.0) / s.duration() << " MB/s" << std::endl;
}
#if OPENSSL_VERSION_NUMBER >= 0x010100000L && !defined(LIBRESSL_VERSION_NUMBER)
{
RsScopeTimer s("AEAD3") ;
rstime::RsScopeTimer s("AEAD3") ;
AEAD_chacha20_poly1305_openssl(key,nonce,ten_megabyte_data,SIZE,aad,12,received_tag,true) ;
std::cerr << " AEAD/poly1305 openssl encryption speed: " << SIZE / (1024.0*1024.0) / s.duration() << " MB/s" << std::endl;
}
#endif
{
RsScopeTimer s("AEAD4") ;
rstime::RsScopeTimer s("AEAD4") ;
AEAD_chacha20_sha256(key,nonce,ten_megabyte_data,SIZE,aad,12,received_tag,true) ;
std::cerr << " AEAD/sha256 encryption speed : " << SIZE / (1024.0*1024.0) / s.duration() << " MB/s" << std::endl;

View file

@ -23,6 +23,7 @@
*
*/
#include "util/folderiterator.h"
#include "util/rstime.h"
#include "rsserver/p3face.h"
#include "directory_storage.h"
@ -92,7 +93,7 @@ void LocalDirectoryUpdater::data_tick()
for(uint32_t i=0;i<10;++i)
{
usleep(1*1000*1000);
rstime::rs_usleep(1*1000*1000);
{
if(mForceUpdate)

View file

@ -24,7 +24,7 @@
*/
#include "util/rsdir.h"
#include "util/rsprint.h"
#include "util/rsscopetimer.h"
#include "util/rstime.h"
#include "rsserver/p3face.h"
#include "pqi/authssl.h"
#include "hash_cache.h"
@ -125,7 +125,7 @@ void HashStorage::data_tick()
std::cerr << "nothing to hash. Sleeping for " << st << " us" << std::endl;
#endif
usleep(st); // when no files to hash, just wait for 2 secs. This avoids a dramatic loop.
rstime::rs_usleep(st); // when no files to hash, just wait for 2 secs. This avoids a dramatic loop.
if(st > MAX_INACTIVITY_SLEEP_TIME)
{
@ -163,7 +163,7 @@ void HashStorage::data_tick()
if(paused) // we need to wait off mutex!!
{
usleep(MAX_INACTIVITY_SLEEP_TIME) ;
rstime::rs_usleep(MAX_INACTIVITY_SLEEP_TIME) ;
std::cerr << "Hashing process currently paused." << std::endl;
return;
}
@ -190,7 +190,7 @@ void HashStorage::data_tick()
RsServer::notify()->notifyHashingInfo(NOTIFY_HASHTYPE_HASH_FILE, tmpout) ;
double seconds_origin = RsScopeTimer::currentTime() ;
double seconds_origin = rstime::RsScopeTimer::currentTime() ;
if(RsDirUtil::getFileHash(job.full_path, hash,size, this))
{
@ -215,7 +215,7 @@ void HashStorage::data_tick()
else
std::cerr << "ERROR: cannot hash file " << job.full_path << std::endl;
mHashingTime += RsScopeTimer::currentTime() - seconds_origin ;
mHashingTime += rstime::RsScopeTimer::currentTime() - seconds_origin ;
mHashedBytes += size ;
if(mHashingTime > 3)

View file

@ -40,6 +40,7 @@
#endif
#include "util/rsdiscspace.h"
#include "util/rsmemory.h"
#include "util/rstime.h"
#include "ft/ftcontroller.h"
@ -219,7 +220,7 @@ void ftController::data_tick()
/* check the queues */
//Waiting 1 sec before start
usleep(1*1000*1000); // 1 sec
rstime::rs_usleep(1*1000*1000); // 1 sec
#ifdef CONTROL_DEBUG
//std::cerr << "ftController::run()";

View file

@ -32,6 +32,7 @@
#include "ft/ftextralist.h"
#include "rsitems/rsconfigitems.h"
#include "util/rsdir.h"
#include "util/rstime.h"
#include <stdio.h>
#include <unistd.h> /* for (u)sleep() */
#include <time.h>
@ -64,12 +65,8 @@ void ftExtraList::data_tick()
/* Hash a file */
hashAFile();
#ifdef WIN32
Sleep(1);
#else
/* microsleep */
usleep(10);
#endif
rstime::rs_usleep(10);
}
else
{
@ -513,16 +510,7 @@ bool ftExtraList::loadList(std::list<RsItem *>& load)
delete (*it);
/* short sleep */
#ifndef WINDOWS_SYS
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
usleep(1000); /* 1000 per second */
#else
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
Sleep(1);
#endif
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
rstime::rs_usleep(1000) ;
}
load.clear() ;
return true;

View file

@ -35,7 +35,7 @@
#include <algorithm>
#ifdef RS_DATA_SERVICE_DEBUG_TIME
#include <util/rsscopetimer.h>
#include <util/rstime.h>
#endif
#include "rsdataservice.h"
@ -1066,7 +1066,7 @@ bool RsDataService::validSize(RsNxsGrp* grp) const
int RsDataService::retrieveNxsGrps(std::map<RsGxsGroupId, RsNxsGrp *> &grp, bool withMeta, bool /* cache */)
{
#ifdef RS_DATA_SERVICE_DEBUG_TIME
RsScopeTimer timer("");
rstime::RsScopeTimer timer("");
int resultCount = 0;
int requestedGroups = grp.size();
#endif
@ -1166,7 +1166,7 @@ void RsDataService::locked_retrieveGroups(RetroCursor* c, std::vector<RsNxsGrp*>
int RsDataService::retrieveNxsMsgs(const GxsMsgReq &reqIds, GxsMsgResult &msg, bool /* cache */, bool withMeta)
{
#ifdef RS_DATA_SERVICE_DEBUG_TIME
RsScopeTimer timer("");
rstime::RsScopeTimer timer("");
int resultCount = 0;
#endif
@ -1254,7 +1254,7 @@ int RsDataService::retrieveGxsMsgMetaData(const GxsMsgReq& reqIds, GxsMsgMetaRes
RsStackMutex stack(mDbMutex);
#ifdef RS_DATA_SERVICE_DEBUG_TIME
RsScopeTimer timer("");
rstime::RsScopeTimer timer("");
int resultCount = 0;
#endif
@ -1341,7 +1341,7 @@ int RsDataService::retrieveGxsGrpMetaData(RsGxsGrpMetaTemporaryMap& grp)
RsStackMutex stack(mDbMutex);
#ifdef RS_DATA_SERVICE_DEBUG_TIME
RsScopeTimer timer("");
rstime::RsScopeTimer timer("");
int resultCount = 0;
int requestedGroups = grp.size();
#endif
@ -1549,7 +1549,7 @@ int RsDataService::retrieveGroupIds(std::vector<RsGxsGroupId> &grpIds)
RsStackMutex stack(mDbMutex);
#ifdef RS_DATA_SERVICE_DEBUG_TIME
RsScopeTimer timer("");
rstime::RsScopeTimer timer("");
int resultCount = 0;
#endif
@ -1586,7 +1586,7 @@ int RsDataService::retrieveGroupIds(std::vector<RsGxsGroupId> &grpIds)
int RsDataService::retrieveMsgIds(const RsGxsGroupId& grpId, RsGxsMessageId::std_vector& msgIds)
{
#ifdef RS_DATA_SERVICE_DEBUG_TIME
RsScopeTimer timer("");
rstime::RsScopeTimer timer("");
int resultCount = 0;
#endif

View file

@ -31,6 +31,7 @@
#include "gxssecurity.h"
#include "util/contentvalue.h"
#include "util/rsprint.h"
#include "util/rstime.h"
#include "retroshare/rsgxsflags.h"
#include "retroshare/rsgxscircles.h"
#include "retroshare/rsgrouter.h"
@ -138,7 +139,7 @@ void RsGenExchange::data_tick()
static const double timeDelta = 0.1; // slow tick in sec
tick();
usleep((int) (timeDelta * 1000 *1000)); // timeDelta sec
rstime::rs_usleep((int) (timeDelta * 1000 *1000)); // timeDelta sec
}
void RsGenExchange::tick()

View file

@ -210,6 +210,7 @@
#include "retroshare/rspeers.h"
#include "pgp/pgpauxutils.h"
#include "util/rsdir.h"
#include "util/rstime.h"
#include "util/rsmemory.h"
#include "util/stacktrace.h"
@ -1787,7 +1788,7 @@ void RsGxsNetService::data_tick()
static const double timeDelta = 0.5;
//Start waiting as nothing to do in runup
usleep((int) (timeDelta * 1000 * 1000)); // timeDelta sec
rstime::rs_usleep((int) (timeDelta * 1000 * 1000)); // timeDelta sec
if(mUpdateCounter >= 120) // 60 seconds
{

View file

@ -1,7 +1,7 @@
!include("../../retroshare.pri"): error("Could not include file ../../retroshare.pri")
TEMPLATE = lib
CONFIG += staticlib bitdht
CONFIG += staticlib
CONFIG += create_prl
CONFIG -= qt
TARGET = retroshare
@ -10,7 +10,14 @@ DESTDIR = lib
#CONFIG += dsdv
# the dht stunner is used to obtain RS' external ip addr. when it is natted
retrotor {
DEFINES *= RETROTOR
CONFIG -= bitdht
} else {
CONFIG += bitdht
}
# the dht stunner is used to obtain RS external ip addr. when it is natted
# this system is unreliable and rs supports a newer and better one (asking connected peers)
# CONFIG += useDhtStunner
@ -90,6 +97,7 @@ HEADERS += tcponudp/udppeer.h \
tcponudp/tcpstream.h \
tcponudp/tou.h \
tcponudp/udprelay.h \
pqi/pqissludp.h \
SOURCES += tcponudp/udppeer.cc \
tcponudp/tcppacket.cc \
@ -97,6 +105,7 @@ SOURCES += tcponudp/udppeer.cc \
tcponudp/tou.cc \
tcponudp/bss_tou.c \
tcponudp/udprelay.cc \
pqi/pqissludp.cc \
useDhtStunner {
HEADERS += dht/stunaddrassist.h \
@ -434,7 +443,6 @@ HEADERS += pqi/authssl.h \
pqi/pqissllistener.h \
pqi/pqisslpersongrp.h \
pqi/pqissli2pbob.h \
pqi/pqissludp.h \
pqi/pqisslproxy.h \
pqi/pqistore.h \
pqi/pqistreamer.h \
@ -539,7 +547,7 @@ HEADERS += util/folderiterator.h \
util/rsmemcache.h \
util/rstickevent.h \
util/rsrecogn.h \
util/rsscopetimer.h \
util/rstime.h \
util/stacktrace.h \
util/rsdeprecate.h \
util/cxx11retrocompat.h
@ -590,7 +598,6 @@ SOURCES += pqi/authgpg.cc \
pqi/pqissllistener.cc \
pqi/pqisslpersongrp.cc \
pqi/pqissli2pbob.cpp \
pqi/pqissludp.cc \
pqi/pqisslproxy.cc \
pqi/pqistore.cc \
pqi/pqistreamer.cc \
@ -688,7 +695,7 @@ SOURCES += util/folderiterator.cc \
util/rsrandom.cc \
util/rstickevent.cc \
util/rsrecogn.cc \
util/rsscopetimer.cc
util/rstime.cc
upnp_miniupnpc {

View file

@ -35,6 +35,7 @@
#include "pgp/pgphandler.h"
#include <util/rsdir.h>
#include <util/rstime.h>
#include <pgp/pgpkeyutil.h>
#include <unistd.h> /* for (u)sleep() */
#include <iostream>
@ -187,7 +188,7 @@ int AuthGPG::GPGInit(const RsPgpId &ownId)
void AuthGPG::data_tick()
{
usleep(100 * 1000); //100 msec
rstime::rs_usleep(100 * 1000); //100 msec
/// every 100 milliseconds
processServices();

View file

@ -718,7 +718,7 @@ void p3NetMgrIMPL::netExtCheck()
#endif
if(sockaddr_storage_isValidNet(tmpip))
{
if(rsBanList->isAddressAccepted(tmpip,RSBANLIST_CHECKING_FLAGS_BLACKLIST))
if( (rsBanList==NULL) || rsBanList->isAddressAccepted(tmpip,RSBANLIST_CHECKING_FLAGS_BLACKLIST))
{
// must be stable???
isStable = true;
@ -761,7 +761,7 @@ void p3NetMgrIMPL::netExtCheck()
/* input network bits */
if (mDhtStunner->getExternalAddr(tmpaddr, isstable))
{
if(rsBanList->isAddressAccepted(tmpaddr,RSBANLIST_CHECKING_FLAGS_BLACKLIST))
if((rsBanList == NULL) || rsBanList->isAddressAccepted(tmpaddr,RSBANLIST_CHECKING_FLAGS_BLACKLIST))
{
// must be stable???
isStable = (isstable == 1);

View file

@ -1237,7 +1237,7 @@ bool p3PeerMgrIMPL::UpdateOwnAddress(const struct sockaddr_storage &localAddr,
std::cerr << ")" << std::endl;
#endif
if(!rsBanList->isAddressAccepted(localAddr, RSBANLIST_CHECKING_FLAGS_BLACKLIST))
if((rsBanList != NULL) && !rsBanList->isAddressAccepted(localAddr, RSBANLIST_CHECKING_FLAGS_BLACKLIST))
{
std::cerr << "(SS) Trying to set own IP to a banned IP " << sockaddr_storage_iptostring(localAddr) << ". This probably means that a friend in under traffic re-routing attack." << std::endl;
return false ;
@ -1376,7 +1376,7 @@ bool p3PeerMgrIMPL::setExtAddress(const RsPeerId &id, const struct sockaddr_s
bool changed = false;
uint32_t check_res = 0 ;
if(!rsBanList->isAddressAccepted(addr,RSBANLIST_CHECKING_FLAGS_BLACKLIST,&check_res))
if(rsBanList!=NULL && !rsBanList->isAddressAccepted(addr,RSBANLIST_CHECKING_FLAGS_BLACKLIST,&check_res))
{
std::cerr << "(SS) trying to set external contact address for peer " << id << " to a banned address " << sockaddr_storage_iptostring(addr )<< std::endl;
return false ;
@ -1550,7 +1550,7 @@ bool p3PeerMgrIMPL::addCandidateForOwnExternalAddress(const RsPeerId &from, cons
// Notify for every friend that has reported a wrong external address, except if that address is in the IP whitelist.
if((!rsBanList->isAddressAccepted(addr_filtered,RSBANLIST_CHECKING_FLAGS_WHITELIST)) && (!sockaddr_storage_sameip(own_addr,addr_filtered)))
if((rsBanList!=NULL && !rsBanList->isAddressAccepted(addr_filtered,RSBANLIST_CHECKING_FLAGS_WHITELIST)) && (!sockaddr_storage_sameip(own_addr,addr_filtered)))
{
std::cerr << " Peer " << from << " reports a connection address (" << sockaddr_storage_iptostring(addr_filtered) <<") that is not your current external address (" << sockaddr_storage_iptostring(own_addr) << "). This is weird." << std::endl;
@ -2805,7 +2805,7 @@ bool p3PeerMgrIMPL::removeBannedIps()
if(cleanIpList(it->second.ipAddrs.mExt.mAddrs,it->first,mLinkMgr)) changed = true ;
if(cleanIpList(it->second.ipAddrs.mLocal.mAddrs,it->first,mLinkMgr)) changed = true ;
if(!rsBanList->isAddressAccepted(it->second.serveraddr,RSBANLIST_CHECKING_FLAGS_BLACKLIST))
if(rsBanList!=NULL && !rsBanList->isAddressAccepted(it->second.serveraddr,RSBANLIST_CHECKING_FLAGS_BLACKLIST))
{
sockaddr_storage_clear(it->second.serveraddr) ;
std::cerr << "(SS) Peer " << it->first << " has a banned server address. Wiping it out." << std::endl;

View file

@ -4,7 +4,9 @@
#include "pqi/pqinetstatebox.h"
#include "time.h"
#ifdef RS_USE_BITDHT
#include "bitdht/bdiface.h"
#endif
// External Interface.

View file

@ -1321,14 +1321,14 @@ int pqissl::Authorise_SSL_Connection()
if (rsPeers->servicePermissionFlags(PeerId()) & RS_NODE_PERM_REQUIRE_WL)
checking_flags |= RSBANLIST_CHECKING_FLAGS_WHITELIST;
if(!rsBanList->isAddressAccepted(remote_addr,checking_flags,&check_result))
if(rsBanList!=NULL && !rsBanList->isAddressAccepted(remote_addr,checking_flags,&check_result))
{
std::cerr << "(SS) refusing connection attempt from IP address " << sockaddr_storage_iptostring(remote_addr) << ". Reason: " <<
std::cerr << "(SS) refusing connection attempt from IP address " << sockaddr_storage_iptostring(remote_addr) << ". Reason: " <<
((check_result == RSBANLIST_CHECK_RESULT_NOT_WHITELISTED)?"not whitelisted (peer requires whitelist)":"blacklisted") << std::endl;
RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_IP_BLACKLISTED, PeerId().toStdString(), sockaddr_storage_iptostring(remote_addr), "", "", check_result);
reset_locked();
return 0 ;
reset_locked();
return 0 ;
}
// check it's the right one.
if (certCorrect)
@ -1371,12 +1371,12 @@ int pqissl::accept_locked(SSL *ssl, int fd, const struct sockaddr_storage &forei
if (rsPeers->servicePermissionFlags(PeerId()) & RS_NODE_PERM_REQUIRE_WL)
checking_flags |= RSBANLIST_CHECKING_FLAGS_WHITELIST;
if(!rsBanList->isAddressAccepted(foreign_addr,checking_flags,&check_result))
if(rsBanList!=NULL && !rsBanList->isAddressAccepted(foreign_addr,checking_flags,&check_result))
{
std::cerr << "(SS) refusing incoming SSL connection from blacklisted foreign address " << sockaddr_storage_iptostring(foreign_addr)
<< ". Reason: " << check_result << "." << std::endl;
RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_IP_BLACKLISTED, PeerId().toStdString(), sockaddr_storage_iptostring(foreign_addr), "", "", check_result);
reset_locked();
reset_locked();
return -1;
}
if (waiting != WAITING_NOT)

View file

@ -36,6 +36,9 @@ static struct RsLog::logInfo pqipersongrpzoneInfo = {RsLog::Default, "pqipersong
/****
* #define PQI_DISABLE_UDP 1
***/
#ifdef RETROTOR
#define PQI_DISABLE_UDP 1
#endif
/********************************** SSL Specific features ***************************/

View file

@ -35,6 +35,7 @@
#include "util/rsdebug.h"
#include "util/rsnet.h"
#include "util/rstime.h"
#include "util/rsstring.h"
#include "pqi/p3linkmgr.h"
@ -571,7 +572,7 @@ bool pqissludp::moretoread(uint32_t usec)
{
return true;
}
usleep(usec);
rstime::rs_usleep(usec);
}
/* check for more to read first ... if nothing... check error
@ -655,7 +656,7 @@ bool pqissludp::cansend(uint32_t usec)
return true;
}
usleep(usec);
rstime::rs_usleep(usec);
}
rslog(RSL_DEBUG_ALL, pqissludpzone,

View file

@ -24,6 +24,7 @@
*/
#include "util/rstime.h"
#include "pqi/pqithreadstreamer.h"
#include <unistd.h>
@ -69,7 +70,7 @@ void pqithreadstreamer::data_tick()
if (!isactive)
{
usleep(DEFAULT_STREAMER_IDLE_SLEEP);
rstime::rs_usleep(DEFAULT_STREAMER_IDLE_SLEEP);
return ;
}
@ -92,7 +93,7 @@ void pqithreadstreamer::data_tick()
if (sleep_period)
{
usleep(sleep_period);
rstime::rs_usleep(sleep_period);
}
}

View file

@ -25,6 +25,7 @@
*/
#include "util/rstime.h"
#include "rsserver/p3face.h"
#include "retroshare/rsplugin.h"
@ -134,11 +135,7 @@ RsServer::~RsServer()
/* Thread Fn: Run the Core */
void RsServer::data_tick()
{
#ifndef WINDOWS_SYS
usleep((int) (mTimeDelta * 1000000));
#else
Sleep((int) (mTimeDelta * 1000));
#endif
rstime::rs_usleep(mTimeDelta * 1000000);
double ts = getCurrentTS();
double delta = ts - mLastts;

View file

@ -71,8 +71,11 @@ RsAccountsDetail::RsAccountsDetail() : mAccountsLocked(false), mPreferredId("")
bool RsAccountsDetail::loadAccounts()
{
int failing_accounts ;
getAvailableAccounts(mAccounts,failing_accounts,mUnsupportedKeys);
#ifdef RETROTOR
getAvailableAccounts(mAccounts,failing_accounts,mUnsupportedKeys,true);
#else
getAvailableAccounts(mAccounts,failing_accounts,mUnsupportedKeys,false);
#endif
loadPreferredAccount();
checkPreferredId();
@ -512,7 +515,7 @@ bool RsAccountsDetail::getAccountOptions(bool &ishidden, bool &isFirstTimeRun)
/* directories with valid certificates in the expected location */
bool RsAccountsDetail::getAvailableAccounts(std::map<RsPeerId, AccountDetails> &accounts,int& failing_accounts,std::map<std::string,std::vector<std::string> >& unsupported_keys)
bool RsAccountsDetail::getAvailableAccounts(std::map<RsPeerId, AccountDetails> &accounts,int& failing_accounts,std::map<std::string,std::vector<std::string> >& unsupported_keys,bool hidden_only)
{
failing_accounts = 0 ;
/* get the directories */
@ -615,6 +618,9 @@ bool RsAccountsDetail::getAvailableAccounts(std::map<RsPeerId, AccountDetails> &
continue;
}
if(hidden_only && !hidden_location)
continue ;
if(valid_prefix && isHexaString(lochex) && (lochex).length() == 32)
{
std::string accountdir = mBaseDirectory + "/" + *it;

View file

@ -142,9 +142,9 @@ class RsAccountsDetail
static bool defaultBaseDirectory();
bool getAvailableAccounts(std::map<RsPeerId, AccountDetails> &accounts,
bool getAvailableAccounts(std::map<RsPeerId, AccountDetails> &accounts,
int& failing_accounts,
std::map<std::string,std::vector<std::string> >& unsupported_keys);
std::map<std::string,std::vector<std::string> >& unsupported_keys, bool hidden_only=false);
bool setupAccount(const std::string& accountdir);

View file

@ -70,6 +70,11 @@
#include <sys/param.h>
#endif
// This needs to be defined here, because when USE_BITDHT is unset, the variable, that is defined in libbitdht (not compiled!) will be missing.
#ifndef RS_USE_BITDHT
RsDht *rsDht = NULL ;
#endif
// for blocking signals
#include <signal.h>
@ -830,9 +835,10 @@ RsGRouter *rsGRouter = NULL ;
#include "pqi/p3linkmgr.h"
#include "pqi/p3netmgr.h"
#ifndef RETROTOR
#include "tcponudp/tou.h"
#include "tcponudp/rsudpstack.h"
#endif
#ifdef RS_USE_BITDHT
@ -1186,9 +1192,9 @@ int RsServer::StartupRetroShare()
#ifdef RS_USE_DHT_STUNNER
mNetMgr->setAddrAssist(new stunAddrAssist(mDhtStunner), new stunAddrAssist(mProxyStunner));
#endif // RS_USE_DHT_STUNNER
#else //RS_USE_BITDHT
/* install NULL Pointer for rsDht Interface */
rsDht = NULL;
// #else //RS_USE_BITDHT
// /* install NULL Pointer for rsDht Interface */
// rsDht = NULL;
#endif //RS_USE_BITDHT
@ -1505,7 +1511,11 @@ int RsServer::StartupRetroShare()
interfaces.mMsgs = rsMsgs;
interfaces.mTurtle = rsTurtle;
interfaces.mDisc = rsDisc;
#ifdef RS_USE_BITDHT
interfaces.mDht = rsDht;
#else
interfaces.mDht = NULL;
#endif
interfaces.mNotify = mNotify;
interfaces.mServiceControl = serviceCtrl;
interfaces.mPluginHandler = mPluginsManager;
@ -1539,10 +1549,17 @@ int RsServer::StartupRetroShare()
#endif
// new services to test.
#ifndef RETROTOR
p3BanList *mBanList = new p3BanList(serviceCtrl, mNetMgr);
rsBanList = mBanList ;
pqih -> addService(mBanList, true);
#else
rsBanList = NULL ;
#endif
#ifdef RS_USE_BITDHT
mBitDht->setupPeerSharer(mBanList);
#endif
p3BandwidthControl *mBwCtrl = new p3BandwidthControl(pqih);
pqih -> addService(mBwCtrl, true);
@ -1608,7 +1625,9 @@ int RsServer::StartupRetroShare()
mConfigMgr->addConfiguration("p3History.cfg", mHistoryMgr);
mConfigMgr->addConfiguration("p3Status.cfg", mStatusSrv);
mConfigMgr->addConfiguration("turtle.cfg", tr);
#ifndef RETROTOR
mConfigMgr->addConfiguration("banlist.cfg", mBanList);
#endif
mConfigMgr->addConfiguration("servicecontrol.cfg", serviceCtrl);
mConfigMgr->addConfiguration("reputations.cfg", mReputations);
#ifdef ENABLE_GROUTER

View file

@ -8,6 +8,7 @@
#include "util/radix32.h"
#include "util/radix64.h"
#include "util/rsdebug.h"
#include "util/rstime.h"
#include "util/rsprint.h"
#include "util/rsrandom.h"
@ -39,7 +40,7 @@ static struct RsLog::logInfo i2pBobLogInfo = {RsLog::Default, "p3I2pBob"};
static const time_t selfCheckPeroid = 30;
void doSleep(useconds_t timeToSleepMS) {
usleep((useconds_t) (timeToSleepMS * 1000));
rstime::rs_usleep((useconds_t) (timeToSleepMS * 1000));
}
p3I2pBob::p3I2pBob(p3PeerMgr *peerMgr)

View file

@ -1,6 +1,7 @@
#include "rsautoproxymonitor.h"
#include <unistd.h> /* for usleep() */
#include "util/rstime.h"
rsAutoProxyMonitor *rsAutoProxyMonitor::mInstance = NULL;
@ -93,7 +94,7 @@ void rsAutoProxyMonitor::stopAllRSShutdown()
// wait for shutdown of all services
uint32_t t = 0, timeout = 15;
do {
usleep(1000 * 1000);
rstime::rs_usleep(1000 * 1000);
RS_STACK_MUTEX(mLock);
std::cout << "(II) waiting for auto proxy service(s) to shut down " << t << "/" << timeout << " (remaining: " << mProxies.size() << ")" << std::endl;
if (mProxies.empty())

View file

@ -34,6 +34,7 @@
#include "util/rsstring.h"
#include "util/radix64.h"
#include "util/rsdir.h"
#include "util/rstime.h"
#include "crypto/hashstream.h"
#include "gxs/gxssecurity.h"
#include "retroshare/rspeers.h"
@ -1071,7 +1072,7 @@ bool p3IdService::signData(const uint8_t *data,uint32_t data_size,const RsGxsId&
#ifdef DEBUG_IDS
std::cerr << " Cannot get key. Waiting for caching. try " << i << "/6" << std::endl;
#endif
usleep(500 * 1000) ; // sleep for 500 msec.
rstime::rs_usleep(500 * 1000) ; // sleep for 500 msec.
}
else
break ;
@ -1110,7 +1111,7 @@ bool p3IdService::validateData(const uint8_t *data,uint32_t data_size,const RsTl
#ifdef DEBUG_IDS
std::cerr << " Cannot get key. Waiting for caching. try " << i << "/6" << std::endl;
#endif
if(force_load) usleep(500 * 1000) ; // sleep for 500 msec.
if(force_load) rstime::rs_usleep(500 * 1000) ; // sleep for 500 msec.
}
else
break ;
@ -1151,7 +1152,7 @@ bool p3IdService::encryptData( const uint8_t *decrypted_data,
if(getKey(encryption_key_id,encryption_key))
break ;
else
usleep(500*1000) ; // sleep half a sec.
rstime::rs_usleep(500*1000) ; // sleep half a sec.
if(encryption_key.keyId.isNull())
{
@ -1222,7 +1223,7 @@ bool p3IdService::encryptData( const uint8_t* decrypted_data,
}
if(keyNotYetFoundIds.empty()) break;
else usleep(500*1000);
else rstime::rs_usleep(500*1000);
}
if(!keyNotYetFoundIds.empty())
@ -1279,7 +1280,7 @@ bool p3IdService::decryptData( const uint8_t *encrypted_data,
int maxRounds = force_load ? 6 : 1;
for(int i=0; i<maxRounds ;++i)
if(getPrivateKey(key_id,encryption_key)) break;
else usleep(500*1000) ; // sleep half a sec.
else rstime::rs_usleep(500*1000) ; // sleep half a sec.
if(encryption_key.keyId.isNull())
{
@ -1356,7 +1357,7 @@ bool p3IdService::decryptData( const uint8_t* encrypted_data,
}
if(keyNotYetFoundIds.empty()) break;
else usleep(500*1000);
else rstime::rs_usleep(500*1000);
}
if(!keyNotYetFoundIds.empty())

View file

@ -33,6 +33,7 @@
#include "util/rsdir.h"
#include "util/rsstring.h"
#include "util/rsrandom.h"
#include "util/rstime.h"
#include "util/rsmemory.h"
#include "util/folderiterator.h"
#include "retroshare/rstypes.h"
@ -711,7 +712,7 @@ bool RsDirUtil::renameFile(const std::string& from, const std::string& to)
#endif
/* set errno? */
return false ;
usleep(100 * 1000); // 100 msec
rstime::rs_usleep(100 * 1000); // 100 msec
if (loops >= 30)
return false ;
@ -917,7 +918,7 @@ RsStackFileLock::RsStackFileLock(const std::string& file_path)
while(RsDirUtil::createLockFile(file_path,_file_handle))
{
std::cerr << "Cannot acquire file lock " << file_path << ", waiting 1 sec." << std::endl;
usleep(1 * 1000 * 1000) ; // 1 sec
rstime::rs_usleep(1 * 1000 * 1000) ; // 1 sec
}
#ifdef RSDIR_DEBUG
std::cerr << "Acquired file handle " << _file_handle << ", lock file:" << file_path << std::endl;
@ -1321,7 +1322,7 @@ bool RsDirUtil::renameWideFile(const std::wstring& from, const std::wstring& to)
#endif
/* set errno? */
return false ;
usleep(100 * 1000); //100 msec
rstime::rs_usleep(100 * 1000); //100 msec
if (loops >= 30)
return false ;

View file

@ -30,6 +30,8 @@
#include <iostream>
#include <time.h>
#include "util/rstime.h"
#ifdef __APPLE__
int __attribute__((weak)) pthread_setname_np(const char *__buf) ;
int RS_pthread_setname_np(pthread_t /*__target_thread*/, const char *__buf) {
@ -289,7 +291,7 @@ void RsQueueThread::data_tick()
THREAD_DEBUG << "RsQueueThread::data_tick() no work: sleeping for: " << mLastSleep << " ms" << std::endl;
#endif
}
usleep(mLastSleep * 1000); // mLastSleep msec
rstime::rs_usleep(mLastSleep * 1000); // mLastSleep msec
}
void RsMutex::unlock()

View file

@ -24,8 +24,29 @@
*/
#include <iostream>
#include <thread>
#include <sys/time.h>
#include "rsscopetimer.h"
#include <sys/unistd.h>
#include <unistd.h>
#include "rstime.h"
namespace rstime {
int rs_usleep(uint32_t micro_seconds)
{
while(micro_seconds >= 1000000)
{
// usleep cannot be called with 1000000 or more.
usleep(500000) ;
usleep(500000) ;
micro_seconds -= 1000000 ;
}
usleep(micro_seconds) ;
return 0 ;
}
RsScopeTimer::RsScopeTimer(const std::string& name)
{
@ -57,3 +78,5 @@ double RsScopeTimer::duration()
{
return currentTime() - _seconds;
}
}

View file

@ -23,29 +23,40 @@
*
*/
// Use this class to measure and display time duration of a given environment:
//
// {
// RsScopeTimer timer("callToMeasure()") ;
//
// callToMeasure() ;
// }
//
#include <string>
class RsScopeTimer
{
public:
RsScopeTimer(const std::string& name);
~RsScopeTimer();
namespace rstime {
void start();
double duration();
/*!
* \brief This is a cross-system definition of usleep, which accepts any 32 bits number of micro-seconds.
*/
static double currentTime();
int rs_usleep(uint32_t micro_seconds);
private:
std::string _name ;
double _seconds ;
};
/* Use this class to measure and display time duration of a given environment:
{
RsScopeTimer timer("callToMeasure()") ;
callToMeasure() ;
}
*/
class RsScopeTimer
{
public:
RsScopeTimer(const std::string& name);
~RsScopeTimer();
void start();
double duration();
static double currentTime();
private:
std::string _name ;
double _seconds ;
};
}