From 66207b81e5154a70718c3aab3b2d0968639add5d Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 26 Dec 2012 18:12:19 +0000 Subject: [PATCH] - made the names consistent between ftdata, ftdatamultiplex and tests/ - added missing virtual functions in ftDataRecv - setup initSSL instance as a static member of AuthSSL, instead of an external (does not change much except the init in rsinit.cc) - changed p3PeerMgrIMPL to take SSL and PGP ids as parameters. This avoids calling AuthSSL and AuthGPG from the constructor => very helpful for tests. - added random creation function in t_RsGenericId<> - added functions setAuthSSL_debug() and setAuthGPG_debug() to manually setup the authSSL and authGPG objects to use. Used in tests. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6035 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/ft/ftdata.h | 4 ++++ libretroshare/src/ft/ftdatamultiplex.cc | 4 ++-- libretroshare/src/ft/ftdatamultiplex.h | 4 ++-- libretroshare/src/ft/ftserver.cc | 4 ++-- libretroshare/src/pqi/authgpg.h | 3 +++ libretroshare/src/pqi/authssl.cc | 6 +++--- libretroshare/src/pqi/authssl.h | 8 ++++---- libretroshare/src/pqi/p3peermgr.cc | 13 ++++++++----- libretroshare/src/pqi/p3peermgr.h | 5 ++++- libretroshare/src/rsserver/rsinit.cc | 7 +++++-- libretroshare/src/turtle/p3turtle.cc | 4 ++-- libretroshare/src/util/rsid.h | 13 +++++++++++++ 12 files changed, 52 insertions(+), 23 deletions(-) diff --git a/libretroshare/src/ft/ftdata.h b/libretroshare/src/ft/ftdata.h index 952e2ae01..a60851498 100644 --- a/libretroshare/src/ft/ftdata.h +++ b/libretroshare/src/ft/ftdata.h @@ -99,6 +99,10 @@ class ftDataRecv /// Send a chunk map virtual bool recvCRC32Map(const std::string& peer_id,const std::string& hash,const CRC32Map& crcmap) = 0; + + virtual bool recvSingleChunkCRCRequest(const std::string& peer_id,const std::string& hash,uint32_t chunk_id) = 0; + virtual bool recvSingleChunkCRC(const std::string& peer_id,const std::string& hash,uint32_t chunk_id,const Sha1CheckSum& sum) = 0; + }; #endif diff --git a/libretroshare/src/ft/ftdatamultiplex.cc b/libretroshare/src/ft/ftdatamultiplex.cc index de5fc71f5..3d4cd373a 100644 --- a/libretroshare/src/ft/ftdatamultiplex.cc +++ b/libretroshare/src/ft/ftdatamultiplex.cc @@ -285,7 +285,7 @@ bool ftDataMultiplex::recvCRC32MapRequest(const std::string& peerId, const std:: return true; } -bool ftDataMultiplex::recvSingleChunkCrcRequest(const std::string& peerId, const std::string& hash,uint32_t chunk_number) +bool ftDataMultiplex::recvSingleChunkCRCRequest(const std::string& peerId, const std::string& hash,uint32_t chunk_number) { #ifdef MPLEX_DEBUG std::cerr << "ftDataMultiplex::recvChunkMapRequest() Server Recv"; @@ -489,7 +489,7 @@ bool ftDataMultiplex::doWork() return true; } -bool ftDataMultiplex::recvSingleChunkCrc(const std::string& peerId, const std::string& hash,uint32_t chunk_number,const Sha1CheckSum& crc) +bool ftDataMultiplex::recvSingleChunkCRC(const std::string& peerId, const std::string& hash,uint32_t chunk_number,const Sha1CheckSum& crc) { RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/ diff --git a/libretroshare/src/ft/ftdatamultiplex.h b/libretroshare/src/ft/ftdatamultiplex.h index 8c804c478..54cdae691 100644 --- a/libretroshare/src/ft/ftdatamultiplex.h +++ b/libretroshare/src/ft/ftdatamultiplex.h @@ -148,8 +148,8 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread /// Receive a CRC map request virtual bool recvCRC32MapRequest(const std::string& peer_id,const std::string& hash) ; - virtual bool recvSingleChunkCrcRequest(const std::string& peer_id,const std::string& hash,uint32_t chunk_id) ; - virtual bool recvSingleChunkCrc(const std::string& peer_id,const std::string& hash,uint32_t chunk_id,const Sha1CheckSum& sum) ; + virtual bool recvSingleChunkCRCRequest(const std::string& peer_id,const std::string& hash,uint32_t chunk_id) ; + virtual bool recvSingleChunkCRC(const std::string& peer_id,const std::string& hash,uint32_t chunk_id,const Sha1CheckSum& sum) ; // Returns the chunk map from the file uploading client. Also initiates a chunk map request if this // map is too old. This supposes that the caller will ask again in a few seconds. diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 1cff47abd..b87d669a6 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -1361,7 +1361,7 @@ FileInfo(ffr); i++; /* count */ /* incoming data */ - mFtDataplex->recvSingleChunkCrcRequest(fscrcr->PeerId(), fscrcr->hash,fscrcr->chunk_number) ; + mFtDataplex->recvSingleChunkCRCRequest(fscrcr->PeerId(), fscrcr->hash,fscrcr->chunk_number) ; delete fscrcr; } @@ -1382,7 +1382,7 @@ FileInfo(ffr); i++; /* count */ /* incoming data */ - mFtDataplex->recvSingleChunkCrc(fscrc->PeerId(), fscrc->hash,fscrc->chunk_number,fscrc->check_sum); + mFtDataplex->recvSingleChunkCRC(fscrc->PeerId(), fscrc->hash,fscrc->chunk_number,fscrc->check_sum); delete fscrcr; } diff --git a/libretroshare/src/pqi/authgpg.h b/libretroshare/src/pqi/authgpg.h index 6b32a8991..a958cbfd8 100644 --- a/libretroshare/src/pqi/authgpg.h +++ b/libretroshare/src/pqi/authgpg.h @@ -225,6 +225,9 @@ class AuthGPG: public p3Config, public RsThread, public PGPHandler /* GPG service */ virtual bool addService(AuthGPGService *service) ; + // This is for debug purpose only. Don't use it !! + static void setAuthGPG_debug(AuthGPG *auth_gpg) { _instance = auth_gpg ; } + protected: AuthGPG(const std::string& path_to_pubring, const std::string& path_to_secring,const std::string& path_to_trustdb,const std::string& pgp_lock_file); virtual ~AuthGPG(); diff --git a/libretroshare/src/pqi/authssl.cc b/libretroshare/src/pqi/authssl.cc index bd8fd9a25..331e88c2c 100644 --- a/libretroshare/src/pqi/authssl.cc +++ b/libretroshare/src/pqi/authssl.cc @@ -59,7 +59,7 @@ ***/ // initialisation du pointeur de singleton -static AuthSSL *instance_ssl = NULL; +AuthSSL *AuthSSL::instance_ssl = NULL; static pthread_mutex_t *mutex_buf = NULL; struct CRYPTO_dynlock_value @@ -200,12 +200,12 @@ void tls_cleanup() } /* hidden function - for testing purposes() */ -void setAuthSSL(AuthSSL *newssl) +void AuthSSL::setAuthSSL_debug(AuthSSL *newssl) { instance_ssl = newssl; } -void AuthSSLInit() +void AuthSSL::AuthSSLInit() { if (instance_ssl == NULL) { diff --git a/libretroshare/src/pqi/authssl.h b/libretroshare/src/pqi/authssl.h index ec4340798..99c9d0488 100644 --- a/libretroshare/src/pqi/authssl.h +++ b/libretroshare/src/pqi/authssl.h @@ -86,7 +86,6 @@ class sslcert }; /* required to install instance */ -extern void AuthSSLInit(); class AuthSSL { @@ -94,6 +93,7 @@ class AuthSSL AuthSSL(); static AuthSSL *getAuthSSL(); +static void AuthSSLInit(); /* Initialisation Functions (Unique) */ virtual bool validateOwnCertificate(X509 *x509, EVP_PKEY *pkey) = 0; @@ -155,6 +155,9 @@ virtual void getCurrentConnectionAttemptInfo( std::string& gpg_id, s virtual bool FailedCertificate(X509 *x509, const std::string& gpgid,const std::string& sslid,const std::string& sslcn,const struct sockaddr_in &addr, bool incoming) = 0; /* store for discovery */ virtual bool CheckCertificate(std::string peerId, X509 *x509) = 0; /* check that they are exact match */ + +static void setAuthSSL_debug(AuthSSL*) ; // used for debug only. The real function is InitSSL() +static AuthSSL *instance_ssl ; }; @@ -235,9 +238,6 @@ virtual bool CheckCertificate(std::string peerId, X509 *x509); /* check that th private: - // the single instance of this - static AuthSSL *instance_ssl; - bool LocalStoreCert(X509* x509); bool RemoveX509(std::string id); diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index a63c320c1..9b09ded06 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -97,7 +97,10 @@ std::string textPeerConnectState(peerState &state) } -p3PeerMgrIMPL::p3PeerMgrIMPL() +p3PeerMgrIMPL::p3PeerMgrIMPL( const std::string& ssl_own_id, + const std::string& gpg_own_id, + const std::string& gpg_own_name, + const std::string& ssl_own_location) :p3Config(CONFIG_TYPE_PEERS), mPeerMtx("p3PeerMgr"), mStatusChanged(false) { @@ -108,10 +111,10 @@ p3PeerMgrIMPL::p3PeerMgrIMPL() mNetMgr = NULL; /* setup basics of own state */ - mOwnState.id = AuthSSL::getAuthSSL()->OwnId(); - mOwnState.gpg_id = AuthGPG::getAuthGPG()->getGPGOwnId(); - mOwnState.name = AuthGPG::getAuthGPG()->getGPGOwnName(); - mOwnState.location = AuthSSL::getAuthSSL()->getOwnLocation(); + mOwnState.id = ssl_own_id ; + mOwnState.gpg_id = gpg_own_id ; + mOwnState.name = gpg_own_name ; + mOwnState.location = ssl_own_location ; mOwnState.netMode = RS_NET_MODE_UPNP; // Default to UPNP. mOwnState.visState = 0; diff --git a/libretroshare/src/pqi/p3peermgr.h b/libretroshare/src/pqi/p3peermgr.h index 14c822cea..5dc58f835 100644 --- a/libretroshare/src/pqi/p3peermgr.h +++ b/libretroshare/src/pqi/p3peermgr.h @@ -290,7 +290,10 @@ virtual bool haveOnceConnected(); /* Extra IMPL Functions (used by p3LinkMgr, p3NetMgr + Setup) */ /************************************************************************************************/ - p3PeerMgrIMPL(); + p3PeerMgrIMPL( const std::string& ssl_own_id, + const std::string& gpg_own_id, + const std::string& gpg_own_name, + const std::string& ssl_own_location) ; void setManagers(p3LinkMgrIMPL *linkMgr, p3NetMgrIMPL *netMgr); diff --git a/libretroshare/src/rsserver/rsinit.cc b/libretroshare/src/rsserver/rsinit.cc index 9fddb8928..45596e3a6 100644 --- a/libretroshare/src/rsserver/rsinit.cc +++ b/libretroshare/src/rsserver/rsinit.cc @@ -598,7 +598,7 @@ int RsInit::InitRetroShare(int argcIgnored, char **argvIgnored, bool strictCheck * 4) Get List of GPG Accounts. */ /* create singletons */ - AuthSSLInit(); + AuthSSL::AuthSSLInit(); AuthSSL::getAuthSSL() -> InitAuth(NULL, NULL, NULL); // first check config directories, and set bootstrap values. @@ -1945,7 +1945,10 @@ int RsServer::StartupRetroShare() /* History Manager */ mHistoryMgr = new p3HistoryMgr(); - mPeerMgr = new p3PeerMgrIMPL(); + mPeerMgr = new p3PeerMgrIMPL( AuthSSL::getAuthSSL()->OwnId(), + AuthGPG::getAuthGPG()->getGPGOwnId(), + AuthGPG::getAuthGPG()->getGPGOwnName(), + AuthSSL::getAuthSSL()->getOwnLocation()); mNetMgr = new p3NetMgrIMPL(); mLinkMgr = new p3LinkMgrIMPL(mPeerMgr, mNetMgr); diff --git a/libretroshare/src/turtle/p3turtle.cc b/libretroshare/src/turtle/p3turtle.cc index 8dbafda05..972e5ca35 100644 --- a/libretroshare/src/turtle/p3turtle.cc +++ b/libretroshare/src/turtle/p3turtle.cc @@ -1343,7 +1343,7 @@ void p3turtle::handleRecvChunkCRC(RsTurtleChunkCrcItem *item) vpid = tunnel.vpid ; } - _ft_server->getMultiplexer()->recvSingleChunkCrc(vpid,hash,item->chunk_number,item->check_sum) ; + _ft_server->getMultiplexer()->recvSingleChunkCRC(vpid,hash,item->chunk_number,item->check_sum) ; } void p3turtle::handleRecvChunkCRCRequest(RsTurtleChunkCrcRequestItem *item) { @@ -1379,7 +1379,7 @@ void p3turtle::handleRecvChunkCRCRequest(RsTurtleChunkCrcRequestItem *item) vpid = tunnel.vpid ; } - _ft_server->getMultiplexer()->recvSingleChunkCrcRequest(vpid,hash,item->chunk_number) ; + _ft_server->getMultiplexer()->recvSingleChunkCRCRequest(vpid,hash,item->chunk_number) ; } void p3turtle::handleRecvFileCRC32Map(RsTurtleFileCrcItem *item) { diff --git a/libretroshare/src/util/rsid.h b/libretroshare/src/util/rsid.h index bfcf845c0..5a6cd5eb0 100644 --- a/libretroshare/src/util/rsid.h +++ b/libretroshare/src/util/rsid.h @@ -31,6 +31,7 @@ #include #include #include +#include template class t_RsGenericIdType { @@ -46,6 +47,18 @@ template class t_RsGenericIdType // explicit t_RsGenericIdType(const unsigned char bytes[]) ; + // Random initialization. Can be useful for testing. + // + static t_RsGenericIdType random() + { + t_RsGenericIdType id ; + + for(uint32_t i=0;i