mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-25 23:49:35 -05:00
Added service functionality to AuthGPG for load and save of certificates in the background (prepared for more when needed).
Added p3disc as service and process the certificats of RsDiscReply with AuthGPG service. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3669 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
923e76bde2
commit
3a60e8cecb
@ -357,6 +357,9 @@ void AuthGPGimpl::run()
|
|||||||
sleep(1);
|
sleep(1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* every second */
|
||||||
|
processServices();
|
||||||
|
|
||||||
/* every minute */
|
/* every minute */
|
||||||
if (++count >= 60) {
|
if (++count >= 60) {
|
||||||
storeAllKeys_tick();
|
storeAllKeys_tick();
|
||||||
@ -365,6 +368,67 @@ void AuthGPGimpl::run()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AuthGPGimpl::processServices()
|
||||||
|
{
|
||||||
|
AuthGPGOperation *operation = NULL;
|
||||||
|
AuthGPGService *service = NULL;
|
||||||
|
|
||||||
|
{
|
||||||
|
RsStackMutex stack(gpgMtxService); /******* LOCKED ******/
|
||||||
|
|
||||||
|
std::list<AuthGPGService*>::iterator serviceIt;
|
||||||
|
for (serviceIt = services.begin(); serviceIt != services.end(); serviceIt++) {
|
||||||
|
operation = (*serviceIt)->getGPGOperation();
|
||||||
|
if (operation) {
|
||||||
|
service = *serviceIt;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} /******* UNLOCKED ******/
|
||||||
|
|
||||||
|
if (operation == NULL) {
|
||||||
|
/* nothing to do */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (service == NULL) {
|
||||||
|
/* huh ? */
|
||||||
|
delete operation;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AuthGPGOperationLoadOrSave *loadOrSave = dynamic_cast<AuthGPGOperationLoadOrSave*>(operation);
|
||||||
|
if (loadOrSave) {
|
||||||
|
if (loadOrSave->m_load) {
|
||||||
|
/* process load operation */
|
||||||
|
|
||||||
|
#ifdef GPG_DEBUG
|
||||||
|
std::cerr << "AuthGPGimpl::processServices() Process load operation" << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* load the certificate */
|
||||||
|
LoadCertificateFromString(loadOrSave->m_certGpg, loadOrSave->m_certGpgId);
|
||||||
|
} else {
|
||||||
|
/* process save operation */
|
||||||
|
|
||||||
|
#ifdef GPG_DEBUG
|
||||||
|
std::cerr << "AuthGPGimpl::processServices() Process save operation" << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* save the certificate to string */
|
||||||
|
loadOrSave->m_certGpg = SaveCertificateToString(loadOrSave->m_certGpgId);
|
||||||
|
}
|
||||||
|
|
||||||
|
service->setGPGOperation(loadOrSave);
|
||||||
|
} else {
|
||||||
|
#ifdef GPG_DEBUG
|
||||||
|
std::cerr << "AuthGPGimpl::processServices() Unknown operation" << std::endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
delete operation;
|
||||||
|
}
|
||||||
|
|
||||||
bool AuthGPGimpl::storeAllKeys_tick() {
|
bool AuthGPGimpl::storeAllKeys_tick() {
|
||||||
#ifdef GPG_DEBUG
|
#ifdef GPG_DEBUG
|
||||||
std::cerr << "AuthGPGimpl::storeAllKeys_tick() called." << std::endl;
|
std::cerr << "AuthGPGimpl::storeAllKeys_tick() called." << std::endl;
|
||||||
@ -892,7 +956,7 @@ bool AuthGPGimpl::DoOwnSignature(const void *data, unsigned int datalen, void *b
|
|||||||
|
|
||||||
|
|
||||||
/* import to GnuPG and other Certificates */
|
/* import to GnuPG and other Certificates */
|
||||||
bool AuthGPGimpl::VerifySignature(const void *data, int datalen, const void *sig, unsigned int siglen, std::string withfingerprint)
|
bool AuthGPGimpl::VerifySignature(const void *data, int datalen, const void *sig, unsigned int siglen, const std::string &withfingerprint)
|
||||||
{
|
{
|
||||||
gpgme_data_t gpgmeSig;
|
gpgme_data_t gpgmeSig;
|
||||||
gpgme_data_t gpgmeData;
|
gpgme_data_t gpgmeData;
|
||||||
@ -1504,7 +1568,7 @@ bool AuthGPGimpl::SignDataBin(const void *data, unsigned int datalen, unsigned c
|
|||||||
sign, signlen);
|
sign, signlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AuthGPGimpl::VerifySignBin(const void *data, uint32_t datalen, unsigned char *sign, unsigned int signlen, std::string withfingerprint) {
|
bool AuthGPGimpl::VerifySignBin(const void *data, uint32_t datalen, unsigned char *sign, unsigned int signlen, const std::string &withfingerprint) {
|
||||||
return VerifySignature(data, datalen,
|
return VerifySignature(data, datalen,
|
||||||
sign, signlen, withfingerprint);
|
sign, signlen, withfingerprint);
|
||||||
}
|
}
|
||||||
@ -2314,3 +2378,15 @@ bool AuthGPGimpl::loadList(std::list<RsItem*> load)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AuthGPGimpl::addService(AuthGPGService *service)
|
||||||
|
{
|
||||||
|
RsStackMutex stack(gpgMtxService); /********* LOCKED *********/
|
||||||
|
|
||||||
|
if (std::find(services.begin(), services.end(), service) != services.end()) {
|
||||||
|
/* it exists already! */
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
services.push_back(service);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@ -84,6 +84,48 @@ class gpgcert
|
|||||||
gpgme_key_t key;
|
gpgme_key_t key;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class AuthGPGOperation
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AuthGPGOperation(void *userdata)
|
||||||
|
{
|
||||||
|
m_userdata = userdata;
|
||||||
|
}
|
||||||
|
virtual ~AuthGPGOperation() {}
|
||||||
|
|
||||||
|
public:
|
||||||
|
void *m_userdata;
|
||||||
|
};
|
||||||
|
|
||||||
|
class AuthGPGOperationLoadOrSave : public AuthGPGOperation
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AuthGPGOperationLoadOrSave(bool load, const std::string &certGpgOrId, void *userdata) : AuthGPGOperation(userdata)
|
||||||
|
{
|
||||||
|
m_load = load;
|
||||||
|
if (m_load) {
|
||||||
|
m_certGpg = certGpgOrId;
|
||||||
|
} else {
|
||||||
|
m_certGpgId = certGpgOrId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool m_load;
|
||||||
|
std::string m_certGpgId; // set for save
|
||||||
|
std::string m_certGpg; // set for load
|
||||||
|
};
|
||||||
|
|
||||||
|
class AuthGPGService
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AuthGPGService() {};
|
||||||
|
~AuthGPGService() {};
|
||||||
|
|
||||||
|
virtual AuthGPGOperation *getGPGOperation() = 0;
|
||||||
|
virtual void setGPGOperation(AuthGPGOperation *operation) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* The certificate map type
|
* The certificate map type
|
||||||
*/
|
*/
|
||||||
@ -135,7 +177,7 @@ virtual bool InitAuth () = 0;
|
|||||||
virtual int GPGInit(std::string ownId) = 0;
|
virtual int GPGInit(std::string ownId) = 0;
|
||||||
virtual bool CloseAuth() = 0;
|
virtual bool CloseAuth() = 0;
|
||||||
virtual bool GeneratePGPCertificate(std::string name, std::string email, std::string passwd, std::string &pgpId, std::string &errString) = 0;
|
virtual bool GeneratePGPCertificate(std::string name, std::string email, std::string passwd, std::string &pgpId, std::string &errString) = 0;
|
||||||
|
|
||||||
/*********************************************************************************/
|
/*********************************************************************************/
|
||||||
/************************* STAGE 3 ***********************************************/
|
/************************* STAGE 3 ***********************************************/
|
||||||
/*********************************************************************************/
|
/*********************************************************************************/
|
||||||
@ -206,11 +248,13 @@ virtual bool TrustCertificate(std::string id, int trustlvl) = 0; //trustlvl is
|
|||||||
//virtual bool SignData(const void *data, const uint32_t len, std::string &sign) = 0;
|
//virtual bool SignData(const void *data, const uint32_t len, std::string &sign) = 0;
|
||||||
//virtual bool SignDataBin(std::string input, unsigned char *sign, unsigned int *signlen) = 0;
|
//virtual bool SignDataBin(std::string input, unsigned char *sign, unsigned int *signlen) = 0;
|
||||||
virtual bool SignDataBin(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen) = 0;
|
virtual bool SignDataBin(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen) = 0;
|
||||||
virtual bool VerifySignBin(const void*, uint32_t, unsigned char*, unsigned int, std::string withfingerprint) = 0;
|
virtual bool VerifySignBin(const void*, uint32_t, unsigned char*, unsigned int, const std::string &withfingerprint) = 0;
|
||||||
virtual bool decryptText(gpgme_data_t CIPHER, gpgme_data_t PLAIN) = 0;
|
virtual bool decryptText(gpgme_data_t CIPHER, gpgme_data_t PLAIN) = 0;
|
||||||
virtual bool encryptText(gpgme_data_t PLAIN, gpgme_data_t CIPHER) = 0;
|
virtual bool encryptText(gpgme_data_t PLAIN, gpgme_data_t CIPHER) = 0;
|
||||||
//END of PGP public functions
|
//END of PGP public functions
|
||||||
|
|
||||||
|
/* GPG service */
|
||||||
|
virtual bool addService(AuthGPGService *service) = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -253,7 +297,7 @@ virtual bool InitAuth ();
|
|||||||
virtual int GPGInit(std::string ownId);
|
virtual int GPGInit(std::string ownId);
|
||||||
virtual bool CloseAuth();
|
virtual bool CloseAuth();
|
||||||
virtual bool GeneratePGPCertificate(std::string name, std::string email, std::string passwd, std::string &pgpId, std::string &errString);
|
virtual bool GeneratePGPCertificate(std::string name, std::string email, std::string passwd, std::string &pgpId, std::string &errString);
|
||||||
|
|
||||||
/*********************************************************************************/
|
/*********************************************************************************/
|
||||||
/************************* STAGE 3 ***********************************************/
|
/************************* STAGE 3 ***********************************************/
|
||||||
/*********************************************************************************/
|
/*********************************************************************************/
|
||||||
@ -325,11 +369,14 @@ virtual bool TrustCertificate(std::string id, int trustlvl); //trustlvl is 2 fo
|
|||||||
//virtual bool SignData(const void *data, const uint32_t len, std::string &sign);
|
//virtual bool SignData(const void *data, const uint32_t len, std::string &sign);
|
||||||
//virtual bool SignDataBin(std::string input, unsigned char *sign, unsigned int *signlen);
|
//virtual bool SignDataBin(std::string input, unsigned char *sign, unsigned int *signlen);
|
||||||
virtual bool SignDataBin(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen);
|
virtual bool SignDataBin(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen);
|
||||||
virtual bool VerifySignBin(const void*, uint32_t, unsigned char*, unsigned int, std::string withfingerprint);
|
virtual bool VerifySignBin(const void*, uint32_t, unsigned char*, unsigned int, const std::string &withfingerprint);
|
||||||
virtual bool decryptText(gpgme_data_t CIPHER, gpgme_data_t PLAIN);
|
virtual bool decryptText(gpgme_data_t CIPHER, gpgme_data_t PLAIN);
|
||||||
virtual bool encryptText(gpgme_data_t PLAIN, gpgme_data_t CIPHER);
|
virtual bool encryptText(gpgme_data_t PLAIN, gpgme_data_t CIPHER);
|
||||||
//END of PGP public functions
|
//END of PGP public functions
|
||||||
|
|
||||||
|
/* GPG service */
|
||||||
|
virtual bool addService(AuthGPGService *service);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/*****************************************************************/
|
/*****************************************************************/
|
||||||
/*********************** p3config ******************************/
|
/*********************** p3config ******************************/
|
||||||
@ -348,7 +395,7 @@ virtual bool encryptText(gpgme_data_t PLAIN, gpgme_data_t CIPHER);
|
|||||||
|
|
||||||
/* Internal functions */
|
/* Internal functions */
|
||||||
bool DoOwnSignature(const void *, unsigned int, void *, unsigned int *);
|
bool DoOwnSignature(const void *, unsigned int, void *, unsigned int *);
|
||||||
bool VerifySignature(const void *data, int datalen, const void *sig, unsigned int siglen, std::string withfingerprint);
|
bool VerifySignature(const void *data, int datalen, const void *sig, unsigned int siglen, const std::string &withfingerprint);
|
||||||
|
|
||||||
/* Sign/Trust stuff */
|
/* Sign/Trust stuff */
|
||||||
int privateSignCertificate(GPG_id id);
|
int privateSignCertificate(GPG_id id);
|
||||||
@ -362,6 +409,9 @@ virtual bool encryptText(gpgme_data_t PLAIN, gpgme_data_t CIPHER);
|
|||||||
// Not used anymore
|
// Not used anymore
|
||||||
// bool updateTrustAllKeys_locked();
|
// bool updateTrustAllKeys_locked();
|
||||||
|
|
||||||
|
/* GPG service */
|
||||||
|
void processServices();
|
||||||
|
|
||||||
bool printAllKeys_locked();
|
bool printAllKeys_locked();
|
||||||
bool printOwnKeys_locked();
|
bool printOwnKeys_locked();
|
||||||
|
|
||||||
@ -393,6 +443,10 @@ private:
|
|||||||
|
|
||||||
std::map<std::string, bool> mAcceptToConnectMap;
|
std::map<std::string, bool> mAcceptToConnectMap;
|
||||||
|
|
||||||
|
RsMutex gpgMtxService;
|
||||||
|
/* Below is protected via the mutex */
|
||||||
|
|
||||||
|
std::list<AuthGPGService*> services;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -2506,6 +2506,12 @@ int RsServer::StartupRetroShare()
|
|||||||
//getPqiNotify()->ClearFeedItems(RS_FEED_ITEM_FILES_NEW);
|
//getPqiNotify()->ClearFeedItems(RS_FEED_ITEM_FILES_NEW);
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/* Add AuthGPG services */
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
|
AuthGPG::getAuthGPG()->addService(ad);
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/* Force Any Last Configuration Options */
|
/* Force Any Last Configuration Options */
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
@ -120,42 +120,6 @@ int p3disc::tick()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string destId;
|
|
||||||
std::string srcId;
|
|
||||||
|
|
||||||
{
|
|
||||||
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
|
||||||
|
|
||||||
while (!sendIdList.empty()) {
|
|
||||||
std::map<std::string, std::list<std::string> >::iterator sendIdIt = sendIdList.begin();
|
|
||||||
|
|
||||||
if (!sendIdIt->second.empty() && mConnMgr->isOnline(sendIdIt->first)) {
|
|
||||||
std::string gpgId = sendIdIt->second.front();
|
|
||||||
sendIdIt->second.pop_front();
|
|
||||||
|
|
||||||
destId = sendIdIt->first;
|
|
||||||
srcId = gpgId;
|
|
||||||
|
|
||||||
/* send only one per tick */
|
|
||||||
#ifdef P3DISC_DEBUG
|
|
||||||
int count = 0;
|
|
||||||
for (sendIdIt = sendIdList.begin(); sendIdIt != sendIdList.end(); sendIdIt++) {
|
|
||||||
count += sendIdIt->second.size();
|
|
||||||
}
|
|
||||||
std::cerr << "p3disc::tick() Count of gpg id's " << count << std::endl;
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
/* peer is not online anymore ... try next */
|
|
||||||
sendIdList.erase(sendIdIt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!destId.empty() && !srcId.empty()) {
|
|
||||||
sendPeerDetails(destId, srcId);
|
|
||||||
}
|
|
||||||
|
|
||||||
return handleIncoming();
|
return handleIncoming();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,8 +167,20 @@ int p3disc::handleIncoming()
|
|||||||
// if discovery reply then respond if haven't already.
|
// if discovery reply then respond if haven't already.
|
||||||
if (NULL != (dri = dynamic_cast<RsDiscReply *> (item))) {
|
if (NULL != (dri = dynamic_cast<RsDiscReply *> (item))) {
|
||||||
|
|
||||||
|
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
|
/* search pending item and remove it, when already exist */
|
||||||
|
std::list<RsDiscReply*>::iterator it;
|
||||||
|
for (it = pendingDiscReplyInList.begin(); it != pendingDiscReplyInList.end(); it++) {
|
||||||
|
if ((*it)->PeerId() == dri->PeerId() && (*it)->aboutId == dri->aboutId) {
|
||||||
|
delete (*it);
|
||||||
|
pendingDiscReplyInList.erase(it);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// add item to list for later process
|
// add item to list for later process
|
||||||
discReplyList.push_back(dri); // no delete
|
pendingDiscReplyInList.push_back(dri); // no delete
|
||||||
}
|
}
|
||||||
else if (NULL != (dvi = dynamic_cast<RsDiscVersion *> (item))) {
|
else if (NULL != (dvi = dynamic_cast<RsDiscVersion *> (item))) {
|
||||||
recvPeerVersionMsg(dvi);
|
recvPeerVersionMsg(dvi);
|
||||||
@ -232,18 +208,6 @@ int p3disc::handleIncoming()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// process one disc item
|
|
||||||
if (!discReplyList.empty()) {
|
|
||||||
RsDiscReply *dri = discReplyList.front();
|
|
||||||
discReplyList.pop_front();
|
|
||||||
recvPeerDetails(dri);
|
|
||||||
nhandled++;
|
|
||||||
#ifdef P3DISC_DEBUG
|
|
||||||
std::cerr << "p3disc::handleIncoming() Count of disc items " << discReplyList.size() << std::endl;
|
|
||||||
#endif
|
|
||||||
delete dri;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef P3DISC_DEBUG
|
#ifdef P3DISC_DEBUG
|
||||||
std::cerr << "p3disc::handleIncoming() finished." << std::endl;
|
std::cerr << "p3disc::handleIncoming() finished." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
@ -294,7 +258,7 @@ void p3disc::statusChange(const std::list<pqipeer> &plist)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void p3disc::sendAllInfoToJustConnectedPeer(std::string id)
|
void p3disc::sendAllInfoToJustConnectedPeer(const std::string &id)
|
||||||
{
|
{
|
||||||
/* get a peer lists */
|
/* get a peer lists */
|
||||||
|
|
||||||
@ -355,7 +319,7 @@ void p3disc::sendAllInfoToJustConnectedPeer(std::string id)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void p3disc::sendJustConnectedPeerInfoToAllPeer(std::string connectedPeerId)
|
void p3disc::sendJustConnectedPeerInfoToAllPeer(const std::string &connectedPeerId)
|
||||||
{
|
{
|
||||||
/* get a peer lists */
|
/* get a peer lists */
|
||||||
|
|
||||||
@ -383,44 +347,43 @@ void p3disc::sendJustConnectedPeerInfoToAllPeer(std::string connectedPeerId)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* (dest (to), source (cert)) */
|
/* (dest (to), source (cert)) */
|
||||||
void p3disc::sendPeerDetails(std::string to, std::string about)
|
RsDiscReply *p3disc::createDiscReply(const std::string &to, const std::string &about)
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef P3DISC_DEBUG
|
#ifdef P3DISC_DEBUG
|
||||||
std::cerr << "p3disc::sendPeerDetails() called. Sending details of: " << about << " to: " << to << std::endl;
|
std::cerr << "p3disc::createDiscReply() called. Sending details of: " << about << " to: " << to << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RsPeerDetails pd;
|
RsPeerDetails pd;
|
||||||
rsPeers->getPeerDetails(to, pd);
|
rsPeers->getPeerDetails(to, pd);
|
||||||
if (!pd.accept_connection || !pd.ownsign) {
|
if (!pd.accept_connection || !pd.ownsign) {
|
||||||
#ifdef P3DISC_DEBUG
|
#ifdef P3DISC_DEBUG
|
||||||
std::cerr << "p3disc::sendPeerDetails() we're not sending the info because the destination gpg key is not signed or not accepted." << std::cerr << std::endl;
|
std::cerr << "p3disc::createDiscReply() we're not sending the info because the destination gpg key is not signed or not accepted." << std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// if off discard item.
|
// if off discard item.
|
||||||
peerConnectState detail;
|
peerConnectState detail;
|
||||||
if (!mConnMgr->getOwnNetStatus(detail) || (detail.visState & RS_VIS_STATE_NODISC)) {
|
if (!mConnMgr->getOwnNetStatus(detail) || (detail.visState & RS_VIS_STATE_NODISC)) {
|
||||||
return;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string aboutGpgId = rsPeers->getGPGId(about);
|
std::string aboutGpgId = rsPeers->getGPGId(about);
|
||||||
if (about == "") {
|
if (aboutGpgId.empty()) {
|
||||||
#ifdef P3DISC_DEBUG
|
#ifdef P3DISC_DEBUG
|
||||||
std::cerr << "p3disc::sendPeerDetails() no info about this id" << std::endl;
|
std::cerr << "p3disc::createDiscReply() no info about this id" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
peerConnectState detailAbout;
|
peerConnectState detailAbout;
|
||||||
if (mConnMgr->getFriendNetStatus(aboutGpgId, detailAbout) && detailAbout.visState & RS_VIS_STATE_NODISC)
|
if (mConnMgr->getFriendNetStatus(aboutGpgId, detailAbout) && detailAbout.visState & RS_VIS_STATE_NODISC)
|
||||||
{
|
{
|
||||||
#ifdef P3DISC_DEBUG
|
#ifdef P3DISC_DEBUG
|
||||||
std::cerr << "p3disc::sendPeerDetails() don't send info about this peer because he has no disc enabled." << std::endl;
|
std::cerr << "p3disc::createDiscReply() don't send info about this peer because he has no disc enabled." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct a message
|
// Construct a message
|
||||||
@ -440,7 +403,7 @@ void p3disc::sendPeerDetails(std::string to, std::string about)
|
|||||||
for (sslChildIt = sslChilds.begin(); sslChildIt != sslChilds.end(); sslChildIt++)
|
for (sslChildIt = sslChilds.begin(); sslChildIt != sslChilds.end(); sslChildIt++)
|
||||||
{
|
{
|
||||||
#ifdef P3DISC_DEBUG
|
#ifdef P3DISC_DEBUG
|
||||||
std::cerr << "p3disc::sendPeerDetails() Found Child SSL Id:" << *sslChildIt;
|
std::cerr << "p3disc::createDiscReply() Found Child SSL Id:" << *sslChildIt;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
if(to != *sslChildIt) // We don't send info to a peer about itself, but we allow sending info
|
if(to != *sslChildIt) // We don't send info to a peer about itself, but we allow sending info
|
||||||
@ -450,14 +413,14 @@ void p3disc::sendPeerDetails(std::string to, std::string about)
|
|||||||
|| detail.visState & RS_VIS_STATE_NODISC)
|
|| detail.visState & RS_VIS_STATE_NODISC)
|
||||||
{
|
{
|
||||||
#ifdef P3DISC_DEBUG
|
#ifdef P3DISC_DEBUG
|
||||||
std::cerr << "p3disc::sendPeerDetails() Skipping cos No Details or NODISC flag";
|
std::cerr << "p3disc::createDiscReply() Skipping cos No Details or NODISC flag";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef P3DISC_DEBUG
|
#ifdef P3DISC_DEBUG
|
||||||
std::cerr << "p3disc::sendPeerDetails() Adding Child SSL Id Details";
|
std::cerr << "p3disc::createDiscReply() Adding Child SSL Id Details";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
shouldWeSendGPGKey = true;
|
shouldWeSendGPGKey = true;
|
||||||
@ -482,7 +445,7 @@ void p3disc::sendPeerDetails(std::string to, std::string about)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef P3DISC_DEBUG
|
#ifdef P3DISC_DEBUG
|
||||||
std::cerr << "p3disc::sendPeerDetails() Skipping cos \"to == sslChildId\"";
|
std::cerr << "p3disc::createDiscReply() Skipping cos \"to == sslChildId\"";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -517,34 +480,14 @@ void p3disc::sendPeerDetails(std::string to, std::string about)
|
|||||||
|
|
||||||
if (!shouldWeSendGPGKey) {
|
if (!shouldWeSendGPGKey) {
|
||||||
#ifdef P3DISC_DEBUG
|
#ifdef P3DISC_DEBUG
|
||||||
std::cerr << "p3disc::sendPeerDetails() GPG key should not be send, no friend with disc on found about it." << std::endl;
|
std::cerr << "p3disc::createDiscReply() GPG key should not be send, no friend with disc on found about it." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
// cleanup!
|
// cleanup!
|
||||||
delete di;
|
delete di;
|
||||||
return;
|
return NULL;
|
||||||
}
|
}
|
||||||
std::string cert = AuthGPG::getAuthGPG()->SaveCertificateToString(about);
|
|
||||||
if (cert == "") {
|
|
||||||
#ifdef P3DISC_DEBUG
|
|
||||||
std::cerr << "p3disc::sendPeerDetails() don't send details because the gpg cert is not good" << std::endl;
|
|
||||||
|
|
||||||
#endif
|
return di;
|
||||||
// cleanup!
|
|
||||||
delete di;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
di -> certGPG = cert;
|
|
||||||
|
|
||||||
// Send off message
|
|
||||||
#ifdef P3DISC_DEBUG
|
|
||||||
std::cerr << "p3disc::sendPeerDetails() About to Send Message:" << std::endl;
|
|
||||||
di->print(std::cerr, 5);
|
|
||||||
#endif
|
|
||||||
sendItem(di);
|
|
||||||
|
|
||||||
#ifdef P3DISC_DEBUG
|
|
||||||
std::cerr << "p3disc::sendPeerDetails() discovery reply sent." << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void p3disc::sendOwnVersion(std::string to)
|
void p3disc::sendOwnVersion(std::string to)
|
||||||
@ -649,7 +592,7 @@ void p3disc::askInfoToAllPeers(std::string about)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void p3disc::recvPeerDetails(RsDiscReply *item)
|
void p3disc::recvPeerDetails(RsDiscReply *item, const std::string &certGpgId)
|
||||||
{
|
{
|
||||||
// discovery is only disabled for sending, not for receiving.
|
// discovery is only disabled for sending, not for receiving.
|
||||||
// // if off discard item.
|
// // if off discard item.
|
||||||
@ -661,8 +604,8 @@ void p3disc::recvPeerDetails(RsDiscReply *item)
|
|||||||
#ifdef P3DISC_DEBUG
|
#ifdef P3DISC_DEBUG
|
||||||
std::cerr << "p3disc::recvPeerFriendMsg() From: " << item->PeerId() << " About " << item->aboutId << std::endl;
|
std::cerr << "p3disc::recvPeerFriendMsg() From: " << item->PeerId() << " About " << item->aboutId << std::endl;
|
||||||
#endif
|
#endif
|
||||||
std::string certGpgId;
|
|
||||||
if (!AuthGPG::getAuthGPG()->LoadCertificateFromString(item->certGPG, certGpgId)) {
|
if (certGpgId.empty()) {
|
||||||
#ifdef P3DISC_DEBUG
|
#ifdef P3DISC_DEBUG
|
||||||
std::cerr << "p3disc::recvPeerFriendMsg() gpg cert is not good, aborting" << std::endl;
|
std::cerr << "p3disc::recvPeerFriendMsg() gpg cert is not good, aborting" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
@ -816,9 +759,11 @@ void p3disc::recvAskInfo(RsDiscAskInfo *item) {
|
|||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sendPeerDetails(item->PeerId(), item->gpg_id);
|
std::list<std::string> &idList = sendIdList[item->PeerId()];
|
||||||
|
|
||||||
return;
|
if (std::find(idList.begin(), idList.end(), item->gpg_id) == idList.end()) {
|
||||||
|
idList.push_back(item->gpg_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void p3disc::removeFriend(std::string ssl_id) {
|
void p3disc::removeFriend(std::string ssl_id) {
|
||||||
@ -831,7 +776,7 @@ void p3disc::removeFriend(std::string ssl_id) {
|
|||||||
std::cerr << "p3disc::removeFriend() gpg_id : " << gpg_id << std::endl;
|
std::cerr << "p3disc::removeFriend() gpg_id : " << gpg_id << std::endl;
|
||||||
#endif
|
#endif
|
||||||
if (gpg_id == AuthGPG::getAuthGPG()->getGPGOwnId() || rsPeers->isGPGAccepted(rsPeers->getGPGId(ssl_id))) {
|
if (gpg_id == AuthGPG::getAuthGPG()->getGPGOwnId() || rsPeers->isGPGAccepted(rsPeers->getGPGId(ssl_id))) {
|
||||||
#ifdef P3DISC_DEBUG
|
#ifdef P3DISC_DEBUG
|
||||||
std::cerr << "p3disc::removeFriend() storing the friend deletion." << ssl_id << std::endl;
|
std::cerr << "p3disc::removeFriend() storing the friend deletion." << ssl_id << std::endl;
|
||||||
#endif
|
#endif
|
||||||
deletedSSLFriendsIds[ssl_id] = time(NULL);//just keep track of the deleted time
|
deletedSSLFriendsIds[ssl_id] = time(NULL);//just keep track of the deleted time
|
||||||
@ -839,6 +784,113 @@ void p3disc::removeFriend(std::string ssl_id) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*************************************************************************************/
|
||||||
|
/* AuthGPGService */
|
||||||
|
/*************************************************************************************/
|
||||||
|
AuthGPGOperation *p3disc::getGPGOperation()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
|
/* process disc reply in list */
|
||||||
|
if (pendingDiscReplyInList.empty() == false) {
|
||||||
|
RsDiscReply *item = pendingDiscReplyInList.front();
|
||||||
|
|
||||||
|
return new AuthGPGOperationLoadOrSave(true, item->certGPG, item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* process disc reply out list */
|
||||||
|
|
||||||
|
std::string destId;
|
||||||
|
std::string srcId;
|
||||||
|
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
|
while (!sendIdList.empty()) {
|
||||||
|
std::map<std::string, std::list<std::string> >::iterator sendIdIt = sendIdList.begin();
|
||||||
|
|
||||||
|
if (!sendIdIt->second.empty() && mConnMgr->isOnline(sendIdIt->first)) {
|
||||||
|
std::string gpgId = sendIdIt->second.front();
|
||||||
|
sendIdIt->second.pop_front();
|
||||||
|
|
||||||
|
destId = sendIdIt->first;
|
||||||
|
srcId = gpgId;
|
||||||
|
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
/* peer is not online anymore ... try next */
|
||||||
|
sendIdList.erase(sendIdIt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!destId.empty() && !srcId.empty()) {
|
||||||
|
RsDiscReply *item = createDiscReply(destId, srcId);
|
||||||
|
if (item) {
|
||||||
|
return new AuthGPGOperationLoadOrSave(false, item->aboutId, item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void p3disc::setGPGOperation(AuthGPGOperation *operation)
|
||||||
|
{
|
||||||
|
AuthGPGOperationLoadOrSave *loadOrSave = dynamic_cast<AuthGPGOperationLoadOrSave*>(operation);
|
||||||
|
if (loadOrSave) {
|
||||||
|
if (loadOrSave->m_load) {
|
||||||
|
/* search in pending in list */
|
||||||
|
RsDiscReply *item = NULL;
|
||||||
|
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
|
std::list<RsDiscReply*>::iterator it = std::find(pendingDiscReplyInList.begin(), pendingDiscReplyInList.end(), loadOrSave->m_userdata);
|
||||||
|
if (it != pendingDiscReplyInList.end()) {
|
||||||
|
item = *it;
|
||||||
|
pendingDiscReplyInList.erase(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item) {
|
||||||
|
recvPeerDetails(item, loadOrSave->m_certGpgId);
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
RsDiscReply *item = (RsDiscReply*) loadOrSave->m_userdata;
|
||||||
|
|
||||||
|
if (item) {
|
||||||
|
if (loadOrSave->m_certGpg.empty()) {
|
||||||
|
#ifdef P3DISC_DEBUG
|
||||||
|
std::cerr << "p3disc::setGPGOperation() don't send details because the gpg cert is not good" << std::endl;
|
||||||
|
#endif
|
||||||
|
delete item;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send off message
|
||||||
|
item->certGPG = loadOrSave->m_certGpg;
|
||||||
|
|
||||||
|
#ifdef P3DISC_DEBUG
|
||||||
|
std::cerr << "p3disc::setGPGOperation() About to Send Message:" << std::endl;
|
||||||
|
item->print(std::cerr, 5);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
sendItem(item);
|
||||||
|
|
||||||
|
#ifdef P3DISC_DEBUG
|
||||||
|
std::cerr << "p3disc::cbkGPGOperationSave() discovery reply sent." << std::endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ignore other operations */
|
||||||
|
}
|
||||||
|
|
||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
/* Storing Network Graph */
|
/* Storing Network Graph */
|
||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
|
@ -42,6 +42,7 @@ class p3ConnectMgr;
|
|||||||
#include "pqi/pqimonitor.h"
|
#include "pqi/pqimonitor.h"
|
||||||
#include "serialiser/rsdiscitems.h"
|
#include "serialiser/rsdiscitems.h"
|
||||||
#include "services/p3service.h"
|
#include "services/p3service.h"
|
||||||
|
#include "pqi/authgpg.h"
|
||||||
|
|
||||||
class autoserver
|
class autoserver
|
||||||
{
|
{
|
||||||
@ -74,7 +75,7 @@ class autoneighbour: public autoserver
|
|||||||
class p3ConnectMgr;
|
class p3ConnectMgr;
|
||||||
|
|
||||||
|
|
||||||
class p3disc: public p3Service, public pqiMonitor, public p3Config
|
class p3disc: public p3Service, public pqiMonitor, public p3Config, public AuthGPGService
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -91,6 +92,10 @@ int tick();
|
|||||||
bool potentialproxies(std::string id, std::list<std::string> &proxyIds);
|
bool potentialproxies(std::string id, std::list<std::string> &proxyIds);
|
||||||
void getversions(std::map<std::string, std::string> &versions);
|
void getversions(std::map<std::string, std::string> &versions);
|
||||||
|
|
||||||
|
/************* from AuthGPService ****************/
|
||||||
|
virtual AuthGPGOperation *getGPGOperation();
|
||||||
|
virtual void setGPGOperation(AuthGPGOperation *operation);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/*****************************************************************/
|
/*****************************************************************/
|
||||||
/*********************** p3config ******************************/
|
/*********************** p3config ******************************/
|
||||||
@ -103,13 +108,13 @@ virtual bool loadList(std::list<RsItem *> load);
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
||||||
void sendAllInfoToJustConnectedPeer(std::string id);
|
void sendAllInfoToJustConnectedPeer(const std::string &id);
|
||||||
void sendJustConnectedPeerInfoToAllPeer(std::string id);
|
void sendJustConnectedPeerInfoToAllPeer(const std::string &id);
|
||||||
|
|
||||||
/* Network Output */
|
/* Network Output */
|
||||||
//void sendOwnDetails(std::string to);
|
//void sendOwnDetails(std::string to);
|
||||||
void sendOwnVersion(std::string to);
|
void sendOwnVersion(std::string to);
|
||||||
void sendPeerDetails(std::string to, std::string about);
|
RsDiscReply *createDiscReply(const std::string &to, const std::string &about);
|
||||||
//void sendPeerIssuer(std::string to, std::string about);
|
//void sendPeerIssuer(std::string to, std::string about);
|
||||||
void sendHeartbeat(std::string to);
|
void sendHeartbeat(std::string to);
|
||||||
void askInfoToAllPeers(std::string about);
|
void askInfoToAllPeers(std::string about);
|
||||||
@ -117,7 +122,7 @@ void askInfoToAllPeers(std::string about);
|
|||||||
/* Network Input */
|
/* Network Input */
|
||||||
int handleIncoming();
|
int handleIncoming();
|
||||||
void recvAskInfo(RsDiscAskInfo *item);
|
void recvAskInfo(RsDiscAskInfo *item);
|
||||||
void recvPeerDetails(RsDiscReply *item);
|
void recvPeerDetails(RsDiscReply *item, const std::string &certGpgId);
|
||||||
//void recvPeerIssuerMsg(RsDiscIssuer *item);
|
//void recvPeerIssuerMsg(RsDiscIssuer *item);
|
||||||
void recvPeerVersionMsg(RsDiscVersion *item);
|
void recvPeerVersionMsg(RsDiscVersion *item);
|
||||||
void recvHeartbeatMsg(RsDiscHeartbeat *item);
|
void recvHeartbeatMsg(RsDiscHeartbeat *item);
|
||||||
@ -131,7 +136,6 @@ int addDiscoveryData(std::string fromId, std::string aboutId,
|
|||||||
|
|
||||||
int idServers();
|
int idServers();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
p3ConnectMgr *mConnMgr;
|
p3ConnectMgr *mConnMgr;
|
||||||
@ -147,7 +151,7 @@ int idServers();
|
|||||||
std::map<std::string, std::string> versions;
|
std::map<std::string, std::string> versions;
|
||||||
|
|
||||||
std::map<std::string, std::list<std::string> > sendIdList;
|
std::map<std::string, std::list<std::string> > sendIdList;
|
||||||
std::list<RsDiscReply*> discReplyList;
|
std::list<RsDiscReply*> pendingDiscReplyInList;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user