exchange of what version of retroshare our friends are using

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1308 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
alexandrut 2009-06-28 20:57:02 +00:00
parent bc82110c97
commit 0b6800a5ce
12 changed files with 335 additions and 51 deletions

View File

@ -226,7 +226,8 @@ HEADERS += dbase/cachestrapper.h \
util/rsnet.h \
util/rsprint.h \
util/rsthreads.h \
util/rswin.h
util/rswin.h \
util/rsversion.h
SOURCES = \
dht/dht_check_peers.cc \
@ -336,5 +337,5 @@ SOURCES = \
util/rsdir.cc \
util/rsnet.cc \
util/rsprint.cc \
util/rsthreads.cc
util/rsthreads.cc \
util/rsversion.cc

View File

@ -29,6 +29,7 @@
#include <inttypes.h>
#include <string>
#include <list>
#include <map>
/* The Main Interface Class - for information about your Peers */
class RsDisc;
@ -42,6 +43,7 @@ class RsDisc
virtual ~RsDisc() { return; }
virtual bool getDiscFriends(std::string id, std::list<std::string> &friends) = 0;
virtual bool getDiscVersions(std::map<std::string, std::string> &versions) = 0;
};

View File

@ -38,3 +38,13 @@ bool p3Discovery::getDiscFriends(std::string id, std::list<std::string> &friends
return false;
}
bool p3Discovery::getDiscVersions(std::map<std::string, std::string> &versions)
{
if (mDisc)
{
mDisc->getversions(versions);
return true;
}
return false;
}

View File

@ -38,6 +38,7 @@ class p3Discovery: public RsDisc
virtual ~p3Discovery() { return; }
virtual bool getDiscFriends(std::string id, std::list<std::string> &friends);
virtual bool getDiscVersions(std::map<std::string, std::string> &versions);
private:

View File

@ -48,6 +48,7 @@ uint32_t RsDiscSerialiser::size(RsItem *i)
RsDiscOwnItem *rdi;
RsDiscReply *rdr;
RsDiscIssuer *rds;
RsDiscVersion *rdv;
/* do reply first - as it is derived from Item */
if (NULL != (rdr = dynamic_cast<RsDiscReply *>(i)))
@ -62,6 +63,10 @@ uint32_t RsDiscSerialiser::size(RsItem *i)
{
return sizeItem(rdi);
}
else if (NULL != (rdv = dynamic_cast<RsDiscVersion *>(i)))
{
return sizeVersion(rdv);
}
return 0;
}
@ -72,6 +77,7 @@ bool RsDiscSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
RsDiscOwnItem *rdi;
RsDiscReply *rdr;
RsDiscIssuer *rds;
RsDiscVersion *rdv;
/* do reply first - as it is derived from Item */
if (NULL != (rdr = dynamic_cast<RsDiscReply *>(i)))
@ -86,6 +92,10 @@ bool RsDiscSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
{
return serialiseItem(rdi, data, pktsize);
}
else if (NULL != (rdv = dynamic_cast<RsDiscVersion *>(i)))
{
return serialiseVersion(rdv, data, pktsize);
}
return false;
}
@ -113,6 +123,9 @@ RsItem *RsDiscSerialiser::deserialise(void *data, uint32_t *pktsize)
case RS_PKT_SUBTYPE_DISC_ISSUER:
return deserialiseIssuer(data, pktsize);
break;
case RS_PKT_SUBTYPE_DISC_VERSION:
return deserialiseVersion(data, pktsize);
break;
default:
return NULL;
break;
@ -186,7 +199,7 @@ bool RsDiscSerialiser::serialiseItem(RsDiscOwnItem *item, void *data, uint32
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::serialiseItem() Header: " << ok << std::endl;
std::cerr << "RsDiscSerialiser::serialiseItem() Size: " << tlvsize << std::endl;
#endif
@ -195,9 +208,9 @@ bool RsDiscSerialiser::serialiseItem(RsDiscOwnItem *item, void *data, uint32
offset += 8;
/* add mandatory parts first */
ok &= SetTlvIpAddrPortV4(data, tlvsize, &offset,
ok &= SetTlvIpAddrPortV4(data, tlvsize, &offset,
TLV_TYPE_IPV4_LOCAL, &(item->laddr));
ok &= SetTlvIpAddrPortV4(data, tlvsize, &offset,
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);
@ -205,7 +218,7 @@ bool RsDiscSerialiser::serialiseItem(RsDiscOwnItem *item, void *data, uint32
if (offset != tlvsize)
{
ok = false;
#ifdef RSSERIAL_DEBUG
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::serialiseItem() Size Error! " << std::endl;
#endif
}
@ -226,7 +239,7 @@ RsDiscOwnItem *RsDiscSerialiser::deserialiseOwnItem(void *data, uint32_t *pktsiz
(RS_SERVICE_TYPE_DISC != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_DISC_OWN != getRsItemSubType(rstype)))
{
#ifdef RSSERIAL_DEBUG
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseItem() Wrong Type" << std::endl;
#endif
return NULL; /* wrong type */
@ -234,7 +247,7 @@ RsDiscOwnItem *RsDiscSerialiser::deserialiseOwnItem(void *data, uint32_t *pktsiz
if (*pktsize < rssize) /* check size */
{
#ifdef RSSERIAL_DEBUG
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseItem() Not Enough Space" << std::endl;
#endif
return NULL; /* not enough data */
@ -253,16 +266,16 @@ RsDiscOwnItem *RsDiscSerialiser::deserialiseOwnItem(void *data, uint32_t *pktsiz
offset += 8;
/* get mandatory parts first */
ok &= GetTlvIpAddrPortV4(data, rssize, &offset,
ok &= GetTlvIpAddrPortV4(data, rssize, &offset,
TLV_TYPE_IPV4_LOCAL, &(item->laddr));
ok &= GetTlvIpAddrPortV4(data, rssize, &offset,
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));
if (offset != rssize)
{
#ifdef RSSERIAL_DEBUG
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseItem() offset != rssize" << std::endl;
#endif
/* error */
@ -272,7 +285,7 @@ RsDiscOwnItem *RsDiscSerialiser::deserialiseOwnItem(void *data, uint32_t *pktsiz
if (!ok)
{
#ifdef RSSERIAL_DEBUG
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseItem() ok = false" << std::endl;
#endif
delete item;
@ -358,7 +371,7 @@ bool RsDiscSerialiser::serialiseReply(RsDiscReply *item, void *data, uint32_
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::serialiseReply() Header: " << ok << std::endl;
std::cerr << "RsDiscSerialiser::serialiseReply() Size: " << tlvsize << std::endl;
#endif
@ -379,7 +392,7 @@ bool RsDiscSerialiser::serialiseReply(RsDiscReply *item, void *data, uint32_
if (offset != tlvsize)
{
ok = false;
#ifdef RSSERIAL_DEBUG
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::serialiseReply() Size Error! " << std::endl;
#endif
}
@ -400,7 +413,7 @@ RsDiscReply *RsDiscSerialiser::deserialiseReply(void *data, uint32_t *pktsize)
(RS_SERVICE_TYPE_DISC != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_DISC_REPLY != getRsItemSubType(rstype)))
{
#ifdef RSSERIAL_DEBUG
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseReply() Wrong Type" << std::endl;
#endif
return NULL; /* wrong type */
@ -408,7 +421,7 @@ RsDiscReply *RsDiscSerialiser::deserialiseReply(void *data, uint32_t *pktsize)
if (*pktsize < rssize) /* check size */
{
#ifdef RSSERIAL_DEBUG
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseReply() pktsize != rssize" << std::endl;
#endif
return NULL; /* not enough data */
@ -427,21 +440,21 @@ RsDiscReply *RsDiscSerialiser::deserialiseReply(void *data, uint32_t *pktsize)
offset += 8;
/* get mandatory parts first */
ok &= GetTlvIpAddrPortV4(data, rssize, &offset,
ok &= GetTlvIpAddrPortV4(data, rssize, &offset,
TLV_TYPE_IPV4_LOCAL, &(item->laddr));
ok &= GetTlvIpAddrPortV4(data, rssize, &offset,
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));
ok &= GetTlvString(data, rssize, &offset,
ok &= GetTlvString(data, rssize, &offset,
TLV_TYPE_STR_PEERID, item->aboutId);
ok &= item->certDER.GetTlv(data, rssize, &offset);
if (offset != rssize)
{
#ifdef RSSERIAL_DEBUG
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseReply() offset != rssize" << std::endl;
#endif
/* error */
@ -451,7 +464,7 @@ RsDiscReply *RsDiscSerialiser::deserialiseReply(void *data, uint32_t *pktsize)
if (!ok)
{
#ifdef RSSERIAL_DEBUG
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseReply() ok = false" << std::endl;
#endif
delete item;
@ -513,7 +526,7 @@ bool RsDiscSerialiser::serialiseIssuer(RsDiscIssuer *item, void *data, uint3
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::serialiseIssuer() Header: " << ok << std::endl;
std::cerr << "RsDiscSerialiser::serialiseIssuer() Size: " << tlvsize << std::endl;
#endif
@ -527,7 +540,7 @@ bool RsDiscSerialiser::serialiseIssuer(RsDiscIssuer *item, void *data, uint3
if (offset != tlvsize)
{
ok = false;
#ifdef RSSERIAL_DEBUG
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::serialiseIssuer() Size Error! " << std::endl;
std::cerr << "Offset: " << offset << " tlvsize: " << tlvsize << std::endl;
#endif
@ -549,7 +562,7 @@ RsDiscIssuer *RsDiscSerialiser::deserialiseIssuer(void *data, uint32_t *pktsize)
(RS_SERVICE_TYPE_DISC != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_DISC_ISSUER != getRsItemSubType(rstype)))
{
#ifdef RSSERIAL_DEBUG
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseIssuer() Wrong Type" << std::endl;
#endif
return NULL; /* wrong type */
@ -557,7 +570,7 @@ RsDiscIssuer *RsDiscSerialiser::deserialiseIssuer(void *data, uint32_t *pktsize)
if (*pktsize < rssize) /* check size */
{
#ifdef RSSERIAL_DEBUG
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseIssuer() pktsize != rssize" << std::endl;
std::cerr << "Pktsize: " << *pktsize << " Rssize: " << rssize << std::endl;
#endif
@ -581,7 +594,7 @@ RsDiscIssuer *RsDiscSerialiser::deserialiseIssuer(void *data, uint32_t *pktsize)
if (offset != rssize)
{
#ifdef RSSERIAL_DEBUG
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseIssuer() offset != rssize" << std::endl;
std::cerr << "Offset: " << offset << " Rssize: " << rssize << std::endl;
#endif
@ -592,7 +605,7 @@ RsDiscIssuer *RsDiscSerialiser::deserialiseIssuer(void *data, uint32_t *pktsize)
if (!ok)
{
#ifdef RSSERIAL_DEBUG
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseIssuer() ok = false" << std::endl;
#endif
delete item;
@ -604,4 +617,138 @@ RsDiscIssuer *RsDiscSerialiser::deserialiseIssuer(void *data, uint32_t *pktsize)
/*************************************************************************/
RsDiscVersion::~RsDiscVersion()
{
return;
}
void RsDiscVersion::clear()
{
version = "";
}
std::ostream &RsDiscVersion::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsDiscVersion", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Version String: " << version << std::endl;
printRsItemEnd(out, "RsDiscVersion", indent);
return out;
}
uint32_t RsDiscSerialiser::sizeVersion(RsDiscVersion *item)
{
uint32_t s = 8;
s += GetTlvStringSize(item->version);
return s;
}
/* serialise the data to the buffer */
bool RsDiscSerialiser::serialiseVersion(RsDiscVersion *item, void *data, uint32_t *pktsize)
{
uint32_t tlvsize = sizeVersion(item);
uint32_t offset = 0;
if (*pktsize < tlvsize)
return false; /* not enough space */
*pktsize = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, *pktsize, item->PacketId(), *pktsize);
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::serialiseVersion() Header: " << ok << std::endl;
std::cerr << "RsDiscSerialiser::serialiseVersion() Size: " << tlvsize << std::endl;
#endif
/* skip the header */
offset += 8;
ok &= setRawString(data, tlvsize, &offset, item->version);
if (offset != tlvsize)
{
ok = false;
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::serialiseVersion() Size Error! " << std::endl;
std::cerr << "Offset: " << offset << " tlvsize: " << tlvsize << std::endl;
#endif
}
return ok;
}
RsDiscVersion *RsDiscSerialiser::deserialiseVersion(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_VERSION != getRsItemSubType(rstype)))
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseVersion() Wrong Type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*pktsize < rssize) /* check size */
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseVersion() 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 */
RsDiscVersion *item = new RsDiscVersion();
item->clear();
/* skip the header */
offset += 8;
ok &= getRawString(data, rssize, &offset, item->version);
if (offset != rssize)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseVersion() 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::deserialiseVersion() ok = false" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*************************************************************************/

View File

@ -32,10 +32,11 @@
#include "serialiser/rstlvbase.h"
#include "serialiser/rstlvtypes.h"
#include "serialiser/rsserviceids.h"
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;
const uint8_t RS_PKT_SUBTYPE_DISC_VERSION = 0x04;
class RsDiscItem: public RsItem
{
@ -43,12 +44,14 @@ class RsDiscItem: public RsItem
RsDiscItem(uint8_t subtype) :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_DISC, subtype) {}
};
class RsDiscOwnItem: public RsDiscItem
{
public:
RsDiscOwnItem() :RsDiscItem(RS_PKT_SUBTYPE_DISC_OWN ) {}
virtual ~RsDiscOwnItem();
virtual void clear();
@ -68,13 +71,13 @@ class RsDiscReply: public RsDiscItem
public:
RsDiscReply()
:RsDiscItem(RS_PKT_SUBTYPE_DISC_REPLY),
:RsDiscItem(RS_PKT_SUBTYPE_DISC_REPLY),
certDER(TLV_TYPE_CERT_XPGP_DER)
{ return; }
virtual ~RsDiscReply();
virtual void clear();
virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
struct sockaddr_in laddr;
@ -99,12 +102,26 @@ class RsDiscIssuer: public RsDiscItem
virtual ~RsDiscIssuer();
virtual void clear();
virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
std::string issuerCert;
};
class RsDiscVersion: public RsDiscItem
{
public:
RsDiscVersion() :RsDiscItem(RS_PKT_SUBTYPE_DISC_VERSION)
{ return; }
virtual ~RsDiscVersion();
virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
std::string version;
};
class RsDiscSerialiser: public RsSerialType
{
public:
@ -132,6 +149,10 @@ virtual uint32_t sizeIssuer(RsDiscIssuer *);
virtual bool serialiseIssuer (RsDiscIssuer *item, void *data, uint32_t *size);
virtual RsDiscIssuer *deserialiseIssuer(void *data, uint32_t *size);
virtual uint32_t sizeVersion(RsDiscVersion *);
virtual bool serialiseVersion(RsDiscVersion *item, void *data, uint32_t *size);
virtual RsDiscVersion *deserialiseVersion(void *data, uint32_t *size);
};

View File

@ -42,6 +42,7 @@ const uint32_t AUTODISC_LDI_SUBTYPE_RPLY = 0x02;
#include "util/rsdebug.h"
#include "util/rsprint.h"
#include "util/rsversion.h"
const int pqidisczone = 2482;
@ -60,6 +61,7 @@ const uint32_t P3DISC_FLAGS_STABLE_UDP = 0x0008;
const uint32_t P3DISC_FLAGS_PEER_ONLINE = 0x0010;
const uint32_t P3DISC_FLAGS_OWN_DETAILS = 0x0020;
const uint32_t P3DISC_FLAGS_PEER_TRUSTS_ME= 0x0040;
const uint32_t P3DISC_FLAGS_ASK_VERSION = 0x0080;
/*****
@ -147,6 +149,7 @@ int p3disc::handleIncoming()
RsDiscOwnItem *dio = NULL;
RsDiscReply *dri = NULL;
RsDiscIssuer *dii = NULL;
RsDiscVersion *dvi = NULL;
#ifdef TO_REMOVE
if (NULL == (di = dynamic_cast<RsDiscItem *> (item)))
@ -172,7 +175,7 @@ int p3disc::handleIncoming()
std::ostringstream out;
out << "p3disc::handleIncoming()";
out << " Received Message!" << std::endl;
di -> print(out);
item -> print(out);
std::cerr << out.str() << std::endl;
#endif
@ -194,6 +197,11 @@ int p3disc::handleIncoming()
nhandled++;
}
#endif
else if (NULL != (dvi = dynamic_cast<RsDiscVersion *> (item)))
{
recvPeerVersionMsg(dvi);
nhandled++;
}
else if (NULL != (dio = dynamic_cast<RsDiscOwnItem *> (item))) /* Ping */
{
recvPeerOwnMsg(dio);
@ -277,13 +285,14 @@ void p3disc::respondToPeer(std::string id)
if (!(detail.visState & RS_VIS_STATE_NODISC))
{
/* send issuer certs ... only do this for friends at initial connections,
/* send issuer certs ... only do this for friends at initial connections,
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)) */
}
}
@ -347,7 +356,7 @@ void p3disc::sendOwnDetails(std::string to)
di -> PeerId(to);
di -> laddr = detail.localaddr;
di -> saddr = detail.serveraddr;
di -> contact_tf = 0;
di -> contact_tf = 0;
/* construct disc flags */
di -> discFlags = 0;
@ -371,6 +380,9 @@ void p3disc::sendOwnDetails(std::string to)
di->discFlags |= P3DISC_FLAGS_STABLE_UDP;
}
// set flag - request for version
di->discFlags |= P3DISC_FLAGS_ASK_VERSION;
di->discFlags |= P3DISC_FLAGS_OWN_DETAILS;
/* send msg */
@ -461,7 +473,7 @@ void p3disc::sendPeerDetails(std::string to, std::string about)
//
RsPeerDetails pd ;
std::string name = rsPeers->getPeerName(about) ;
if(rsPeers->getPeerDetails(to,pd))
if(rsPeers->getPeerDetails(to,pd))
for(std::list<std::string>::const_iterator it(pd.signers.begin());it!=pd.signers.end();++it)
if(*it == name)
{
@ -549,6 +561,28 @@ void p3disc::sendPeerIssuer(std::string to, std::string about)
#endif
}
void p3disc::sendOwnVersion(std::string to)
{
{
#ifdef P3DISC_DEBUG
std::ostringstream out;
out << "p3disc::sendOwnVersion()";
out << " Sending rs version to: " << to << std::endl;
std::cerr << out.str() << std::endl;
#endif
}
RsDiscVersion *di = new RsDiscVersion();
di->PeerId(to);
di->version = RsUtil::retroshareVersion();
/* send the message */
sendItem(di);
#ifdef P3DISC_DEBUG
std::cerr << "Sent DI Message" << std::endl;
#endif
}
/*************************************************************************************/
/* Input Network Msgs */
@ -560,8 +594,8 @@ void p3disc::recvPeerOwnMsg(RsDiscOwnItem *item)
#endif
/* tells us their exact address (mConnectMgr can ignore if it looks wrong) */
uint32_t type = 0;
uint32_t flags = 0;
uint32_t type = 0;
uint32_t flags = 0;
/* translate flags */
if (item->discFlags & P3DISC_FLAGS_USE_DISC)
@ -591,17 +625,23 @@ void p3disc::recvPeerOwnMsg(RsDiscOwnItem *item)
flags |= RS_NET_FLAGS_STABLE_UDP;
}
mConnMgr->peerStatus(item->PeerId(), item->laddr, item->saddr,
mConnMgr->peerStatus(item->PeerId(), item->laddr, item->saddr,
type, flags, RS_CB_PERSON);
/* also add as potential stun buddy */
std::string hashid1 = RsUtil::HashId(item->PeerId(), false);
mConnMgr->stunStatus(hashid1, item->saddr, type,
mConnMgr->stunStatus(hashid1, item->saddr, type,
RS_STUN_ONLINE | RS_STUN_FRIEND);
/* now reply with all details */
respondToPeer(item->PeerId());
/*sending rs versio if i was asked*/
if (item->discFlags & P3DISC_FLAGS_ASK_VERSION)
{
sendOwnVersion(item->PeerId());
}
addDiscoveryData(item->PeerId(), item->PeerId(), item->laddr, item->saddr, item->discFlags, time(NULL));
/* cleanup (handled by caller) */
@ -627,14 +667,14 @@ void p3disc::recvPeerFriendMsg(RsDiscReply *item)
bool loaded = mAuthMgr->LoadCertificateFromBinary(certptr, len, peerId);
uint32_t type = 0;
uint32_t flags = 0;
uint32_t type = 0;
uint32_t flags = 0;
/* translate flags */
if (item->discFlags & P3DISC_FLAGS_USE_DISC) flags |= RS_NET_FLAGS_USE_DISC;
if (item->discFlags & P3DISC_FLAGS_USE_DHT) flags |= RS_NET_FLAGS_USE_DHT;
if (item->discFlags & P3DISC_FLAGS_PEER_ONLINE) flags |= RS_NET_FLAGS_ONLINE;
if (item->discFlags & P3DISC_FLAGS_PEER_TRUSTS_ME)
if (item->discFlags & P3DISC_FLAGS_PEER_TRUSTS_ME)
{
std::cerr << " Found a peer that trust me: " << peerId << " (" << rsPeers->getPeerName(peerId) << ")" << std::endl ;
flags |= RS_NET_FLAGS_TRUSTS_ME;
@ -667,7 +707,7 @@ void p3disc::recvPeerFriendMsg(RsDiscReply *item)
addDiscoveryData(item->PeerId(), peerId, item->laddr, item->saddr, item->discFlags, time(NULL));
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_NEIGHBOURS, NOTIFY_TYPE_MOD);
/* cleanup (handled by caller) */
}
@ -691,6 +731,18 @@ void p3disc::recvPeerIssuerMsg(RsDiscIssuer *item)
return;
}
void p3disc::recvPeerVersionMsg(RsDiscVersion *item)
{
#ifdef P3DISC_DEBUG
std::cerr << "p3disc::recvPeerVersionMsg() From: " << item->PeerId();
std::cerr << std::endl;
#endif
// dont need protection
versions[item->PeerId()] = item->version;
return;
}
/*************************************************************************************/
/* Storing Network Graph */
@ -734,7 +786,7 @@ int p3disc::addDiscoveryData(std::string fromId, std::string aboutId, struct soc
bool authDetails = (as.id == it->second.id);
/* KEY decision about address */
if ((authDetails) ||
if ((authDetails) ||
((!(it->second.authoritative)) && (as.ts > it->second.ts)))
{
/* copy details to an */
@ -780,6 +832,10 @@ bool p3disc::potentialproxies(std::string id, std::list<std::string> &proxyIds)
return true;
}
void p3disc::getversions(std::map<std::string, std::string> &versions)
{
versions = this->versions;
}
int p3disc::idServers()
{
@ -808,7 +864,7 @@ int p3disc::idServers()
out << " -->DiscFlags: 0x" << std::hex << nit->second.discFlags;
out << std::dec << std::endl;
for(sit = (nit->second.neighbour_of).begin();
for(sit = (nit->second.neighbour_of).begin();
sit != (nit->second.neighbour_of).end(); sit++)
{
out << "\tConnected via: " << (sit->first);
@ -869,7 +925,7 @@ int convertTRangeToTDelta(int trange)
{
if (trange <= 0)
return -1;
return (int) (pow(10.0, trange) - 1.5); // (int) xxx98.5 -> xxx98
}

View File

@ -90,6 +90,7 @@ int tick();
/* GUI requires access */
bool potentialproxies(std::string id, std::list<std::string> &proxyIds);
void getversions(std::map<std::string, std::string> &versions);
private:
@ -98,6 +99,7 @@ void respondToPeer(std::string id);
/* Network Output */
void sendOwnDetails(std::string to);
void sendOwnVersion(std::string to);
void sendPeerDetails(std::string to, std::string about);
void sendPeerIssuer(std::string to, std::string about);
@ -106,10 +108,11 @@ int handleIncoming();
void recvPeerOwnMsg(RsDiscOwnItem *item);
void recvPeerFriendMsg(RsDiscReply *item);
void recvPeerIssuerMsg(RsDiscIssuer *item);
void recvPeerVersionMsg(RsDiscVersion *item);
/* handle network shape */
int addDiscoveryData(std::string fromId, std::string aboutId,
struct sockaddr_in laddr, struct sockaddr_in raddr,
struct sockaddr_in laddr, struct sockaddr_in raddr,
uint32_t flags, time_t ts);
int idServers();
@ -128,7 +131,7 @@ int idServers();
bool mLocalDisc;
std::map<std::string, autoneighbour> neighbours;
std::map<std::string, std::string> versions;
};

View File

@ -0,0 +1,13 @@
/*
* rsversion.cc
*
* Created on: Jun 23, 2009
* Author: alexandrut
*/
#include "rsversion.h"
std::string RsUtil::retroshareVersion()
{
return std::string(VERSION);
}

View File

@ -0,0 +1,21 @@
/*
* rsversion.h
*
* Created on: Jun 23, 2009
* Author: alexandrut
*/
#ifndef RSVERSIONXX_H_
#define RSVERSIONXX_H_
#include <string>
#define VERSION "0.4.13a"
namespace RsUtil {
std::string retroshareVersion();
}
#endif /* RSVERSION_H_ */

View File

@ -38,6 +38,7 @@
#include <sstream>
#include "rsiface/rsfiles.h"
#include "rsiface/rspeers.h"
#include "rsiface/rsdisc.h"
#include <algorithm>
/* Images for context menu icons */
@ -608,6 +609,10 @@ void TransfersDialog::insertTransfers()
/* continue to next download item if no peers to add */
if (!info.peers.size()) continue;
std::map<std::string, std::string>::iterator vit;
std::map<std::string, std::string> versions;
bool retv = rsDisc->getDiscVersions(versions);
int dlPeers = 0;
for (pit = info.peers.begin(); pit != info.peers.end(); pit++) {
symbol = "";
@ -617,8 +622,10 @@ void TransfersDialog::insertTransfers()
fileSize = info.size;
progress = (info.transfered * 100.0) / info.size;
dlspeed = pit->tfRate * 1024.0;
//sources = QString("rShare v %1").arg(tr("0.4.13a"));//TODO: take it from somewhere
sources = "";
if (retv && versions.end() != (vit = versions.find(pit->peerId))) {
sources = QString("rShare v") + QString::fromStdString(vit->second);
}
if (info.downloadStatus == FT_STATE_COMPLETE) {
status = tr("Complete");

View File

@ -29,6 +29,7 @@
#include <inttypes.h>
#include <string>
#include <list>
#include <map>
/* The Main Interface Class - for information about your Peers */
class RsDisc;
@ -42,6 +43,7 @@ class RsDisc
virtual ~RsDisc() { return; }
virtual bool getDiscFriends(std::string id, std::list<std::string> &friends) = 0;
virtual bool getDiscVersions(std::map<std::string, std::string> &versions) = 0;
};