Added Round Trip Time service (revived old p3VoRS service).

- Fixed gxs priority level.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.6-initdev@6776 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2013-09-29 07:11:02 +00:00
parent ba157e4891
commit 41daabe1ef
10 changed files with 1147 additions and 9 deletions

View file

@ -87,9 +87,9 @@ const uint8_t QOS_PRIORITY_RS_CHAT_AVATAR_ITEM = 2 ;
const uint8_t QOS_PRIORITY_RS_MSG_ITEM = 2 ;
const uint8_t QOS_PRIORITY_RS_STATUS_ITEM = 2 ;
// VOIP
// RTT
//
const uint8_t QOS_PRIORITY_RS_VOIP_PING = 9 ;
const uint8_t QOS_PRIORITY_RS_RTT_PING = 9 ;
// BanList
//

View file

@ -70,7 +70,7 @@ public:
RsNxsItem(uint16_t servtype, uint8_t subtype)
: RsItem(RS_PKT_VERSION_SERVICE, servtype, subtype), transactionNumber(0)
{
setPriorityLevel(QOS_PRIORITY_RS_VOIP_PING);
setPriorityLevel(QOS_PRIORITY_RS_GXS_NET);
return;
}
virtual ~RsNxsItem(){ return; }

View file

@ -0,0 +1,373 @@
/*
* libretroshare/src/serialiser: rsrttitems.cc
*
* RetroShare Serialiser.
*
* Copyright 2011-2013 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#include "serialiser/rsbaseserial.h"
#include "serialiser/rsrttitems.h"
#include "serialiser/rstlvbase.h"
/***
#define RSSERIAL_DEBUG 1
***/
#include <iostream>
/*************************************************************************/
RsRttPingItem::~RsRttPingItem()
{
return;
}
void RsRttPingItem::clear()
{
mSeqNo = 0;
mPingTS = 0;
}
std::ostream& RsRttPingItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsRttPingItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "SeqNo: " << mSeqNo << std::endl;
printIndent(out, int_Indent);
out << "PingTS: " << std::hex << mPingTS << std::dec << std::endl;
printRsItemEnd(out, "RsRttPingItem", indent);
return out;
}
RsRttPongItem::~RsRttPongItem()
{
return;
}
void RsRttPongItem::clear()
{
mSeqNo = 0;
mPingTS = 0;
mPongTS = 0;
}
std::ostream& RsRttPongItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsRttPongItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "SeqNo: " << mSeqNo << std::endl;
printIndent(out, int_Indent);
out << "PingTS: " << std::hex << mPingTS << std::dec << std::endl;
printIndent(out, int_Indent);
out << "PongTS: " << std::hex << mPongTS << std::dec << std::endl;
printRsItemEnd(out, "RsRttPongItem", indent);
return out;
}
/*************************************************************************/
uint32_t RsRttSerialiser::sizeRttPingItem(RsRttPingItem */*item*/)
{
uint32_t s = 8; /* header */
s += 4; /* seqno */
s += 8; /* pingTS */
return s;
}
/* serialise the data to the buffer */
bool RsRttSerialiser::serialiseRttPingItem(RsRttPingItem *item, void *data, uint32_t *pktsize)
{
uint32_t tlvsize = sizeRttPingItem(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 << "RsRttSerialiser::serialiseRttPingItem() Header: " << ok << std::endl;
std::cerr << "RsRttSerialiser::serialiseRttPingItem() Size: " << tlvsize << std::endl;
#endif
/* skip the header */
offset += 8;
/* add mandatory parts first */
ok &= setRawUInt32(data, tlvsize, &offset, item->mSeqNo);
ok &= setRawUInt64(data, tlvsize, &offset, item->mPingTS);
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsRttSerialiser::serialiseRttPingItem() Size Error! " << std::endl;
}
return ok;
}
RsRttPingItem *RsRttSerialiser::deserialiseRttPingItem(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_RTT != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_RTT_PING != getRsItemSubType(rstype)))
{
return NULL; /* wrong type */
}
if (*pktsize < rssize) /* check size */
return NULL; /* not enough data */
/* set the packet length */
*pktsize = rssize;
bool ok = true;
/* ready to load */
RsRttPingItem *item = new RsRttPingItem();
item->clear();
/* skip the header */
offset += 8;
/* get mandatory parts first */
ok &= getRawUInt32(data, rssize, &offset, &(item->mSeqNo));
ok &= getRawUInt64(data, rssize, &offset, &(item->mPingTS));
if (offset != rssize)
{
/* error */
delete item;
return NULL;
}
if (!ok)
{
delete item;
return NULL;
}
return item;
}
/*************************************************************************/
/*************************************************************************/
uint32_t RsRttSerialiser::sizeRttPongItem(RsRttPongItem */*item*/)
{
uint32_t s = 8; /* header */
s += 4; /* seqno */
s += 8; /* pingTS */
s += 8; /* pongTS */
return s;
}
/* serialise the data to the buffer */
bool RsRttSerialiser::serialiseRttPongItem(RsRttPongItem *item, void *data, uint32_t *pktsize)
{
uint32_t tlvsize = sizeRttPongItem(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 << "RsRttSerialiser::serialiseRttPongItem() Header: " << ok << std::endl;
std::cerr << "RsRttSerialiser::serialiseRttPongItem() Size: " << tlvsize << std::endl;
#endif
/* skip the header */
offset += 8;
/* add mandatory parts first */
ok &= setRawUInt32(data, tlvsize, &offset, item->mSeqNo);
ok &= setRawUInt64(data, tlvsize, &offset, item->mPingTS);
ok &= setRawUInt64(data, tlvsize, &offset, item->mPongTS);
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsRttSerialiser::serialiseRttPongItem() Size Error! " << std::endl;
}
return ok;
}
RsRttPongItem *RsRttSerialiser::deserialiseRttPongItem(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_RTT != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_RTT_PONG != getRsItemSubType(rstype)))
{
return NULL; /* wrong type */
}
if (*pktsize < rssize) /* check size */
return NULL; /* not enough data */
/* set the packet length */
*pktsize = rssize;
bool ok = true;
/* ready to load */
RsRttPongItem *item = new RsRttPongItem();
item->clear();
/* skip the header */
offset += 8;
/* get mandatory parts first */
ok &= getRawUInt32(data, rssize, &offset, &(item->mSeqNo));
ok &= getRawUInt64(data, rssize, &offset, &(item->mPingTS));
ok &= getRawUInt64(data, rssize, &offset, &(item->mPongTS));
if (offset != rssize)
{
/* error */
delete item;
return NULL;
}
if (!ok)
{
delete item;
return NULL;
}
return item;
}
/*************************************************************************/
uint32_t RsRttSerialiser::size(RsItem *i)
{
RsRttPingItem *ping;
RsRttPongItem *pong;
if (NULL != (ping = dynamic_cast<RsRttPingItem *>(i)))
{
return sizeRttPingItem(ping);
}
else if (NULL != (pong = dynamic_cast<RsRttPongItem *>(i)))
{
return sizeRttPongItem(pong);
}
return 0;
}
bool RsRttSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsMsgSerialiser::serialise()" << std::endl;
#endif
RsRttPingItem *ping;
RsRttPongItem *pong;
if (NULL != (ping = dynamic_cast<RsRttPingItem *>(i)))
{
return serialiseRttPingItem(ping, data, pktsize);
}
else if (NULL != (pong = dynamic_cast<RsRttPongItem *>(i)))
{
return serialiseRttPongItem(pong, data, pktsize);
}
return false;
}
RsItem* RsRttSerialiser::deserialise(void *data, uint32_t *pktsize)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsRttSerialiser::deserialise()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_TYPE_RTT != getRsItemService(rstype)))
{
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_RTT_PING:
return deserialiseRttPingItem(data, pktsize);
break;
case RS_PKT_SUBTYPE_RTT_PONG:
return deserialiseRttPongItem(data, pktsize);
break;
default:
return NULL;
break;
}
return NULL;
}
/*************************************************************************/

View file

@ -0,0 +1,108 @@
#ifndef RS_RTT_ITEMS_H
#define RS_RTT_ITEMS_H
/*
* libretroshare/src/serialiser: rsrttitems.h
*
* RetroShare Serialiser.
*
* Copyright 2011-2013 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#include <map>
#include "serialiser/rsserviceids.h"
#include "serialiser/rsserial.h"
#include "serialiser/rstlvtypes.h"
/**************************************************************************/
const uint8_t RS_PKT_SUBTYPE_RTT_PING = 0x01;
const uint8_t RS_PKT_SUBTYPE_RTT_PONG = 0x02;
class RsRttItem: public RsItem
{
public:
RsRttItem(uint8_t chat_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_RTT,chat_subtype)
{ setPriorityLevel(QOS_PRIORITY_RS_RTT_PING) ;} // should be refined later.
virtual ~RsRttItem() {};
virtual void clear() {};
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) = 0 ;
};
class RsRttPingItem: public RsRttItem
{
public:
RsRttPingItem() :RsRttItem(RS_PKT_SUBTYPE_RTT_PING) {}
virtual ~RsRttPingItem();
virtual void clear();
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
uint32_t mSeqNo;
uint64_t mPingTS;
};
class RsRttPongItem: public RsRttItem
{
public:
RsRttPongItem() :RsRttItem(RS_PKT_SUBTYPE_RTT_PONG) {}
virtual ~RsRttPongItem();
virtual void clear();
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
uint32_t mSeqNo;
uint64_t mPingTS;
uint64_t mPongTS;
};
class RsRttSerialiser: public RsSerialType
{
public:
RsRttSerialiser()
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_RTT)
{ return; }
virtual ~RsRttSerialiser() { return; }
virtual uint32_t size(RsItem *);
virtual bool serialise (RsItem *item, void *data, uint32_t *size);
virtual RsItem * deserialise(void *data, uint32_t *size);
private:
virtual uint32_t sizeRttPingItem(RsRttPingItem *);
virtual bool serialiseRttPingItem (RsRttPingItem *item, void *data, uint32_t *size);
virtual RsRttPingItem *deserialiseRttPingItem(void *data, uint32_t *size);
virtual uint32_t sizeRttPongItem(RsRttPongItem *);
virtual bool serialiseRttPongItem (RsRttPongItem *item, void *data, uint32_t *size);
virtual RsRttPongItem *deserialiseRttPongItem(void *data, uint32_t *size);
};
/**************************************************************************/
#endif /* RS_RTT_ITEMS_H */

View file

@ -104,12 +104,15 @@ const uint16_t RS_SERVICE_TYPE_PROXY = 0xf030;
/* DSDV Testing at the moment - Service Only */
const uint16_t RS_SERVICE_TYPE_DSDV = 0xf050;
/* Latency RTT Measurements */
const uint16_t RS_SERVICE_TYPE_RTT = 0xf051;
/* Bandwidth Testing at the moment - Service Only */
const uint16_t RS_SERVICE_TYPE_BWCTRL = 0xf060;
//const uint16_t RS_SERVICE_TYPE_DISTRIB = 0xf110;
//const uint16_t RS_SERVICE_TYPE_FORUM = 0xf120;
//const uint16_t RS_SERVICE_TYPE_CHANNEL = 0xf130;