p3StatusService::getStatusQueue

- memory leak -> "RsItem* item" was not freed, when "dynamic_cast<RsStatusItem*>" failed
- optimized return of std::list as parameter and not as return. return will copy the list and its not necessary

p3StatusService::getStatus
- memory leak -> items in "std::list<RsStatusItem* > status_items" was not freed
- potential crash, when receiving a status for an unknown peer

p3Peers::getPeerDetails
- optimized - call to "AuthSSL::getAuthSSL()->OwnId()" only once
- optimized - add ip addresses directly to "d.ipAddressList"

PeersDialog::insertPeers
- fixed possible crash, when ssl child has disappeared and was removed from tree, there was a missing continue

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3125 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2010-06-13 12:26:23 +00:00
parent 61f2c14663
commit 0d1eaba890
5 changed files with 53 additions and 51 deletions

View File

@ -996,17 +996,19 @@ bool AuthGPG::getGPGDetails(std::string id, RsPeerDetails &d)
certmap::iterator it; certmap::iterator it;
if (mKeyList.end() != (it = mKeyList.find(id))) if (mKeyList.end() != (it = mKeyList.find(id)))
{ {
d.id = it->second.id; //keep, it but can be bug gen gpgcert &cert = it->second;
d.gpg_id = it->second.id;
d.name = it->second.name;
d.email = it->second.email;
d.trustLvl = it->second.trustLvl;
d.validLvl = it->second.validLvl;
d.ownsign = it->second.ownsign;
d.gpgSigners = it->second.signers;
d.fpr = it->second.fpr;
d.accept_connection = it->second.accept_connection; d.id = cert.id; //keep, it but can be bug gen
d.gpg_id = cert.id;
d.name = cert.name;
d.email = cert.email;
d.trustLvl = cert.trustLvl;
d.validLvl = cert.validLvl;
d.ownsign = cert.ownsign;
d.gpgSigners = cert.signers;
d.fpr = cert.fpr;
d.accept_connection = cert.accept_connection;
//did the peer signed me ? //did the peer signed me ?
d.hasSignedMe = false; d.hasSignedMe = false;
@ -1019,7 +1021,7 @@ bool AuthGPG::getGPGDetails(std::string id, RsPeerDetails &d)
} }
#ifdef GPG_DEBUG #ifdef GPG_DEBUG
std::cerr << "AuthGPG::getPGPDetails() Name : " << it->second.name << std::endl; std::cerr << "AuthGPG::getPGPDetails() Name : " << cert.name << std::endl;
#endif #endif
return true; return true;
} }

View File

@ -276,8 +276,9 @@ bool p3Peers::getPeerDetails(std::string id, RsPeerDetails &d)
std::cerr << "p3Peers::getPeerDetails() called for id : " << id << std::endl; std::cerr << "p3Peers::getPeerDetails() called for id : " << id << std::endl;
#endif #endif
//first, check if it's a gpg or a ssl id. //first, check if it's a gpg or a ssl id.
std::string sOwnId = AuthSSL::getAuthSSL()->OwnId();
peerConnectState pcs; peerConnectState pcs;
if (id != AuthSSL::getAuthSSL()->OwnId() && !mConnMgr->getFriendNetStatus(id, pcs)) { if (id != sOwnId && !mConnMgr->getFriendNetStatus(id, pcs)) {
//assume is not SSL, because every ssl_id has got a friend correspondance in mConnMgr //assume is not SSL, because every ssl_id has got a friend correspondance in mConnMgr
#ifdef P3PEERS_DEBUG #ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::getPeerDetails() got a gpg id and is returning GPG details only for id : " << id << std::endl; std::cerr << "p3Peers::getPeerDetails() got a gpg id and is returning GPG details only for id : " << id << std::endl;
@ -289,7 +290,7 @@ bool p3Peers::getPeerDetails(std::string id, RsPeerDetails &d)
std::cerr << "p3Peers::getPeerDetails() got a SSL id and is returning SSL and GPG details for id : " << id << std::endl; std::cerr << "p3Peers::getPeerDetails() got a SSL id and is returning SSL and GPG details for id : " << id << std::endl;
#endif #endif
if (id == AuthSSL::getAuthSSL()->OwnId()) { if (id == sOwnId) {
mConnMgr->getOwnNetStatus(pcs); mConnMgr->getOwnNetStatus(pcs);
pcs.gpg_id = AuthGPG::getAuthGPG()->getGPGOwnId(); pcs.gpg_id = AuthGPG::getAuthGPG()->getGPGOwnId();
} }
@ -322,14 +323,13 @@ bool p3Peers::getPeerDetails(std::string id, RsPeerDetails &d)
d.dyndns = pcs.dyndns; d.dyndns = pcs.dyndns;
d.lastConnect = pcs.lastcontact; d.lastConnect = pcs.lastcontact;
d.connectPeriod = 0; d.connectPeriod = 0;
std::list<std::string> ipAddressList;
std::list<IpAddressTimed> pcsList = pcs.getIpAddressList(); std::list<IpAddressTimed> pcsList = pcs.getIpAddressList();
d.ipAddressList.clear();
for (std::list<IpAddressTimed>::iterator ipListIt = pcsList.begin(); ipListIt!=(pcsList.end()); ipListIt++) { for (std::list<IpAddressTimed>::iterator ipListIt = pcsList.begin(); ipListIt!=(pcsList.end()); ipListIt++) {
std::ostringstream toto; std::ostringstream toto;
toto << ntohs(ipListIt->ipAddr.sin_port) << " " << (time(NULL) - ipListIt->seenTime) << " sec"; toto << ntohs(ipListIt->ipAddr.sin_port) << " " << (time(NULL) - ipListIt->seenTime) << " sec";
ipAddressList.push_back(std::string(inet_ntoa(ipListIt->ipAddr.sin_addr)) + ":" + toto.str()); d.ipAddressList.push_back(std::string(inet_ntoa(ipListIt->ipAddr.sin_addr)) + ":" + toto.str());
} }
d.ipAddressList = ipAddressList;
/* Translate */ /* Translate */

View File

@ -65,8 +65,8 @@ bool p3StatusService::getStatus(std::list<StatusInfo>& statusInfo)
statusInfo.clear(); statusInfo.clear();
std::list<RsStatusItem* > status_items = getStatusQueue(); std::list<RsStatusItem* > status_items;
std::list<RsStatusItem* >::iterator rit; getStatusQueue(status_items);
std::map<std::string, StatusInfo>::iterator mit; std::map<std::string, StatusInfo>::iterator mit;
std::list<std::string> peers, peersOnline; std::list<std::string> peers, peersOnline;
std::list<std::string>::iterator pit, pit_online; std::list<std::string>::iterator pit, pit_online;
@ -98,29 +98,24 @@ bool p3StatusService::getStatus(std::list<StatusInfo>& statusInfo)
} }
// now note members who have sent specific status updates // now note members who have sent specific status updates
for(rit = status_items.begin(); rit != status_items.end(); rit++){ while (status_items.size()){
RsStatusItem* si = status_items.front();
RsStatusItem* si = dynamic_cast<RsStatusItem* >(*rit); status_items.pop_front();
if(si == NULL){
std::cerr << "p3Status::getStatus() " << "Failed to cast Item \n" << std::endl;
}
mit = mStatusInfoMap.find(si->PeerId()); mit = mStatusInfoMap.find(si->PeerId());
if(mit != mStatusInfoMap.end()){
#ifdef STATUS_DEBUG
if(mit == mStatusInfoMap.end()){
std::cerr << "p3GetStatus() " << "Could not find Peer" << si->PeerId();
std::cerr << std::endl;
}
#endif
mit->second.id = si->PeerId(); mit->second.id = si->PeerId();
mit->second.status = si->status; mit->second.status = si->status;
mit->second.time_stamp = si->sendTime; mit->second.time_stamp = si->sendTime;
#ifdef STATUS_DEBUG
} else {
std::cerr << "p3GetStatus() " << "Could not find Peer" << si->PeerId();
std::cerr << std::endl;
#endif
}
delete (si);
} }
// then fill up statusInfo list with this information // then fill up statusInfo list with this information
@ -190,19 +185,22 @@ bool p3StatusService::statusAvailable(){
/******************************/ /******************************/
std::list<RsStatusItem* > p3StatusService::getStatusQueue(){ void p3StatusService::getStatusQueue(std::list<RsStatusItem* > &ilist)
{
time_t time_now = time(NULL); time_t time_now = time(NULL);
RsItem* item; RsItem* item;
std::list<RsStatusItem* > ilist;
while(NULL != (item = recvItem())){ while(NULL != (item = recvItem())){
RsStatusItem* status_item = dynamic_cast<RsStatusItem*>(item); RsStatusItem* status_item = dynamic_cast<RsStatusItem*>(item);
if(status_item != NULL){ if(status_item == NULL) {
std::cerr << "p3Status::getStatusQueue() " << "Failed to cast Item \n" << std::endl;
delete (item);
continue;
}
#ifdef STATUS_DEBUG #ifdef STATUS_DEBUG
std::cerr << "p3StatusService::getStatusQueue()" << std::endl; std::cerr << "p3StatusService::getStatusQueue()" << std::endl;
std::cerr << "PeerId : " << status_item->PeerId() << std::endl; std::cerr << "PeerId : " << status_item->PeerId() << std::endl;
@ -212,9 +210,6 @@ std::list<RsStatusItem* > p3StatusService::getStatusQueue(){
status_item->recvTime = time_now; status_item->recvTime = time_now;
ilist.push_back(status_item); ilist.push_back(status_item);
} }
}
return ilist;
} }
/* p3Config */ /* p3Config */

View File

@ -83,7 +83,7 @@ virtual bool loadList(std::list<RsItem*> load);
private: private:
virtual std::list<RsStatusItem* > getStatusQueue(); virtual void getStatusQueue(std::list<RsStatusItem* > &ilist);
p3ConnectMgr *mConnMgr; p3ConnectMgr *mConnMgr;

View File

@ -512,9 +512,11 @@ void PeersDialog::insertPeers()
continue; continue;
} }
bool bNew = false;
if (gpg_item == NULL) { if (gpg_item == NULL) {
gpg_item = new MyTreeWidgetItem(peertreeWidget, 0); //set type to 0 for custom popup menu gpg_item = new MyTreeWidgetItem(peertreeWidget, 0); //set type to 0 for custom popup menu
gpg_item->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless); gpg_item->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless);
bNew = true;
} }
gpg_item -> setText(COLUMN_NAME, QString::fromStdString(detail.name)); gpg_item -> setText(COLUMN_NAME, QString::fromStdString(detail.name));
@ -565,6 +567,7 @@ void PeersDialog::insertPeers()
if (sslItem) { if (sslItem) {
gpg_item->removeChild(sslItem); gpg_item->removeChild(sslItem);
} }
continue;
} }
if (newChild) { if (newChild) {
@ -733,9 +736,11 @@ void PeersDialog::insertPeers()
} }
} }
/* add gpg item to the list. If item is already in the list, it won't be duplicated thanks to Qt */ if (bNew) {
/* add gpg item to the list */
peertreeWidget->addTopLevelItem(gpg_item); peertreeWidget->addTopLevelItem(gpg_item);
} }
}
} }
/* Utility Fns */ /* Utility Fns */