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;
@ -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

@ -36,6 +36,7 @@
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();
@ -105,6 +108,20 @@ 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);
@ -284,6 +292,7 @@ void p3disc::respondToPeer(std::string id)
#ifdef RS_USE_PGPSSL
sendPeerIssuer(id, *it);
#endif
sendPeerDetails(id, *it); /* (dest (to), source (cert)) */
}
}
@ -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 */
@ -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 */
@ -602,6 +636,12 @@ void p3disc::recvPeerOwnMsg(RsDiscOwnItem *item)
/* 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) */
@ -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 */
@ -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()
{

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,6 +108,7 @@ 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,
@ -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;
};