Added more debug to serialisers.

* print out messages when serialisation fails.
 * removed BUG in TlvGetString() which allows a zero length TLV 



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4496 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2011-07-29 15:17:39 +00:00
parent 1ee26e3ef2
commit 3d71e6338e
4 changed files with 194 additions and 73 deletions

View File

@ -29,8 +29,11 @@
#include "retroshare/rspeers.h" #include "retroshare/rspeers.h"
/*** /***
#define RSSERIAL_DEBUG 1 * #define RSSERIAL_DEBUG 1
***/ * #define RSSERIAL_ERROR_DEBUG 1
***/
#define RSSERIAL_ERROR_DEBUG 1
#include <iostream> #include <iostream>
@ -256,7 +259,7 @@ bool RsFileConfigSerialiser::serialiseTransfer(RsFileTransfer *item, void *d
if (offset != tlvsize) if (offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsFileConfigSerialiser::serialiseTransfer() Size Error! " << std::endl; std::cerr << "RsFileConfigSerialiser::serialiseTransfer() Size Error! " << std::endl;
#endif #endif
} }
@ -380,7 +383,7 @@ bool RsFileConfigSerialiser::serialiseFileItem(RsFileConfigItem *item, void
if (offset != tlvsize) if (offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsFileConfigSerialiser::serialiseFileItem() Size Error! " << std::endl; std::cerr << "RsFileConfigSerialiser::serialiseFileItem() Size Error! " << std::endl;
#endif #endif
} }
@ -497,7 +500,7 @@ RsItem *RsGeneralConfigSerialiser::deserialise(void *data, uint32_t *pktsize)
(RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) ||
(RS_PKT_TYPE_GENERAL_CONFIG != getRsItemType(rstype))) (RS_PKT_TYPE_GENERAL_CONFIG != getRsItemType(rstype)))
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsGeneralConfigSerialiser::deserialise() Wrong Type" << std::endl; std::cerr << "RsGeneralConfigSerialiser::deserialise() Wrong Type" << std::endl;
#endif #endif
return NULL; /* wrong type */ return NULL; /* wrong type */
@ -576,7 +579,7 @@ bool RsGeneralConfigSerialiser::serialiseKeyValueSet(RsConfigKeyValueSet *it
if (offset != tlvsize) if (offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsGeneralConfigSerialiser::serialiseKeyValueSet() Size Error! " << std::endl; std::cerr << "RsGeneralConfigSerialiser::serialiseKeyValueSet() Size Error! " << std::endl;
#endif #endif
} }
@ -598,7 +601,7 @@ RsConfigKeyValueSet *RsGeneralConfigSerialiser::deserialiseKeyValueSet(void *dat
(RS_PKT_TYPE_GENERAL_CONFIG != getRsItemType(rstype)) || (RS_PKT_TYPE_GENERAL_CONFIG != getRsItemType(rstype)) ||
(RS_PKT_SUBTYPE_KEY_VALUE != getRsItemSubType(rstype))) (RS_PKT_SUBTYPE_KEY_VALUE != getRsItemSubType(rstype)))
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsGeneralConfigSerialiser::deserialiseKeyValueSet() Wrong Type" << std::endl; std::cerr << "RsGeneralConfigSerialiser::deserialiseKeyValueSet() Wrong Type" << std::endl;
#endif #endif
return NULL; /* wrong type */ return NULL; /* wrong type */
@ -606,7 +609,7 @@ RsConfigKeyValueSet *RsGeneralConfigSerialiser::deserialiseKeyValueSet(void *dat
if (*pktsize < rssize) /* check size */ if (*pktsize < rssize) /* check size */
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsGeneralConfigSerialiser::deserialiseKeyValueSet() Not Enough Space" << std::endl; std::cerr << "RsGeneralConfigSerialiser::deserialiseKeyValueSet() Not Enough Space" << std::endl;
#endif #endif
return NULL; /* not enough data */ return NULL; /* not enough data */
@ -629,7 +632,7 @@ RsConfigKeyValueSet *RsGeneralConfigSerialiser::deserialiseKeyValueSet(void *dat
if (offset != rssize) if (offset != rssize)
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsGeneralConfigSerialiser::deserialiseKeyValueSet() offset != rssize" << std::endl; std::cerr << "RsGeneralConfigSerialiser::deserialiseKeyValueSet() offset != rssize" << std::endl;
#endif #endif
/* error */ /* error */
@ -639,7 +642,7 @@ RsConfigKeyValueSet *RsGeneralConfigSerialiser::deserialiseKeyValueSet(void *dat
if (!ok) if (!ok)
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsGeneralConfigSerialiser::deserialiseKeyValueSet() ok = false" << std::endl; std::cerr << "RsGeneralConfigSerialiser::deserialiseKeyValueSet() ok = false" << std::endl;
#endif #endif
delete item; delete item;
@ -724,7 +727,7 @@ RsItem *RsPeerConfigSerialiser::deserialise(void *data, uint32_t *pktsize)
(RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) ||
(RS_PKT_TYPE_PEER_CONFIG != getRsItemType(rstype))) (RS_PKT_TYPE_PEER_CONFIG != getRsItemType(rstype)))
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsPeerConfigSerialiser::deserialise() Wrong Type" << std::endl; std::cerr << "RsPeerConfigSerialiser::deserialise() Wrong Type" << std::endl;
#endif #endif
return NULL; /* wrong type */ return NULL; /* wrong type */
@ -845,6 +848,10 @@ bool RsPeerConfigSerialiser::serialiseOldNet(RsPeerOldNetItem *item, void *data,
uint32_t tlvsize = RsPeerConfigSerialiser::sizeOldNet(item); uint32_t tlvsize = RsPeerConfigSerialiser::sizeOldNet(item);
uint32_t offset = 0; uint32_t offset = 0;
#ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsPeerConfigSerialiser::serialiseOldNet() ERROR should never use this function" << std::endl;
#endif
if(*size < tlvsize) if(*size < tlvsize)
return false; /* not enough space */ return false; /* not enough space */
@ -857,8 +864,8 @@ bool RsPeerConfigSerialiser::serialiseOldNet(RsPeerOldNetItem *item, void *data,
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
std::cerr << "RsPeerConfigSerialiser::serialiseNet() Header: " << ok << std::endl; std::cerr << "RsPeerConfigSerialiser::serialiseOldNet() Header: " << ok << std::endl;
std::cerr << "RsPeerConfigSerialiser::serialiseNet() Header test: " << tlvsize << std::endl; std::cerr << "RsPeerConfigSerialiser::serialiseOldNet() Header test: " << tlvsize << std::endl;
#endif #endif
/* skip the header */ /* skip the header */
@ -885,7 +892,7 @@ bool RsPeerConfigSerialiser::serialiseOldNet(RsPeerOldNetItem *item, void *data,
if(offset != tlvsize) if(offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsPeerConfigSerialiser::serialise() Size Error! " << std::endl; std::cerr << "RsPeerConfigSerialiser::serialise() Size Error! " << std::endl;
#endif #endif
} }
@ -902,6 +909,9 @@ RsPeerOldNetItem *RsPeerConfigSerialiser::deserialiseOldNet(void *data, uint32_t
uint32_t offset = 0; uint32_t offset = 0;
#ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsPeerConfigSerialiser::serialiseOldNet() ERROR should never use this function" << std::endl;
#endif
if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) || if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) ||
(RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) ||
@ -1091,8 +1101,17 @@ bool RsPeerConfigSerialiser::serialiseNet(RsPeerNetItem *item, void *data, uint3
uint32_t tlvsize = RsPeerConfigSerialiser::sizeNet(item); uint32_t tlvsize = RsPeerConfigSerialiser::sizeNet(item);
uint32_t offset = 0; uint32_t offset = 0;
#ifdef RSSERIAL_DEBUG
std::cerr << "RsPeerConfigSerialiser::serialiseNet() tlvsize: " << tlvsize << std::endl;
#endif
if(*size < tlvsize) if(*size < tlvsize)
{
#ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsPeerConfigSerialiser::serialiseNet() ERROR not enough space" << std::endl;
#endif
return false; /* not enough space */ return false; /* not enough space */
}
*size = tlvsize; *size = tlvsize;
@ -1127,8 +1146,8 @@ bool RsPeerConfigSerialiser::serialiseNet(RsPeerNetItem *item, void *data, uint3
if(offset != tlvsize) if(offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsPeerConfigSerialiser::serialise() Size Error! " << std::endl; std::cerr << "RsPeerConfigSerialiser::serialiseNet() Size Error! " << std::endl;
#endif #endif
} }
@ -1145,16 +1164,28 @@ RsPeerNetItem *RsPeerConfigSerialiser::deserialiseNet(void *data, uint32_t *size
uint32_t offset = 0; uint32_t offset = 0;
#ifdef RSSERIAL_DEBUG
std::cerr << "RsPeerConfigSerialiser::deserialiseNet() rssize: " << rssize << std::endl;
#endif
if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) || if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) ||
(RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) ||
(RS_PKT_TYPE_PEER_CONFIG != getRsItemType(rstype)) || (RS_PKT_TYPE_PEER_CONFIG != getRsItemType(rstype)) ||
(RS_PKT_SUBTYPE_PEER_NET != getRsItemSubType(rstype))) (RS_PKT_SUBTYPE_PEER_NET != getRsItemSubType(rstype)))
{ {
#ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsPeerConfigSerialiser::deserialiseNet() ERROR Type" << std::endl;
#endif
return NULL; /* wrong type */ return NULL; /* wrong type */
} }
if (*size < rssize) /* check size */ if (*size < rssize) /* check size */
{
#ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsPeerConfigSerialiser::deserialiseNet() ERROR not enough data" << std::endl;
#endif
return NULL; /* not enough data */ return NULL; /* not enough data */
}
/* set the packet length */ /* set the packet length */
*size = rssize; *size = rssize;
@ -1181,10 +1212,11 @@ RsPeerNetItem *RsPeerConfigSerialiser::deserialiseNet(void *data, uint32_t *size
ok &= item->extAddrList.GetTlv(data, rssize, &offset); ok &= item->extAddrList.GetTlv(data, rssize, &offset);
//if (offset != rssize) if (offset != rssize)
if (false) //use this line for backward compatibility
{ {
#ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsPeerConfigSerialiser::deserialiseNet() ERROR size mismatch" << std::endl;
#endif
/* error */ /* error */
delete item; delete item;
return NULL; return NULL;
@ -1257,7 +1289,7 @@ bool RsPeerConfigSerialiser::serialiseStun(RsPeerStunItem *item, void *data, uin
if(offset != tlvsize) if(offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsPeerConfigSerialiser::serialiseStun() Size Error! " << std::endl; std::cerr << "RsPeerConfigSerialiser::serialiseStun() Size Error! " << std::endl;
#endif #endif
} }
@ -1427,7 +1459,7 @@ bool RsPeerConfigSerialiser::serialiseGroup(RsPeerGroupItem *item, void *data, u
if(offset != tlvsize) if(offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsPeerConfigSerialiser::serialiseGroup() Size Error! " << std::endl; std::cerr << "RsPeerConfigSerialiser::serialiseGroup() Size Error! " << std::endl;
#endif #endif
} }
@ -1607,7 +1639,7 @@ bool RsCacheConfigSerialiser::serialise(RsItem *i, void *data, uint32_t *size)
if (offset !=tlvsize) if (offset !=tlvsize)
{ {
ok = false; ok = false;
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsConfigSerialiser::serialisertransfer() Size Error! " << std::endl; std::cerr << "RsConfigSerialiser::serialisertransfer() Size Error! " << std::endl;
#endif #endif
} }

View File

@ -34,8 +34,11 @@
#include "serialiser/rstlvtypes.h" #include "serialiser/rstlvtypes.h"
/*** /***
#define RSSERIAL_DEBUG 1 * #define RSSERIAL_DEBUG 1
***/ * #define RSSERIAL_ERROR_DEBUG 1
***/
#define RSSERIAL_ERROR_DEBUG 1
#include <iostream> #include <iostream>
@ -191,7 +194,7 @@ bool RsDiscSerialiser::serialiseAskInfo(RsDiscAskInfo *item, void *data, uin
if (offset != tlvsize) { if (offset != tlvsize) {
ok = false; ok = false;
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::serialiseAskInfo() Size Error! " << std::endl; std::cerr << "RsDiscSerialiser::serialiseAskInfo() Size Error! " << std::endl;
#endif #endif
} }
@ -211,7 +214,7 @@ RsDiscAskInfo *RsDiscSerialiser::deserialiseAskInfo(void *data, uint32_t *pktsiz
(RS_SERVICE_TYPE_DISC != getRsItemService(rstype)) || (RS_SERVICE_TYPE_DISC != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_DISC_ASK_INFO != getRsItemSubType(rstype))) (RS_PKT_SUBTYPE_DISC_ASK_INFO != getRsItemSubType(rstype)))
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseAskInfo() Wrong Type" << std::endl; std::cerr << "RsDiscSerialiser::deserialiseAskInfo() Wrong Type" << std::endl;
#endif #endif
return NULL; /* wrong type */ return NULL; /* wrong type */
@ -219,7 +222,7 @@ RsDiscAskInfo *RsDiscSerialiser::deserialiseAskInfo(void *data, uint32_t *pktsiz
if (*pktsize < rssize) /* check size */ if (*pktsize < rssize) /* check size */
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseAskInfo() Not Enough Space" << std::endl; std::cerr << "RsDiscSerialiser::deserialiseAskInfo() Not Enough Space" << std::endl;
#endif #endif
return NULL; /* not enough data */ return NULL; /* not enough data */
@ -241,7 +244,7 @@ RsDiscAskInfo *RsDiscSerialiser::deserialiseAskInfo(void *data, uint32_t *pktsiz
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PEERID, item->gpg_id); ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PEERID, item->gpg_id);
if (offset != rssize) { if (offset != rssize) {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseAskInfo() offset != rssize" << std::endl; std::cerr << "RsDiscSerialiser::deserialiseAskInfo() offset != rssize" << std::endl;
#endif #endif
/* error */ /* error */
@ -250,7 +253,7 @@ RsDiscAskInfo *RsDiscSerialiser::deserialiseAskInfo(void *data, uint32_t *pktsiz
} }
if (!ok) { if (!ok) {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseAskInfo() ok = false" << std::endl; std::cerr << "RsDiscSerialiser::deserialiseAskInfo() ok = false" << std::endl;
#endif #endif
delete item; delete item;
@ -302,13 +305,33 @@ std::ostream &RsDiscReply::print(std::ostream &out, uint16_t indent)
uint32_t RsDiscSerialiser::sizeReply(RsDiscReply *item) uint32_t RsDiscSerialiser::sizeReply(RsDiscReply *item)
{ {
uint32_t s = 8; /* header */ uint32_t s = 8; /* header */
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::sizeReply() Header Size: " << s << std::endl;
#endif
s += GetTlvStringSize(item->aboutId); s += GetTlvStringSize(item->aboutId);
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::sizeReply() +AboutId Size: " << s << std::endl;
#endif
s += GetTlvStringSize(item->certGPG); s += GetTlvStringSize(item->certGPG);
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::sizeReply() +certGPG Size: " << s << std::endl;
#endif
RsPeerConfigSerialiser rss ; RsPeerConfigSerialiser rss ;
for (std::list<RsPeerNetItem>::iterator it = item->rsPeerList.begin(); it != item->rsPeerList.end(); it++) for (std::list<RsPeerNetItem>::iterator it = item->rsPeerList.begin(); it != item->rsPeerList.end(); it++)
{
s += rss.size(&(*it)) ; s += rss.size(&(*it)) ;
#ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::sizeReply() +RsPeerNetItem Size: " << s << std::endl;
#endif
}
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::sizeReply() Total Size: " << s << std::endl;
#endif
return s; return s;
} }
@ -319,8 +342,20 @@ bool RsDiscSerialiser::serialiseReply(RsDiscReply *item, void *data, uint32_
uint32_t tlvsize = sizeReply(item); uint32_t tlvsize = sizeReply(item);
uint32_t offset = 0; uint32_t offset = 0;
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::serialiseReply() tlvsize: " << tlvsize;
std::cerr << std::endl;
#endif
if (*pktsize < tlvsize) if (*pktsize < tlvsize)
{
#ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::serialiseReply() ERROR not enough space" << std::endl;
std::cerr << "RsDiscSerialiser::serialiseReply() ERROR *pktsize: " << *pktsize << " tlvsize: " << tlvsize;
std::cerr << std::endl;
#endif
return false; /* not enough space */ return false; /* not enough space */
}
*pktsize = tlvsize; *pktsize = tlvsize;
@ -340,6 +375,10 @@ bool RsDiscSerialiser::serialiseReply(RsDiscReply *item, void *data, uint32_
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);
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::serialiseReply() Offset After Strings: " << offset << std::endl;
#endif
//store the ip list //store the ip list
RsPeerConfigSerialiser rss ; RsPeerConfigSerialiser rss ;
std::list<RsPeerNetItem>::iterator pitemIt; std::list<RsPeerNetItem>::iterator pitemIt;
@ -352,12 +391,18 @@ bool RsDiscSerialiser::serialiseReply(RsDiscReply *item, void *data, uint32_
// The size has been updated to its exact value. // The size has been updated to its exact value.
offset += size; offset += size;
#ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::serialiseReply() RsPeerNetItem ok?: " << ok << std::endl;
std::cerr << "RsDiscSerialiser::serialiseReply() Offset After RsPeerNetItem: " << offset << std::endl;
#endif
} }
if (offset != tlvsize) if (offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::serialiseReply() Size Error: " << tlvsize << " != " << offset << std::endl; std::cerr << "RsDiscSerialiser::serialiseReply() Size Error: " << tlvsize << " != " << offset << std::endl;
#endif #endif
} }
@ -373,12 +418,16 @@ RsDiscReply *RsDiscSerialiser::deserialiseReply(void *data, uint32_t *pktsize)
uint32_t offset = 0; uint32_t offset = 0;
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseReply() Pkt Type: " << std::hex << rstype << std::dec;
std::cerr << "RsDiscSerialiser::deserialiseReply() Pkt Size: " << rssize << std::endl;
#endif
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_TYPE_DISC != getRsItemService(rstype)) || (RS_SERVICE_TYPE_DISC != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_DISC_REPLY != getRsItemSubType(rstype))) (RS_PKT_SUBTYPE_DISC_REPLY != getRsItemSubType(rstype)))
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseReply() Wrong Type" << std::endl; std::cerr << "RsDiscSerialiser::deserialiseReply() Wrong Type" << std::endl;
#endif #endif
return NULL; /* wrong type */ return NULL; /* wrong type */
@ -386,7 +435,7 @@ RsDiscReply *RsDiscSerialiser::deserialiseReply(void *data, uint32_t *pktsize)
if (*pktsize < rssize) /* check size */ if (*pktsize < rssize) /* check size */
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseReply() pktsize != rssize" << std::endl; std::cerr << "RsDiscSerialiser::deserialiseReply() pktsize != rssize" << std::endl;
#endif #endif
return NULL; /* not enough data */ return NULL; /* not enough data */
@ -408,6 +457,10 @@ RsDiscReply *RsDiscSerialiser::deserialiseReply(void *data, uint32_t *pktsize)
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);
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseReply() offset after Strings: " << offset << std::endl;
#endif
//get the peernet address list //get the peernet address list
RsPeerConfigSerialiser rss ; RsPeerConfigSerialiser rss ;
@ -416,10 +469,20 @@ RsDiscReply *RsDiscSerialiser::deserialiseReply(void *data, uint32_t *pktsize)
uint32_t peerNetSize = rssize - offset ; uint32_t peerNetSize = rssize - offset ;
RsPeerNetItem *rsPeerNetItem = (RsPeerNetItem*)rss.deserialise((void *) (((char *) data) + offset), &peerNetSize); RsPeerNetItem *rsPeerNetItem = (RsPeerNetItem*)rss.deserialise((void *) (((char *) data) + offset), &peerNetSize);
offset += peerNetSize; offset += peerNetSize;
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseReply() offset aft PeerNetItem: " << offset << std::endl;
#endif
if(rsPeerNetItem == NULL) if(rsPeerNetItem == NULL)
{
#ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseReply() ERROR deserialise PeerNetItem Failed" << std::endl;
#endif
break ; break ;
}
item->rsPeerList.push_back(*rsPeerNetItem); item->rsPeerList.push_back(*rsPeerNetItem);
delete rsPeerNetItem ; delete rsPeerNetItem ;
@ -427,7 +490,7 @@ RsDiscReply *RsDiscSerialiser::deserialiseReply(void *data, uint32_t *pktsize)
if (offset != rssize) if (offset != rssize)
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseReply() offset != rssize" << std::endl; std::cerr << "RsDiscSerialiser::deserialiseReply() offset != rssize" << std::endl;
#endif #endif
/* error */ /* error */
@ -437,7 +500,7 @@ RsDiscReply *RsDiscSerialiser::deserialiseReply(void *data, uint32_t *pktsize)
if (!ok) if (!ok)
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseReply() ok = false" << std::endl; std::cerr << "RsDiscSerialiser::deserialiseReply() ok = false" << std::endl;
#endif #endif
delete item; delete item;
@ -495,7 +558,7 @@ bool RsDiscSerialiser::serialiseVersion(RsDiscVersion *item, void *data, uint32_
ok &= setRsItemHeader(data, *pktsize, item->PacketId(), *pktsize); ok &= setRsItemHeader(data, *pktsize, item->PacketId(), *pktsize);
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::serialiseVersion() Header: " << ok << std::endl; std::cerr << "RsDiscSerialiser::serialiseVersion() Header: " << ok << std::endl;
std::cerr << "RsDiscSerialiser::serialiseVersion() Size: " << tlvsize << std::endl; std::cerr << "RsDiscSerialiser::serialiseVersion() Size: " << tlvsize << std::endl;
#endif #endif
@ -507,7 +570,7 @@ bool RsDiscSerialiser::serialiseVersion(RsDiscVersion *item, void *data, uint32_
if (offset != tlvsize) if (offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::serialiseVersion() Size Error! " << std::endl; std::cerr << "RsDiscSerialiser::serialiseVersion() Size Error! " << std::endl;
std::cerr << "Offset: " << offset << " tlvsize: " << tlvsize << std::endl; std::cerr << "Offset: " << offset << " tlvsize: " << tlvsize << std::endl;
#endif #endif
@ -528,7 +591,7 @@ RsDiscVersion *RsDiscSerialiser::deserialiseVersion(void *data, uint32_t *pktsiz
(RS_SERVICE_TYPE_DISC != getRsItemService(rstype)) || (RS_SERVICE_TYPE_DISC != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_DISC_VERSION != getRsItemSubType(rstype))) (RS_PKT_SUBTYPE_DISC_VERSION != getRsItemSubType(rstype)))
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseVersion() Wrong Type" << std::endl; std::cerr << "RsDiscSerialiser::deserialiseVersion() Wrong Type" << std::endl;
#endif #endif
return NULL; /* wrong type */ return NULL; /* wrong type */
@ -536,7 +599,7 @@ RsDiscVersion *RsDiscSerialiser::deserialiseVersion(void *data, uint32_t *pktsiz
if (*pktsize < rssize) /* check size */ if (*pktsize < rssize) /* check size */
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseVersion() pktsize != rssize" << std::endl; std::cerr << "RsDiscSerialiser::deserialiseVersion() pktsize != rssize" << std::endl;
std::cerr << "Pktsize: " << *pktsize << " Rssize: " << rssize << std::endl; std::cerr << "Pktsize: " << *pktsize << " Rssize: " << rssize << std::endl;
#endif #endif
@ -559,7 +622,7 @@ RsDiscVersion *RsDiscSerialiser::deserialiseVersion(void *data, uint32_t *pktsiz
if (offset != rssize) if (offset != rssize)
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseVersion() offset != rssize" << std::endl; std::cerr << "RsDiscSerialiser::deserialiseVersion() offset != rssize" << std::endl;
std::cerr << "Offset: " << offset << " Rssize: " << rssize << std::endl; std::cerr << "Offset: " << offset << " Rssize: " << rssize << std::endl;
#endif #endif
@ -570,7 +633,7 @@ RsDiscVersion *RsDiscSerialiser::deserialiseVersion(void *data, uint32_t *pktsiz
if (!ok) if (!ok)
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseVersion() ok = false" << std::endl; std::cerr << "RsDiscSerialiser::deserialiseVersion() ok = false" << std::endl;
#endif #endif
delete item; delete item;
@ -632,7 +695,7 @@ bool RsDiscSerialiser::serialiseHeartbeat(RsDiscHeartbeat *item, void *data, uin
if (offset != tlvsize) if (offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::serialiseHeartbeat() Size Error! " << std::endl; std::cerr << "RsDiscSerialiser::serialiseHeartbeat() Size Error! " << std::endl;
std::cerr << "Offset: " << offset << " tlvsize: " << tlvsize << std::endl; std::cerr << "Offset: " << offset << " tlvsize: " << tlvsize << std::endl;
#endif #endif
@ -653,7 +716,7 @@ RsDiscHeartbeat *RsDiscSerialiser::deserialiseHeartbeat(void *data, uint32_t *pk
(RS_SERVICE_TYPE_DISC != getRsItemService(rstype)) || (RS_SERVICE_TYPE_DISC != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_DISC_HEARTBEAT != getRsItemSubType(rstype))) (RS_PKT_SUBTYPE_DISC_HEARTBEAT != getRsItemSubType(rstype)))
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseHeartbeat() Wrong Type" << std::endl; std::cerr << "RsDiscSerialiser::deserialiseHeartbeat() Wrong Type" << std::endl;
#endif #endif
return NULL; /* wrong type */ return NULL; /* wrong type */
@ -661,7 +724,7 @@ RsDiscHeartbeat *RsDiscSerialiser::deserialiseHeartbeat(void *data, uint32_t *pk
if (*pktsize < rssize) /* check size */ if (*pktsize < rssize) /* check size */
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseHeartbeat() pktsize != rssize" << std::endl; std::cerr << "RsDiscSerialiser::deserialiseHeartbeat() pktsize != rssize" << std::endl;
std::cerr << "Pktsize: " << *pktsize << " Rssize: " << rssize << std::endl; std::cerr << "Pktsize: " << *pktsize << " Rssize: " << rssize << std::endl;
#endif #endif
@ -682,7 +745,7 @@ RsDiscHeartbeat *RsDiscSerialiser::deserialiseHeartbeat(void *data, uint32_t *pk
if (offset != rssize) if (offset != rssize)
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseHeartbeat() offset != rssize" << std::endl; std::cerr << "RsDiscSerialiser::deserialiseHeartbeat() offset != rssize" << std::endl;
std::cerr << "Offset: " << offset << " Rssize: " << rssize << std::endl; std::cerr << "Offset: " << offset << " Rssize: " << rssize << std::endl;
#endif #endif
@ -693,7 +756,7 @@ RsDiscHeartbeat *RsDiscSerialiser::deserialiseHeartbeat(void *data, uint32_t *pk
if (!ok) if (!ok)
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseHeartbeat() ok = false" << std::endl; std::cerr << "RsDiscSerialiser::deserialiseHeartbeat() ok = false" << std::endl;
#endif #endif
delete item; delete item;

View File

@ -34,10 +34,15 @@
#include <iostream> #include <iostream>
/*** /***
#define RSSERIAL_DEBUG 1 * #define RSSERIAL_DEBUG 1
* #define RSSERIAL_ERROR_DEBUG 1
***/ ***/
#ifdef RSSERIAL_DEBUG // As these represent SERIOUS ERRORs, this debug should be left one.
#define RSSERIAL_ERROR_DEBUG 1
#if defined(RSSERIAL_DEBUG) || defined(RSSERIAL_ERROR_DEBUG)
#include <sstream> #include <sstream>
#endif #endif
@ -277,11 +282,11 @@ uint32_t RsSerialiser::size(RsItem *item)
if (serialisers.end() == (it = serialisers.find(type))) if (serialisers.end() == (it = serialisers.find(type)))
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsSerialiser::size() serialiser missing!"; std::cerr << "RsSerialiser::size() ERROR serialiser missing!";
std::ostringstream out; std::ostringstream out;
out << std::hex << item->PacketId(); out << std::hex << item->PacketId() << std::dec;
std::cerr << "RsSerialiser::size() PacketId: "; std::cerr << "RsSerialiser::size() PacketId: ";
std::cerr << out.str(); std::cerr << out.str();
@ -319,10 +324,10 @@ bool RsSerialiser::serialise (RsItem *item, void *data, uint32_t *size)
if (serialisers.end() == (it = serialisers.find(type))) if (serialisers.end() == (it = serialisers.find(type)))
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsSerialiser::serialise() serialiser missing!"; std::cerr << "RsSerialiser::serialise() ERROR serialiser missing!";
std::ostringstream out; std::ostringstream out;
out << std::hex << item->PacketId(); out << std::hex << item->PacketId() << std::dec;
std::cerr << "RsSerialiser::serialise() PacketId: "; std::cerr << "RsSerialiser::serialise() PacketId: ";
std::cerr << out.str(); std::cerr << out.str();
@ -350,8 +355,8 @@ RsItem * RsSerialiser::deserialise(void *data, uint32_t *size)
/* find the type */ /* find the type */
if (*size < 8) if (*size < 8)
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsSerialiser::deserialise() Not Enough Data(1)"; std::cerr << "RsSerialiser::deserialise() ERROR Not Enough Data(1)";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
return NULL; return NULL;
@ -360,10 +365,13 @@ RsItem * RsSerialiser::deserialise(void *data, uint32_t *size)
uint32_t type = (getRsItemId(data) & 0xFFFFFF00); uint32_t type = (getRsItemId(data) & 0xFFFFFF00);
uint32_t pkt_size = getRsItemSize(data); uint32_t pkt_size = getRsItemSize(data);
//std::cerr << "RsSerialiser::deserialise() RsItem Type: " << std::hex << getRsItemId(data) << " Size: " << pkt_size;
//std::cerr << std::endl;
if (pkt_size < *size) if (pkt_size < *size)
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsSerialiser::deserialise() Not Enough Data(2)"; std::cerr << "RsSerialiser::deserialise() ERROR Not Enough Data(2)";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
return NULL; return NULL;
@ -384,10 +392,10 @@ RsItem * RsSerialiser::deserialise(void *data, uint32_t *size)
if (serialisers.end() == (it = serialisers.find(type))) if (serialisers.end() == (it = serialisers.find(type)))
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsSerialiser::deserialise() deserialiser missing!"; std::cerr << "RsSerialiser::deserialise() ERROR deserialiser missing!";
std::ostringstream out; std::ostringstream out;
out << std::hex << getRsItemId(data); out << std::hex << getRsItemId(data) << std::dec;
std::cerr << "RsSerialiser::deserialise() PacketId: "; std::cerr << "RsSerialiser::deserialise() PacketId: ";
std::cerr << out.str(); std::cerr << out.str();
@ -401,17 +409,43 @@ RsItem * RsSerialiser::deserialise(void *data, uint32_t *size)
RsItem *item = (it->second)->deserialise(data, &pkt_size); RsItem *item = (it->second)->deserialise(data, &pkt_size);
if (!item) if (!item)
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsSerialiser::deserialise() Failed!"; std::cerr << "RsSerialiser::deserialise() ERROR Failed!";
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << "RsSerialiser::deserialise() pkt_size: " << pkt_size << " vs *size: " << *size;
std::cerr << std::endl;
uint32_t failedtype = getRsItemId(data);
std::cerr << "RsSerialiser::deserialise() FAILED PACKET Size: ";
std::cerr << getRsItemSize(data) << " ID: ";
std::cerr << std::hex << failedtype << std::dec;
std::cerr << "RsSerialiser::deserialise() FAILED PACKET: ";
std::cerr << " Version: " << std::hex << (uint32_t) getRsItemVersion(failedtype) << std::dec;
std::cerr << " Class: " << std::hex << (uint32_t) getRsItemClass(failedtype) << std::dec;
std::cerr << " Type: " << std::hex << (uint32_t) getRsItemType(failedtype) << std::dec;
std::cerr << " SubType: " << std::hex << (uint32_t) getRsItemSubType(failedtype) << std::dec;
std::cerr << std::endl;
#endif #endif
return NULL; return NULL;
} }
if (pkt_size != *size) if (pkt_size != *size)
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsSerialiser::deserialise() Warning: size mismatch!"; std::cerr << "RsSerialiser::deserialise() ERROR: size mismatch!";
std::cerr << std::endl;
std::cerr << "RsSerialiser::deserialise() pkt_size: " << pkt_size << " vs *size: " << *size;
std::cerr << std::endl;
uint32_t failedtype = getRsItemId(data);
std::cerr << "RsSerialiser::deserialise() FAILED PACKET Size: ";
std::cerr << getRsItemSize(data) << " ID: ";
std::cerr << std::hex << failedtype << std::dec;
std::cerr << "RsSerialiser::deserialise() FAILED PACKET: ";
std::cerr << " Version: " << std::hex << (uint32_t) getRsItemVersion(failedtype) << std::dec;
std::cerr << " Class: " << std::hex << (uint32_t) getRsItemClass(failedtype) << std::dec;
std::cerr << " Type: " << std::hex << (uint32_t) getRsItemType(failedtype) << std::dec;
std::cerr << " SubType: " << std::hex << (uint32_t) getRsItemSubType(failedtype) << std::dec;
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
} }

View File

@ -409,14 +409,6 @@ bool GetTlvString(void *data, uint32_t size, uint32_t *offset,
if (!data) if (!data)
return false; return false;
// Check if we have a null string (this happens with certs)
//
if (size == *offset)
{
in = "" ;
return true ;
}
if (size < *offset) if (size < *offset)
{ {
#ifdef TLV_BASE_DEBUG #ifdef TLV_BASE_DEBUG