mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
enhanced key sharing;
shared key now saved if not subscribed and rs is shutdown also 'blue font' update sent once shared key received git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3972 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
2f3287b898
commit
920ebe3a5a
@ -123,9 +123,12 @@ int p3GroupDistrib::tick()
|
|||||||
mGroupsRepublish = false;
|
mGroupsRepublish = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool attemptRecv = false;
|
||||||
|
|
||||||
{
|
{
|
||||||
RsStackMutex stack(distribMtx);
|
RsStackMutex stack(distribMtx);
|
||||||
toPublish = (mPendingPubKeyRecipients.size() > 0) && (now > (time_t) (mPubPeriod + mLastKeyPublishTime));
|
toPublish = (mPendingPubKeyRecipients.size() > 0) && (now > (time_t) (mPubPeriod + mLastKeyPublishTime));
|
||||||
|
attemptRecv = (mRecvdPubKeys.size() > 0) && (now > (time_t) (mPubPeriod + mLastKeyPublishTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(toPublish){
|
if(toPublish){
|
||||||
@ -133,6 +136,12 @@ int p3GroupDistrib::tick()
|
|||||||
locked_sharePubKey();
|
locked_sharePubKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(attemptRecv)
|
||||||
|
{
|
||||||
|
attemptPublishKeysRecvd();
|
||||||
|
}
|
||||||
|
|
||||||
bool toReceive = receivedItems();
|
bool toReceive = receivedItems();
|
||||||
|
|
||||||
if(toReceive){
|
if(toReceive){
|
||||||
@ -485,7 +494,7 @@ void p3GroupDistrib::loadGroup(RsDistribGrp *newGrp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void p3GroupDistrib::loadGroupKey(RsDistribGrpKey *newKey)
|
bool p3GroupDistrib::loadGroupKey(RsDistribGrpKey *newKey)
|
||||||
{
|
{
|
||||||
/* load Key */
|
/* load Key */
|
||||||
const std::string &gid = newKey -> grpId;
|
const std::string &gid = newKey -> grpId;
|
||||||
@ -521,13 +530,14 @@ void p3GroupDistrib::loadGroupKey(RsDistribGrpKey *newKey)
|
|||||||
// make sure key does not exist
|
// make sure key does not exist
|
||||||
if(mRecvdPubKeys.find(gid) == mRecvdPubKeys.end()){
|
if(mRecvdPubKeys.find(gid) == mRecvdPubKeys.end()){
|
||||||
mRecvdPubKeys.insert(std::pair<std::string, RsDistribGrpKey*>(gid, newKey));
|
mRecvdPubKeys.insert(std::pair<std::string, RsDistribGrpKey*>(gid, newKey));
|
||||||
mPubKeyAvailableGrpId.push_back(gid);
|
return true;
|
||||||
}else{
|
}else{
|
||||||
#ifdef DISTRIB_DEBUG
|
#ifdef DISTRIB_DEBUG
|
||||||
std::cerr << "p3GroupDistrib::loadGroupKey() Key already received; discarding";
|
std::cerr << "p3GroupDistrib::loadGroupKey() Key already received; discarding";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
delete newKey;
|
delete newKey;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -536,11 +546,13 @@ void p3GroupDistrib::loadGroupKey(RsDistribGrpKey *newKey)
|
|||||||
std::cerr << "p3GroupDistrib::loadGroupKey() Key out of date: discarding";
|
std::cerr << "p3GroupDistrib::loadGroupKey() Key out of date: discarding";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
delete newKey;
|
delete newKey;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -572,59 +584,28 @@ void p3GroupDistrib::loadGroupKey(RsDistribGrpKey *newKey)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
updateOk = true;
|
updateOk = true;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::string, RsDistribGrpKey* >::iterator kit;
|
|
||||||
std::list<std::string>::iterator sit;
|
|
||||||
bool canAdd = false;
|
|
||||||
|
|
||||||
// check to see if client has received a private publish key
|
|
||||||
if(mRecvdPubKeys.end() != (kit = mRecvdPubKeys.find(gid))){
|
|
||||||
|
|
||||||
if(!locked_updateGroupPublishKey(it->second, kit->second)){
|
|
||||||
#ifdef DISTRIB_DEBUG
|
|
||||||
std::cerr << "p3GroupDistrib::loadGroupKey() Failed Recvd Publish Key Update";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
}else{
|
|
||||||
#ifdef DISTRIB_DEBUG
|
|
||||||
std::cerr << "p3GroupDistrib::loadGroupKey() Recvd Publish Key Update";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
sit = mPubKeyAvailableGrpId.begin();
|
|
||||||
for(; sit != mPubKeyAvailableGrpId.end(); sit++){
|
|
||||||
|
|
||||||
if(gid == *sit)
|
|
||||||
canAdd = true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(canAdd)
|
|
||||||
mPubKeyAvailableGrpId.push_back(gid);
|
|
||||||
|
|
||||||
mRecvdPubKeys.erase(gid);
|
|
||||||
updateOk = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (updateOk)
|
|
||||||
{
|
|
||||||
locked_notifyGroupChanged(it->second, GRP_LOAD_KEY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DISTRIB_DEBUG
|
#ifdef DISTRIB_DEBUG
|
||||||
std::cerr << "p3GroupDistrib::loadGroupKey() Done - Cleaning up.";
|
std::cerr << "p3GroupDistrib::loadGroupKey() Done - Cleaning up.";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
delete newKey;
|
|
||||||
|
|
||||||
return;
|
GroupInfo *gi = locked_getGroupInfo(gid);
|
||||||
|
|
||||||
|
// special case, if user is not subscribed then save key
|
||||||
|
if(!(gi->flags & RS_DISTRIB_SUBSCRIBED) && updateOk){
|
||||||
|
|
||||||
|
mRecvdPubKeys.insert(std::pair<std::string, RsDistribGrpKey*>(gid, newKey));
|
||||||
|
return updateOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete newKey;
|
||||||
|
return updateOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1325,19 +1306,15 @@ bool p3GroupDistrib::subscribeToGroup(const std::string &grpId, bool subscrib
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool p3GroupDistrib::attemptPublishKeysRecvd(GroupInfo& info)
|
bool p3GroupDistrib::attemptPublishKeysRecvd()
|
||||||
{
|
{
|
||||||
|
|
||||||
std::map<std::string, RsDistribGrpKey*>::iterator mit;
|
std::map<std::string, RsDistribGrpKey*>::iterator mit;
|
||||||
mit = mRecvdPubKeys.find(info.grpId);
|
mit = mRecvdPubKeys.begin();
|
||||||
|
|
||||||
if(mit == mRecvdPubKeys.end())
|
for(; mit != mRecvdPubKeys.end(); mit++){
|
||||||
return false;
|
loadGroupKey(mit->second);
|
||||||
|
}
|
||||||
if(locked_updateGroupPublishKey(info, mit->second))
|
|
||||||
mRecvdPubKeys.erase(mit);
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -2121,6 +2098,8 @@ void p3GroupDistrib::receivePubKeys(){
|
|||||||
|
|
||||||
|
|
||||||
RsItem* item;
|
RsItem* item;
|
||||||
|
GroupInfo *gi = NULL;
|
||||||
|
std::string gid;
|
||||||
|
|
||||||
while(NULL != (item = recvItem())){
|
while(NULL != (item = recvItem())){
|
||||||
|
|
||||||
@ -2137,81 +2116,45 @@ void p3GroupDistrib::receivePubKeys(){
|
|||||||
#endif
|
#endif
|
||||||
if(key_item->key.keyFlags & RSTLV_KEY_TYPE_FULL){
|
if(key_item->key.keyFlags & RSTLV_KEY_TYPE_FULL){
|
||||||
|
|
||||||
loadGroupKey(key_item);
|
gid = key_item->grpId;
|
||||||
|
if(loadGroupKey(key_item)){
|
||||||
|
|
||||||
|
if(NULL != (gi = locked_getGroupInfo(gid))){
|
||||||
|
locked_notifyGroupChanged(*gi, GRP_LOAD_KEY);
|
||||||
|
gi = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
mPubKeyAvailableGrpId.insert(gid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
std::cerr << "p3GroupDistrib::locked_receiveKeys():" << "Not full public key"
|
std::cerr << "p3GroupDistrib::locked_receiveKeys():" << "Not full public key"
|
||||||
<< "Deleting item"<< std::endl;
|
<< "Deleting item"<< std::endl;
|
||||||
delete key_item;
|
delete key_item;
|
||||||
}
|
}
|
||||||
}else{
|
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
|
||||||
delete item;
|
delete item;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
RsStackMutex stack(distribMtx);
|
RsStackMutex stack(distribMtx);
|
||||||
|
|
||||||
// indicate config changed and also record the groups keys received for
|
// indicate config changed and also record the groups keys received for
|
||||||
if(!mRecvdPubKeys.empty())
|
if(!mRecvdPubKeys.empty())
|
||||||
IndicateConfigChanged();
|
IndicateConfigChanged();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
void p3GroupDistrib::locked_loadRecvdPubKeys(){
|
|
||||||
|
|
||||||
std::map<std::string, RsDistribGrpKey* >::iterator mit;
|
|
||||||
std::list<std::string>::iterator lit;
|
|
||||||
GroupInfo *gi;
|
|
||||||
bool cont = false;
|
|
||||||
|
|
||||||
#ifdef DISTRIB_DEBUG
|
|
||||||
std::cerr << "p3GroupDistrib::locked_loadRecvdPubKeys() " << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// look for keys to add to private publish key received notify list
|
|
||||||
for(mit = mRecvdPubKeys.begin(); mit != mRecvdPubKeys.end(); mit++ ){
|
|
||||||
|
|
||||||
gi = locked_getGroupInfo(mit->second->grpId);
|
|
||||||
|
|
||||||
if(gi != NULL){
|
|
||||||
|
|
||||||
/* ensure grpId not added already */
|
|
||||||
for(lit=mPubKeyAvailableGrpId.begin(); lit != mPubKeyAvailableGrpId.end(); lit++){
|
|
||||||
|
|
||||||
if(mit->second->grpId == *lit){
|
|
||||||
cont = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(cont)
|
|
||||||
{
|
|
||||||
cont = false;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
mPubKeyAvailableGrpId.push_back(mit->second->grpId);
|
|
||||||
locked_notifyGroupChanged(*gi, GRP_UPDATE);
|
|
||||||
|
|
||||||
}else{
|
|
||||||
|
|
||||||
std::cerr << "p3GroupDistrib::locked_loadRecvdPubKeys(): group does not exist" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mLastRecvdKeyTime = time(NULL);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string p3GroupDistrib::publishMsg(RsDistribMsg *msg, bool personalSign)
|
std::string p3GroupDistrib::publishMsg(RsDistribMsg *msg, bool personalSign)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -3230,7 +3173,10 @@ RsDistribMsg *p3GroupDistrib::unpackDistribSignedMsg(RsDistribSignedMsg *newMsg)
|
|||||||
void p3GroupDistrib::getGrpListPubKeyAvailable(std::list<std::string>& grpList)
|
void p3GroupDistrib::getGrpListPubKeyAvailable(std::list<std::string>& grpList)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(distribMtx);
|
RsStackMutex stack(distribMtx);
|
||||||
grpList = mPubKeyAvailableGrpId;
|
std::set<std::string>::const_iterator cit = mPubKeyAvailableGrpId.begin();
|
||||||
|
|
||||||
|
for(; cit != mPubKeyAvailableGrpId.end(); cit++)
|
||||||
|
grpList.push_back(*cit);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,8 @@
|
|||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
#include <openssl/evp.h>
|
#include <openssl/evp.h>
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Group Messages....
|
* Group Messages....
|
||||||
*
|
*
|
||||||
@ -281,7 +283,7 @@ class p3GroupDistrib: public CacheSource, public CacheStore, public p3Config, pu
|
|||||||
* Attempt to load public key from recvd list if it exists for grpId
|
* Attempt to load public key from recvd list if it exists for grpId
|
||||||
* @param grpId the id for the group for which private publish key is wanted
|
* @param grpId the id for the group for which private publish key is wanted
|
||||||
*/
|
*/
|
||||||
bool attemptPublishKeysRecvd(GroupInfo& info);
|
bool attemptPublishKeysRecvd();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@ -304,9 +306,11 @@ class p3GroupDistrib: public CacheSource, public CacheStore, public p3Config, pu
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Adds new keys dependent on whether it is an admin or publish key
|
* Adds new keys dependent on whether it is an admin or publish key
|
||||||
|
* on return resource pointed to by newKey should be considered invalid
|
||||||
* @param newKey key to be added
|
* @param newKey key to be added
|
||||||
|
* @return if key is loaded to group or stored return true
|
||||||
*/
|
*/
|
||||||
void loadGroupKey(RsDistribGrpKey *newKey);
|
bool loadGroupKey(RsDistribGrpKey *newKey);
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************************/
|
/***************************************************************************************/
|
||||||
@ -509,13 +513,6 @@ class p3GroupDistrib: public CacheSource, public CacheStore, public p3Config, pu
|
|||||||
*/
|
*/
|
||||||
virtual void receivePubKeys();
|
virtual void receivePubKeys();
|
||||||
|
|
||||||
/*!
|
|
||||||
* utility function to check whether grps exist
|
|
||||||
* for private publish keys received
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
virtual void locked_loadRecvdPubKeys();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows group admin(s) to change group icon, description and name
|
* Allows group admin(s) to change group icon, description and name
|
||||||
*@param grpId group id
|
*@param grpId group id
|
||||||
@ -684,7 +681,7 @@ class p3GroupDistrib: public CacheSource, public CacheStore, public p3Config, pu
|
|||||||
|
|
||||||
std::map<std::string, RsDistribGrpKey* > mRecvdPubKeys; /// full publishing keys received from users
|
std::map<std::string, RsDistribGrpKey* > mRecvdPubKeys; /// full publishing keys received from users
|
||||||
std::map<std::string, std::list<std::string> > mPendingPubKeyRecipients; /// peers to receive publics key for a given grp
|
std::map<std::string, std::list<std::string> > mPendingPubKeyRecipients; /// peers to receive publics key for a given grp
|
||||||
std::list<std::string> mPubKeyAvailableGrpId; // groups id for which public keys are available
|
std::set<std::string> mPubKeyAvailableGrpId; // groups id for which public keys are available
|
||||||
time_t mLastKeyPublishTime, mLastRecvdKeyTime;
|
time_t mLastKeyPublishTime, mLastRecvdKeyTime;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user