diff --git a/libretroshare/src/serialiser/rsdiscitems.cc b/libretroshare/src/serialiser/rsdiscitems.cc index cbec5dce4..27ff9bbf4 100644 --- a/libretroshare/src/serialiser/rsdiscitems.cc +++ b/libretroshare/src/serialiser/rsdiscitems.cc @@ -45,7 +45,7 @@ uint32_t RsDiscSerialiser::size(RsItem *i) { - RsDiscItem *rdi; + RsDiscOwnItem *rdi; RsDiscReply *rdr; RsDiscIssuer *rds; @@ -58,7 +58,7 @@ uint32_t RsDiscSerialiser::size(RsItem *i) { return sizeIssuer(rds); } - else if (NULL != (rdi = dynamic_cast(i))) + else if (NULL != (rdi = dynamic_cast(i))) { return sizeItem(rdi); } @@ -69,7 +69,7 @@ uint32_t RsDiscSerialiser::size(RsItem *i) /* serialise the data to the buffer */ bool RsDiscSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize) { - RsDiscItem *rdi; + RsDiscOwnItem *rdi; RsDiscReply *rdr; RsDiscIssuer *rds; @@ -82,7 +82,7 @@ bool RsDiscSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize) { return serialiseIssuer(rds, data, pktsize); } - else if (NULL != (rdi = dynamic_cast(i))) + else if (NULL != (rdi = dynamic_cast(i))) { return serialiseItem(rdi, data, pktsize); } @@ -107,8 +107,8 @@ RsItem *RsDiscSerialiser::deserialise(void *data, uint32_t *pktsize) case RS_PKT_SUBTYPE_DISC_REPLY: return deserialiseReply(data, pktsize); break; - case RS_PKT_SUBTYPE_DISC_ITEM: - return deserialiseItem(data, pktsize); + case RS_PKT_SUBTYPE_DISC_OWN: + return deserialiseOwnItem(data, pktsize); break; case RS_PKT_SUBTYPE_DISC_ISSUER: return deserialiseIssuer(data, pktsize); @@ -122,12 +122,12 @@ RsItem *RsDiscSerialiser::deserialise(void *data, uint32_t *pktsize) /*************************************************************************/ -RsDiscItem::~RsDiscItem() +RsDiscOwnItem::~RsDiscOwnItem() { return; } -void RsDiscItem::clear() +void RsDiscOwnItem::clear() { memset(&laddr, 0, sizeof(laddr)); memset(&saddr, 0, sizeof(laddr)); @@ -135,9 +135,9 @@ void RsDiscItem::clear() 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; printIndent(out, int_Indent); @@ -155,12 +155,12 @@ std::ostream &RsDiscItem::print(std::ostream &out, uint16_t indent) printIndent(out, int_Indent); out << "DiscFlags: " << discFlags << std::endl; - printRsItemEnd(out, "RsDiscItem", indent); + printRsItemEnd(out, "RsDiscOwnItem", indent); return out; } -uint32_t RsDiscSerialiser::sizeItem(RsDiscItem *item) +uint32_t RsDiscSerialiser::sizeItem(RsDiscOwnItem *item) { uint32_t s = 8; /* header */ s += GetTlvIpAddrPortV4Size(); /* laddr */ @@ -172,7 +172,7 @@ uint32_t RsDiscSerialiser::sizeItem(RsDiscItem *item) } /* 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 offset = 0; @@ -213,7 +213,7 @@ bool RsDiscSerialiser::serialiseItem(RsDiscItem *item, void *data, uint32_t return ok; } -RsDiscItem *RsDiscSerialiser::deserialiseItem(void *data, uint32_t *pktsize) +RsDiscOwnItem *RsDiscSerialiser::deserialiseOwnItem(void *data, uint32_t *pktsize) { /* get the type and size */ uint32_t rstype = getRsItemId(data); @@ -224,7 +224,7 @@ RsDiscItem *RsDiscSerialiser::deserialiseItem(void *data, uint32_t *pktsize) if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_DISC != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_DISC_ITEM != getRsItemSubType(rstype))) + (RS_PKT_SUBTYPE_DISC_OWN != getRsItemSubType(rstype))) { #ifdef RSSERIAL_DEBUG std::cerr << "RsDiscSerialiser::deserialiseItem() Wrong Type" << std::endl; @@ -246,7 +246,7 @@ RsDiscItem *RsDiscSerialiser::deserialiseItem(void *data, uint32_t *pktsize) bool ok = true; /* ready to load */ - RsDiscItem *item = new RsDiscItem(); + RsDiscOwnItem *item = new RsDiscOwnItem(); item->clear(); /* skip the header */ diff --git a/libretroshare/src/serialiser/rsdiscitems.h b/libretroshare/src/serialiser/rsdiscitems.h index 19ba3bed8..47bd74050 100644 --- a/libretroshare/src/serialiser/rsdiscitems.h +++ b/libretroshare/src/serialiser/rsdiscitems.h @@ -33,29 +33,26 @@ #include "serialiser/rstlvtypes.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_ISSUER = 0x03; class RsDiscItem: public RsItem { protected: - RsDiscItem(uint8_t subtype) - :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_DISC, - subtype) - { return; } + RsDiscItem(uint8_t subtype) :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_DISC, subtype) {} +}; +class RsDiscOwnItem: public RsDiscItem +{ public: - RsDiscItem() - :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_DISC, - RS_PKT_SUBTYPE_DISC_ITEM) - { return; } + RsDiscOwnItem() :RsDiscItem(RS_PKT_SUBTYPE_DISC_OWN ) {} -virtual ~RsDiscItem(); + virtual ~RsDiscOwnItem(); -virtual void clear(); -virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); + virtual void clear(); + virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); struct sockaddr_in laddr; struct sockaddr_in saddr; @@ -80,6 +77,14 @@ virtual ~RsDiscReply(); virtual void clear(); 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; RsTlvBinaryData certDER; }; @@ -115,9 +120,9 @@ virtual RsItem * deserialise(void *data, uint32_t *size); private: -virtual uint32_t sizeItem(RsDiscItem *); -virtual bool serialiseItem (RsDiscItem *item, void *data, uint32_t *size); -virtual RsDiscItem *deserialiseItem(void *data, uint32_t *size); +virtual uint32_t sizeItem(RsDiscOwnItem *); +virtual bool serialiseItem (RsDiscOwnItem *item, void *data, uint32_t *size); +virtual RsDiscOwnItem *deserialiseOwnItem(void *data, uint32_t *size); virtual uint32_t sizeReply(RsDiscReply *); virtual bool serialiseReply (RsDiscReply *item, void *data, uint32_t *size); diff --git a/libretroshare/src/services/p3disc.cc b/libretroshare/src/services/p3disc.cc index 3f8e55f81..52f4698b9 100644 --- a/libretroshare/src/services/p3disc.cc +++ b/libretroshare/src/services/p3disc.cc @@ -65,7 +65,6 @@ const uint32_t P3DISC_FLAGS_PEER_TRUSTS_ME= 0x0040; /***** * #define P3DISC_DEBUG 1 ****/ -#define P3DISC_DEBUG 1 /*********** NOTE *************** * @@ -145,10 +144,11 @@ int p3disc::handleIncoming() // While messages read while(NULL != (item = recvItem())) { - RsDiscItem *di = NULL; + RsDiscOwnItem *dio = NULL; RsDiscReply *dri = NULL; RsDiscIssuer *dii = NULL; +#ifdef TO_REMOVE if (NULL == (di = dynamic_cast (item))) { @@ -166,8 +166,7 @@ int p3disc::handleIncoming() continue; } - nhandled++; - +#endif { #ifdef P3DISC_DEBUG std::ostringstream out; @@ -181,21 +180,26 @@ int p3disc::handleIncoming() // if discovery reply then respond if haven't already. - if (NULL != (dri = dynamic_cast (di))) + if (NULL != (dri = dynamic_cast (item))) { recvPeerFriendMsg(dri); + nhandled++; } - else if (NULL != (dii = dynamic_cast (di))) +#ifdef RS_USE_PGPSSL + else if (NULL != (dii = dynamic_cast (item))) { recvPeerIssuerMsg(dii); + nhandled++; } - else /* Ping */ +#endif + else if (NULL != (dio = dynamic_cast (item))) /* Ping */ { - recvPeerOwnMsg(di); + recvPeerOwnMsg(dio); + nhandled++; } - delete di; + delete item; } return nhandled; } @@ -277,7 +281,9 @@ void p3disc::respondToPeer(std::string id) no need to do with onlineId list. */ +#ifdef RS_USE_PGPSSL sendPeerIssuer(id, *it); +#endif sendPeerDetails(id, *it); /* (dest (to), source (cert)) */ } } @@ -321,7 +327,7 @@ void p3disc::sendOwnDetails(std::string to) } // Construct a message - RsDiscItem *di = new RsDiscItem(); + RsDiscOwnItem *di = new RsDiscOwnItem(); /* components: * laddr @@ -547,7 +553,7 @@ void p3disc::sendPeerIssuer(std::string to, std::string about) /*************************************************************************************/ /* Input Network Msgs */ /*************************************************************************************/ -void p3disc::recvPeerOwnMsg(RsDiscItem *item) +void p3disc::recvPeerOwnMsg(RsDiscOwnItem *item) { #ifdef P3DISC_DEBUG std::cerr << "p3disc::recvPeerOwnMsg() From: " << item->PeerId() << std::endl; diff --git a/libretroshare/src/services/p3disc.h b/libretroshare/src/services/p3disc.h index 0e30f0e3f..00d99638f 100644 --- a/libretroshare/src/services/p3disc.h +++ b/libretroshare/src/services/p3disc.h @@ -103,7 +103,7 @@ void sendPeerIssuer(std::string to, std::string about); /* Network Input */ int handleIncoming(); -void recvPeerOwnMsg(RsDiscItem *item); +void recvPeerOwnMsg(RsDiscOwnItem *item); void recvPeerFriendMsg(RsDiscReply *item); void recvPeerIssuerMsg(RsDiscIssuer *item);