mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-21 23:40:26 -04:00
- 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
This commit is contained in:
parent
69859f2a43
commit
66207b81e5
12 changed files with 52 additions and 23 deletions
|
@ -99,6 +99,10 @@ class ftDataRecv
|
||||||
|
|
||||||
/// Send a chunk map
|
/// Send a chunk map
|
||||||
virtual bool recvCRC32Map(const std::string& peer_id,const std::string& hash,const CRC32Map& crcmap) = 0;
|
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
|
#endif
|
||||||
|
|
|
@ -285,7 +285,7 @@ bool ftDataMultiplex::recvCRC32MapRequest(const std::string& peerId, const std::
|
||||||
|
|
||||||
return true;
|
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
|
#ifdef MPLEX_DEBUG
|
||||||
std::cerr << "ftDataMultiplex::recvChunkMapRequest() Server Recv";
|
std::cerr << "ftDataMultiplex::recvChunkMapRequest() Server Recv";
|
||||||
|
@ -489,7 +489,7 @@ bool ftDataMultiplex::doWork()
|
||||||
return true;
|
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 ******/
|
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
|
||||||
|
|
||||||
|
|
|
@ -148,8 +148,8 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread
|
||||||
/// Receive a CRC map request
|
/// Receive a CRC map request
|
||||||
virtual bool recvCRC32MapRequest(const std::string& peer_id,const std::string& hash) ;
|
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 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 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
|
// 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.
|
// map is too old. This supposes that the caller will ask again in a few seconds.
|
||||||
|
|
|
@ -1361,7 +1361,7 @@ FileInfo(ffr);
|
||||||
i++; /* count */
|
i++; /* count */
|
||||||
|
|
||||||
/* incoming data */
|
/* incoming data */
|
||||||
mFtDataplex->recvSingleChunkCrcRequest(fscrcr->PeerId(), fscrcr->hash,fscrcr->chunk_number) ;
|
mFtDataplex->recvSingleChunkCRCRequest(fscrcr->PeerId(), fscrcr->hash,fscrcr->chunk_number) ;
|
||||||
|
|
||||||
delete fscrcr;
|
delete fscrcr;
|
||||||
}
|
}
|
||||||
|
@ -1382,7 +1382,7 @@ FileInfo(ffr);
|
||||||
i++; /* count */
|
i++; /* count */
|
||||||
|
|
||||||
/* incoming data */
|
/* 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;
|
delete fscrcr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,6 +225,9 @@ class AuthGPG: public p3Config, public RsThread, public PGPHandler
|
||||||
/* GPG service */
|
/* GPG service */
|
||||||
virtual bool addService(AuthGPGService *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:
|
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);
|
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();
|
virtual ~AuthGPG();
|
||||||
|
|
|
@ -59,7 +59,7 @@
|
||||||
***/
|
***/
|
||||||
|
|
||||||
// initialisation du pointeur de singleton
|
// initialisation du pointeur de singleton
|
||||||
static AuthSSL *instance_ssl = NULL;
|
AuthSSL *AuthSSL::instance_ssl = NULL;
|
||||||
static pthread_mutex_t *mutex_buf = NULL;
|
static pthread_mutex_t *mutex_buf = NULL;
|
||||||
|
|
||||||
struct CRYPTO_dynlock_value
|
struct CRYPTO_dynlock_value
|
||||||
|
@ -200,12 +200,12 @@ void tls_cleanup()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* hidden function - for testing purposes() */
|
/* hidden function - for testing purposes() */
|
||||||
void setAuthSSL(AuthSSL *newssl)
|
void AuthSSL::setAuthSSL_debug(AuthSSL *newssl)
|
||||||
{
|
{
|
||||||
instance_ssl = newssl;
|
instance_ssl = newssl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AuthSSLInit()
|
void AuthSSL::AuthSSLInit()
|
||||||
{
|
{
|
||||||
if (instance_ssl == NULL)
|
if (instance_ssl == NULL)
|
||||||
{
|
{
|
||||||
|
|
|
@ -86,7 +86,6 @@ class sslcert
|
||||||
};
|
};
|
||||||
|
|
||||||
/* required to install instance */
|
/* required to install instance */
|
||||||
extern void AuthSSLInit();
|
|
||||||
|
|
||||||
class AuthSSL
|
class AuthSSL
|
||||||
{
|
{
|
||||||
|
@ -94,6 +93,7 @@ class AuthSSL
|
||||||
AuthSSL();
|
AuthSSL();
|
||||||
|
|
||||||
static AuthSSL *getAuthSSL();
|
static AuthSSL *getAuthSSL();
|
||||||
|
static void AuthSSLInit();
|
||||||
|
|
||||||
/* Initialisation Functions (Unique) */
|
/* Initialisation Functions (Unique) */
|
||||||
virtual bool validateOwnCertificate(X509 *x509, EVP_PKEY *pkey) = 0;
|
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 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 */
|
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:
|
private:
|
||||||
|
|
||||||
// the single instance of this
|
|
||||||
static AuthSSL *instance_ssl;
|
|
||||||
|
|
||||||
bool LocalStoreCert(X509* x509);
|
bool LocalStoreCert(X509* x509);
|
||||||
bool RemoveX509(std::string id);
|
bool RemoveX509(std::string id);
|
||||||
|
|
||||||
|
|
|
@ -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)
|
:p3Config(CONFIG_TYPE_PEERS), mPeerMtx("p3PeerMgr"), mStatusChanged(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -108,10 +111,10 @@ p3PeerMgrIMPL::p3PeerMgrIMPL()
|
||||||
mNetMgr = NULL;
|
mNetMgr = NULL;
|
||||||
|
|
||||||
/* setup basics of own state */
|
/* setup basics of own state */
|
||||||
mOwnState.id = AuthSSL::getAuthSSL()->OwnId();
|
mOwnState.id = ssl_own_id ;
|
||||||
mOwnState.gpg_id = AuthGPG::getAuthGPG()->getGPGOwnId();
|
mOwnState.gpg_id = gpg_own_id ;
|
||||||
mOwnState.name = AuthGPG::getAuthGPG()->getGPGOwnName();
|
mOwnState.name = gpg_own_name ;
|
||||||
mOwnState.location = AuthSSL::getAuthSSL()->getOwnLocation();
|
mOwnState.location = ssl_own_location ;
|
||||||
mOwnState.netMode = RS_NET_MODE_UPNP; // Default to UPNP.
|
mOwnState.netMode = RS_NET_MODE_UPNP; // Default to UPNP.
|
||||||
mOwnState.visState = 0;
|
mOwnState.visState = 0;
|
||||||
|
|
||||||
|
|
|
@ -290,7 +290,10 @@ virtual bool haveOnceConnected();
|
||||||
/* Extra IMPL Functions (used by p3LinkMgr, p3NetMgr + Setup) */
|
/* 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);
|
void setManagers(p3LinkMgrIMPL *linkMgr, p3NetMgrIMPL *netMgr);
|
||||||
|
|
||||||
|
|
|
@ -598,7 +598,7 @@ int RsInit::InitRetroShare(int argcIgnored, char **argvIgnored, bool strictCheck
|
||||||
* 4) Get List of GPG Accounts.
|
* 4) Get List of GPG Accounts.
|
||||||
*/
|
*/
|
||||||
/* create singletons */
|
/* create singletons */
|
||||||
AuthSSLInit();
|
AuthSSL::AuthSSLInit();
|
||||||
AuthSSL::getAuthSSL() -> InitAuth(NULL, NULL, NULL);
|
AuthSSL::getAuthSSL() -> InitAuth(NULL, NULL, NULL);
|
||||||
|
|
||||||
// first check config directories, and set bootstrap values.
|
// first check config directories, and set bootstrap values.
|
||||||
|
@ -1945,7 +1945,10 @@ int RsServer::StartupRetroShare()
|
||||||
|
|
||||||
/* History Manager */
|
/* History Manager */
|
||||||
mHistoryMgr = new p3HistoryMgr();
|
mHistoryMgr = new p3HistoryMgr();
|
||||||
mPeerMgr = new p3PeerMgrIMPL();
|
mPeerMgr = new p3PeerMgrIMPL( AuthSSL::getAuthSSL()->OwnId(),
|
||||||
|
AuthGPG::getAuthGPG()->getGPGOwnId(),
|
||||||
|
AuthGPG::getAuthGPG()->getGPGOwnName(),
|
||||||
|
AuthSSL::getAuthSSL()->getOwnLocation());
|
||||||
mNetMgr = new p3NetMgrIMPL();
|
mNetMgr = new p3NetMgrIMPL();
|
||||||
mLinkMgr = new p3LinkMgrIMPL(mPeerMgr, mNetMgr);
|
mLinkMgr = new p3LinkMgrIMPL(mPeerMgr, mNetMgr);
|
||||||
|
|
||||||
|
|
|
@ -1343,7 +1343,7 @@ void p3turtle::handleRecvChunkCRC(RsTurtleChunkCrcItem *item)
|
||||||
vpid = tunnel.vpid ;
|
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)
|
void p3turtle::handleRecvChunkCRCRequest(RsTurtleChunkCrcRequestItem *item)
|
||||||
{
|
{
|
||||||
|
@ -1379,7 +1379,7 @@ void p3turtle::handleRecvChunkCRCRequest(RsTurtleChunkCrcRequestItem *item)
|
||||||
vpid = tunnel.vpid ;
|
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)
|
void p3turtle::handleRecvFileCRC32Map(RsTurtleFileCrcItem *item)
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <util/rsrandom.h>
|
||||||
|
|
||||||
template<uint32_t ID_SIZE_IN_BYTES> class t_RsGenericIdType
|
template<uint32_t ID_SIZE_IN_BYTES> class t_RsGenericIdType
|
||||||
{
|
{
|
||||||
|
@ -46,6 +47,18 @@ template<uint32_t ID_SIZE_IN_BYTES> class t_RsGenericIdType
|
||||||
//
|
//
|
||||||
explicit t_RsGenericIdType(const unsigned char bytes[]) ;
|
explicit t_RsGenericIdType(const unsigned char bytes[]) ;
|
||||||
|
|
||||||
|
// Random initialization. Can be useful for testing.
|
||||||
|
//
|
||||||
|
static t_RsGenericIdType<ID_SIZE_IN_BYTES> random()
|
||||||
|
{
|
||||||
|
t_RsGenericIdType<ID_SIZE_IN_BYTES> id ;
|
||||||
|
|
||||||
|
for(uint32_t i=0;i<ID_SIZE_IN_BYTES;++i)
|
||||||
|
id.bytes[i] = RSRandom::random_u32() & 0xff ;
|
||||||
|
|
||||||
|
return id ;
|
||||||
|
}
|
||||||
|
|
||||||
// Converts to a std::string using cached value.
|
// Converts to a std::string using cached value.
|
||||||
//
|
//
|
||||||
std::string toStdString(bool upper_case = true) const ;
|
std::string toStdString(bool upper_case = true) const ;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue