Ported branch commits:

2951: cleaned up some desastrous code in rsdiscitems.cc

	2952: put back an exit when the local address+port are already in use. 
			Otherwise this corrupts file lists, config files etc.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2953 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-05-19 20:08:58 +00:00
parent 8673924374
commit 4b9b15be27
2 changed files with 39 additions and 36 deletions

View File

@ -213,7 +213,7 @@ int pqissllistenbase::setuplisten()
pqioutput(PQL_ALERT, pqissllistenzone, out.str()); pqioutput(PQL_ALERT, pqissllistenzone, out.str());
std::cerr << out.str() << std::endl; std::cerr << out.str() << std::endl;
return -1; exit(1) ;
} }
else else
{ {

View File

@ -231,7 +231,7 @@ RsDiscAskInfo *RsDiscSerialiser::deserialiseAskInfo(void *data, uint32_t *pktsiz
bool ok = true; bool ok = true;
/* ready to load */ /* ready to load */
RsDiscAskInfo *item = new RsDiscAskInfo(); RsDiscAskInfo *item = new RsDiscAskInfo();
item->clear(); item->clear();
/* skip the header */ /* skip the header */
@ -303,13 +303,12 @@ uint32_t RsDiscSerialiser::sizeReply(RsDiscReply *item)
{ {
uint32_t s = 8; /* header */ uint32_t s = 8; /* header */
s += GetTlvStringSize(item->aboutId); s += GetTlvStringSize(item->aboutId);
s += GetTlvStringSize(item->certGPG); s += GetTlvStringSize(item->certGPG);
RsPeerConfigSerialiser *rss = new RsPeerConfigSerialiser(); RsPeerConfigSerialiser rss ;
for (std::list<RsPeerNetItem>::iterator it = item->rsPeerList.begin(); it != item->rsPeerList.end(); it++){
RsPeerNetItem pitem = *it; for (std::list<RsPeerNetItem>::iterator it = item->rsPeerList.begin(); it != item->rsPeerList.end(); it++)
s += rss->size(&pitem); s += rss.size(&(*it)) ;
}
return s; return s;
} }
@ -339,22 +338,21 @@ bool RsDiscSerialiser::serialiseReply(RsDiscReply *item, void *data, uint32_
/* add mandatory parts first */ /* add mandatory parts first */
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PEERID, item->aboutId); ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PEERID, item->aboutId);
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_CERT_GPG, item->certGPG); ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_CERT_GPG, item->certGPG);
//store the ip list //store the ip list
RsPeerConfigSerialiser *rss = new RsPeerConfigSerialiser(); RsPeerConfigSerialiser rss ;
std::list<RsPeerNetItem>::iterator pitemIt; std::list<RsPeerNetItem>::iterator pitemIt;
for (pitemIt = item->rsPeerList.begin(); pitemIt!=(item->rsPeerList.end()); pitemIt++) {
void *pitemData = malloc(16000); for (pitemIt = item->rsPeerList.begin(); pitemIt!=(item->rsPeerList.end()) && ok; ++pitemIt)
uint32_t size = 16000; {
RsPeerNetItem pitem = *pitemIt; uint32_t size = 0;
ok &= rss->serialise(&pitem, pitemData, &size); ok &= rss.serialise(&(*pitemIt), (void *) (((char *) data) + offset), &size);
memcpy((void *) (((char *) data) + offset), pitemData, size); offset += size;
free(pitemData);
offset += size;
} }
if (offset != tlvsize) { if (offset != tlvsize)
{
ok = false; ok = false;
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::serialiseReply() Size Error! " << std::endl; std::cerr << "RsDiscSerialiser::serialiseReply() Size Error! " << std::endl;
@ -404,24 +402,28 @@ RsDiscReply *RsDiscSerialiser::deserialiseReply(void *data, uint32_t *pktsize)
offset += 8; offset += 8;
/* get mandatory parts first */ /* get mandatory parts first */
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PEERID, item->aboutId); ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PEERID, item->aboutId);
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_CERT_GPG, item->certGPG); ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_CERT_GPG, item->certGPG);
//get the peernet address list //get the peernet address list
RsPeerConfigSerialiser *rss = new RsPeerConfigSerialiser(); RsPeerConfigSerialiser rss ;
std::list<RsPeerNetItem> rsPeerNetItemList;
while (offset < rssize) {
void *peerNetdata = malloc(16000);
uint32_t peerNetSize = (*pktsize) - offset;
memcpy(peerNetdata, (void *) (((char *) data) + offset), peerNetSize);
RsPeerNetItem *rsPeerNetItem = (RsPeerNetItem*)rss->deserialise(peerNetdata, &peerNetSize);
offset += peerNetSize;
if(rsPeerNetItem != NULL) while (offset < rssize)
item->rsPeerList.push_back(*rsPeerNetItem); {
uint32_t peerNetSize = rssize - offset ;
RsPeerNetItem *rsPeerNetItem = (RsPeerNetItem*)rss.deserialise((void *) (((char *) data) + offset), &peerNetSize);
offset += peerNetSize;
if(rsPeerNetItem == NULL)
break ;
item->rsPeerList.push_back(*rsPeerNetItem);
delete rsPeerNetItem ;
} }
if (offset != rssize) { if (offset != rssize)
{
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseReply() offset != rssize" << std::endl; std::cerr << "RsDiscSerialiser::deserialiseReply() offset != rssize" << std::endl;
#endif #endif
@ -430,7 +432,8 @@ RsDiscReply *RsDiscSerialiser::deserialiseReply(void *data, uint32_t *pktsize)
return NULL; return NULL;
} }
if (!ok) { if (!ok)
{
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseReply() ok = false" << std::endl; std::cerr << "RsDiscSerialiser::deserialiseReply() ok = false" << std::endl;
#endif #endif