changed internal storage of groups of friend nodes so as to use an abstract ID instead of a string (phase 1 of local circles)

This commit is contained in:
csoler 2016-07-04 23:55:48 -04:00
parent 9f7ef8b46b
commit 4ee9effc4e
12 changed files with 420 additions and 349 deletions

View File

@ -138,8 +138,6 @@ p3LinkMgrIMPL::p3LinkMgrIMPL(p3PeerMgrIMPL *peerMgr, p3NetMgrIMPL *netMgr)
mDNSResolver = new DNSResolver();
mRetryPeriod = MIN_RETRY_PERIOD;
lastGroupId = 1;
/* setup Banned Ip Address - static for now
*/

View File

@ -132,7 +132,7 @@ class peerConnectState
};
class p3tunnel;
class RsPeerGroupItem;
class RsPeerGroupItem_deprecated;
class RsGroupInfo;
class p3PeerMgr;
@ -339,9 +339,6 @@ private:
std::map<RsPeerId, peerConnectState> mFriendList;
std::map<RsPeerId, peerConnectState> mOthersList;
std::list<RsPeerGroupItem *> groupList;
uint32_t lastGroupId;
/* relatively static list of banned ip addresses */
std::list<struct sockaddr_storage> mBannedIpList;
};

View File

@ -130,8 +130,6 @@ p3PeerMgrIMPL::p3PeerMgrIMPL(const RsPeerId& ssl_own_id, const RsPgpId& gpg_own_
mOwnState.vs_disc = RS_VS_DISC_FULL;
mOwnState.vs_dht = RS_VS_DHT_FULL;
lastGroupId = 1;
// setup default ProxyServerAddress.
// Tor
sockaddr_storage_clear(mProxyServerAddressTor);
@ -1071,7 +1069,7 @@ bool p3PeerMgrIMPL::removeFriend(const RsPgpId &id)
std::list<RsPgpId> ids ;
ids.push_back(id) ;
assignPeersToGroup("", ids, false);
assignPeersToGroup(RsNodeGroupId(), ids, false);
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
@ -1145,7 +1143,7 @@ bool p3PeerMgrIMPL::removeFriend(const RsPeerId &id, bool removePgpId)
/* remove id from all groups */
assignPeersToGroup("", pgpid_toRemove, false);
assignPeersToGroup(RsNodeGroupId(), pgpid_toRemove, false);
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
@ -1915,7 +1913,7 @@ RsSerialiser *p3PeerMgrIMPL::setupSerialiser()
bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
{
/* create a list of current peers */
cleanup = false;
cleanup = true;
bool useExtAddrFinder = mNetMgr->getIPServersEnabled();
/* gather these information before mPeerMtx is locked! */
@ -1971,7 +1969,6 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
#endif
saveData.push_back(item);
saveCleanupList.push_back(item);
/* iterate through all friends and save */
std::map<RsPeerId, peerState>::iterator it;
@ -2003,7 +2000,6 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
item->domain_port = (it->second).hiddenPort;
saveData.push_back(item);
saveCleanupList.push_back(item);
#ifdef PEER_DEBUG
std::cerr << "p3PeerMgrIMPL::saveList() Peer Config Item:" << std::endl;
item->print(std::cerr, 10);
@ -2024,7 +2020,6 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
}
saveData.push_back(sitem) ;
saveCleanupList.push_back(sitem);
// Now save config for network digging strategies
@ -2066,14 +2061,11 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
vitem->tlvkvs.pairs.push_back(kv) ;
saveData.push_back(vitem);
saveCleanupList.push_back(vitem);
/* save groups */
std::list<RsPeerGroupItem *>::iterator groupIt;
for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) {
saveData.push_back(*groupIt); // no delete
}
for ( std::map<RsNodeGroupId,RsGroupInfo>::iterator groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt)
saveData.push_back(new RsNodeGroupItem(groupIt->second)); // no delete
return true;
}
@ -2294,7 +2286,8 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
continue;
}
RsPeerGroupItem *gitem = dynamic_cast<RsPeerGroupItem *>(*it) ;
RsPeerGroupItem_deprecated *gitem = dynamic_cast<RsPeerGroupItem_deprecated *>(*it) ;
if (gitem)
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
@ -2304,20 +2297,48 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
gitem->print(std::cerr, 10);
std::cerr << std::endl;
#endif
RsGroupInfo ginfo ;
ginfo.flag = gitem->flag ;
ginfo.name = gitem->name ;
ginfo.peerIds = gitem->pgpList.ids ;
ginfo.id = RsNodeGroupId::random() ;
groupList.push_back(gitem); // don't delete
// Ensure backward compatibility when loading the group in old format. The id must matchthe standard default id.
if ((gitem->flag & RS_GROUP_FLAG_STANDARD) == 0) {
/* calculate group id */
uint32_t groupId = atoi(gitem->id.c_str());
if (groupId > lastGroupId) {
lastGroupId = groupId;
}
}
if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_FRIENDS )) ginfo.id = RS_GROUP_ID_FRIENDS ;
if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_COWORKERS)) ginfo.id = RS_GROUP_ID_COWORKERS ;
if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_FAMILY )) ginfo.id = RS_GROUP_ID_FAMILY ;
if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_FAVORITES)) ginfo.id = RS_GROUP_ID_FAVORITES ;
if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_OTHERS )) ginfo.id = RS_GROUP_ID_OTHERS ;
groupList[ginfo.id] = ginfo ;
std::cerr << "(II) Creating new group for old format local group \"" << gitem->name << "\". Id=" << ginfo.id << std::endl;
continue;
}
RsNodeGroupItem *gitem2 = dynamic_cast<RsNodeGroupItem*>(*it) ;
if (gitem2)
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
#ifdef PEER_DEBUG
std::cerr << "p3PeerMgrIMPL::loadList() Peer group item:" << std::endl;
gitem->print(std::cerr, 10);
std::cerr << std::endl;
#endif
RsGroupInfo info ;
info.peerIds = gitem2->pgpList.ids ;
info.id = gitem2->id ;
info.name = gitem2->name ;
info.flag = gitem2->flag ;
groupList[info.id] = info ;
continue;
}
RsPeerBandwidthLimitsItem *pblitem = dynamic_cast<RsPeerBandwidthLimitsItem*>(*it) ;
if(pblitem)
@ -2363,41 +2384,18 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
/* Standard groups */
const int standardGroupCount = 5;
const char *standardGroup[standardGroupCount] = { RS_GROUP_ID_FRIENDS, RS_GROUP_ID_FAMILY, RS_GROUP_ID_COWORKERS, RS_GROUP_ID_OTHERS, RS_GROUP_ID_FAVORITES };
bool foundStandardGroup[standardGroupCount] = { false, false, false, false, false };
const RsNodeGroupId standardGroupIds [standardGroupCount] = { RS_GROUP_ID_FRIENDS, RS_GROUP_ID_FAMILY, RS_GROUP_ID_COWORKERS, RS_GROUP_ID_OTHERS, RS_GROUP_ID_FAVORITES };
const char *standardGroupNames[standardGroupCount] = { RS_GROUP_DEFAULT_NAME_FRIENDS, RS_GROUP_DEFAULT_NAME_FAMILY, RS_GROUP_DEFAULT_NAME_COWORKERS, RS_GROUP_DEFAULT_NAME_OTHERS, RS_GROUP_DEFAULT_NAME_FAVORITES };
std::list<RsPeerGroupItem *>::iterator groupIt;
for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) {
if ((*groupIt)->flag & RS_GROUP_FLAG_STANDARD) {
int i;
for (i = 0; i < standardGroupCount; ++i) {
if ((*groupIt)->id == standardGroup[i]) {
foundStandardGroup[i] = true;
break;
}
}
for(uint32_t k=0;k<standardGroupCount;++k)
if(groupList.find(standardGroupIds[k]) == groupList.end())
{
RsGroupInfo info ;
info.id = standardGroupIds[k];
info.name = standardGroupNames[k];
info.flag |= RS_GROUP_FLAG_STANDARD;
if (i >= standardGroupCount) {
/* No more a standard group, remove the flag standard */
(*groupIt)->flag &= ~RS_GROUP_FLAG_STANDARD;
}
} else {
uint32_t groupId = atoi((*groupIt)->id.c_str());
if (groupId == 0) {
rs_sprintf((*groupIt)->id, "%lu", lastGroupId++);
}
}
}
/* Initialize standard groups */
for (int i = 0; i < standardGroupCount; ++i) {
if (foundStandardGroup[i] == false) {
RsPeerGroupItem *gitem = new RsPeerGroupItem;
gitem->id = standardGroup[i];
gitem->name = standardGroup[i];
gitem->flag |= RS_GROUP_FLAG_STANDARD;
groupList.push_back(gitem);
}
groupList[info.id] = info;
}
}
@ -2478,19 +2476,13 @@ bool p3PeerMgrIMPL::addGroup(RsGroupInfo &groupInfo)
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
RsPeerGroupItem *groupItem = new RsPeerGroupItem;
groupItem->set(groupInfo);
rs_sprintf(groupItem->id, "%lu", ++lastGroupId);
groupInfo.id = RsNodeGroupId::random() ;//groupItem->id; // at creation time, we generate a random id.
RsGroupInfo groupItem(groupInfo) ;
// remove standard flag
groupItem->flag &= ~RS_GROUP_FLAG_STANDARD;
groupItem->PeerId(getOwnId());
groupList.push_back(groupItem);
groupInfo.id = groupItem->id;
groupItem.flag &= ~RS_GROUP_FLAG_STANDARD;
groupList[groupInfo.id] = groupItem;
}
RsServer::notify()->notifyListChange(NOTIFY_LIST_GROUPLIST, NOTIFY_TYPE_ADD);
@ -2500,35 +2492,39 @@ bool p3PeerMgrIMPL::addGroup(RsGroupInfo &groupInfo)
return true;
}
bool p3PeerMgrIMPL::editGroup(const std::string &groupId, RsGroupInfo &groupInfo)
bool p3PeerMgrIMPL::editGroup(const RsNodeGroupId& groupId, RsGroupInfo &groupInfo)
{
if (groupId.empty()) {
if (groupId.isNull())
return false;
}
bool changed = false;
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
std::list<RsPeerGroupItem*>::iterator groupIt;
for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) {
if ((*groupIt)->id == groupId) {
break;
}
std::map<RsNodeGroupId,RsGroupInfo>::iterator it = groupList.find(groupId) ;
if(it == groupList.end())
{
std::cerr << "(EE) cannot find local node group with ID " << groupId << std::endl;
return false ;
}
if (groupIt != groupList.end()) {
if ((*groupIt)->flag & RS_GROUP_FLAG_STANDARD) {
if (it->second.flag & RS_GROUP_FLAG_STANDARD)
{
// can't edit standard groups
} else {
changed = true;
(*groupIt)->set(groupInfo);
std::cerr << "(EE) cannot edit standard group with ID " << groupId << std::endl;
return false ;
}
else
{
changed = true;
it->second = groupInfo;
}
}
if (changed) {
if (changed)
{
RsServer::notify()->notifyListChange(NOTIFY_LIST_GROUPLIST, NOTIFY_TYPE_MOD);
IndicateConfigChanged();
@ -2537,31 +2533,35 @@ bool p3PeerMgrIMPL::editGroup(const std::string &groupId, RsGroupInfo &groupInfo
return changed;
}
bool p3PeerMgrIMPL::removeGroup(const std::string &groupId)
bool p3PeerMgrIMPL::removeGroup(const RsNodeGroupId& groupId)
{
if (groupId.empty()) {
return false;
}
bool changed = false;
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
std::list<RsPeerGroupItem*>::iterator groupIt;
for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) {
if ((*groupIt)->id == groupId) {
break;
}
}
std::map<RsNodeGroupId,RsGroupInfo>::iterator it = groupList.find(groupId) ;
if (groupIt != groupList.end()) {
if ((*groupIt)->flag & RS_GROUP_FLAG_STANDARD) {
if (it != groupList.end()) {
if (it->second.flag & RS_GROUP_FLAG_STANDARD)
{
// can't remove standard groups
} else {
std::cerr << "(EE) cannot remove standard group with ID " << groupId << std::endl;
return false ;
}
#warning we need to check that the local group is not used. Otherwise deleting it is going to cause problems!
// else if(!it->second.used_gxs_groups.empty())
// {
// std::cerr << "(EE) cannot remove standard group with ID " << groupId << " because it is used in the following groups: " << std::endl;
// for(std::set<RsGxsGroupId>::const_iterator it2(it->second.used_gxs_groups.begin());it2!=it->second.used_gxs_groups.end();++it2)
// std::cerr << " " << *it2 << std::endl;
//
// return false ;
// }
else
{
changed = true;
delete(*groupIt);
groupList.erase(groupIt);
groupList.erase(it);
}
}
}
@ -2575,83 +2575,70 @@ bool p3PeerMgrIMPL::removeGroup(const std::string &groupId)
return changed;
}
bool p3PeerMgrIMPL::getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo)
bool p3PeerMgrIMPL::getGroupInfo(const RsNodeGroupId& groupId, RsGroupInfo &groupInfo)
{
if (groupId.empty()) {
return false;
}
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
std::list<RsPeerGroupItem*>::iterator groupIt;
for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) {
if ((*groupIt)->id == groupId) {
(*groupIt)->get(groupInfo);
std::map<RsNodeGroupId,RsGroupInfo>::iterator it = groupList.find(groupId) ;
if(it == groupList.end())
return false ;
groupInfo = it->second;
return true;
}
}
return false;
}
bool p3PeerMgrIMPL::getGroupInfoList(std::list<RsGroupInfo>& groupInfoList)
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
std::list<RsPeerGroupItem*>::iterator groupIt;
for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) {
RsGroupInfo groupInfo;
(*groupIt)->get(groupInfo);
groupInfoList.push_back(groupInfo);
}
for (std::map<RsNodeGroupId,RsGroupInfo> ::const_iterator groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt)
groupInfoList.push_back(groupIt->second);
return true;
}
// groupId == "" && assign == false -> remove from all groups
bool p3PeerMgrIMPL::assignPeersToGroup(const std::string &groupId, const std::list<RsPgpId> &peerIds, bool assign)
{
if (groupId.empty() && assign == true) {
return false;
}
// groupId.isNull() && assign == false -> remove from all groups
if (peerIds.empty()) {
bool p3PeerMgrIMPL::assignPeersToGroup(const RsNodeGroupId &groupId, const std::list<RsPgpId> &peerIds, bool assign)
{
if (groupId.isNull() && assign == true)
return false;
if (peerIds.empty())
return false;
}
bool changed = false;
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
std::list<RsPeerGroupItem*>::iterator groupIt;
for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) {
if (groupId.empty() || (*groupIt)->id == groupId) {
RsPeerGroupItem *groupItem = *groupIt;
for (std::map<RsNodeGroupId,RsGroupInfo>::iterator groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt)
if (groupId.isNull() || groupIt->first == groupId)
{
RsGroupInfo& groupItem = groupIt->second;
std::list<RsPgpId>::const_iterator peerIt;
for (peerIt = peerIds.begin(); peerIt != peerIds.end(); ++peerIt) {
std::set<RsPgpId>::iterator peerIt1 = std::find(groupItem->pgpList.ids.begin(), groupItem->pgpList.ids.end(), *peerIt);
if (assign) {
if (peerIt1 == groupItem->pgpList.ids.end()) {
groupItem->pgpList.ids.insert(*peerIt);
for (std::list<RsPgpId>::const_iterator peerIt = peerIds.begin(); peerIt != peerIds.end(); ++peerIt)
{
std::set<RsPgpId>::iterator peerIt1 = groupItem.peerIds.find(*peerIt);
if (assign)
{
groupItem.peerIds.insert(*peerIt);
changed = true;
}
} else {
if (peerIt1 != groupItem->pgpList.ids.end()) {
groupItem->pgpList.ids.erase(peerIt1);
else
{
groupItem.peerIds.erase(*peerIt);
changed = true;
}
}
}
if (groupId.empty() == false) {
if (!groupId.isNull())
break;
}
}
}
}
if (changed) {
RsServer::notify()->notifyListChange(NOTIFY_LIST_GROUPLIST, NOTIFY_TYPE_MOD);

View File

@ -106,7 +106,7 @@ class peerState
uint32_t maxDnRate ;
};
class RsPeerGroupItem;
class RsNodeGroupItem;
class RsGroupInfo;
std::string textPeerState(peerState &state);
@ -139,11 +139,11 @@ virtual bool removeAllFriendLocations(const RsPgpId &gpgid) = 0;
/* This is solely used by p3peers - makes sense */
virtual bool addGroup(RsGroupInfo &groupInfo) = 0;
virtual bool editGroup(const std::string &groupId, RsGroupInfo &groupInfo) = 0;
virtual bool removeGroup(const std::string &groupId) = 0;
virtual bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo) = 0;
virtual bool editGroup(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo) = 0;
virtual bool removeGroup(const RsNodeGroupId &groupId) = 0;
virtual bool getGroupInfo(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo) = 0;
virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList) = 0;
virtual bool assignPeersToGroup(const std::string &groupId, const std::list<RsPgpId> &peerIds, bool assign) = 0;
virtual bool assignPeersToGroup(const RsNodeGroupId &groupId, const std::list<RsPgpId> &peerIds, bool assign) = 0;
virtual bool resetOwnExternalAddressList() = 0 ;
@ -253,11 +253,11 @@ virtual bool removeAllFriendLocations(const RsPgpId &gpgid);
/* This is solely used by p3peers - makes sense */
virtual bool addGroup(RsGroupInfo &groupInfo);
virtual bool editGroup(const std::string &groupId, RsGroupInfo &groupInfo);
virtual bool removeGroup(const std::string &groupId);
virtual bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo);
virtual bool editGroup(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo);
virtual bool removeGroup(const RsNodeGroupId &groupId);
virtual bool getGroupInfo(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo);
virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList);
virtual bool assignPeersToGroup(const std::string &groupId, const std::list<RsPgpId> &peerIds, bool assign);
virtual bool assignPeersToGroup(const RsNodeGroupId &groupId, const std::list<RsPgpId> &peerIds, bool assign);
virtual ServicePermissionFlags servicePermissionFlags(const RsPgpId& gpg_id) ;
virtual ServicePermissionFlags servicePermissionFlags(const RsPeerId& ssl_id) ;
@ -394,7 +394,7 @@ private:
std::map<RsPeerId,sockaddr_storage> mReportedOwnAddresses ;
std::list<RsPeerGroupItem *> groupList;
std::map<RsNodeGroupId,RsGroupInfo> groupList;
uint32_t lastGroupId;
std::list<RsItem *> saveCleanupList; /* TEMPORARY LIST WHEN SAVING */

View File

@ -73,14 +73,13 @@ template<uint32_t ID_SIZE_IN_BYTES,bool UPPER_CASE,uint32_t UNIQUE_IDENTIFIER> c
memcpy(bytes,id.toByteArray(),ID_SIZE_IN_BYTES) ;
}
// Random initialization. Can be useful for testing.
// Random initialization. Can be useful for testing and to generate new ids.
//
static t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER> random()
{
t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER> id ;
for(uint32_t i=0;i<ID_SIZE_IN_BYTES;++i)
id.bytes[i] = RSRandom::random_u32() & 0xff ;
RSRandom::random_bytes(id.bytes,ID_SIZE_IN_BYTES) ;
return id ;
}
@ -220,6 +219,7 @@ static const uint32_t RS_GENERIC_ID_GXS_CIRCLE_ID_TYPE = 0x0008 ;
static const uint32_t RS_GENERIC_ID_GROUTER_ID_TYPE = 0x0009 ;
static const uint32_t RS_GENERIC_ID_GXS_TUNNEL_ID_TYPE = 0x0010 ;
static const uint32_t RS_GENERIC_ID_GXS_DISTANT_CHAT_ID_TYPE = 0x0011 ;
static const uint32_t RS_GENERIC_ID_NODE_GROUP_ID_TYPE = 0x0012 ;
typedef t_RsGenericIdType< SSL_ID_SIZE , false, RS_GENERIC_ID_SSL_ID_TYPE> SSLIdType ;
typedef t_RsGenericIdType< PGP_KEY_ID_SIZE , true, RS_GENERIC_ID_PGP_ID_TYPE> PGPIdType ;
@ -231,4 +231,5 @@ typedef t_RsGenericIdType< CERT_SIGN_LEN , false, RS_GENERIC_ID_GXS_I
typedef t_RsGenericIdType< CERT_SIGN_LEN , false, RS_GENERIC_ID_GXS_CIRCLE_ID_TYPE > GXSCircleId ;
typedef t_RsGenericIdType< SSL_ID_SIZE , false, RS_GENERIC_ID_GXS_TUNNEL_ID_TYPE > GXSTunnelId ;
typedef t_RsGenericIdType< SSL_ID_SIZE , false, RS_GENERIC_ID_GXS_DISTANT_CHAT_ID_TYPE > DistantChatPeerId ;
typedef t_RsGenericIdType< CERT_SIGN_LEN , false, RS_GENERIC_ID_NODE_GROUP_ID_TYPE > RsNodeGroupId ;

View File

@ -185,11 +185,17 @@ const uint32_t RS_NET_PROXY_STATUS_OK = 0x0001 ;
/* Groups */
#define RS_GROUP_ID_FRIENDS "Friends"
#define RS_GROUP_ID_FAMILY "Family"
#define RS_GROUP_ID_COWORKERS "Co-Workers"
#define RS_GROUP_ID_OTHERS "Other Contacts"
#define RS_GROUP_ID_FAVORITES "Favorites"
static const RsNodeGroupId RS_GROUP_ID_FRIENDS ("00000000000000000000000000000001");
static const RsNodeGroupId RS_GROUP_ID_FAMILY ("00000000000000000000000000000002");
static const RsNodeGroupId RS_GROUP_ID_COWORKERS ("00000000000000000000000000000003");
static const RsNodeGroupId RS_GROUP_ID_OTHERS ("00000000000000000000000000000004");
static const RsNodeGroupId RS_GROUP_ID_FAVORITES ("00000000000000000000000000000005");
#define RS_GROUP_DEFAULT_NAME_FRIENDS "Friends"
#define RS_GROUP_DEFAULT_NAME_FAMILY "Family"
#define RS_GROUP_DEFAULT_NAME_COWORKERS "Co-Workers"
#define RS_GROUP_DEFAULT_NAME_OTHERS "Other Contacts"
#define RS_GROUP_DEFAULT_NAME_FAVORITES "Favorites"
const uint32_t RS_GROUP_FLAG_STANDARD = 0x0001;
@ -295,7 +301,7 @@ class RsGroupInfo
public:
RsGroupInfo();
std::string id;
RsNodeGroupId id;
std::string name;
uint32_t flag;
@ -400,13 +406,13 @@ public:
/* Group Stuff */
virtual bool addGroup(RsGroupInfo& groupInfo) = 0;
virtual bool editGroup(const std::string &groupId, RsGroupInfo &groupInfo) = 0;
virtual bool removeGroup(const std::string &groupId) = 0;
virtual bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo) = 0;
virtual bool editGroup(const RsNodeGroupId& groupId, RsGroupInfo& groupInfo) = 0;
virtual bool removeGroup(const RsNodeGroupId& groupId) = 0;
virtual bool getGroupInfo(const RsNodeGroupId& groupId, RsGroupInfo& groupInfo) = 0;
virtual bool getGroupInfoList(std::list<RsGroupInfo>& groupInfoList) = 0;
// groupId == "" && assign == false -> remove from all groups
virtual bool assignPeerToGroup(const std::string &groupId, const RsPgpId& peerId, bool assign) = 0;
virtual bool assignPeersToGroup(const std::string &groupId, const std::list<RsPgpId> &peerIds, bool assign) = 0;
virtual bool assignPeerToGroup(const RsNodeGroupId& groupId, const RsPgpId& peerId, bool assign) = 0;
virtual bool assignPeersToGroup(const RsNodeGroupId& groupId, const std::list<RsPgpId>& peerIds, bool assign) = 0;
/* Group sharing permission */

View File

@ -1280,7 +1280,7 @@ bool p3Peers::addGroup(RsGroupInfo &groupInfo)
return res ;
}
bool p3Peers::editGroup(const std::string &groupId, RsGroupInfo &groupInfo)
bool p3Peers::editGroup(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::editGroup()" << std::endl;
@ -1292,7 +1292,7 @@ bool p3Peers::editGroup(const std::string &groupId, RsGroupInfo &groupInfo)
return res ;
}
bool p3Peers::removeGroup(const std::string &groupId)
bool p3Peers::removeGroup(const RsNodeGroupId &groupId)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::removeGroup()" << std::endl;
@ -1303,7 +1303,7 @@ bool p3Peers::removeGroup(const std::string &groupId)
return res ;
}
bool p3Peers::getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo)
bool p3Peers::getGroupInfo(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::getGroupInfo()" << std::endl;
@ -1321,7 +1321,7 @@ bool p3Peers::getGroupInfoList(std::list<RsGroupInfo> &groupInfoList)
return mPeerMgr->getGroupInfoList(groupInfoList);
}
bool p3Peers::assignPeerToGroup(const std::string &groupId, const RsPgpId& peerId, bool assign)
bool p3Peers::assignPeerToGroup(const RsNodeGroupId &groupId, const RsPgpId& peerId, bool assign)
{
std::list<RsPgpId> peerIds;
peerIds.push_back(peerId);
@ -1329,7 +1329,7 @@ bool p3Peers::assignPeerToGroup(const std::string &groupId, const RsPgpId& peerI
return assignPeersToGroup(groupId, peerIds, assign);
}
bool p3Peers::assignPeersToGroup(const std::string &groupId, const std::list<RsPgpId> &peerIds, bool assign)
bool p3Peers::assignPeersToGroup(const RsNodeGroupId &groupId, const std::list<RsPgpId> &peerIds, bool assign)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::assignPeersToGroup()" << std::endl;

View File

@ -124,12 +124,12 @@ public:
/* Group Stuff */
virtual bool addGroup(RsGroupInfo &groupInfo);
virtual bool editGroup(const std::string &groupId, RsGroupInfo &groupInfo);
virtual bool removeGroup(const std::string &groupId);
virtual bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo);
virtual bool editGroup(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo);
virtual bool removeGroup(const RsNodeGroupId &groupId);
virtual bool getGroupInfo(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo);
virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList);
virtual bool assignPeerToGroup(const std::string &groupId, const RsPgpId &peerId, bool assign);
virtual bool assignPeersToGroup(const std::string &groupId, const std::list<RsPgpId>& peerIds, bool assign);
virtual bool assignPeerToGroup(const RsNodeGroupId &groupId, const RsPgpId &peerId, bool assign);
virtual bool assignPeersToGroup(const RsNodeGroupId &groupId, const std::list<RsPgpId>& peerIds, bool assign);
virtual FileSearchFlags computePeerPermissionFlags(const RsPeerId& peer_id,FileStorageFlags share_flags,const std::list<std::string>& parent_groups);

View File

@ -682,7 +682,7 @@ uint32_t RsPeerConfigSerialiser::size(RsItem *i)
{
RsPeerStunItem *psi;
RsPeerNetItem *pni;
RsPeerGroupItem *pgi;
RsPeerGroupItem_deprecated *pgi;
RsPeerServicePermissionItem *pri;
RsPeerBandwidthLimitsItem *pblitem;
@ -694,7 +694,7 @@ uint32_t RsPeerConfigSerialiser::size(RsItem *i)
{
return sizeStun(psi);
}
else if (NULL != (pgi = dynamic_cast<RsPeerGroupItem *>(i)))
else if (NULL != (pgi = dynamic_cast<RsPeerGroupItem_deprecated *>(i)))
{
return sizeGroup(pgi);
}
@ -715,7 +715,7 @@ bool RsPeerConfigSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsi
{
RsPeerNetItem *pni;
RsPeerStunItem *psi;
RsPeerGroupItem *pgi;
RsPeerGroupItem_deprecated *pgi;
RsPeerServicePermissionItem *pri;
RsPeerBandwidthLimitsItem *pblitem;
@ -727,7 +727,7 @@ bool RsPeerConfigSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsi
{
return serialiseStun(psi, data, pktsize);
}
else if (NULL != (pgi = dynamic_cast<RsPeerGroupItem *>(i)))
else if (NULL != (pgi = dynamic_cast<RsPeerGroupItem_deprecated *>(i)))
{
return serialiseGroup(pgi, data, pktsize);
}
@ -764,7 +764,7 @@ RsItem *RsPeerConfigSerialiser::deserialise(void *data, uint32_t *pktsize)
return deserialiseNet(data, pktsize);
case RS_PKT_SUBTYPE_PEER_STUN:
return deserialiseStun(data, pktsize);
case RS_PKT_SUBTYPE_PEER_GROUP:
case RS_PKT_SUBTYPE_PEER_GROUP_deprecated:
return deserialiseGroup(data, pktsize);
case RS_PKT_SUBTYPE_PEER_PERMISSIONS:
return deserialisePermissions(data, pktsize);
@ -1312,16 +1312,11 @@ RsPeerStunItem *RsPeerConfigSerialiser::deserialiseStun(void *data, uint32_t *si
}
/*************************************************************************/
RsPeerGroupItem::RsPeerGroupItem() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_PEER_GROUP)
RsNodeGroupItem::RsNodeGroupItem() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_NODE_GROUP)
{
}
RsPeerGroupItem::~RsPeerGroupItem()
{
}
void RsPeerGroupItem::clear()
void RsNodeGroupItem::clear()
{
id.clear();
name.clear();
@ -1329,7 +1324,68 @@ void RsPeerGroupItem::clear()
pgpList.ids.clear();
}
std::ostream &RsPeerGroupItem::print(std::ostream &out, uint16_t indent)
std::ostream &RsNodeGroupItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsNodeGroupItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "groupId: " << id << std::endl;
printIndent(out, int_Indent);
out << "groupName: " << name << std::endl;
printIndent(out, int_Indent);
out << "groupFlag: " << flag << std::endl;
std::set<RsPgpId>::iterator it;
for (it = pgpList.ids.begin(); it != pgpList.ids.end(); ++it) {
printIndent(out, int_Indent);
out << "peerId: " << it->toStdString() << std::endl;
}
printRsItemEnd(out, "RsNodeGroupItem", indent);
return out;
}
/* set data from RsGroupInfo to RsPeerGroupItem */
void RsNodeGroupItem::set(RsGroupInfo &groupInfo)
{
id = groupInfo.id;
name = groupInfo.name;
flag = groupInfo.flag;
pgpList.ids = groupInfo.peerIds;
}
/* get data from RsGroupInfo to RsPeerGroupItem */
void RsNodeGroupItem::get(RsGroupInfo &groupInfo)
{
groupInfo.id = id;
groupInfo.name = name;
groupInfo.flag = flag;
groupInfo.peerIds = pgpList.ids;
}
/*************************************************************************/
/* DEPRECATED CODE. SHOULD BE REMOVED WHEN EVERYONE USES THE NEW CLASS */
/*************************************************************************/
RsPeerGroupItem_deprecated::RsPeerGroupItem_deprecated() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_PEER_GROUP_deprecated)
{
}
RsPeerGroupItem_deprecated::~RsPeerGroupItem_deprecated()
{
}
void RsPeerGroupItem_deprecated::clear()
{
id.clear();
name.clear();
flag = 0;
pgpList.ids.clear();
}
std::ostream &RsPeerGroupItem_deprecated::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsPeerGroupItem", indent);
uint16_t int_Indent = indent + 2;
@ -1354,7 +1410,7 @@ std::ostream &RsPeerGroupItem::print(std::ostream &out, uint16_t indent)
}
/* set data from RsGroupInfo to RsPeerGroupItem */
void RsPeerGroupItem::set(RsGroupInfo &groupInfo)
void RsPeerGroupItem_deprecated::set(RsGroupInfo &groupInfo)
{
id = groupInfo.id;
name = groupInfo.name;
@ -1363,7 +1419,7 @@ void RsPeerGroupItem::set(RsGroupInfo &groupInfo)
}
/* get data from RsGroupInfo to RsPeerGroupItem */
void RsPeerGroupItem::get(RsGroupInfo &groupInfo)
void RsPeerGroupItem_deprecated::get(RsGroupInfo &groupInfo)
{
groupInfo.id = id;
groupInfo.name = name;
@ -1373,7 +1429,7 @@ void RsPeerGroupItem::get(RsGroupInfo &groupInfo)
/*************************************************************************/
uint32_t RsPeerConfigSerialiser::sizeGroup(RsPeerGroupItem *i)
uint32_t RsPeerConfigSerialiser::sizeGroup(RsPeerGroupItem_deprecated *i)
{
uint32_t s = 8; /* header */
s += 4; /* version */
@ -1384,7 +1440,7 @@ uint32_t RsPeerConfigSerialiser::sizeGroup(RsPeerGroupItem *i)
return s;
}
bool RsPeerConfigSerialiser::serialiseGroup(RsPeerGroupItem *item, void *data, uint32_t *size)
bool RsPeerConfigSerialiser::serialiseGroup(RsPeerGroupItem_deprecated *item, void *data, uint32_t *size)
{
uint32_t tlvsize = RsPeerConfigSerialiser::sizeGroup(item);
uint32_t offset = 0;
@ -1426,7 +1482,7 @@ bool RsPeerConfigSerialiser::serialiseGroup(RsPeerGroupItem *item, void *data, u
return ok;
}
RsPeerGroupItem *RsPeerConfigSerialiser::deserialiseGroup(void *data, uint32_t *size)
RsPeerGroupItem_deprecated *RsPeerConfigSerialiser::deserialiseGroup(void *data, uint32_t *size)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
@ -1437,7 +1493,7 @@ RsPeerGroupItem *RsPeerConfigSerialiser::deserialiseGroup(void *data, uint32_t *
if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) ||
(RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) ||
(RS_PKT_TYPE_PEER_CONFIG != getRsItemType(rstype)) ||
(RS_PKT_SUBTYPE_PEER_GROUP != getRsItemSubType(rstype)))
(RS_PKT_SUBTYPE_PEER_GROUP_deprecated != getRsItemSubType(rstype)))
{
return NULL; /* wrong type */
}
@ -1450,7 +1506,7 @@ RsPeerGroupItem *RsPeerConfigSerialiser::deserialiseGroup(void *data, uint32_t *
bool ok = true;
RsPeerGroupItem *item = new RsPeerGroupItem();
RsPeerGroupItem_deprecated *item = new RsPeerGroupItem_deprecated();
item->clear();
/* skip the header */

View File

@ -52,9 +52,10 @@ const uint8_t RS_PKT_SUBTYPE_KEY_VALUE = 0x01;
/* PEER CONFIG SUBTYPES */
const uint8_t RS_PKT_SUBTYPE_PEER_STUN = 0x02;
const uint8_t RS_PKT_SUBTYPE_PEER_NET = 0x03;
const uint8_t RS_PKT_SUBTYPE_PEER_GROUP = 0x04;
const uint8_t RS_PKT_SUBTYPE_PEER_GROUP_deprecated = 0x04;
const uint8_t RS_PKT_SUBTYPE_PEER_PERMISSIONS = 0x05;
const uint8_t RS_PKT_SUBTYPE_PEER_BANDLIMITS = 0x06;
const uint8_t RS_PKT_SUBTYPE_NODE_GROUP = 0x07;
/* FILE CONFIG SUBTYPES */
const uint8_t RS_PKT_SUBTYPE_FILE_TRANSFER = 0x01;
@ -134,11 +135,11 @@ class RsPeerBandwidthLimitsItem : public RsItem
std::map<RsPgpId,PeerBandwidthLimits> peers ;
};
class RsPeerGroupItem : public RsItem
class RsPeerGroupItem_deprecated : public RsItem
{
public:
RsPeerGroupItem();
virtual ~RsPeerGroupItem();
RsPeerGroupItem_deprecated();
virtual ~RsPeerGroupItem_deprecated();
virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
@ -156,6 +157,29 @@ public:
RsTlvPgpIdSet pgpList;
};
class RsNodeGroupItem: public RsItem
{
public:
RsNodeGroupItem();
virtual ~RsNodeGroupItem() {}
virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
explicit RsNodeGroupItem(const RsGroupInfo&) ;
// /* set data from RsGroupInfo to RsPeerGroupItem */
// void set(RsGroupInfo &groupInfo);
// /* get data from RsGroupInfo to RsPeerGroupItem */
// void get(RsGroupInfo &groupInfo);
/* Mandatory */
RsNodeGroupId id;
std::string name;
uint32_t flag;
RsTlvPgpIdSet pgpList;
};
class RsPeerStunItem: public RsItem
{
@ -197,9 +221,9 @@ virtual uint32_t sizeStun(RsPeerStunItem *);
virtual bool serialiseStun (RsPeerStunItem *item, void *data, uint32_t *size);
virtual RsPeerStunItem * deserialiseStun(void *data, uint32_t *size);
virtual uint32_t sizeGroup(RsPeerGroupItem *);
virtual bool serialiseGroup (RsPeerGroupItem *item, void *data, uint32_t *size);
virtual RsPeerGroupItem * deserialiseGroup(void *data, uint32_t *size);
virtual uint32_t sizeGroup(RsPeerGroupItem_deprecated *);
virtual bool serialiseGroup (RsPeerGroupItem_deprecated *item, void *data, uint32_t *size);
virtual RsPeerGroupItem_deprecated * deserialiseGroup(void *data, uint32_t *size);
virtual uint32_t sizePeerBandwidthLimits(RsPeerBandwidthLimitsItem *);
virtual bool serialisePeerBandwidthLimits (RsPeerBandwidthLimitsItem *item, void *data, uint32_t *size);

View File

@ -204,6 +204,7 @@ const uint16_t TLV_TYPE_PGPIDSET = 0x1023;
const uint16_t TLV_TYPE_RECOGNSET = 0x1024;
const uint16_t TLV_TYPE_GXSIDSET = 0x1025;
const uint16_t TLV_TYPE_GXSCIRCLEIDSET= 0x1026;
const uint16_t TLV_TYPE_GXSGROUPIDSET = 0x1027;
const uint16_t TLV_TYPE_SERVICESET = 0x1030;

View File

@ -120,6 +120,7 @@ typedef t_RsTlvIdSet<RsPgpId,TLV_TYPE_PGPIDSET> RsTlvPgpIdSet ;
typedef t_RsTlvIdSet<Sha1CheckSum, TLV_TYPE_HASHSET> RsTlvHashSet ;
typedef t_RsTlvIdSet<RsGxsId, TLV_TYPE_GXSIDSET> RsTlvGxsIdSet ;
typedef t_RsTlvIdSet<RsGxsCircleId,TLV_TYPE_GXSCIRCLEIDSET> RsTlvGxsCircleIdSet ;
typedef t_RsTlvIdSet<RsGxsGroupId, TLV_TYPE_GXSGROUPIDSET> RsTlvGxsGroupIdSet ;
class RsTlvServiceIdSet: public RsTlvItem
{