mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
implemented publish key sharing between peers for channels.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7582 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
1d6bf4190e
commit
d0469ccfc3
@ -865,6 +865,31 @@ int RsDataService::updateGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int RsDataService::updateGroupKeys(const RsGxsGroupId& grpId,const RsTlvSecurityKeySet& keys,uint32_t subscribe_flags)
|
||||
{
|
||||
RsStackMutex stack(mDbMutex);
|
||||
|
||||
// begin transaction
|
||||
mDb->execSQL("BEGIN;");
|
||||
|
||||
/*!
|
||||
* STORE key set
|
||||
**/
|
||||
|
||||
ContentValue cv;
|
||||
//cv.put(KEY_NXS_FLAGS, (int32_t)grpMetaPtr->mGroupFlags); ?
|
||||
|
||||
uint32_t offset = 0;
|
||||
char keySetData[keys.TlvSize()];
|
||||
keys.SetTlv(keySetData, keys.TlvSize(), &offset);
|
||||
cv.put(KEY_KEY_SET, keys.TlvSize(), keySetData);
|
||||
cv.put(KEY_GRP_SUBCR_FLAG, (int32_t)subscribe_flags);
|
||||
|
||||
mDb->sqlUpdate(GRP_TABLE_NAME, "grpId='" + grpId.toStdString() + "'", cv);
|
||||
|
||||
// finish transaction
|
||||
return mDb->execSQL("COMMIT;");
|
||||
}
|
||||
|
||||
bool RsDataService::validSize(RsNxsGrp* grp) const
|
||||
{
|
||||
|
@ -175,6 +175,13 @@ public:
|
||||
bool validSize(RsNxsMsg* msg) const;
|
||||
bool validSize(RsNxsGrp* grp) const;
|
||||
|
||||
/*!
|
||||
* Convenience function used to only update group keys. This is used when sending
|
||||
* publish keys between peers.
|
||||
* @return SQL error code
|
||||
*/
|
||||
|
||||
int updateGroupKeys(const RsGxsGroupId& grpId,const RsTlvSecurityKeySet& keys, uint32_t subscribe_flags) ;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -230,6 +230,7 @@ public:
|
||||
*/
|
||||
virtual int updateGroupMetaData(GrpLocMetaData& meta) = 0;
|
||||
|
||||
virtual int updateGroupKeys(const RsGxsGroupId& grpId,const RsTlvSecurityKeySet& keys,uint32_t subscribed_flags) = 0 ;
|
||||
|
||||
/*!
|
||||
* Completely clear out data stored in
|
||||
|
@ -87,6 +87,14 @@ RsGenExchange::RsGenExchange(RsGeneralDataService *gds, RsNetworkExchangeService
|
||||
|
||||
}
|
||||
|
||||
void RsGenExchange::setNetworkExchangeService(RsNetworkExchangeService *ns)
|
||||
{
|
||||
if(mNetService != NULL)
|
||||
std::cerr << "(EE) Cannot override existing network exchange service. Make sure it has been deleted otherwise." << std::endl;
|
||||
else
|
||||
mNetService = ns ;
|
||||
}
|
||||
|
||||
#ifdef TO_BE_DELETED_IF_NOT_USEFUL
|
||||
// This class has been tested so as to see where the database gets modified.
|
||||
class RsDataBaseTester
|
||||
@ -1436,6 +1444,7 @@ void RsGenExchange::notifyNewGroups(std::vector<RsNxsGrp *> &groups)
|
||||
|
||||
}
|
||||
|
||||
|
||||
void RsGenExchange::notifyNewMessages(std::vector<RsNxsMsg *>& messages)
|
||||
{
|
||||
RsStackMutex stack(mGenMtx);
|
||||
@ -2019,6 +2028,7 @@ void RsGenExchange::processGroupUpdatePublish()
|
||||
mGroupUpdatePublish.clear();
|
||||
}
|
||||
|
||||
|
||||
void RsGenExchange::processGroupDelete()
|
||||
{
|
||||
RsStackMutex stack(mGenMtx);
|
||||
@ -2349,6 +2359,14 @@ bool RsGenExchange::getGroupKeys(const RsGxsGroupId &grpId, RsTlvSecurityKeySet
|
||||
return true;
|
||||
}
|
||||
|
||||
void RsGenExchange::shareGroupPublishKey(const RsGxsGroupId& grpId,const std::list<RsPeerId>& peers)
|
||||
{
|
||||
if(grpId.isNull())
|
||||
return ;
|
||||
|
||||
mNetService->sharePublishKey(grpId,peers) ;
|
||||
}
|
||||
|
||||
void RsGenExchange::processRecvdData()
|
||||
{
|
||||
processRecvdGroups();
|
||||
@ -2356,6 +2374,7 @@ void RsGenExchange::processRecvdData()
|
||||
processRecvdMessages();
|
||||
|
||||
performUpdateValidation();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -137,6 +137,7 @@ public:
|
||||
// and passes to network service.
|
||||
virtual RsServiceInfo getServiceInfo() = 0;
|
||||
|
||||
void setNetworkExchangeService(RsNetworkExchangeService *ns) ;
|
||||
|
||||
/** S: Observer implementation **/
|
||||
|
||||
@ -632,6 +633,12 @@ public:
|
||||
*/
|
||||
void setMsgServiceString(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, const std::string& servString );
|
||||
|
||||
/*!
|
||||
* sets the message service string
|
||||
*/
|
||||
|
||||
void shareGroupPublishKey(const RsGxsGroupId& grpId,const std::list<RsPeerId>& peers) ;
|
||||
|
||||
protected:
|
||||
|
||||
/** Notifications **/
|
||||
|
@ -51,7 +51,7 @@ RsGxsNetService::RsGxsNetService(uint16_t servType, RsGeneralDataService *gds,
|
||||
: p3ThreadedService(), p3Config(), mTransactionN(0),
|
||||
mObserver(nxsObs), mDataStore(gds), mServType(servType),
|
||||
mTransactionTimeOut(TRANSAC_TIMEOUT), mNetMgr(netMgr), mNxsMutex("RsGxsNetService"),
|
||||
mSyncTs(0), mSYNC_PERIOD(SYNC_PERIOD), mCircles(circles), mReputations(reputations),
|
||||
mSyncTs(0), mLastKeyPublishTs(0), mSYNC_PERIOD(SYNC_PERIOD), mCircles(circles), mReputations(reputations),
|
||||
mPgpUtils(pgpUtils),
|
||||
mGrpAutoSync(grpAutoSync), mGrpServerUpdateItem(NULL),
|
||||
mServiceInfo(serviceInfo)
|
||||
@ -74,8 +74,8 @@ int RsGxsNetService::tick()
|
||||
if(receivedItems())
|
||||
recvNxsItemQueue();
|
||||
|
||||
uint32_t now = time(NULL);
|
||||
uint32_t elapsed = mSYNC_PERIOD + mSyncTs;
|
||||
time_t now = time(NULL);
|
||||
time_t elapsed = mSYNC_PERIOD + mSyncTs;
|
||||
|
||||
if((elapsed) < now)
|
||||
{
|
||||
@ -83,6 +83,12 @@ int RsGxsNetService::tick()
|
||||
mSyncTs = now;
|
||||
}
|
||||
|
||||
if(now > 10 + mLastKeyPublishTs)
|
||||
{
|
||||
sharePublishKeysPending() ;
|
||||
mLastKeyPublishTs = now ;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -754,6 +760,7 @@ void RsGxsNetService::recvNxsItemQueue(){
|
||||
{
|
||||
case RS_PKT_SUBTYPE_NXS_SYNC_GRP: handleRecvSyncGroup (dynamic_cast<RsNxsSyncGrp*>(ni)) ; break ;
|
||||
case RS_PKT_SUBTYPE_NXS_SYNC_MSG: handleRecvSyncMessage (dynamic_cast<RsNxsSyncMsg*>(ni)) ; break ;
|
||||
case RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY: handleRecvPublishKeys (dynamic_cast<RsNxsGroupPublishKeyItem*>(ni)) ; break ;
|
||||
default:
|
||||
std::cerr << "Unhandled item subtype " << (uint32_t) ni->PacketSubType() << " in RsGxsNetService: " << std::endl; break;
|
||||
}
|
||||
@ -2727,3 +2734,205 @@ void RsGxsNetService::processExplicitGroupRequests()
|
||||
|
||||
mExplicitRequest.clear();
|
||||
}
|
||||
|
||||
#define NXS_NET_DEBUG
|
||||
int RsGxsNetService::sharePublishKey(const RsGxsGroupId& grpId,const std::list<RsPeerId>& peers)
|
||||
{
|
||||
RsStackMutex stack(mNxsMutex);
|
||||
|
||||
mPendingPublishKeyRecipients[grpId] = peers ;
|
||||
|
||||
std::cerr << "RsGxsNetService::sharePublishKeys() " << (void*)this << " adding publish keys for grp " << grpId << " to sending list" << std::endl;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
void RsGxsNetService::sharePublishKeysPending()
|
||||
{
|
||||
RsStackMutex stack(mNxsMutex);
|
||||
|
||||
if(mPendingPublishKeyRecipients.empty())
|
||||
return ;
|
||||
|
||||
#ifdef NXS_NET_DEBUG
|
||||
std::cerr << "RsGxsNetService::sharePublishKeys() " << (void*)this << std::endl;
|
||||
#endif
|
||||
// get list of peers that are online
|
||||
|
||||
std::set<RsPeerId> peersOnline;
|
||||
std::list<RsGxsGroupId> toDelete;
|
||||
std::map<RsGxsGroupId,std::list<RsPeerId> >::iterator mit ;
|
||||
|
||||
mNetMgr->getOnlineList(mServiceInfo.mServiceType, peersOnline);
|
||||
|
||||
#ifdef NXS_NET_DEBUG
|
||||
std::cerr << " " << peersOnline.size() << " peers online." << std::endl;
|
||||
#endif
|
||||
/* send public key to peers online */
|
||||
|
||||
for(mit = mPendingPublishKeyRecipients.begin(); mit != mPendingPublishKeyRecipients.end(); ++mit)
|
||||
{
|
||||
// Compute the set of peers to send to. We start with this, to avoid retrieving the data for nothing.
|
||||
|
||||
std::list<RsPeerId> recipients ;
|
||||
std::list<RsPeerId> offline_recipients ;
|
||||
|
||||
for(std::list<RsPeerId>::const_iterator it(mit->second.begin());it!=mit->second.end();++it)
|
||||
if(peersOnline.find(*it) != peersOnline.end())
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG
|
||||
std::cerr << " " << *it << ": online. Adding." << std::endl;
|
||||
#endif
|
||||
recipients.push_back(*it) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG
|
||||
std::cerr << " " << *it << ": offline. Keeping for next try." << std::endl;
|
||||
#endif
|
||||
offline_recipients.push_back(*it) ;
|
||||
}
|
||||
|
||||
// If empty, skip
|
||||
|
||||
if(recipients.empty())
|
||||
{
|
||||
std::cerr << " No recipients online. Skipping." << std::endl;
|
||||
continue ;
|
||||
}
|
||||
|
||||
// Get the meta data for this group Id
|
||||
//
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMetaMap;
|
||||
grpMetaMap[mit->first] = NULL;
|
||||
mDataStore->retrieveGxsGrpMetaData(grpMetaMap);
|
||||
|
||||
// Find the publish keys in the retrieved info
|
||||
|
||||
RsGxsGrpMetaData *grpMeta = grpMetaMap[mit->first] ;
|
||||
|
||||
if(grpMeta == NULL)
|
||||
{
|
||||
std::cerr << "(EE) RsGxsNetService::sharePublishKeys() Publish keys cannot be found for group " << mit->first << std::endl;
|
||||
continue ;
|
||||
}
|
||||
|
||||
const RsTlvSecurityKeySet& keys = grpMeta->keys;
|
||||
|
||||
std::map<RsGxsId, RsTlvSecurityKey>::const_iterator kit = keys.keys.begin(), kit_end = keys.keys.end();
|
||||
bool publish_key_found = false;
|
||||
RsTlvSecurityKey publishKey ;
|
||||
|
||||
for(; kit != kit_end && !publish_key_found; ++kit)
|
||||
{
|
||||
publish_key_found = (kit->second.keyFlags == (RSTLV_KEY_DISTRIB_PRIVATE | RSTLV_KEY_TYPE_FULL));
|
||||
publishKey = kit->second ;
|
||||
}
|
||||
|
||||
if(!publish_key_found)
|
||||
{
|
||||
std::cerr << "(EE) no publish key in group " << mit->first << ". Cannot share!" << std::endl;
|
||||
continue ;
|
||||
}
|
||||
|
||||
|
||||
#ifdef NXS_NET_DEBUG
|
||||
std::cerr << " using publish key ID=" << publishKey.keyId << ", flags=" << publishKey.keyFlags << std::endl;
|
||||
#endif
|
||||
for(std::list<RsPeerId>::const_iterator it(recipients.begin());it!=recipients.end();++it)
|
||||
{
|
||||
/* Create publish key sharing item */
|
||||
RsNxsGroupPublishKeyItem *publishKeyItem = new RsNxsGroupPublishKeyItem(mServType);
|
||||
|
||||
publishKeyItem->clear();
|
||||
publishKeyItem->grpId = mit->first;
|
||||
|
||||
publishKeyItem->key = publishKey ;
|
||||
publishKeyItem->PeerId(*it);
|
||||
|
||||
sendItem(publishKeyItem);
|
||||
#ifdef NXS_NET_DEBUG
|
||||
std::cerr << " sent key item to " << *it << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
mit->second = offline_recipients ;
|
||||
|
||||
// If given peers have all received key(s) then stop sending for group
|
||||
if(offline_recipients.empty())
|
||||
toDelete.push_back(mit->first);
|
||||
}
|
||||
|
||||
// delete pending peer list which are done with
|
||||
for(std::list<RsGxsGroupId>::const_iterator lit = toDelete.begin(); lit != toDelete.end(); lit++)
|
||||
mPendingPublishKeyRecipients.erase(*lit);
|
||||
}
|
||||
|
||||
void RsGxsNetService::handleRecvPublishKeys(RsNxsGroupPublishKeyItem *item)
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG
|
||||
std::cerr << "RsGxsNetService::sharePublishKeys() " << std::endl;
|
||||
#endif
|
||||
RsStackMutex stack(mNxsMutex);
|
||||
|
||||
#ifdef NXS_NET_DEBUG
|
||||
std::cerr << " PeerId : " << item->PeerId() << std::endl;
|
||||
std::cerr << " GrpId: " << item->grpId << std::endl;
|
||||
std::cerr << " Got key Item: " << item->key.keyId << std::endl;
|
||||
#endif
|
||||
|
||||
// Get the meta data for this group Id
|
||||
//
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMetaMap;
|
||||
grpMetaMap[item->grpId] = NULL;
|
||||
mDataStore->retrieveGxsGrpMetaData(grpMetaMap);
|
||||
|
||||
// update the publish keys in this group meta info
|
||||
|
||||
RsGxsGrpMetaData *grpMeta = grpMetaMap[item->grpId] ;
|
||||
|
||||
// Check that the keys correspond, and that FULL keys are supplied, etc.
|
||||
|
||||
std::cerr << " Key received: " << std::endl;
|
||||
|
||||
bool admin = (item->key.keyFlags & RSTLV_KEY_DISTRIB_ADMIN) && (item->key.keyFlags & RSTLV_KEY_TYPE_FULL) ;
|
||||
bool publi = (item->key.keyFlags & RSTLV_KEY_DISTRIB_PRIVATE) && (item->key.keyFlags & RSTLV_KEY_TYPE_FULL) ;
|
||||
|
||||
std::cerr << " Key id = " << item->key.keyId << " admin=" << admin << ", publish=" << publi << " ts=" << item->key.endTS << std::endl;
|
||||
|
||||
if(!(!admin && publi))
|
||||
{
|
||||
std::cerr << " Key is not a publish private key. Discarding!" << std::endl;
|
||||
return ;
|
||||
}
|
||||
// Also check that we don't already have full keys for that group.
|
||||
|
||||
std::map<RsGxsId,RsTlvSecurityKey>::iterator it = grpMeta->keys.keys.find(item->key.keyId) ;
|
||||
|
||||
if(it == grpMeta->keys.keys.end())
|
||||
{
|
||||
std::cerr << " (EE) Key not found in known group keys. This is an inconsistency." << std::endl;
|
||||
return ;
|
||||
}
|
||||
|
||||
if((it->second.keyFlags & RSTLV_KEY_DISTRIB_PRIVATE) && (it->second.keyFlags & RSTLV_KEY_TYPE_FULL))
|
||||
{
|
||||
std::cerr << " (EE) Publish key already present in database. Discarding message." << std::endl;
|
||||
// return ;
|
||||
}
|
||||
|
||||
// Store/update the info.
|
||||
|
||||
//std::cerr << " (WW) Skipping key update, until fully debugged." << std::endl;
|
||||
|
||||
it->second = item->key ;
|
||||
bool ret = mDataStore->updateGroupKeys(item->grpId,grpMeta->keys, grpMeta->mSubscribeFlags | GXS_SERV::GROUP_SUBSCRIBE_PUBLISH) ;
|
||||
|
||||
if(!ret)
|
||||
std::cerr << "(EE) could not update database. Something went wrong." << std::endl;
|
||||
#ifdef NXS_NET_DEBUG
|
||||
else
|
||||
std::cerr << " updated database with new publish keys." << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -122,8 +122,13 @@ public:
|
||||
*/
|
||||
int requestGrp(const std::list<RsGxsGroupId>& grpId, const RsPeerId& peerId);
|
||||
|
||||
/* p3Config methods */
|
||||
/*!
|
||||
* share publish keys for the specified group with the peers in the specified list.
|
||||
*/
|
||||
|
||||
int sharePublishKey(const RsGxsGroupId& grpId,const std::list<RsPeerId>& peers) ;
|
||||
|
||||
/* p3Config methods */
|
||||
public:
|
||||
|
||||
bool loadList(std::list<RsItem *>& load);
|
||||
@ -141,7 +146,6 @@ public:
|
||||
* Processes transactions and job queue
|
||||
*/
|
||||
void run();
|
||||
|
||||
private:
|
||||
|
||||
/*!
|
||||
@ -296,6 +300,12 @@ private:
|
||||
*/
|
||||
void handleRecvSyncMessage(RsNxsSyncMsg* item);
|
||||
|
||||
/*!
|
||||
* Handles an nxs item for group publish key
|
||||
* @param item contaims keys/grp info
|
||||
*/
|
||||
void handleRecvPublishKeys(RsNxsGroupPublishKeyItem*) ;
|
||||
|
||||
/** E: item handlers **/
|
||||
|
||||
|
||||
@ -344,6 +354,11 @@ private:
|
||||
typedef std::vector<RsNxsGrp*> GrpFragments;
|
||||
typedef std::vector<RsNxsMsg*> MsgFragments;
|
||||
|
||||
/*!
|
||||
* Loops over pending publish key orders.
|
||||
*/
|
||||
void sharePublishKeysPending() ;
|
||||
|
||||
/*!
|
||||
* Fragment a message into individual fragments which are at most 150kb
|
||||
* @param msg message to fragment
|
||||
@ -421,6 +436,7 @@ private:
|
||||
// for an active transaction
|
||||
uint32_t mTransactionTimeOut;
|
||||
|
||||
std::map<RsGxsGroupId,std::list<RsPeerId> > mPendingPublishKeyRecipients ;
|
||||
|
||||
RsPeerId mOwnId;
|
||||
|
||||
@ -430,6 +446,7 @@ private:
|
||||
RsMutex mNxsMutex;
|
||||
|
||||
uint32_t mSyncTs;
|
||||
uint32_t mLastKeyPublishTs;
|
||||
|
||||
const uint32_t mSYNC_PERIOD;
|
||||
|
||||
|
@ -112,6 +112,12 @@ public:
|
||||
virtual int requestGrp(const std::list<RsGxsGroupId>& grpId, const RsPeerId& peerId) = 0;
|
||||
|
||||
|
||||
/*!
|
||||
* Request for this group is sent through to peers on your network
|
||||
* and how many hops from them you've indicated
|
||||
*/
|
||||
virtual int sharePublishKey(const RsGxsGroupId& grpId,const std::list<RsPeerId>& peers)=0 ;
|
||||
|
||||
};
|
||||
|
||||
#endif // RSGNP_H
|
||||
|
@ -101,7 +101,7 @@ virtual bool getChannelAutoDownload(const RsGxsGroupId &groupid) = 0;
|
||||
//virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask);
|
||||
|
||||
//virtual bool groupRestoreKeys(const std::string &groupId);
|
||||
//virtual bool groupShareKeys(const std::string &groupId, std::list<std::string>& peers);
|
||||
virtual bool groupShareKeys(const RsGxsGroupId &groupId, std::list<RsPeerId>& peers)=0;
|
||||
|
||||
// Overloaded subscribe fn.
|
||||
virtual bool subscribeToGroup(uint32_t &token, const RsGxsGroupId &groupId, bool subscribe) = 0;
|
||||
|
@ -1382,7 +1382,7 @@ int RsServer::StartupRetroShare()
|
||||
mGxsIdService, mGxsCircles,
|
||||
pgpAuxUtils);
|
||||
|
||||
|
||||
mGxsChannels->setNetworkExchangeService(gxschannels_ns) ;
|
||||
|
||||
#if 0 // PHOTO IS DISABLED FOR THE MOMENT
|
||||
/**** Photo service ****/
|
||||
|
@ -42,9 +42,13 @@ uint32_t RsNxsSerialiser::size(RsItem *item) {
|
||||
RsNxsSyncMsg* sgm;
|
||||
RsNxsSyncMsgItem* sgml;
|
||||
RsNxsTransac* ntx;
|
||||
RsNxsGroupPublishKeyItem* npk;
|
||||
|
||||
|
||||
if((sg = dynamic_cast<RsNxsSyncGrp*>(item)) != NULL)
|
||||
if((npk = dynamic_cast<RsNxsGroupPublishKeyItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeNxsGroupPublishKeyItem(npk);
|
||||
} else if((sg = dynamic_cast<RsNxsSyncGrp*>(item)) != NULL)
|
||||
{
|
||||
return sizeNxsSyncGrp(sg);
|
||||
|
||||
@ -109,6 +113,8 @@ RsItem* RsNxsSerialiser::deserialise(void *data, uint32_t *size) {
|
||||
return deserialNxsMsg(data, size);
|
||||
case RS_PKT_SUBTYPE_NXS_TRANS:
|
||||
return deserialNxsTrans(data, size);
|
||||
case RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY:
|
||||
return deserialNxsGroupPublishKeyItem(data, size);
|
||||
default:
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
@ -132,6 +138,7 @@ bool RsNxsSerialiser::serialise(RsItem *item, void *data, uint32_t *size){
|
||||
RsNxsSyncMsg* sgm;
|
||||
RsNxsSyncMsgItem* sgml;
|
||||
RsNxsTransac* ntx;
|
||||
RsNxsGroupPublishKeyItem* gpk;
|
||||
|
||||
if((sg = dynamic_cast<RsNxsSyncGrp*>(item)) != NULL)
|
||||
{
|
||||
@ -157,6 +164,9 @@ bool RsNxsSerialiser::serialise(RsItem *item, void *data, uint32_t *size){
|
||||
}else if((nmg = dynamic_cast<RsNxsMsg*>(item)) != NULL)
|
||||
{
|
||||
return serialiseNxsMsg(nmg, data, size);
|
||||
}else if((gpk = dynamic_cast<RsNxsGroupPublishKeyItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseNxsGroupPublishKeyItem(gpk, data, size);
|
||||
}
|
||||
|
||||
#ifdef NXS_DEBUG
|
||||
@ -469,7 +479,6 @@ bool RsNxsSerialiser::serialiseNxsSyncGrpItem(RsNxsSyncGrpItem *item, void *data
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
bool RsNxsSerialiser::serialiseNxsSyncMsg(RsNxsSyncMsg *item, void *data, uint32_t *size){
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsNxsSerialiser::serialiseNxsSyncMsg()" << std::endl;
|
||||
@ -518,6 +527,46 @@ bool RsNxsSerialiser::serialiseNxsSyncMsg(RsNxsSyncMsg *item, void *data, uint32
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
bool RsNxsSerialiser::serialiseNxsGroupPublishKeyItem(RsNxsGroupPublishKeyItem *item, void *data, uint32_t *size){
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsNxsSerialiser::serialiseNxsSyncMsg()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeNxsGroupPublishKeyItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize){
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsNxsSerialiser::serialiseNxsSyncMsg()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= item->grpId.serialise(data, *size, offset) ;
|
||||
ok &= item->key.SetTlv(data, *size, &offset) ;
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
std::cerr << "RsNxsSerialiser::serialiseGroupPublishKeyItem() FAIL Size Error! " << std::endl;
|
||||
ok = false;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
std::cerr << "RsNxsSerialiser::serialiseGroupPublishKeyItem( NOK" << std::endl;
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
/*** deserialisation ***/
|
||||
|
||||
|
||||
@ -1001,6 +1050,68 @@ RsNxsSyncMsg* RsNxsSerialiser::deserialNxsSyncMsg(void *data, uint32_t *size)
|
||||
|
||||
return item;
|
||||
}
|
||||
RsNxsGroupPublishKeyItem* RsNxsSerialiser::deserialNxsGroupPublishKeyItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsNxsSerialiser::deserialNxsGroupPublishKeyItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(SERVICE_TYPE != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY != getRsItemSubType(rstype)))
|
||||
{
|
||||
std::cerr << "RsNxsSerialiser::deserialNxsGroupPublishKeyItem() FAIL wrong type" << std::endl;
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
std::cerr << "RsNxsSerialiser::deserialNxsGroupPublishKeyItem() FAIL wrong size" << std::endl;
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsNxsGroupPublishKeyItem* item = new RsNxsGroupPublishKeyItem(getRsItemService(rstype));
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= item->grpId.deserialise(data, *size, offset);
|
||||
ok &= item->key.GetTlv(data, *size, &offset) ;
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsNxsSerialiser::deserialNxsGroupPublishKeyItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsNxsSerialiser::deserialNxsGroupPublishKeyItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
/*** size functions ***/
|
||||
@ -1034,7 +1145,15 @@ uint32_t RsNxsSerialiser::sizeNxsGrp(RsNxsGrp *item)
|
||||
return s;
|
||||
}
|
||||
|
||||
uint32_t RsNxsSerialiser::sizeNxsGroupPublishKeyItem(RsNxsGroupPublishKeyItem *item)
|
||||
{
|
||||
uint32_t s = 8; // header size
|
||||
|
||||
s += item->grpId.serial_size() ;
|
||||
s += item->key.TlvSize();
|
||||
|
||||
return s;
|
||||
}
|
||||
uint32_t RsNxsSerialiser::sizeNxsSyncGrp(RsNxsSyncGrp *item)
|
||||
{
|
||||
uint32_t s = 8; // header size
|
||||
@ -1129,7 +1248,10 @@ void RsNxsSyncGrp::clear()
|
||||
syncHash.clear();
|
||||
updateTS = 0;
|
||||
}
|
||||
|
||||
void RsNxsGroupPublishKeyItem::clear()
|
||||
{
|
||||
key.TlvClear();
|
||||
}
|
||||
void RsNxsSyncMsg::clear()
|
||||
{
|
||||
grpId.clear();
|
||||
@ -1162,7 +1284,6 @@ void RsNxsTransac::clear(){
|
||||
timestamp = 0;
|
||||
transactionNumber = 0;
|
||||
}
|
||||
|
||||
std::ostream& RsNxsSyncGrp::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
|
||||
@ -1182,6 +1303,21 @@ std::ostream& RsNxsSyncGrp::print(std::ostream &out, uint16_t indent)
|
||||
|
||||
return out;
|
||||
}
|
||||
std::ostream& RsNxsGroupPublishKeyItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
|
||||
printRsItemBase(out, "RsNxsGroupPublishKeyItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out , int_Indent);
|
||||
out << "GroupId: " << grpId << std::endl;
|
||||
printIndent(out , int_Indent);
|
||||
out << "keyId: " << key.keyId << std::endl;
|
||||
|
||||
printRsItemEnd(out ,"RsNxsGroupPublishKeyItem", indent);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
std::ostream& RsNxsSyncMsg::print(std::ostream &out, uint16_t indent)
|
||||
|
@ -44,6 +44,7 @@ const uint8_t RS_PKT_SUBTYPE_NXS_SYNC_MSG_ITEM = 0x0008;
|
||||
const uint8_t RS_PKT_SUBTYPE_NXS_SYNC_MSG = 0x0010;
|
||||
const uint8_t RS_PKT_SUBTYPE_NXS_MSG = 0x0020;
|
||||
const uint8_t RS_PKT_SUBTYPE_NXS_TRANS = 0x0040;
|
||||
const uint8_t RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY = 0x0080;
|
||||
|
||||
|
||||
// possibility create second service to deal with this functionality
|
||||
@ -106,6 +107,23 @@ public:
|
||||
|
||||
};
|
||||
|
||||
/*!
|
||||
* Use to request grp list from peer
|
||||
* Server may advise client peer to use sync file
|
||||
* while serving his request. This results
|
||||
*/
|
||||
class RsNxsGroupPublishKeyItem : public RsNxsItem
|
||||
{
|
||||
public:
|
||||
RsNxsGroupPublishKeyItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY) { clear(); return;}
|
||||
|
||||
virtual void clear();
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
RsGxsGroupId grpId ;
|
||||
RsTlvSecurityKey key ;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
@ -462,6 +480,12 @@ private:
|
||||
virtual bool serialiseNxsTrans(RsNxsTransac* item, void* data, uint32_t* size);
|
||||
virtual RsNxsTransac* deserialNxsTrans(void* data, uint32_t *size);
|
||||
|
||||
/* RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY */
|
||||
virtual uint32_t sizeNxsGroupPublishKeyItem(RsNxsGroupPublishKeyItem* item);
|
||||
virtual bool serialiseNxsGroupPublishKeyItem(RsNxsGroupPublishKeyItem* item, void* data, uint32_t* size);
|
||||
virtual RsNxsGroupPublishKeyItem* deserialNxsGroupPublishKeyItem(void* data, uint32_t *size);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
const uint16_t SERVICE_TYPE;
|
||||
|
@ -225,6 +225,13 @@ bool p3GxsChannels::getGroupData(const uint32_t &token, std::vector<RsGxsChannel
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool p3GxsChannels::groupShareKeys(const RsGxsGroupId &groupId, std::list<RsPeerId>& peers)
|
||||
{
|
||||
RsGenExchange::shareGroupPublishKey(groupId,peers) ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
|
||||
/* Okay - chris is not going to be happy with this...
|
||||
* but I can't be bothered with crazy data structures
|
||||
* at the moment - fix it up later
|
||||
|
@ -88,7 +88,7 @@ virtual bool getRelatedPosts(const uint32_t &token, std::vector<RsGxsChannelPost
|
||||
//virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask);
|
||||
|
||||
//virtual bool groupRestoreKeys(const std::string &groupId);
|
||||
//virtual bool groupShareKeys(const std::string &groupId, std::list<std::string>& peers);
|
||||
virtual bool groupShareKeys(const RsGxsGroupId &groupId, std::list<RsPeerId>& peers) ;
|
||||
|
||||
virtual bool createGroup(uint32_t &token, RsGxsChannelGroup &group);
|
||||
virtual bool createPost(uint32_t &token, RsGxsChannelPost &post);
|
||||
|
@ -166,8 +166,8 @@ class p3MsgService: public p3Service, public p3Config, public pqiServiceMonitor,
|
||||
|
||||
void initStandardTagTypes();
|
||||
|
||||
p3ServiceControl *mServiceCtrl;
|
||||
p3IdService *mIdService ;
|
||||
p3ServiceControl *mServiceCtrl;
|
||||
p3GRouter *mGRouter ;
|
||||
|
||||
/* Mutex Required for stuff below */
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
#include "gui/settings/rsharesettings.h"
|
||||
#include "gui/RetroShareLink.h"
|
||||
#include "gui/channels/ShareKey.h"
|
||||
#include "gui/gxschannels/GxsChannelShareKey.h"
|
||||
#include "gui/common/RSTreeWidget.h"
|
||||
#include "gui/notifyqt.h"
|
||||
#include "gui/common/UIStateHelper.h"
|
||||
@ -432,10 +432,10 @@ void GxsGroupFrameDialog::shareKey()
|
||||
return;
|
||||
}
|
||||
|
||||
QMessageBox::warning(this, "", "ToDo");
|
||||
// QMessageBox::warning(this, "", "ToDo");
|
||||
|
||||
// ShareKey shareUi(this, mGroupId.toStdString(), shareKeyType());
|
||||
// shareUi.exec();
|
||||
ChannelShareKey shareUi(this, mGroupId, shareKeyType());
|
||||
shareUi.exec();
|
||||
}
|
||||
|
||||
void GxsGroupFrameDialog::loadComment(const RsGxsGroupId &grpId, const RsGxsMessageId &msgId, const QString &title)
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include "GxsChannelGroupDialog.h"
|
||||
#include "GxsChannelPostsWidget.h"
|
||||
#include "GxsChannelUserNotify.h"
|
||||
#include "gui/channels/ShareKey.h"
|
||||
#include "GxsChannelShareKey.h"
|
||||
#include "gui/feeds/GxsChannelPostItem.h"
|
||||
#include "gui/settings/rsharesettings.h"
|
||||
#include "gui/notifyqt.h"
|
||||
@ -78,7 +78,6 @@ QString GxsChannelDialog::text(TextType type)
|
||||
return tr("Create Channel");
|
||||
case TEXT_TODO:
|
||||
return "<b>Open points:</b><ul>"
|
||||
"<li>Share key"
|
||||
"<li>Restore channel keys"
|
||||
"<li>Navigate channel link"
|
||||
"<li>Don't show own posts as unread"
|
||||
|
@ -19,18 +19,17 @@
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#include "ShareKey.h"
|
||||
#include "GxsChannelShareKey.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <algorithm>
|
||||
|
||||
//#include <retroshare/rschannels.h>
|
||||
//#include <retroshare/rsforums.h>
|
||||
#include <retroshare/rspeers.h>
|
||||
#include <retroshare/rsgxschannels.h>
|
||||
|
||||
#include "gui/common/PeerDefs.h"
|
||||
|
||||
ShareKey::ShareKey(QWidget *parent, std::string grpId, int grpType) :
|
||||
ChannelShareKey::ChannelShareKey(QWidget *parent, const RsGxsGroupId &grpId, int grpType) :
|
||||
QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint), mGrpId(grpId), mGrpType(grpType)
|
||||
{
|
||||
ui = new Ui::ShareKey();
|
||||
@ -49,12 +48,12 @@ ShareKey::ShareKey(QWidget *parent, std::string grpId, int grpType) :
|
||||
ui->keyShareList->start();
|
||||
}
|
||||
|
||||
ShareKey::~ShareKey()
|
||||
ChannelShareKey::~ChannelShareKey()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ShareKey::changeEvent(QEvent *e)
|
||||
void ChannelShareKey::changeEvent(QEvent *e)
|
||||
{
|
||||
QDialog::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
@ -66,7 +65,7 @@ void ShareKey::changeEvent(QEvent *e)
|
||||
}
|
||||
}
|
||||
|
||||
void ShareKey::shareKey()
|
||||
void ChannelShareKey::shareKey()
|
||||
{
|
||||
std::list<RsPeerId> shareList;
|
||||
ui->keyShareList->selectedIds<RsPeerId,FriendSelectionWidget::IDTYPE_SSL>(shareList, false);
|
||||
@ -77,28 +76,26 @@ void ShareKey::shareKey()
|
||||
return;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (mGrpType & CHANNEL_KEY_SHARE) {
|
||||
if (!rsChannels)
|
||||
if (!rsGxsChannels)
|
||||
return;
|
||||
|
||||
if (!rsChannels->channelShareKeys(mGrpId, shareList)) {
|
||||
if (!rsGxsChannels->groupShareKeys(mGrpId, shareList)) {
|
||||
std::cerr << "Failed to share keys!" << std::endl;
|
||||
return;
|
||||
}
|
||||
} else if(mGrpType & FORUM_KEY_SHARE) {
|
||||
if(!rsForums)
|
||||
return;
|
||||
|
||||
if (!rsForums->forumShareKeys(mGrpId, shareList)) {
|
||||
std::cerr << "Failed to share keys!" << std::endl;
|
||||
return;
|
||||
}
|
||||
QMessageBox::warning(NULL,"Not implemented.","Not implemented") ;
|
||||
|
||||
// if (!rsForums->forumShareKeys(mGrpId, shareList)) {
|
||||
// std::cerr << "Failed to share keys!" << std::endl;
|
||||
//return;
|
||||
//}
|
||||
} else {
|
||||
// incorrect type
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
close();
|
||||
}
|
@ -8,7 +8,7 @@
|
||||
#define CHANNEL_KEY_SHARE 0x00000001
|
||||
#define FORUM_KEY_SHARE 0x00000002
|
||||
|
||||
class ShareKey : public QDialog
|
||||
class ChannelShareKey : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -16,8 +16,8 @@ public:
|
||||
/*
|
||||
*@param chanId The channel id to send request for
|
||||
*/
|
||||
ShareKey(QWidget *parent = 0, std::string grpId = "", int grpType = 0);
|
||||
~ShareKey();
|
||||
ChannelShareKey(QWidget *parent = 0, const RsGxsGroupId& grpId = RsGxsGroupId(), int grpType = 0);
|
||||
~ChannelShareKey();
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent *e);
|
||||
@ -26,7 +26,7 @@ private slots:
|
||||
void shareKey();
|
||||
|
||||
private:
|
||||
std::string mGrpId;
|
||||
RsGxsGroupId mGrpId;
|
||||
int mGrpType;
|
||||
|
||||
Ui::ShareKey *ui;
|
@ -24,7 +24,7 @@
|
||||
#include "GxsForumThreadWidget.h"
|
||||
#include "GxsForumUserNotify.h"
|
||||
#include "gui/notifyqt.h"
|
||||
#include "gui/channels/ShareKey.h"
|
||||
#include "gui/gxschannels/GxsChannelShareKey.h"
|
||||
|
||||
/** Constructor */
|
||||
GxsForumsDialog::GxsForumsDialog(QWidget *parent)
|
||||
|
@ -515,7 +515,6 @@ HEADERS += rshare.h \
|
||||
gui/statistics/DhtWindow.h \
|
||||
gui/statistics/StatisticsWindow.h \
|
||||
gui/statistics/BwCtrlWindow.h \
|
||||
gui/channels/ShareKey.h \
|
||||
gui/GetStartedDialog.h \
|
||||
gui/statistics/RttStatistics.h \
|
||||
|
||||
@ -627,7 +626,6 @@ FORMS += gui/StartDialog.ui \
|
||||
gui/statistics/DhtWindow.ui \
|
||||
gui/statistics/StatisticsWindow.ui \
|
||||
gui/statistics/BwCtrlWindow.ui \
|
||||
gui/channels/ShareKey.ui \
|
||||
gui/GetStartedDialog.ui \
|
||||
gui/statistics/RttStatistics.ui \
|
||||
|
||||
@ -845,7 +843,6 @@ SOURCES += main.cpp \
|
||||
gui/statistics/DhtWindow.cpp \
|
||||
gui/statistics/StatisticsWindow.cpp \
|
||||
gui/statistics/BwCtrlWindow.cpp \
|
||||
gui/channels/ShareKey.cpp \
|
||||
gui/GetStartedDialog.cpp \
|
||||
gui/statistics/RttStatistics.cpp \
|
||||
|
||||
@ -1192,6 +1189,7 @@ gxschannels {
|
||||
gui/gxschannels/GxsChannelPostsWidget.h \
|
||||
gui/gxschannels/GxsChannelFilesWidget.h \
|
||||
gui/gxschannels/GxsChannelFilesStatusWidget.h \
|
||||
gui/gxschannels/GxsChannelShareKey.h \
|
||||
gui/feeds/GxsChannelPostItem.h \
|
||||
gui/gxschannels/GxsChannelUserNotify.h
|
||||
|
||||
@ -1199,6 +1197,7 @@ gxschannels {
|
||||
gui/gxschannels/GxsChannelFilesWidget.ui \
|
||||
gui/gxschannels/GxsChannelFilesStatusWidget.ui \
|
||||
gui/gxschannels/CreateGxsChannelMsg.ui \
|
||||
gui/gxschannels/GxsChannelShareKey.ui \
|
||||
gui/feeds/GxsChannelPostItem.ui
|
||||
|
||||
SOURCES += gui/gxschannels/GxsChannelDialog.cpp \
|
||||
@ -1206,6 +1205,7 @@ gxschannels {
|
||||
gui/gxschannels/GxsChannelFilesWidget.cpp \
|
||||
gui/gxschannels/GxsChannelFilesStatusWidget.cpp \
|
||||
gui/gxschannels/GxsChannelGroupDialog.cpp \
|
||||
gui/gxschannels/GxsChannelShareKey.cpp \
|
||||
gui/gxschannels/CreateGxsChannelMsg.cpp \
|
||||
gui/feeds/GxsChannelPostItem.cpp \
|
||||
gui/gxschannels/GxsChannelUserNotify.cpp
|
||||
|
Loading…
Reference in New Issue
Block a user