From 4ee9effc4e50f263100eaa433ec68b9fd67a3e06 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 4 Jul 2016 23:55:48 -0400 Subject: [PATCH] changed internal storage of groups of friend nodes so as to use an abstract ID instead of a string (phase 1 of local circles) --- libretroshare/src/pqi/p3linkmgr.cc | 2 - libretroshare/src/pqi/p3linkmgr.h | 5 +- libretroshare/src/pqi/p3peermgr.cc | 291 +++++++++--------- libretroshare/src/pqi/p3peermgr.h | 264 ++++++++-------- libretroshare/src/retroshare/rsids.h | 7 +- libretroshare/src/retroshare/rspeers.h | 32 +- libretroshare/src/rsserver/p3peers.cc | 10 +- libretroshare/src/rsserver/p3peers.h | 10 +- libretroshare/src/serialiser/rsconfigitems.cc | 90 +++++- libretroshare/src/serialiser/rsconfigitems.h | 46 ++- libretroshare/src/serialiser/rstlvbase.h | 1 + libretroshare/src/serialiser/rstlvidset.h | 11 +- 12 files changed, 420 insertions(+), 349 deletions(-) diff --git a/libretroshare/src/pqi/p3linkmgr.cc b/libretroshare/src/pqi/p3linkmgr.cc index 2e58b8f4b..26a27dc45 100644 --- a/libretroshare/src/pqi/p3linkmgr.cc +++ b/libretroshare/src/pqi/p3linkmgr.cc @@ -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 */ diff --git a/libretroshare/src/pqi/p3linkmgr.h b/libretroshare/src/pqi/p3linkmgr.h index c7a551177..1fee7d6f2 100644 --- a/libretroshare/src/pqi/p3linkmgr.h +++ b/libretroshare/src/pqi/p3linkmgr.h @@ -132,7 +132,7 @@ class peerConnectState }; class p3tunnel; -class RsPeerGroupItem; +class RsPeerGroupItem_deprecated; class RsGroupInfo; class p3PeerMgr; @@ -339,9 +339,6 @@ private: std::map mFriendList; std::map mOthersList; - std::list groupList; - uint32_t lastGroupId; - /* relatively static list of banned ip addresses */ std::list mBannedIpList; }; diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index 53ac4f12f..f6271b003 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -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 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& 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& saveData) #endif saveData.push_back(item); - saveCleanupList.push_back(item); /* iterate through all friends and save */ std::map::iterator it; @@ -2003,7 +2000,6 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list& 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& 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& saveData) vitem->tlvkvs.pairs.push_back(kv) ; saveData.push_back(vitem); - saveCleanupList.push_back(vitem); /* save groups */ - std::list::iterator groupIt; - for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) { - saveData.push_back(*groupIt); // no delete - } + for ( std::map::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& load) continue; } - RsPeerGroupItem *gitem = dynamic_cast(*it) ; + RsPeerGroupItem_deprecated *gitem = dynamic_cast(*it) ; + if (gitem) { RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ @@ -2304,20 +2297,48 @@ bool p3PeerMgrIMPL::loadList(std::list& 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 ; - continue; + 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(*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(*it) ; if(pblitem) @@ -2363,42 +2384,19 @@ bool p3PeerMgrIMPL::loadList(std::list& 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::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) { - /* 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++); - } + groupList[info.id] = info; } - } - - /* 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); - } - } } // If we are hidden - don't want ExtAddrFinder - ever! @@ -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 *******/ + { + RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ - std::list::iterator groupIt; - for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) { - if ((*groupIt)->id == groupId) { - break; - } - } + std::map::iterator it = groupList.find(groupId) ; - if (groupIt != groupList.end()) { - if ((*groupIt)->flag & RS_GROUP_FLAG_STANDARD) { - // can't edit standard groups - } else { - changed = true; - (*groupIt)->set(groupInfo); - } - } - } + if(it == groupList.end()) + { + std::cerr << "(EE) cannot find local node group with ID " << groupId << std::endl; + return false ; + } - if (changed) { + if (it->second.flag & RS_GROUP_FLAG_STANDARD) + { + // can't edit standard groups + std::cerr << "(EE) cannot edit standard group with ID " << groupId << std::endl; + return false ; + } + else + { + changed = true; + it->second = groupInfo; + } + } + + 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::iterator groupIt; - for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) { - if ((*groupIt)->id == groupId) { - break; - } - } + std::map::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::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,82 +2575,69 @@ 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::iterator groupIt; - for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) { - if ((*groupIt)->id == groupId) { - (*groupIt)->get(groupInfo); + std::map::iterator it = groupList.find(groupId) ; - return true; - } - } + if(it == groupList.end()) + return false ; - return false; + groupInfo = it->second; + + return true; } -bool p3PeerMgrIMPL::getGroupInfoList(std::list &groupInfoList) +bool p3PeerMgrIMPL::getGroupInfoList(std::list& groupInfoList) { RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ - std::list::iterator groupIt; - for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) { - RsGroupInfo groupInfo; - (*groupIt)->get(groupInfo); - groupInfoList.push_back(groupInfo); - } + for (std::map ::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 &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 &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::iterator groupIt; - for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) { - if (groupId.empty() || (*groupIt)->id == groupId) { - RsPeerGroupItem *groupItem = *groupIt; + for (std::map::iterator groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) + if (groupId.isNull() || groupIt->first == groupId) + { + RsGroupInfo& groupItem = groupIt->second; - std::list::const_iterator peerIt; - for (peerIt = peerIds.begin(); peerIt != peerIds.end(); ++peerIt) { - std::set::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); - changed = true; - } - } else { - if (peerIt1 != groupItem->pgpList.ids.end()) { - groupItem->pgpList.ids.erase(peerIt1); - changed = true; - } + for (std::list::const_iterator peerIt = peerIds.begin(); peerIt != peerIds.end(); ++peerIt) + { + std::set::iterator peerIt1 = groupItem.peerIds.find(*peerIt); + + if (assign) + { + groupItem.peerIds.insert(*peerIt); + changed = true; + } + else + { + groupItem.peerIds.erase(*peerIt); + changed = true; } } - if (groupId.empty() == false) { + if (!groupId.isNull()) break; - } } - } } if (changed) { diff --git a/libretroshare/src/pqi/p3peermgr.h b/libretroshare/src/pqi/p3peermgr.h index 62c194bbf..e73377677 100644 --- a/libretroshare/src/pqi/p3peermgr.h +++ b/libretroshare/src/pqi/p3peermgr.h @@ -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 &groupInfoList) = 0; -virtual bool assignPeersToGroup(const std::string &groupId, const std::list &peerIds, bool assign) = 0; +virtual bool assignPeersToGroup(const RsNodeGroupId &groupId, const std::list &peerIds, bool assign) = 0; virtual bool resetOwnExternalAddressList() = 0 ; @@ -231,181 +231,181 @@ virtual bool locked_computeCurrentBestOwnExtAddressCandidate(sockaddr_storage class p3PeerMgrIMPL: public p3PeerMgr, public p3Config { - public: +public: -/************************************************************************************************/ -/* EXTERNAL INTERFACE */ -/************************************************************************************************/ + /************************************************************************************************/ + /* EXTERNAL INTERFACE */ + /************************************************************************************************/ -virtual bool addFriend(const RsPeerId&ssl_id, const RsPgpId&gpg_id, uint32_t netMode = RS_NET_MODE_UDP, - uint16_t vsDisc = RS_VS_DISC_FULL, uint16_t vsDht = RS_VS_DHT_FULL, - time_t lastContact = 0,ServicePermissionFlags = ServicePermissionFlags(RS_NODE_PERM_DEFAULT)); -virtual bool removeFriend(const RsPeerId &ssl_id, bool removePgpId); -virtual bool removeFriend(const RsPgpId &pgp_id); + virtual bool addFriend(const RsPeerId&ssl_id, const RsPgpId&gpg_id, uint32_t netMode = RS_NET_MODE_UDP, + uint16_t vsDisc = RS_VS_DISC_FULL, uint16_t vsDht = RS_VS_DHT_FULL, + time_t lastContact = 0,ServicePermissionFlags = ServicePermissionFlags(RS_NODE_PERM_DEFAULT)); + virtual bool removeFriend(const RsPeerId &ssl_id, bool removePgpId); + virtual bool removeFriend(const RsPgpId &pgp_id); -virtual bool isFriend(const RsPeerId &ssl_id); + virtual bool isFriend(const RsPeerId &ssl_id); -virtual bool getAssociatedPeers(const RsPgpId &gpg_id, std::list &ids); -virtual bool removeAllFriendLocations(const RsPgpId &gpgid); + virtual bool getAssociatedPeers(const RsPgpId &gpg_id, std::list &ids); + virtual bool removeAllFriendLocations(const RsPgpId &gpgid); - /******************** Groups **********************/ - /* This is solely used by p3peers - makes sense */ + /******************** Groups **********************/ + /* 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 getGroupInfoList(std::list &groupInfoList); -virtual bool assignPeersToGroup(const std::string &groupId, const std::list &peerIds, bool assign); + virtual bool addGroup(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 &groupInfoList); + virtual bool assignPeersToGroup(const RsNodeGroupId &groupId, const std::list &peerIds, bool assign); virtual ServicePermissionFlags servicePermissionFlags(const RsPgpId& gpg_id) ; - virtual ServicePermissionFlags servicePermissionFlags(const RsPeerId& ssl_id) ; - virtual void setServicePermissionFlags(const RsPgpId& gpg_id,const ServicePermissionFlags& flags) ; + virtual ServicePermissionFlags servicePermissionFlags(const RsPeerId& ssl_id) ; + virtual void setServicePermissionFlags(const RsPgpId& gpg_id,const ServicePermissionFlags& flags) ; - /**************** Set Net Info ****************/ - /* - * These functions are used by: - * 1) p3linkmgr - * 2) p3peers - reasonable - * 3) p3disc - reasonable - */ + /**************** Set Net Info ****************/ + /* + * These functions are used by: + * 1) p3linkmgr + * 2) p3peers - reasonable + * 3) p3disc - reasonable + */ -virtual bool setLocalAddress(const RsPeerId &id, const struct sockaddr_storage &addr); -virtual bool setExtAddress(const RsPeerId &id, const struct sockaddr_storage &addr); -virtual bool setDynDNS(const RsPeerId &id, const std::string &dyndns); -virtual bool addCandidateForOwnExternalAddress(const RsPeerId& from, const struct sockaddr_storage &addr) ; -virtual bool getExtAddressReportedByFriends(struct sockaddr_storage& addr, uint8_t &isstable) ; + virtual bool setLocalAddress(const RsPeerId &id, const struct sockaddr_storage &addr); + virtual bool setExtAddress(const RsPeerId &id, const struct sockaddr_storage &addr); + virtual bool setDynDNS(const RsPeerId &id, const std::string &dyndns); + virtual bool addCandidateForOwnExternalAddress(const RsPeerId& from, const struct sockaddr_storage &addr) ; + virtual bool getExtAddressReportedByFriends(struct sockaddr_storage& addr, uint8_t &isstable) ; -virtual bool setNetworkMode(const RsPeerId &id, uint32_t netMode); -virtual bool setVisState(const RsPeerId &id, uint16_t vs_disc, uint16_t vs_dht); + virtual bool setNetworkMode(const RsPeerId &id, uint32_t netMode); + virtual bool setVisState(const RsPeerId &id, uint16_t vs_disc, uint16_t vs_dht); -virtual bool setLocation(const RsPeerId &pid, const std::string &location); -virtual bool setHiddenDomainPort(const RsPeerId &id, const std::string &domain_addr, const uint16_t domain_port); - -virtual bool updateCurrentAddress(const RsPeerId& id, const pqiIpAddress &addr); -virtual bool updateLastContact(const RsPeerId& id); -virtual bool updateAddressList(const RsPeerId& id, const pqiIpAddrSet &addrs); + virtual bool setLocation(const RsPeerId &pid, const std::string &location); + virtual bool setHiddenDomainPort(const RsPeerId &id, const std::string &domain_addr, const uint16_t domain_port); + + virtual bool updateCurrentAddress(const RsPeerId& id, const pqiIpAddress &addr); + virtual bool updateLastContact(const RsPeerId& id); + virtual bool updateAddressList(const RsPeerId& id, const pqiIpAddrSet &addrs); virtual bool resetOwnExternalAddressList() ; - // THIS MUST ONLY BE CALLED BY NETMGR!!!! -virtual bool UpdateOwnAddress(const struct sockaddr_storage &local_addr, const struct sockaddr_storage &ext_addr); - /**************** Net Status Info ****************/ - /* - * MUST RATIONALISE THE DATA FROM THESE FUNCTIONS - * These functions are used by: - * 1) p3face-config ... to remove! - * 2) p3peers - reasonable - * 3) p3disc - reasonable - */ + // THIS MUST ONLY BE CALLED BY NETMGR!!!! + virtual bool UpdateOwnAddress(const struct sockaddr_storage &local_addr, const struct sockaddr_storage &ext_addr); + /**************** Net Status Info ****************/ + /* + * MUST RATIONALISE THE DATA FROM THESE FUNCTIONS + * These functions are used by: + * 1) p3face-config ... to remove! + * 2) p3peers - reasonable + * 3) p3disc - reasonable + */ -virtual bool getOwnNetStatus(peerState &state); -virtual bool getFriendNetStatus(const RsPeerId &id, peerState &state); -virtual bool getOthersNetStatus(const RsPeerId &id, peerState &state); + virtual bool getOwnNetStatus(peerState &state); + virtual bool getFriendNetStatus(const RsPeerId &id, peerState &state); + virtual bool getOthersNetStatus(const RsPeerId &id, peerState &state); -virtual bool getPeerName(const RsPeerId& ssl_id, std::string& name); -virtual bool getGpgId(const RsPeerId& sslId, RsPgpId& gpgId); -virtual uint32_t getConnectionType(const RsPeerId& sslId); + virtual bool getPeerName(const RsPeerId& ssl_id, std::string& name); + virtual bool getGpgId(const RsPeerId& sslId, RsPgpId& gpgId); + virtual uint32_t getConnectionType(const RsPeerId& sslId); -virtual bool setProxyServerAddress(const uint32_t type, const struct sockaddr_storage &proxy_addr); -virtual bool getProxyServerAddress(const uint32_t type, struct sockaddr_storage &proxy_addr); -virtual bool getProxyServerStatus(const uint32_t type, uint32_t &proxy_status); -virtual bool isHidden(); -virtual bool isHidden(const uint32_t type); -virtual bool isHiddenPeer(const RsPeerId &ssl_id); -virtual bool isHiddenPeer(const RsPeerId &ssl_id, const uint32_t type); -virtual bool getProxyAddress(const RsPeerId& ssl_id, struct sockaddr_storage &proxy_addr, std::string &domain_addr, uint16_t &domain_port); -virtual uint32_t hiddenDomainToHiddenType(const std::string &domain); -virtual uint32_t getHiddenType(const RsPeerId &ssl_id); + virtual bool setProxyServerAddress(const uint32_t type, const struct sockaddr_storage &proxy_addr); + virtual bool getProxyServerAddress(const uint32_t type, struct sockaddr_storage &proxy_addr); + virtual bool getProxyServerStatus(const uint32_t type, uint32_t &proxy_status); + virtual bool isHidden(); + virtual bool isHidden(const uint32_t type); + virtual bool isHiddenPeer(const RsPeerId &ssl_id); + virtual bool isHiddenPeer(const RsPeerId &ssl_id, const uint32_t type); + virtual bool getProxyAddress(const RsPeerId& ssl_id, struct sockaddr_storage &proxy_addr, std::string &domain_addr, uint16_t &domain_port); + virtual uint32_t hiddenDomainToHiddenType(const std::string &domain); + virtual uint32_t getHiddenType(const RsPeerId &ssl_id); -virtual int getFriendCount(bool ssl, bool online); + virtual int getFriendCount(bool ssl, bool online); - /************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/ + /************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/ - // Single Use Function... shouldn't be here. used by p3serverconfig.cc -virtual bool haveOnceConnected(); + // Single Use Function... shouldn't be here. used by p3serverconfig.cc + virtual bool haveOnceConnected(); -virtual bool setMaxRates(const RsPgpId& pid,uint32_t maxUp,uint32_t maxDn); -virtual bool getMaxRates(const RsPgpId& pid,uint32_t& maxUp,uint32_t& maxDn); -virtual bool getMaxRates(const RsPeerId& pid,uint32_t& maxUp,uint32_t& maxDn); + virtual bool setMaxRates(const RsPgpId& pid,uint32_t maxUp,uint32_t maxDn); + virtual bool getMaxRates(const RsPgpId& pid,uint32_t& maxUp,uint32_t& maxDn); + virtual bool getMaxRates(const RsPeerId& pid,uint32_t& maxUp,uint32_t& maxDn); -/************************************************************************************************/ -/* Extra IMPL Functions (used by p3LinkMgr, p3NetMgr + Setup) */ -/************************************************************************************************/ + /************************************************************************************************/ + /* Extra IMPL Functions (used by p3LinkMgr, p3NetMgr + Setup) */ + /************************************************************************************************/ - p3PeerMgrIMPL( const RsPeerId& ssl_own_id, - const RsPgpId& gpg_own_id, - const std::string& gpg_own_name, - const std::string& ssl_own_location) ; + p3PeerMgrIMPL( const RsPeerId& ssl_own_id, + const RsPgpId& gpg_own_id, + const std::string& gpg_own_name, + const std::string& ssl_own_location) ; -void setManagers(p3LinkMgrIMPL *linkMgr, p3NetMgrIMPL *netMgr); + void setManagers(p3LinkMgrIMPL *linkMgr, p3NetMgrIMPL *netMgr); -bool forceHiddenNode(); -bool setupHiddenNode(const std::string &hiddenAddress, const uint16_t hiddenPort); + bool forceHiddenNode(); + bool setupHiddenNode(const std::string &hiddenAddress, const uint16_t hiddenPort); -void tick(); + void tick(); -const RsPeerId& getOwnId(); -bool setOwnNetworkMode(uint32_t netMode); -bool setOwnVisState(uint16_t vs_disc, uint16_t vs_dht); + const RsPeerId& getOwnId(); + bool setOwnNetworkMode(uint32_t netMode); + bool setOwnVisState(uint16_t vs_disc, uint16_t vs_dht); -int getConnectAddresses(const RsPeerId &id, - struct sockaddr_storage &lAddr, struct sockaddr_storage &eAddr, - pqiIpAddrSet &histAddrs, std::string &dyndns); + int getConnectAddresses(const RsPeerId &id, + struct sockaddr_storage &lAddr, struct sockaddr_storage &eAddr, + pqiIpAddrSet &histAddrs, std::string &dyndns); protected: - /* Internal Functions */ + /* Internal Functions */ -bool removeUnusedLocations(); -bool removeBannedIps(); + bool removeUnusedLocations(); + bool removeBannedIps(); -void printPeerLists(std::ostream &out); + void printPeerLists(std::ostream &out); -virtual bool locked_computeCurrentBestOwnExtAddressCandidate(sockaddr_storage &addr, uint32_t &count); + virtual bool locked_computeCurrentBestOwnExtAddressCandidate(sockaddr_storage &addr, uint32_t &count); - protected: -/*****************************************************************/ -/*********************** p3config ******************************/ - /* Key Functions to be overloaded for Full Configuration */ - virtual RsSerialiser *setupSerialiser(); - virtual bool saveList(bool &cleanup, std::list&); - virtual void saveDone(); - virtual bool loadList(std::list& load); -/*****************************************************************/ +protected: + /*****************************************************************/ + /*********************** p3config ******************************/ + /* Key Functions to be overloaded for Full Configuration */ + virtual RsSerialiser *setupSerialiser(); + virtual bool saveList(bool &cleanup, std::list&); + virtual void saveDone(); + virtual bool loadList(std::list& load); + /*****************************************************************/ - /* other important managers */ + /* other important managers */ + + p3LinkMgrIMPL *mLinkMgr; + p3NetMgrIMPL *mNetMgr; - p3LinkMgrIMPL *mLinkMgr; - p3NetMgrIMPL *mNetMgr; - private: - RsMutex mPeerMtx; /* protects below */ + RsMutex mPeerMtx; /* protects below */ - bool mStatusChanged; + bool mStatusChanged; - std::list clients; + std::list clients; - peerState mOwnState; + peerState mOwnState; - std::map mFriendList; // - std::map mOthersList; + std::map mFriendList; // + std::map mOthersList; - std::map mReportedOwnAddresses ; - - std::list groupList; - uint32_t lastGroupId; + std::map mReportedOwnAddresses ; - std::list saveCleanupList; /* TEMPORARY LIST WHEN SAVING */ + std::map groupList; + uint32_t lastGroupId; - std::map mFriendsPermissionFlags ; // permission flags for each gpg key - std::map mPeerBandwidthLimits ; // bandwidth limits for each gpg key + std::list saveCleanupList; /* TEMPORARY LIST WHEN SAVING */ - struct sockaddr_storage mProxyServerAddressTor; - struct sockaddr_storage mProxyServerAddressI2P; - uint32_t mProxyServerStatusTor ; - uint32_t mProxyServerStatusI2P ; + std::map mFriendsPermissionFlags ; // permission flags for each gpg key + std::map mPeerBandwidthLimits ; // bandwidth limits for each gpg key + + struct sockaddr_storage mProxyServerAddressTor; + struct sockaddr_storage mProxyServerAddressI2P; + uint32_t mProxyServerStatusTor ; + uint32_t mProxyServerStatusI2P ; }; diff --git a/libretroshare/src/retroshare/rsids.h b/libretroshare/src/retroshare/rsids.h index 6cd97f5ad..60b5392c7 100644 --- a/libretroshare/src/retroshare/rsids.h +++ b/libretroshare/src/retroshare/rsids.h @@ -73,14 +73,13 @@ template 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 random() { t_RsGenericIdType id ; - for(uint32_t i=0;i 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 ; diff --git a/libretroshare/src/retroshare/rspeers.h b/libretroshare/src/retroshare/rspeers.h index 3cad47cad..6d9246c81 100644 --- a/libretroshare/src/retroshare/rspeers.h +++ b/libretroshare/src/retroshare/rspeers.h @@ -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; @@ -399,14 +405,14 @@ public: virtual bool trustGPGCertificate(const RsPgpId &gpg_id, uint32_t trustlvl) = 0; /* 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 getGroupInfoList(std::list &groupInfoList) = 0; + virtual bool addGroup(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& 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 &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& peerIds, bool assign) = 0; /* Group sharing permission */ diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index a415f4987..e0dff3dd6 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -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 &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 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 &peerIds, bool assign) +bool p3Peers::assignPeersToGroup(const RsNodeGroupId &groupId, const std::list &peerIds, bool assign) { #ifdef P3PEERS_DEBUG std::cerr << "p3Peers::assignPeersToGroup()" << std::endl; diff --git a/libretroshare/src/rsserver/p3peers.h b/libretroshare/src/rsserver/p3peers.h index 25d38c9a3..7a67039f0 100644 --- a/libretroshare/src/rsserver/p3peers.h +++ b/libretroshare/src/rsserver/p3peers.h @@ -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 &groupInfoList); - virtual bool assignPeerToGroup(const std::string &groupId, const RsPgpId &peerId, bool assign); - virtual bool assignPeersToGroup(const std::string &groupId, const std::list& peerIds, bool assign); + virtual bool assignPeerToGroup(const RsNodeGroupId &groupId, const RsPgpId &peerId, bool assign); + virtual bool assignPeersToGroup(const RsNodeGroupId &groupId, const std::list& peerIds, bool assign); virtual FileSearchFlags computePeerPermissionFlags(const RsPeerId& peer_id,FileStorageFlags share_flags,const std::list& parent_groups); diff --git a/libretroshare/src/serialiser/rsconfigitems.cc b/libretroshare/src/serialiser/rsconfigitems.cc index 313beb33a..6e040f0dd 100644 --- a/libretroshare/src/serialiser/rsconfigitems.cc +++ b/libretroshare/src/serialiser/rsconfigitems.cc @@ -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(i))) + else if (NULL != (pgi = dynamic_cast(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(i))) + else if (NULL != (pgi = dynamic_cast(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,72 @@ 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 RsNodeGroupItem::clear() +{ + id.clear(); + name.clear(); + flag = 0; + pgpList.ids.clear(); +} + +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::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) { } -void RsPeerGroupItem::clear() +RsPeerGroupItem_deprecated::~RsPeerGroupItem_deprecated() +{ +} + +void RsPeerGroupItem_deprecated::clear() { id.clear(); name.clear(); @@ -1329,7 +1385,7 @@ void RsPeerGroupItem::clear() pgpList.ids.clear(); } -std::ostream &RsPeerGroupItem::print(std::ostream &out, uint16_t indent) +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 */ diff --git a/libretroshare/src/serialiser/rsconfigitems.h b/libretroshare/src/serialiser/rsconfigitems.h index 6fc9f1f6d..acf33b0e7 100644 --- a/libretroshare/src/serialiser/rsconfigitems.h +++ b/libretroshare/src/serialiser/rsconfigitems.h @@ -50,11 +50,12 @@ const uint8_t RS_PKT_TYPE_HISTORY_CONFIG = 0x06; 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_PERMISSIONS = 0x05; -const uint8_t RS_PKT_SUBTYPE_PEER_BANDLIMITS = 0x06; +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_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 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); diff --git a/libretroshare/src/serialiser/rstlvbase.h b/libretroshare/src/serialiser/rstlvbase.h index 73e0112f4..54c6cd5ed 100644 --- a/libretroshare/src/serialiser/rstlvbase.h +++ b/libretroshare/src/serialiser/rstlvbase.h @@ -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; diff --git a/libretroshare/src/serialiser/rstlvidset.h b/libretroshare/src/serialiser/rstlvidset.h index e5b3d257b..06d2906af 100644 --- a/libretroshare/src/serialiser/rstlvidset.h +++ b/libretroshare/src/serialiser/rstlvidset.h @@ -115,11 +115,12 @@ template class t_RsTlvIdSet: public RsTlvItem std::set ids ; }; -typedef t_RsTlvIdSet RsTlvPeerIdSet ; -typedef t_RsTlvIdSet RsTlvPgpIdSet ; -typedef t_RsTlvIdSet RsTlvHashSet ; -typedef t_RsTlvIdSet RsTlvGxsIdSet ; -typedef t_RsTlvIdSet RsTlvGxsCircleIdSet ; +typedef t_RsTlvIdSet RsTlvPeerIdSet ; +typedef t_RsTlvIdSet RsTlvPgpIdSet ; +typedef t_RsTlvIdSet RsTlvHashSet ; +typedef t_RsTlvIdSet RsTlvGxsIdSet ; +typedef t_RsTlvIdSet RsTlvGxsCircleIdSet ; +typedef t_RsTlvIdSet RsTlvGxsGroupIdSet ; class RsTlvServiceIdSet: public RsTlvItem {