ask disc info when adding a new friend

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2083 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
joss17 2010-01-19 19:15:22 +00:00
parent e4b7ee7766
commit b4d89ccd94
4 changed files with 146 additions and 327 deletions

View File

@ -45,9 +45,8 @@
uint32_t RsDiscSerialiser::size(RsItem *i) uint32_t RsDiscSerialiser::size(RsItem *i)
{ {
RsDiscOwnItem *rdi; RsDiscAskInfo *inf;
RsDiscReply *rdr; RsDiscReply *rdr;
RsDiscIssuer *rds;
RsDiscVersion *rdv; RsDiscVersion *rdv;
RsDiscHeartbeat *rdt; RsDiscHeartbeat *rdt;
@ -56,13 +55,9 @@ uint32_t RsDiscSerialiser::size(RsItem *i)
{ {
return sizeReply(rdr); return sizeReply(rdr);
} }
else if (NULL != (rds = dynamic_cast<RsDiscIssuer *>(i))) else if (NULL != (inf = dynamic_cast<RsDiscAskInfo *>(i)))
{ {
return sizeIssuer(rds); return sizeAskInfo(inf);
}
else if (NULL != (rdi = dynamic_cast<RsDiscOwnItem *>(i)))
{
return sizeItem(rdi);
} }
else if (NULL != (rdv = dynamic_cast<RsDiscVersion *>(i))) else if (NULL != (rdv = dynamic_cast<RsDiscVersion *>(i)))
{ {
@ -79,9 +74,8 @@ 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)
{ {
RsDiscOwnItem *rdi; RsDiscAskInfo *inf;
RsDiscReply *rdr; RsDiscReply *rdr;
RsDiscIssuer *rds;
RsDiscVersion *rdv; RsDiscVersion *rdv;
RsDiscHeartbeat *rdt; RsDiscHeartbeat *rdt;
@ -90,13 +84,9 @@ bool RsDiscSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
{ {
return serialiseReply(rdr, data, pktsize); return serialiseReply(rdr, data, pktsize);
} }
else if (NULL != (rds = dynamic_cast<RsDiscIssuer *>(i))) else if (NULL != (inf = dynamic_cast<RsDiscAskInfo *>(i)))
{ {
return serialiseIssuer(rds, data, pktsize); return serialiseAskInfo(inf, data, pktsize);
}
else if (NULL != (rdi = dynamic_cast<RsDiscOwnItem *>(i)))
{
return serialiseItem(rdi, data, pktsize);
} }
else if (NULL != (rdv = dynamic_cast<RsDiscVersion *>(i))) else if (NULL != (rdv = dynamic_cast<RsDiscVersion *>(i)))
{ {
@ -127,11 +117,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_OWN: case RS_PKT_SUBTYPE_DISC_ASK_INFO:
return deserialiseOwnItem(data, pktsize); return deserialiseAskInfo(data, pktsize);
break;
case RS_PKT_SUBTYPE_DISC_ISSUER:
return deserialiseIssuer(data, pktsize);
break; break;
case RS_PKT_SUBTYPE_DISC_VERSION: case RS_PKT_SUBTYPE_DISC_VERSION:
return deserialiseVersion(data, pktsize); return deserialiseVersion(data, pktsize);
@ -148,76 +135,40 @@ RsItem *RsDiscSerialiser::deserialise(void *data, uint32_t *pktsize)
/*************************************************************************/ /*************************************************************************/
RsDiscOwnItem::~RsDiscOwnItem() RsDiscAskInfo::~RsDiscAskInfo()
{ {
return; return;
} }
void RsDiscOwnItem::clear() void RsDiscAskInfo::clear()
{ {
memset(&laddr, 0, sizeof(laddr)); gpg_id.clear();
memset(&saddr, 0, sizeof(laddr));
contact_tf = 0;
discFlags = 0;
ipAddressList.clear();
} }
std::ostream &RsDiscOwnItem::print(std::ostream &out, uint16_t indent) std::ostream &RsDiscAskInfo::print(std::ostream &out, uint16_t indent)
{ {
printRsItemBase(out, "RsDiscOwnItem", indent); printRsItemBase(out, "RsDiscAskInfo", indent);
uint16_t int_Indent = indent + 2; uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent); printIndent(out, int_Indent);
out << "Local Address: " << inet_ntoa(laddr.sin_addr); out << "gpg_id: " << gpg_id << std::endl;
out << " Port: " << ntohs(laddr.sin_port) << std::endl;
printIndent(out, int_Indent);
out << "Server Address: " << inet_ntoa(saddr.sin_addr);
out << " Port: " << ntohs(saddr.sin_port) << std::endl;
printIndent(out, int_Indent);
out << "Contact TimeFrame: " << contact_tf;
out << std::endl;
printIndent(out, int_Indent);
out << "DiscFlags: " << discFlags << std::endl;
printIndent(out, int_Indent);
out << "IpAddressListSize: " << ipAddressList.size() << std::endl;
printIndent(out, int_Indent);
out << "RsDiscOwnItem::print() IpAddressList: " << std::endl;
for (std::list<IpAddressTimed>::iterator ipListIt = ipAddressList.begin(); ipListIt!=(ipAddressList.end()); ipListIt++) {
printIndent(out, int_Indent);
out << inet_ntoa(ipListIt->ipAddr.sin_addr) << ":" << ntohs(ipListIt->ipAddr.sin_port) << " seenTime : " << ipListIt->seenTime << std::endl;
}
printRsItemEnd(out, "RsDiscOwnItem", indent); printRsItemEnd(out, "RsDiscOwnItem", indent);
return out; return out;
} }
uint32_t RsDiscSerialiser::sizeItem(RsDiscOwnItem *item) uint32_t RsDiscSerialiser::sizeAskInfo(RsDiscAskInfo *item)
{ {
uint32_t s = 8; /* header */ uint32_t s = 8; /* header */
s += GetTlvIpAddrPortV4Size(); /* laddr */ s += GetTlvStringSize(item->gpg_id);
s += GetTlvIpAddrPortV4Size(); /* saddr */
s += 2; /* contact_tf */
s += 4; /* discFlags */
s += 4; /* ipaddress list size */
//add the size of the ip list
int ipListSize = item->ipAddressList.size();
s += ipListSize * GetTlvIpAddrPortV4Size();
s += ipListSize * 8; //size of an uint64
return s; return s;
} }
/* serialise the data to the buffer */ /* serialise the data to the buffer */
bool RsDiscSerialiser::serialiseItem(RsDiscOwnItem *item, void *data, uint32_t *pktsize) bool RsDiscSerialiser::serialiseAskInfo(RsDiscAskInfo *item, void *data, uint32_t *pktsize)
{ {
uint32_t tlvsize = sizeItem(item); uint32_t tlvsize = sizeAskInfo(item);
uint32_t offset = 0; uint32_t offset = 0;
if (*pktsize < tlvsize) if (*pktsize < tlvsize)
@ -230,42 +181,27 @@ bool RsDiscSerialiser::serialiseItem(RsDiscOwnItem *item, void *data, uint32
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::serialiseItem() Header: " << ok << std::endl; std::cerr << "RsDiscSerialiser::serialiseAskInfo() Header: " << ok << std::endl;
std::cerr << "RsDiscSerialiser::serialiseItem() Size: " << tlvsize << std::endl; std::cerr << "RsDiscSerialiser::serialiseAskInfo() Size: " << tlvsize << std::endl;
#endif #endif
/* skip the header */ /* skip the header */
offset += 8; offset += 8;
/* add mandatory parts first */ /* add mandatory parts first */
ok &= SetTlvIpAddrPortV4(data, tlvsize, &offset, ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PEERID, item->gpg_id);
TLV_TYPE_IPV4_LOCAL, &(item->laddr));
ok &= SetTlvIpAddrPortV4(data, tlvsize, &offset,
TLV_TYPE_IPV4_REMOTE, &(item->saddr));
ok &= setRawUInt16(data, tlvsize, &offset, item->contact_tf);
ok &= setRawUInt32(data, tlvsize, &offset, item->discFlags);
ok &= setRawUInt32(data, tlvsize, &offset, item->ipAddressList.size()); if (offset != tlvsize) {
//store the ip list
for (std::list<IpAddressTimed>::iterator ipListIt = item->ipAddressList.begin(); ipListIt != item->ipAddressList.end(); ipListIt++) {
ok &= SetTlvIpAddrPortV4(data, tlvsize, &offset, TLV_TYPE_IPV4_REMOTE, &(ipListIt->ipAddr));
ok &= setRawUInt64(data, tlvsize, &offset, ipListIt->seenTime);
}
if (offset != tlvsize)
{
ok = false; ok = false;
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::serialiseItem() Size Error! " << std::endl; std::cerr << "RsDiscSerialiser::serialiseAskInfo() Size Error! " << std::endl;
#endif #endif
} }
return ok; return ok;
} }
RsDiscOwnItem *RsDiscSerialiser::deserialiseOwnItem(void *data, uint32_t *pktsize) RsDiscAskInfo *RsDiscSerialiser::deserialiseAskInfo(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);
uint32_t rssize = getRsItemSize(data); uint32_t rssize = getRsItemSize(data);
@ -275,10 +211,10 @@ RsDiscOwnItem *RsDiscSerialiser::deserialiseOwnItem(void *data, uint32_t *pktsiz
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_OWN != getRsItemSubType(rstype))) (RS_PKT_SUBTYPE_DISC_ASK_INFO != getRsItemSubType(rstype)))
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseItem() Wrong Type" << std::endl; std::cerr << "RsDiscSerialiser::deserialiseAskInfo() Wrong Type" << std::endl;
#endif #endif
return NULL; /* wrong type */ return NULL; /* wrong type */
} }
@ -286,7 +222,7 @@ RsDiscOwnItem *RsDiscSerialiser::deserialiseOwnItem(void *data, uint32_t *pktsiz
if (*pktsize < rssize) /* check size */ if (*pktsize < rssize) /* check size */
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseItem() 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 */
} }
@ -297,54 +233,27 @@ RsDiscOwnItem *RsDiscSerialiser::deserialiseOwnItem(void *data, uint32_t *pktsiz
bool ok = true; bool ok = true;
/* ready to load */ /* ready to load */
RsDiscOwnItem *item = new RsDiscOwnItem(); RsDiscAskInfo *item = new RsDiscAskInfo();
item->clear(); item->clear();
/* skip the header */ /* skip the header */
offset += 8; offset += 8;
/* get mandatory parts first */ /* get mandatory parts first */
ok &= GetTlvIpAddrPortV4(data, rssize, &offset, ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PEERID, item->gpg_id);
TLV_TYPE_IPV4_LOCAL, &(item->laddr));
ok &= GetTlvIpAddrPortV4(data, rssize, &offset,
TLV_TYPE_IPV4_REMOTE, &(item->saddr));
ok &= getRawUInt16(data, rssize, &offset, &(item->contact_tf));
ok &= getRawUInt32(data, rssize, &offset, &(item->discFlags));
uint32_t listSize; if (offset != rssize) {
ok &= getRawUInt32(data, rssize, &offset, &listSize);
//get the ip adress list
int count = 0;
std::list<IpAddressTimed> ipTimedList;
while (offset < rssize && count < (int)listSize) {
count++;
IpAddressTimed ipTimed;
sockaddr_clear(&ipTimed.ipAddr);
ok &= GetTlvIpAddrPortV4(data, rssize, &offset, TLV_TYPE_IPV4_REMOTE, &ipTimed.ipAddr);
if (!ok) { break; }
uint64_t time = 0;
ok &= getRawUInt64(data, rssize, &offset, &time);
if (!ok) { break; }
ipTimed.seenTime = time;
ipTimedList.push_back(ipTimed);
}
item->ipAddressList = ipTimedList;
if (offset != rssize)
{
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseItem() offset != rssize" << std::endl; std::cerr << "RsDiscSerialiser::deserialiseAskInfo() offset != rssize" << std::endl;
#endif #endif
/* error */ /* error */
delete item; delete item;
return NULL; return NULL;
} }
if (!ok) if (!ok) {
{
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseItem() ok = false" << std::endl; std::cerr << "RsDiscSerialiser::deserialiseAskInfo() ok = false" << std::endl;
#endif #endif
delete item; delete item;
return NULL; return NULL;
@ -532,149 +441,6 @@ RsDiscReply *RsDiscSerialiser::deserialiseReply(void *data, uint32_t *pktsize)
return item; return item;
} }
/*************************************************************************/
RsDiscIssuer::~RsDiscIssuer()
{
return;
}
void RsDiscIssuer::clear()
{
certGPG.clear();
}
std::ostream &RsDiscIssuer::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsDiscIssuer", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "GPG Cert String: " << certGPG << std::endl;
printRsItemEnd(out, "RsDiscIssuer", indent);
return out;
}
uint32_t RsDiscSerialiser::sizeIssuer(RsDiscIssuer *item)
{
uint32_t s = 8; /* header */
s += 4; /* size in RawString() */
s += item->certGPG.length();
return s;
}
/* serialise the data to the buffer */
bool RsDiscSerialiser::serialiseIssuer(RsDiscIssuer *item, void *data, uint32_t *pktsize)
{
uint32_t tlvsize = sizeIssuer(item);
uint32_t offset = 0;
if (*pktsize < tlvsize)
return false; /* not enough space */
*pktsize = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::serialiseIssuer() Header: " << ok << std::endl;
std::cerr << "RsDiscSerialiser::serialiseIssuer() Size: " << tlvsize << std::endl;
#endif
/* skip the header */
offset += 8;
/* add mandatory parts first */
ok &= setRawString(data, tlvsize, &offset, item->certGPG);
if (offset != tlvsize)
{
ok = false;
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::serialiseIssuer() Size Error! " << std::endl;
std::cerr << "Offset: " << offset << " tlvsize: " << tlvsize << std::endl;
#endif
}
return ok;
}
RsDiscIssuer *RsDiscSerialiser::deserialiseIssuer(void *data, uint32_t *pktsize)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_TYPE_DISC != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_DISC_ISSUER != getRsItemSubType(rstype)))
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseIssuer() Wrong Type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*pktsize < rssize) /* check size */
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseIssuer() pktsize != rssize" << std::endl;
std::cerr << "Pktsize: " << *pktsize << " Rssize: " << rssize << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*pktsize = rssize;
bool ok = true;
/* ready to load */
RsDiscIssuer *item = new RsDiscIssuer();
item->clear();
/* skip the header */
offset += 8;
/* get mandatory parts first */
ok &= getRawString(data, rssize, &offset, item->certGPG);
if (offset != rssize)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseIssuer() offset != rssize" << std::endl;
std::cerr << "Offset: " << offset << " Rssize: " << rssize << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseIssuer() ok = false" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*************************************************************************/ /*************************************************************************/

View File

@ -34,9 +34,9 @@
#include "serialiser/rsserviceids.h" #include "serialiser/rsserviceids.h"
#include "serialiser/rsconfigitems.h" #include "serialiser/rsconfigitems.h"
const uint8_t RS_PKT_SUBTYPE_DISC_OWN = 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_ASK_INFO = 0x03;
const uint8_t RS_PKT_SUBTYPE_DISC_VERSION = 0x05; const uint8_t RS_PKT_SUBTYPE_DISC_VERSION = 0x05;
const uint8_t RS_PKT_SUBTYPE_DISC_HEARTBEAT = 0x06; const uint8_t RS_PKT_SUBTYPE_DISC_HEARTBEAT = 0x06;
@ -47,30 +47,30 @@ class RsDiscItem: public RsItem
}; };
class RsDiscOwnItem: public RsDiscItem //class RsDiscOwnItem: public RsDiscItem
{ //{
public: // public:
//
RsDiscOwnItem() :RsDiscItem(RS_PKT_SUBTYPE_DISC_OWN ) {} // RsDiscOwnItem() :RsDiscItem(RS_PKT_SUBTYPE_DISC_OWN ) {}
//
//
virtual ~RsDiscOwnItem(); // 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);
//
//use for transmitting ip address list // //use for transmitting ip address list
std::list<IpAddressTimed> ipAddressList; // std::list<IpAddressTimed> ipAddressList;
//
//use for transmitting my own adress list // //use for transmitting my own adress list
struct sockaddr_in laddr; // struct sockaddr_in laddr;
struct sockaddr_in saddr; // struct sockaddr_in saddr;
//
// time frame of recent connections. // // time frame of recent connections.
uint16_t contact_tf; // uint16_t contact_tf;
// flags... // // flags...
uint32_t discFlags; // uint32_t discFlags;
}; //};
class RsDiscReply: public RsDiscItem class RsDiscReply: public RsDiscItem
{ {
@ -101,20 +101,20 @@ virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
std::string certGPG; std::string certGPG;
}; };
class RsDiscIssuer: public RsDiscItem class RsDiscAskInfo: public RsDiscItem
{ {
public: public:
RsDiscIssuer() RsDiscAskInfo()
:RsDiscItem(RS_PKT_SUBTYPE_DISC_ISSUER) :RsDiscItem(RS_PKT_SUBTYPE_DISC_ASK_INFO)
{ return; } { return; }
virtual ~RsDiscIssuer(); virtual ~RsDiscAskInfo();
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);
std::string certGPG; std::string gpg_id;
}; };
class RsDiscVersion: public RsDiscItem class RsDiscVersion: public RsDiscItem
@ -158,17 +158,17 @@ virtual RsItem * deserialise(void *data, uint32_t *size);
private: private:
virtual uint32_t sizeItem(RsDiscOwnItem *); virtual uint32_t sizeAskInfo(RsDiscAskInfo *);
virtual bool serialiseItem (RsDiscOwnItem *item, void *data, uint32_t *size); virtual bool serialiseAskInfo(RsDiscAskInfo *item, void *data, uint32_t *size);
virtual RsDiscOwnItem *deserialiseOwnItem(void *data, uint32_t *size); virtual RsDiscAskInfo *deserialiseAskInfo(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);
virtual RsDiscReply *deserialiseReply(void *data, uint32_t *size); virtual RsDiscReply *deserialiseReply(void *data, uint32_t *size);
virtual uint32_t sizeIssuer(RsDiscIssuer *); //virtual uint32_t sizeIssuer(RsDiscIssuer *);
virtual bool serialiseIssuer (RsDiscIssuer *item, void *data, uint32_t *size); //virtual bool serialiseIssuer (RsDiscIssuer *item, void *data, uint32_t *size);
virtual RsDiscIssuer *deserialiseIssuer(void *data, uint32_t *size); //virtual RsDiscIssuer *deserialiseIssuer(void *data, uint32_t *size);
virtual uint32_t sizeVersion(RsDiscVersion *); virtual uint32_t sizeVersion(RsDiscVersion *);
virtual bool serialiseVersion(RsDiscVersion *item, void *data, uint32_t *size); virtual bool serialiseVersion(RsDiscVersion *item, void *data, uint32_t *size);

View File

@ -158,9 +158,9 @@ int p3disc::handleIncoming()
// While messages read // While messages read
while(NULL != (item = recvItem())) while(NULL != (item = recvItem()))
{ {
RsDiscOwnItem *dio = NULL; RsDiscAskInfo *inf = NULL;
RsDiscReply *dri = NULL; RsDiscReply *dri = NULL;
RsDiscIssuer *dii = NULL; //RsDiscIssuer *dii = NULL;
RsDiscVersion *dvi = NULL; RsDiscVersion *dvi = NULL;
RsDiscHeartbeat *dta = NULL; RsDiscHeartbeat *dta = NULL;
@ -179,19 +179,12 @@ int p3disc::handleIncoming()
recvPeerDetails(dri); recvPeerDetails(dri);
nhandled++; nhandled++;
} }
#ifdef RS_USE_PGPSSL
else if (NULL != (dii = dynamic_cast<RsDiscIssuer *> (item))) {
//recvPeerIssuerMsg(dii);
nhandled++;
}
#endif
else if (NULL != (dvi = dynamic_cast<RsDiscVersion *> (item))) { else if (NULL != (dvi = dynamic_cast<RsDiscVersion *> (item))) {
recvPeerVersionMsg(dvi); recvPeerVersionMsg(dvi);
nhandled++; nhandled++;
} }
else if (NULL != (dio = dynamic_cast<RsDiscOwnItem *> (item))) /* Ping */ { else if (NULL != (inf = dynamic_cast<RsDiscAskInfo *> (item))) /* Ping */ {
//recvPeerOwnMsg(dio); recvAskInfo(inf);
nhandled++; nhandled++;
} }
else if (NULL != (dta = dynamic_cast<RsDiscHeartbeat *> (item))) { else if (NULL != (dta = dynamic_cast<RsDiscHeartbeat *> (item))) {
@ -212,11 +205,6 @@ void p3disc::statusChange(const std::list<pqipeer> &plist)
std::cerr << "p3disc::statusChange()"; std::cerr << "p3disc::statusChange()";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
// if off discard item.
peerConnectState detail;
if (!mConnMgr->getOwnNetStatus(detail) || (detail.visState & RS_VIS_STATE_NODISC)) {
return;
}
std::list<pqipeer>::const_iterator pit; std::list<pqipeer>::const_iterator pit;
/* if any have switched to 'connected' then we notify */ /* if any have switched to 'connected' then we notify */
@ -225,9 +213,10 @@ void p3disc::statusChange(const std::list<pqipeer> &plist)
sendOwnVersion(pit->id); sendOwnVersion(pit->id);
sendAllInfoToJustConnectedPeer(pit->id); sendAllInfoToJustConnectedPeer(pit->id);
sendJustConnectedPeerInfoToAllPeer(pit->id); sendJustConnectedPeerInfoToAllPeer(pit->id);
} } else if (!(pit->state & RS_PEER_S_FRIEND) && (pit->actions & RS_PEER_MOVED)) {
if (!(pit->state & RS_PEER_S_FRIEND) && (pit->actions & RS_PEER_MOVED)) {
this->removeFriend(pit->id); this->removeFriend(pit->id);
} else if ((pit->state & RS_PEER_S_FRIEND) && (pit->actions & RS_PEER_NEW)) {
this->askInfoToAllPeers(pit->id);
} }
} }
} }
@ -302,7 +291,19 @@ void p3disc::sendPeerDetails(std::string to, std::string about) {
#endif #endif
} }
// if off discard item.
peerConnectState detail;
if (!mConnMgr->getOwnNetStatus(detail) || (detail.visState & RS_VIS_STATE_NODISC)) {
return;
}
about = rsPeers->getGPGId(about); about = rsPeers->getGPGId(about);
if (about == "") {
#ifdef P3DISC_DEBUG
std::cerr << "p3disc::sendPeerDetails() no info about this id" << std::endl;
#endif
return;
}
// Construct a message // Construct a message
RsDiscReply *di = new RsDiscReply(); RsDiscReply *di = new RsDiscReply();
@ -318,7 +319,7 @@ void p3disc::sendPeerDetails(std::string to, std::string about) {
rsPeers->getSSLChildListOfGPGId(about, sslChilds); rsPeers->getSSLChildListOfGPGId(about, sslChilds);
for (std::list<std::string>::iterator sslChildIt = sslChilds.begin(); sslChildIt != sslChilds.end(); sslChildIt++) { for (std::list<std::string>::iterator sslChildIt = sslChilds.begin(); sslChildIt != sslChilds.end(); sslChildIt++) {
peerConnectState detail; peerConnectState detail;
if (!mConnMgr->getFriendNetStatus(*sslChildIt, detail)) { if (!mConnMgr->getFriendNetStatus(*sslChildIt, detail) || detail.visState & RS_VIS_STATE_NODISC) {
continue; continue;
} }
RsPeerNetItem *rsPeerNetItem = new RsPeerNetItem(); RsPeerNetItem *rsPeerNetItem = new RsPeerNetItem();
@ -414,6 +415,46 @@ void p3disc::sendHeartbeat(std::string to)
#endif #endif
} }
void p3disc::askInfoToAllPeers(std::string about)
{
{
#ifdef P3DISC_DEBUG
std::ostringstream out;
out << "p3disc::askInfoToAllPeers()" << " about " << about;
std::cerr << out.str() << std::endl;
#endif
}
about = rsPeers->getGPGId(about);
if (about == "") {
#ifdef P3DISC_DEBUG
std::cerr << "p3disc::askInfoToAllPeers() no gpg id found" << std::endl;
#endif
}
// if off discard item.
peerConnectState detail;
if (!mConnMgr->getOwnNetStatus(detail) || (detail.visState & RS_VIS_STATE_NODISC)) {
return;
}
std::list<std::string> onlineIds;
std::list<std::string>::iterator onlineIdsIt;
rsPeers->getOnlineList(onlineIds);
/* send them a list of all friend's details */
for(onlineIdsIt = onlineIds.begin(); onlineIdsIt != onlineIds.end(); onlineIdsIt++) {
RsDiscAskInfo *di = new RsDiscAskInfo();
di->PeerId(*onlineIdsIt);
di->gpg_id = about;
sendItem(di);
}
#ifdef P3DISC_DEBUG
std::cerr << "Sent ask info message to all connected peers." << std::endl;
#endif
}
void p3disc::recvPeerDetails(RsDiscReply *item) void p3disc::recvPeerDetails(RsDiscReply *item)
{ {
// if off discard item. // if off discard item.
@ -451,7 +492,7 @@ void p3disc::recvPeerDetails(RsDiscReply *item)
//check that the friend is not a deleted one //check that the friend is not a deleted one
if (deletedSSLFriendsIds.find(pitem->pid) == deletedSSLFriendsIds.end()) { if (deletedSSLFriendsIds.find(pitem->pid) == deletedSSLFriendsIds.end()) {
//|| { //|| {
mConnMgr->addFriend(pitem->pid, pitem->gpg_id, pitem->netMode, RS_VIS_STATE_NODISC, 0); //add with no disc bay default. If friend already exist, it will do nothing mConnMgr->addFriend(pitem->pid, pitem->gpg_id, pitem->netMode, RS_VIS_STATE_NODISC, 0); //add with no disc by default. If friend already exist, it will do nothing
} else if ((pitem->lastContact - deletedSSLFriendsIds[pitem->pid]) > 3600*48) { // the friend was seen 48hours before we deleted it, we will readd it } else if ((pitem->lastContact - deletedSSLFriendsIds[pitem->pid]) > 3600*48) { // the friend was seen 48hours before we deleted it, we will readd it
mConnMgr->addFriend(pitem->pid, pitem->gpg_id, pitem->netMode, RS_VIS_STATE_NODISC, 0); //add with no disc bay default. If friend already exist, it will do nothing mConnMgr->addFriend(pitem->pid, pitem->gpg_id, pitem->netMode, RS_VIS_STATE_NODISC, 0); //add with no disc bay default. If friend already exist, it will do nothing
} }
@ -520,6 +561,17 @@ void p3disc::recvHeartbeatMsg(RsDiscHeartbeat *item)
return; return;
} }
void p3disc::recvAskInfo(RsDiscAskInfo *item) {
#ifdef P3DISC_DEBUG
std::cerr << "p3disc::recvAskInfo() From: " << item->PeerId();
std::cerr << std::endl;
#endif
sendPeerDetails(item->PeerId(), item->gpg_id);
return;
}
void p3disc::removeFriend(std::string ssl_id) { void p3disc::removeFriend(std::string ssl_id) {
#ifdef P3DISC_DEBUG #ifdef P3DISC_DEBUG
std::cerr << "p3disc::removeFriend() called for : " << ssl_id << std::endl; std::cerr << "p3disc::removeFriend() called for : " << ssl_id << std::endl;

View File

@ -112,10 +112,11 @@ void sendOwnVersion(std::string to);
void sendPeerDetails(std::string to, std::string about); void sendPeerDetails(std::string to, std::string about);
//void sendPeerIssuer(std::string to, std::string about); //void sendPeerIssuer(std::string to, std::string about);
void sendHeartbeat(std::string to); void sendHeartbeat(std::string to);
void askInfoToAllPeers(std::string about);
/* Network Input */ /* Network Input */
int handleIncoming(); int handleIncoming();
//void recvPeerOwnMsg(RsDiscOwnItem *item); void recvAskInfo(RsDiscAskInfo *item);
void recvPeerDetails(RsDiscReply *item); void recvPeerDetails(RsDiscReply *item);
//void recvPeerIssuerMsg(RsDiscIssuer *item); //void recvPeerIssuerMsg(RsDiscIssuer *item);
void recvPeerVersionMsg(RsDiscVersion *item); void recvPeerVersionMsg(RsDiscVersion *item);