Restored backward compatibility in p3disc:

- created a subclass for Own item parts, which is compatible with old format.
- suppressed sending of Issuer packets when not using PGP



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1307 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2009-06-23 21:36:02 +00:00
parent f16c136cbb
commit bc82110c97
4 changed files with 54 additions and 43 deletions

View File

@ -45,7 +45,7 @@
uint32_t RsDiscSerialiser::size(RsItem *i) uint32_t RsDiscSerialiser::size(RsItem *i)
{ {
RsDiscItem *rdi; RsDiscOwnItem *rdi;
RsDiscReply *rdr; RsDiscReply *rdr;
RsDiscIssuer *rds; RsDiscIssuer *rds;
@ -58,7 +58,7 @@ uint32_t RsDiscSerialiser::size(RsItem *i)
{ {
return sizeIssuer(rds); return sizeIssuer(rds);
} }
else if (NULL != (rdi = dynamic_cast<RsDiscItem *>(i))) else if (NULL != (rdi = dynamic_cast<RsDiscOwnItem *>(i)))
{ {
return sizeItem(rdi); return sizeItem(rdi);
} }
@ -69,7 +69,7 @@ uint32_t RsDiscSerialiser::size(RsItem *i)
/* serialise the data to the buffer */ /* serialise the data to the buffer */
bool RsDiscSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize) bool RsDiscSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
{ {
RsDiscItem *rdi; RsDiscOwnItem *rdi;
RsDiscReply *rdr; RsDiscReply *rdr;
RsDiscIssuer *rds; RsDiscIssuer *rds;
@ -82,7 +82,7 @@ bool RsDiscSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
{ {
return serialiseIssuer(rds, data, pktsize); return serialiseIssuer(rds, data, pktsize);
} }
else if (NULL != (rdi = dynamic_cast<RsDiscItem *>(i))) else if (NULL != (rdi = dynamic_cast<RsDiscOwnItem *>(i)))
{ {
return serialiseItem(rdi, data, pktsize); return serialiseItem(rdi, data, pktsize);
} }
@ -107,8 +107,8 @@ RsItem *RsDiscSerialiser::deserialise(void *data, uint32_t *pktsize)
case RS_PKT_SUBTYPE_DISC_REPLY: case RS_PKT_SUBTYPE_DISC_REPLY:
return deserialiseReply(data, pktsize); return deserialiseReply(data, pktsize);
break; break;
case RS_PKT_SUBTYPE_DISC_ITEM: case RS_PKT_SUBTYPE_DISC_OWN:
return deserialiseItem(data, pktsize); return deserialiseOwnItem(data, pktsize);
break; break;
case RS_PKT_SUBTYPE_DISC_ISSUER: case RS_PKT_SUBTYPE_DISC_ISSUER:
return deserialiseIssuer(data, pktsize); return deserialiseIssuer(data, pktsize);
@ -122,12 +122,12 @@ RsItem *RsDiscSerialiser::deserialise(void *data, uint32_t *pktsize)
/*************************************************************************/ /*************************************************************************/
RsDiscItem::~RsDiscItem() RsDiscOwnItem::~RsDiscOwnItem()
{ {
return; return;
} }
void RsDiscItem::clear() void RsDiscOwnItem::clear()
{ {
memset(&laddr, 0, sizeof(laddr)); memset(&laddr, 0, sizeof(laddr));
memset(&saddr, 0, sizeof(laddr)); memset(&saddr, 0, sizeof(laddr));
@ -135,9 +135,9 @@ void RsDiscItem::clear()
discFlags = 0; discFlags = 0;
} }
std::ostream &RsDiscItem::print(std::ostream &out, uint16_t indent) std::ostream &RsDiscOwnItem::print(std::ostream &out, uint16_t indent)
{ {
printRsItemBase(out, "RsDiscItem", indent); printRsItemBase(out, "RsDiscOwnItem", indent);
uint16_t int_Indent = indent + 2; uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent); printIndent(out, int_Indent);
@ -155,12 +155,12 @@ std::ostream &RsDiscItem::print(std::ostream &out, uint16_t indent)
printIndent(out, int_Indent); printIndent(out, int_Indent);
out << "DiscFlags: " << discFlags << std::endl; out << "DiscFlags: " << discFlags << std::endl;
printRsItemEnd(out, "RsDiscItem", indent); printRsItemEnd(out, "RsDiscOwnItem", indent);
return out; return out;
} }
uint32_t RsDiscSerialiser::sizeItem(RsDiscItem *item) uint32_t RsDiscSerialiser::sizeItem(RsDiscOwnItem *item)
{ {
uint32_t s = 8; /* header */ uint32_t s = 8; /* header */
s += GetTlvIpAddrPortV4Size(); /* laddr */ s += GetTlvIpAddrPortV4Size(); /* laddr */
@ -172,7 +172,7 @@ uint32_t RsDiscSerialiser::sizeItem(RsDiscItem *item)
} }
/* serialise the data to the buffer */ /* serialise the data to the buffer */
bool RsDiscSerialiser::serialiseItem(RsDiscItem *item, void *data, uint32_t *pktsize) bool RsDiscSerialiser::serialiseItem(RsDiscOwnItem *item, void *data, uint32_t *pktsize)
{ {
uint32_t tlvsize = sizeItem(item); uint32_t tlvsize = sizeItem(item);
uint32_t offset = 0; uint32_t offset = 0;
@ -213,7 +213,7 @@ bool RsDiscSerialiser::serialiseItem(RsDiscItem *item, void *data, uint32_t
return ok; return ok;
} }
RsDiscItem *RsDiscSerialiser::deserialiseItem(void *data, uint32_t *pktsize) RsDiscOwnItem *RsDiscSerialiser::deserialiseOwnItem(void *data, uint32_t *pktsize)
{ {
/* get the type and size */ /* get the type and size */
uint32_t rstype = getRsItemId(data); uint32_t rstype = getRsItemId(data);
@ -224,7 +224,7 @@ RsDiscItem *RsDiscSerialiser::deserialiseItem(void *data, uint32_t *pktsize)
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_ITEM != getRsItemSubType(rstype))) (RS_PKT_SUBTYPE_DISC_OWN != getRsItemSubType(rstype)))
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseItem() Wrong Type" << std::endl; std::cerr << "RsDiscSerialiser::deserialiseItem() Wrong Type" << std::endl;
@ -246,7 +246,7 @@ RsDiscItem *RsDiscSerialiser::deserialiseItem(void *data, uint32_t *pktsize)
bool ok = true; bool ok = true;
/* ready to load */ /* ready to load */
RsDiscItem *item = new RsDiscItem(); RsDiscOwnItem *item = new RsDiscOwnItem();
item->clear(); item->clear();
/* skip the header */ /* skip the header */

View File

@ -33,29 +33,26 @@
#include "serialiser/rstlvtypes.h" #include "serialiser/rstlvtypes.h"
#include "serialiser/rsserviceids.h" #include "serialiser/rsserviceids.h"
const uint8_t RS_PKT_SUBTYPE_DISC_ITEM = 0x01; const uint8_t RS_PKT_SUBTYPE_DISC_OWN = 0x01;
const uint8_t RS_PKT_SUBTYPE_DISC_REPLY = 0x02; const uint8_t RS_PKT_SUBTYPE_DISC_REPLY = 0x02;
const uint8_t RS_PKT_SUBTYPE_DISC_ISSUER = 0x03; const uint8_t RS_PKT_SUBTYPE_DISC_ISSUER = 0x03;
class RsDiscItem: public RsItem class RsDiscItem: public RsItem
{ {
protected: protected:
RsDiscItem(uint8_t subtype) RsDiscItem(uint8_t subtype) :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_DISC, subtype) {}
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_DISC, };
subtype)
{ return; }
class RsDiscOwnItem: public RsDiscItem
{
public: public:
RsDiscItem() RsDiscOwnItem() :RsDiscItem(RS_PKT_SUBTYPE_DISC_OWN ) {}
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_DISC,
RS_PKT_SUBTYPE_DISC_ITEM)
{ return; }
virtual ~RsDiscItem(); virtual ~RsDiscOwnItem();
virtual void clear(); virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
struct sockaddr_in laddr; struct sockaddr_in laddr;
struct sockaddr_in saddr; struct sockaddr_in saddr;
@ -80,6 +77,14 @@ virtual ~RsDiscReply();
virtual void clear(); virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
struct sockaddr_in laddr;
struct sockaddr_in saddr;
// time frame of recent connections.
uint16_t contact_tf;
// flags...
uint32_t discFlags;
std::string aboutId; std::string aboutId;
RsTlvBinaryData certDER; RsTlvBinaryData certDER;
}; };
@ -115,9 +120,9 @@ virtual RsItem * deserialise(void *data, uint32_t *size);
private: private:
virtual uint32_t sizeItem(RsDiscItem *); virtual uint32_t sizeItem(RsDiscOwnItem *);
virtual bool serialiseItem (RsDiscItem *item, void *data, uint32_t *size); virtual bool serialiseItem (RsDiscOwnItem *item, void *data, uint32_t *size);
virtual RsDiscItem *deserialiseItem(void *data, uint32_t *size); virtual RsDiscOwnItem *deserialiseOwnItem(void *data, uint32_t *size);
virtual uint32_t sizeReply(RsDiscReply *); virtual uint32_t sizeReply(RsDiscReply *);
virtual bool serialiseReply (RsDiscReply *item, void *data, uint32_t *size); virtual bool serialiseReply (RsDiscReply *item, void *data, uint32_t *size);

View File

@ -65,7 +65,6 @@ const uint32_t P3DISC_FLAGS_PEER_TRUSTS_ME= 0x0040;
/***** /*****
* #define P3DISC_DEBUG 1 * #define P3DISC_DEBUG 1
****/ ****/
#define P3DISC_DEBUG 1
/*********** NOTE *************** /*********** NOTE ***************
* *
@ -145,10 +144,11 @@ int p3disc::handleIncoming()
// While messages read // While messages read
while(NULL != (item = recvItem())) while(NULL != (item = recvItem()))
{ {
RsDiscItem *di = NULL; RsDiscOwnItem *dio = NULL;
RsDiscReply *dri = NULL; RsDiscReply *dri = NULL;
RsDiscIssuer *dii = NULL; RsDiscIssuer *dii = NULL;
#ifdef TO_REMOVE
if (NULL == (di = dynamic_cast<RsDiscItem *> (item))) if (NULL == (di = dynamic_cast<RsDiscItem *> (item)))
{ {
@ -166,8 +166,7 @@ int p3disc::handleIncoming()
continue; continue;
} }
nhandled++; #endif
{ {
#ifdef P3DISC_DEBUG #ifdef P3DISC_DEBUG
std::ostringstream out; std::ostringstream out;
@ -181,21 +180,26 @@ int p3disc::handleIncoming()
// if discovery reply then respond if haven't already. // if discovery reply then respond if haven't already.
if (NULL != (dri = dynamic_cast<RsDiscReply *> (di))) if (NULL != (dri = dynamic_cast<RsDiscReply *> (item)))
{ {
recvPeerFriendMsg(dri); recvPeerFriendMsg(dri);
nhandled++;
} }
else if (NULL != (dii = dynamic_cast<RsDiscIssuer *> (di))) #ifdef RS_USE_PGPSSL
else if (NULL != (dii = dynamic_cast<RsDiscIssuer *> (item)))
{ {
recvPeerIssuerMsg(dii); recvPeerIssuerMsg(dii);
nhandled++;
} }
else /* Ping */ #endif
else if (NULL != (dio = dynamic_cast<RsDiscOwnItem *> (item))) /* Ping */
{ {
recvPeerOwnMsg(di); recvPeerOwnMsg(dio);
nhandled++;
} }
delete di; delete item;
} }
return nhandled; return nhandled;
} }
@ -277,7 +281,9 @@ void p3disc::respondToPeer(std::string id)
no need to do with onlineId list. no need to do with onlineId list.
*/ */
#ifdef RS_USE_PGPSSL
sendPeerIssuer(id, *it); sendPeerIssuer(id, *it);
#endif
sendPeerDetails(id, *it); /* (dest (to), source (cert)) */ sendPeerDetails(id, *it); /* (dest (to), source (cert)) */
} }
} }
@ -321,7 +327,7 @@ void p3disc::sendOwnDetails(std::string to)
} }
// Construct a message // Construct a message
RsDiscItem *di = new RsDiscItem(); RsDiscOwnItem *di = new RsDiscOwnItem();
/* components: /* components:
* laddr * laddr
@ -547,7 +553,7 @@ void p3disc::sendPeerIssuer(std::string to, std::string about)
/*************************************************************************************/ /*************************************************************************************/
/* Input Network Msgs */ /* Input Network Msgs */
/*************************************************************************************/ /*************************************************************************************/
void p3disc::recvPeerOwnMsg(RsDiscItem *item) void p3disc::recvPeerOwnMsg(RsDiscOwnItem *item)
{ {
#ifdef P3DISC_DEBUG #ifdef P3DISC_DEBUG
std::cerr << "p3disc::recvPeerOwnMsg() From: " << item->PeerId() << std::endl; std::cerr << "p3disc::recvPeerOwnMsg() From: " << item->PeerId() << std::endl;

View File

@ -103,7 +103,7 @@ void sendPeerIssuer(std::string to, std::string about);
/* Network Input */ /* Network Input */
int handleIncoming(); int handleIncoming();
void recvPeerOwnMsg(RsDiscItem *item); void recvPeerOwnMsg(RsDiscOwnItem *item);
void recvPeerFriendMsg(RsDiscReply *item); void recvPeerFriendMsg(RsDiscReply *item);
void recvPeerIssuerMsg(RsDiscIssuer *item); void recvPeerIssuerMsg(RsDiscIssuer *item);