mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-23 08:11:24 -04:00
More changes to support front end of group update
- still need to make sync changes git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs_finale@6741 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
33eb99d812
commit
3799910188
7 changed files with 131 additions and 18 deletions
|
@ -663,7 +663,7 @@ int RsDataService::updateGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
|
||||||
if(!validSize(grpPtr)) continue;
|
if(!validSize(grpPtr)) continue;
|
||||||
|
|
||||||
std::string grpFile = mServiceDir + "/" + grpPtr->grpId;
|
std::string grpFile = mServiceDir + "/" + grpPtr->grpId;
|
||||||
std::fstream ostrm(grpFile.c_str(), std::ios::binary | std::ios::app | std::ios::out);
|
std::fstream ostrm(grpFile.c_str(), std::ios::binary | std::ios::app | std::ios::trunc);
|
||||||
ostrm.seekg(0, std::ios::end); // go to end to append
|
ostrm.seekg(0, std::ios::end); // go to end to append
|
||||||
uint32_t offset = ostrm.tellg(); // get fill offset
|
uint32_t offset = ostrm.tellg(); // get fill offset
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,7 @@ public:
|
||||||
* @param grpIds all grpids in store is inserted into this vector
|
* @param grpIds all grpids in store is inserted into this vector
|
||||||
* @return error code
|
* @return error code
|
||||||
*/
|
*/
|
||||||
int RsDataService::retrieveGroupIds(std::vector<std::string> &grpIds);
|
int retrieveGroupIds(std::vector<std::string> &grpIds);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @return the cache size set for this RsGeneralDataService in bytes
|
* @return the cache size set for this RsGeneralDataService in bytes
|
||||||
|
|
|
@ -167,14 +167,14 @@ public:
|
||||||
* @param grpIds ids of groups to be removed
|
* @param grpIds ids of groups to be removed
|
||||||
* @return error code
|
* @return error code
|
||||||
*/
|
*/
|
||||||
virtual int removeGroups(std::vector<RsGxsGroupId>& grpIds) = 0;
|
virtual int removeGroups(const std::vector<RsGxsGroupId>& grpIds) = 0;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Retrieves all group ids in store
|
* Retrieves all group ids in store
|
||||||
* @param grpIds all grpids in store is inserted into this vector
|
* @param grpIds all grpids in store is inserted into this vector
|
||||||
* @return error code
|
* @return error code
|
||||||
*/
|
*/
|
||||||
virtual int retrieveGroupIds(const std::vector<RsGxsGroupId>& grpIds) = 0;
|
virtual int retrieveGroupIds(std::vector<RsGxsGroupId>& grpIds) = 0;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @return the cache size set for this RsGeneralDataService in bytes
|
* @return the cache size set for this RsGeneralDataService in bytes
|
||||||
|
@ -186,13 +186,6 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual int setCacheSize(uint32_t size) = 0;
|
virtual int setCacheSize(uint32_t size) = 0;
|
||||||
|
|
||||||
/*!
|
|
||||||
* Stores a list of signed messages into data store
|
|
||||||
* @param msg map of message and decoded meta data information
|
|
||||||
* @return error code
|
|
||||||
*/
|
|
||||||
virtual int storeMessage(std::map<RsNxsMsg*, RsGxsMsgMetaData*>& msgs) = 0;
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Stores a list of signed messages into data store
|
* Stores a list of signed messages into data store
|
||||||
* @param msg map of message and decoded meta data information
|
* @param msg map of message and decoded meta data information
|
||||||
|
|
|
@ -1369,6 +1369,20 @@ void RsGenExchange::publishGroup(uint32_t& token, RsGxsGrpItem *grpItem)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void RsGenExchange::updateGroup(uint32_t& token, RsGxsGrpItem* grpItem)
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mGenMtx);
|
||||||
|
token = mDataAccess->generatePublicToken();
|
||||||
|
mGroupUpdatePublish.push_back(GroupUpdatePublish(grpItem, token));
|
||||||
|
|
||||||
|
#ifdef GEN_EXCH_DEBUG
|
||||||
|
std::cerr << "RsGenExchange::updateGroup() token: " << token;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void RsGenExchange::publishMsg(uint32_t& token, RsGxsMsgItem *msgItem)
|
void RsGenExchange::publishMsg(uint32_t& token, RsGxsMsgItem *msgItem)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mGenMtx);
|
RsStackMutex stack(mGenMtx);
|
||||||
|
@ -1785,6 +1799,76 @@ RsGenExchange::ServiceCreate_Return RsGenExchange::service_CreateGroup(RsGxsGrpI
|
||||||
|
|
||||||
#define PENDING_SIGN_TIMEOUT 10 // 5 seconds
|
#define PENDING_SIGN_TIMEOUT 10 // 5 seconds
|
||||||
|
|
||||||
|
|
||||||
|
void RsGenExchange::processGroupUpdatePublish()
|
||||||
|
{
|
||||||
|
|
||||||
|
RsStackMutex stack(mGenMtx);
|
||||||
|
|
||||||
|
// get keys for group update publish
|
||||||
|
|
||||||
|
// first build meta request map for groups to be updated
|
||||||
|
std::map<std::string, RsGxsGrpMetaData*> grpMeta;
|
||||||
|
std::vector<GroupUpdatePublish>::iterator vit = mGroupUpdatePublish.begin();
|
||||||
|
|
||||||
|
for(; vit != mGroupUpdatePublish.end(); vit++)
|
||||||
|
{
|
||||||
|
GroupUpdatePublish& gup = *vit;
|
||||||
|
const RsGxsGroupId& groupId = gup.grpItem->meta.mGroupId;
|
||||||
|
grpMeta.insert(std::make_pair(groupId, (RsGxsGrpMetaData*)(NULL)));
|
||||||
|
}
|
||||||
|
|
||||||
|
mDataStore->retrieveGxsGrpMetaData(grpMeta);
|
||||||
|
|
||||||
|
// now
|
||||||
|
vit = mGroupUpdatePublish.begin();
|
||||||
|
for(; vit != mGroupUpdatePublish.end(); vit++)
|
||||||
|
{
|
||||||
|
GroupUpdatePublish& gup = *vit;
|
||||||
|
const RsGxsGroupId& groupId = gup.grpItem->meta.mGroupId;
|
||||||
|
RsGxsGrpMetaData* meta = grpMeta[groupId];
|
||||||
|
|
||||||
|
GxsGrpPendingSign ggps(ggps.mItem, ggps.mToken);
|
||||||
|
|
||||||
|
bool split = splitKeys(meta->keys, ggps.mPrivateKeys, ggps.mPublicKeys);
|
||||||
|
|
||||||
|
if(split)
|
||||||
|
{
|
||||||
|
ggps.mHaveKeys = true;
|
||||||
|
ggps.mStartTS = time(NULL);
|
||||||
|
ggps.mLastAttemptTS = 0;
|
||||||
|
mGrpsToPublish.push_back(ggps);
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
delete gup.grpItem;
|
||||||
|
mDataAccess->updatePublicRequestStatus(gup.mToken, RsTokenService::GXS_REQUEST_V2_STATUS_FAILED);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
mGroupUpdatePublish.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RsGenExchange::splitKeys(const RsTlvSecurityKeySet& keySet, RsTlvSecurityKeySet& privateKeySet, RsTlvSecurityKeySet& publicKeySet)
|
||||||
|
{
|
||||||
|
|
||||||
|
typedef std::map<std::string, RsTlvSecurityKey> keyMap;
|
||||||
|
const keyMap& allKeys = keySet.keys;
|
||||||
|
keyMap::const_iterator cit = allKeys.begin();
|
||||||
|
|
||||||
|
for(; cit != allKeys.end(); cit++)
|
||||||
|
{
|
||||||
|
const RsTlvSecurityKey& key = cit->second;
|
||||||
|
if(key.keyFlags & RSTLV_KEY_TYPE_PUBLIC_ONLY)
|
||||||
|
publicKeySet.keys.insert(std::make_pair(key.keyId, key));
|
||||||
|
else if(key.keyFlags & RSTLV_KEY_TYPE_FULL)
|
||||||
|
privateKeySet.keys.insert(std::make_pair(key.keyId, key));
|
||||||
|
}
|
||||||
|
|
||||||
|
// user must have both private and public parts of publish and admin keys
|
||||||
|
return (privateKeySet.keys.size() == 2) && (publicKeySet.keys.size() == 2);
|
||||||
|
}
|
||||||
|
|
||||||
void RsGenExchange::publishGrps()
|
void RsGenExchange::publishGrps()
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mGenMtx);
|
RsStackMutex stack(mGenMtx);
|
||||||
|
@ -1906,6 +1990,10 @@ void RsGenExchange::publishGrps()
|
||||||
{
|
{
|
||||||
grpId = grp->grpId;
|
grpId = grp->grpId;
|
||||||
computeHash(grp->grp, grp->metaData->mHash);
|
computeHash(grp->grp, grp->metaData->mHash);
|
||||||
|
|
||||||
|
if(ggps.mIsUpdate)
|
||||||
|
mDataAccess->updateGroupData(grp);
|
||||||
|
else
|
||||||
mDataAccess->addGroupData(grp);
|
mDataAccess->addGroupData(grp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -2195,7 +2283,8 @@ void RsGenExchange::processRecvdGroups()
|
||||||
RsStackMutex stack(mGenMtx);
|
RsStackMutex stack(mGenMtx);
|
||||||
|
|
||||||
NxsGrpPendValidVect::iterator vit = mReceivedGrps.begin();
|
NxsGrpPendValidVect::iterator vit = mReceivedGrps.begin();
|
||||||
std::vector<std::string> existingGrpIds, grpIds;
|
std::vector<std::string> existingGrpIds;
|
||||||
|
std::list<std::string> grpIds;
|
||||||
|
|
||||||
std::map<RsNxsGrp*, RsGxsGrpMetaData*> grps;
|
std::map<RsNxsGrp*, RsGxsGrpMetaData*> grps;
|
||||||
|
|
||||||
|
|
|
@ -71,13 +71,14 @@ class GxsGrpPendingSign
|
||||||
public:
|
public:
|
||||||
|
|
||||||
GxsGrpPendingSign(RsGxsGrpItem* item, uint32_t token): mLastAttemptTS(0), mStartTS(time(NULL)), mToken(token),
|
GxsGrpPendingSign(RsGxsGrpItem* item, uint32_t token): mLastAttemptTS(0), mStartTS(time(NULL)), mToken(token),
|
||||||
mItem(item), mHaveKeys(false)
|
mItem(item), mHaveKeys(false), mIsUpdate(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
time_t mLastAttemptTS, mStartTS;
|
time_t mLastAttemptTS, mStartTS;
|
||||||
uint32_t mToken;
|
uint32_t mToken;
|
||||||
RsGxsGrpItem* mItem;
|
RsGxsGrpItem* mItem;
|
||||||
bool mHaveKeys; // mKeys->first == true if key present
|
bool mHaveKeys; // mKeys->first == true if key present
|
||||||
|
bool mIsUpdate;
|
||||||
RsTlvSecurityKeySet mPrivateKeys;
|
RsTlvSecurityKeySet mPrivateKeys;
|
||||||
RsTlvSecurityKeySet mPublicKeys;
|
RsTlvSecurityKeySet mPublicKeys;
|
||||||
};
|
};
|
||||||
|
@ -516,7 +517,6 @@ protected:
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Enables publication of a group item \n
|
* Enables publication of a group item \n
|
||||||
* If the item exists already this is simply versioned \n
|
|
||||||
* This will induce a related change message \n
|
* This will induce a related change message \n
|
||||||
* Ownership of item passes to this rsgenexchange \n
|
* Ownership of item passes to this rsgenexchange \n
|
||||||
* @param token
|
* @param token
|
||||||
|
@ -524,6 +524,16 @@ protected:
|
||||||
*/
|
*/
|
||||||
void publishGroup(uint32_t& token, RsGxsGrpItem* grpItem);
|
void publishGroup(uint32_t& token, RsGxsGrpItem* grpItem);
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Updates an existing group item \n
|
||||||
|
* This will induce a related change message \n
|
||||||
|
* Ownership of item passes to this rsgenexchange \n
|
||||||
|
* @param token
|
||||||
|
* @param grpItem
|
||||||
|
*/
|
||||||
|
void updateGroup(uint32_t& token, RsGxsGrpItem* grpItem);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/*!
|
/*!
|
||||||
* Enables publication of a message item \n
|
* Enables publication of a message item \n
|
||||||
|
@ -629,6 +639,8 @@ private:
|
||||||
|
|
||||||
void publishGrps();
|
void publishGrps();
|
||||||
|
|
||||||
|
void processGroupUpdatePublish();
|
||||||
|
|
||||||
void publishMsgs();
|
void publishMsgs();
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -750,6 +762,8 @@ private:
|
||||||
*/
|
*/
|
||||||
bool updateValid(RsGxsGrpMetaData& oldGrp, RsNxsGrp& newGrp) const;
|
bool updateValid(RsGxsGrpMetaData& oldGrp, RsNxsGrp& newGrp) const;
|
||||||
|
|
||||||
|
bool splitKeys(const RsTlvSecurityKeySet& keySet, RsTlvSecurityKeySet& privateKeySet, RsTlvSecurityKeySet& publicKeySet);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
RsMutex mGenMtx;
|
RsMutex mGenMtx;
|
||||||
|
@ -815,7 +829,10 @@ private:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::vector<GroupUpdate> mGroupUpdates;
|
std::vector<GroupUpdate> mGroupUpdates, mPeersGroupUpdate;
|
||||||
|
|
||||||
|
std::vector<GroupUpdatePublish> mGroupUpdatePublish;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RSGENEXCHANGE_H
|
#endif // RSGENEXCHANGE_H
|
||||||
|
|
|
@ -1487,7 +1487,14 @@ bool RsGxsDataAccess::addGroupData(RsNxsGrp* grp) {
|
||||||
return mDataStore->storeGroup(grpM);
|
return mDataStore->storeGroup(grpM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RsGxsDataAccess::updateGroupData(RsNxsGrp* grp) {
|
||||||
|
|
||||||
|
RsStackMutex stack(mDataMutex);
|
||||||
|
|
||||||
|
std::map<RsNxsGrp*, RsGxsGrpMetaData*> grpM;
|
||||||
|
grpM.insert(std::make_pair(grp, grp->metaData));
|
||||||
|
return mDataStore->updateGroup(grpM);
|
||||||
|
}
|
||||||
|
|
||||||
bool RsGxsDataAccess::addMsgData(RsNxsMsg* msg) {
|
bool RsGxsDataAccess::addMsgData(RsNxsMsg* msg) {
|
||||||
|
|
||||||
|
|
|
@ -126,14 +126,21 @@ public:
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* This adds a groups to the gxs data base, this is a blocking call
|
* This adds a groups to the gxs data base, this is a blocking call \n
|
||||||
* Responsibility for grp still lies with callee \n
|
|
||||||
* If function returns successfully DataAccess can be queried for grp
|
* If function returns successfully DataAccess can be queried for grp
|
||||||
* @param grp the group to add, responsibility grp passed lies with callee
|
* @param grp the group to add, responsibility grp passed lies with callee
|
||||||
* @return false if group cound not be added
|
* @return false if group cound not be added
|
||||||
*/
|
*/
|
||||||
bool addGroupData(RsNxsGrp* grp);
|
bool addGroupData(RsNxsGrp* grp);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* This updates a groups in the gxs data base, this is a blocking call \n
|
||||||
|
* If function returns successfully DataAccess can be queried for grp
|
||||||
|
* @param grp the group to add, responsibility grp passed lies with callee
|
||||||
|
* @return false if group cound not be added
|
||||||
|
*/
|
||||||
|
bool updateGroupData(RsNxsGrp* grp);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* This adds a group to the gxs data base, this is a blocking call \n
|
* This adds a group to the gxs data base, this is a blocking call \n
|
||||||
* Responsibility for msg still lies with callee \n
|
* Responsibility for msg still lies with callee \n
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue