merge of QoS branch into trunk

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4588 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2011-09-04 20:01:30 +00:00
parent 663ce50630
commit 0ed60eaf86
23 changed files with 734 additions and 337 deletions

View file

@ -0,0 +1,75 @@
/*
* libretroshare/src/serialiser: itempriorities.h
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2011-2011 by Cyril Soler
*
* 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 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 "csoler@users.sourceforge.net"
*
*/
// This file centralises QoS priorities for all transfer RsItems.
//
const uint8_t QOS_PRIORITY_UNKNOWN = 0 ;
const uint8_t QOS_PRIORITY_DEFAULT = 3 ;
const uint8_t QOS_PRIORITY_TOP = 9 ;
// Turtle traffic
//
const uint8_t QOS_PRIORITY_RS_TURTLE_OPEN_TUNNEL = 6 ;
const uint8_t QOS_PRIORITY_RS_TURTLE_TUNNEL_OK = 6 ;
const uint8_t QOS_PRIORITY_RS_TURTLE_SEARCH_REQUEST = 5 ;
const uint8_t QOS_PRIORITY_RS_TURTLE_FILE_REQUEST = 5 ;
const uint8_t QOS_PRIORITY_RS_TURTLE_FILE_CRC_REQUEST = 5 ;
const uint8_t QOS_PRIORITY_RS_TURTLE_FILE_MAP_REQUEST = 5 ;
const uint8_t QOS_PRIORITY_RS_TURTLE_SEARCH_RESULT = 3 ;
const uint8_t QOS_PRIORITY_RS_TURTLE_FILE_DATA = 3 ;
const uint8_t QOS_PRIORITY_RS_TURTLE_FILE_CRC = 3 ;
const uint8_t QOS_PRIORITY_RS_TURTLE_FILE_MAP = 3 ;
const uint8_t QOS_PRIORITY_RS_TURTLE_GENERIC_ITEM = 3 ;
const uint8_t QOS_PRIORITY_RS_TURTLE_FORWARD_FILE_DATA= 2 ;
// File transfer
//
const uint8_t QOS_PRIORITY_RS_FILE_REQUEST = 5 ;
const uint8_t QOS_PRIORITY_RS_FILE_CRC_REQUEST = 5 ;
const uint8_t QOS_PRIORITY_RS_FILE_MAP_REQUEST = 5 ;
const uint8_t QOS_PRIORITY_RS_CACHE_REQUEST = 4 ;
const uint8_t QOS_PRIORITY_RS_FILE_DATA = 3 ;
const uint8_t QOS_PRIORITY_RS_FILE_CRC = 3 ;
const uint8_t QOS_PRIORITY_RS_FILE_MAP = 3 ;
const uint8_t QOS_PRIORITY_RS_CACHE_ITEM = 3 ;
// Discovery
//
const uint8_t QOS_PRIORITY_RS_DISC_HEART_BEAT = 8 ;
const uint8_t QOS_PRIORITY_RS_DISC_ASK_INFO = 2 ;
const uint8_t QOS_PRIORITY_RS_DISC_REPLY = 1 ;
const uint8_t QOS_PRIORITY_RS_DISC_VERSION = 1 ;
// Chat/Msgs
//
const uint8_t QOS_PRIORITY_RS_CHAT_ITEM = 7 ;
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
//
const uint8_t QOS_PRIORITY_RS_VOIP_PING = 9 ;

View file

@ -55,7 +55,9 @@ class RsFileRequest: public RsItem
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_BASE,
RS_PKT_TYPE_FILE,
RS_PKT_SUBTYPE_FI_REQUEST)
{ return; }
{
setPriorityLevel(QOS_PRIORITY_RS_FILE_REQUEST) ;
}
virtual ~RsFileRequest();
virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
@ -74,7 +76,9 @@ class RsFileData: public RsItem
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_BASE,
RS_PKT_TYPE_FILE,
RS_PKT_SUBTYPE_FI_DATA)
{ return; }
{
setPriorityLevel(QOS_PRIORITY_RS_FILE_DATA) ;
}
virtual ~RsFileData();
virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
@ -87,7 +91,9 @@ class RsFileChunkMapRequest: public RsItem
public:
RsFileChunkMapRequest()
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_BASE, RS_PKT_TYPE_FILE, RS_PKT_SUBTYPE_FI_CHUNK_MAP_REQUEST)
{}
{
setPriorityLevel(QOS_PRIORITY_RS_FILE_MAP_REQUEST) ;
}
virtual ~RsFileChunkMapRequest() {}
virtual void clear() {}
@ -102,7 +108,9 @@ class RsFileChunkMap: public RsItem
public:
RsFileChunkMap()
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_BASE, RS_PKT_TYPE_FILE, RS_PKT_SUBTYPE_FI_CHUNK_MAP)
{}
{
setPriorityLevel(QOS_PRIORITY_RS_FILE_MAP) ;
}
virtual ~RsFileChunkMap() {}
virtual void clear() {}
@ -118,7 +126,9 @@ class RsFileCRC32MapRequest: public RsItem
public:
RsFileCRC32MapRequest()
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_BASE, RS_PKT_TYPE_FILE, RS_PKT_SUBTYPE_FI_CRC32_MAP_REQUEST)
{}
{
setPriorityLevel(QOS_PRIORITY_RS_FILE_CRC_REQUEST) ;
}
virtual ~RsFileCRC32MapRequest() {}
virtual void clear() {}
@ -132,7 +142,9 @@ class RsFileCRC32Map: public RsItem
public:
RsFileCRC32Map()
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_BASE, RS_PKT_TYPE_FILE, RS_PKT_SUBTYPE_FI_CRC32_MAP)
{}
{
setPriorityLevel(QOS_PRIORITY_RS_FILE_CRC) ;
}
virtual ~RsFileCRC32Map() {}
virtual void clear() {}
@ -190,7 +202,9 @@ class RsCacheRequest: public RsItem
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_BASE,
RS_PKT_TYPE_CACHE,
RS_PKT_SUBTYPE_CACHE_REQUEST)
{ return; }
{
setPriorityLevel(QOS_PRIORITY_RS_CACHE_REQUEST);
}
virtual ~RsCacheRequest();
virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
@ -209,7 +223,9 @@ class RsCacheItem: public RsItem
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_BASE,
RS_PKT_TYPE_CACHE,
RS_PKT_SUBTYPE_CACHE_ITEM)
{ return; }
{
setPriorityLevel(QOS_PRIORITY_RS_CACHE_ITEM);
}
virtual ~RsCacheItem();
virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);

View file

@ -78,7 +78,9 @@ class RsDiscReply: public RsDiscItem
RsDiscReply()
:RsDiscItem(RS_PKT_SUBTYPE_DISC_REPLY)
{ return; }
{
setPriorityLevel(QOS_PRIORITY_RS_DISC_REPLY);
}
virtual ~RsDiscReply();
@ -107,7 +109,9 @@ class RsDiscAskInfo: public RsDiscItem
RsDiscAskInfo()
:RsDiscItem(RS_PKT_SUBTYPE_DISC_ASK_INFO)
{ return; }
{
setPriorityLevel(QOS_PRIORITY_RS_DISC_ASK_INFO);
}
virtual ~RsDiscAskInfo();
@ -121,7 +125,9 @@ class RsDiscVersion: public RsDiscItem
{
public:
RsDiscVersion() :RsDiscItem(RS_PKT_SUBTYPE_DISC_VERSION)
{ return; }
{
setPriorityLevel(QOS_PRIORITY_RS_DISC_VERSION);
}
virtual ~RsDiscVersion();
@ -135,7 +141,9 @@ class RsDiscHeartbeat: public RsDiscItem
{
public:
RsDiscHeartbeat() :RsDiscItem(RS_PKT_SUBTYPE_DISC_HEARTBEAT)
{ return; }
{
setPriorityLevel(QOS_PRIORITY_RS_DISC_HEART_BEAT) ;
}
virtual ~RsDiscHeartbeat();

View file

@ -33,6 +33,7 @@
#define RSSERIAL_DEBUG 1
#define CHAT_DEBUG 1
***/
#define CHAT_DEBUG 1
#include <iostream>
@ -244,6 +245,10 @@ bool RsChatMsgItem::serialise(void *data, uint32_t& pktsize)
std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ;
#endif
std::cerr << "Serialization result: " ;
for(int i=0;i<20;++i)
std::cerr << (int)((uint8_t*)data)[i] << " " ;
std::cerr << std::endl ;
return ok;
}
@ -379,6 +384,11 @@ RsChatMsgItem::RsChatMsgItem(void *data,uint32_t /*size*/)
uint32_t rssize = getRsItemSize(data);
bool ok = true ;
std::cerr << "Received packet result: " ;
for(int i=0;i<20;++i)
std::cerr << (int)((uint8_t*)data)[i] << " " ;
std::cerr << std::endl ;
/* get mandatory parts first */
ok &= getRawUInt32(data, rssize, &offset, &chatFlags);
ok &= getRawUInt32(data, rssize, &offset, &sendTime);

View file

@ -61,7 +61,10 @@ const uint8_t RS_PKT_SUBTYPE_MSG_PARENT_TAG = 0x06;
class RsChatItem: public RsItem
{
public:
RsChatItem(uint8_t chat_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_CHAT,chat_subtype) {}
RsChatItem(uint8_t chat_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_CHAT,chat_subtype)
{
setPriorityLevel(QOS_PRIORITY_RS_CHAT_ITEM) ;
}
virtual ~RsChatItem() {}
virtual void clear() {}
@ -78,7 +81,9 @@ class RsChatItem: public RsItem
class RsChatMsgItem: public RsChatItem
{
public:
RsChatMsgItem() :RsChatItem(RS_PKT_SUBTYPE_DEFAULT) {}
RsChatMsgItem() :RsChatItem(RS_PKT_SUBTYPE_DEFAULT)
{
}
RsChatMsgItem(void *data,uint32_t size) ; // deserialization
virtual ~RsChatMsgItem() {}
@ -148,7 +153,7 @@ class RsChatStatusItem: public RsChatItem
class RsChatAvatarItem: public RsChatItem
{
public:
RsChatAvatarItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_AVATAR) {}
RsChatAvatarItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_AVATAR) {setPriorityLevel(QOS_PRIORITY_RS_CHAT_AVATAR_ITEM) ;}
RsChatAvatarItem(void *data,uint32_t size) ; // deserialization
virtual ~RsChatAvatarItem() ;
@ -196,12 +201,12 @@ class RsMsgItem: public RsItem
RsMsgItem()
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_MSG,
RS_PKT_SUBTYPE_DEFAULT)
{ return; }
{ setPriorityLevel(QOS_PRIORITY_RS_MSG_ITEM) ; }
RsMsgItem(uint16_t type)
:RsItem(RS_PKT_VERSION_SERVICE, type,
RS_PKT_SUBTYPE_DEFAULT)
{ return; }
{ setPriorityLevel(QOS_PRIORITY_RS_MSG_ITEM) ; }
virtual ~RsMsgItem();
virtual void clear();

View file

@ -49,7 +49,7 @@
RsItem::RsItem(uint32_t t)
:type(t)
{
return;
_priority_level = QOS_PRIORITY_UNKNOWN ; // This value triggers PQIInterface to complain about undefined priorities
}
#ifdef DO_STATISTICS
@ -116,13 +116,13 @@ void RsItem::operator delete(void *p,size_t s)
RsItem::RsItem(uint8_t ver, uint8_t cls, uint8_t t, uint8_t subtype)
{
_priority_level = QOS_PRIORITY_UNKNOWN ; // This value triggers PQIInterface to complain about undefined priorities
type = (ver << 24) + (cls << 16) + (t << 8) + subtype;
return;
}
RsItem::~RsItem()
{
return;
}
@ -158,6 +158,7 @@ uint8_t RsItem::PacketSubType()
/* For Service Packets */
RsItem::RsItem(uint8_t ver, uint16_t service, uint8_t subtype)
{
_priority_level = QOS_PRIORITY_UNKNOWN ; // This value triggers PQIInterface to complain about undefined priorities
type = (ver << 24) + (service << 8) + subtype;
return;
}

View file

@ -57,6 +57,7 @@
******************************************************************/
#include <util/smallobject.h>
#include "itempriorities.h"
const uint8_t RS_PKT_VERSION1 = 0x01;
const uint8_t RS_PKT_VERSION_SERVICE = 0x02;
@ -70,40 +71,40 @@ const uint8_t RS_PKT_SUBTYPE_DEFAULT = 0x01; /* if only one subtype */
class RsItem: public RsMemoryManagement::SmallObject
{
public:
RsItem(uint32_t t);
RsItem(uint8_t ver, uint8_t cls, uint8_t t, uint8_t subtype);
RsItem(uint32_t t);
RsItem(uint8_t ver, uint8_t cls, uint8_t t, uint8_t subtype);
#ifdef DO_STATISTICS
void *operator new(size_t s) ;
void operator delete(void *,size_t s) ;
void *operator new(size_t s) ;
void operator delete(void *,size_t s) ;
#endif
virtual ~RsItem();
virtual void clear() = 0;
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0) = 0;
virtual ~RsItem();
virtual void clear() = 0;
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0) = 0;
/* source / destination id */
const std::string& PeerId() const { return peerId; }
void PeerId(const std::string& id) { peerId = id; }
/* source / destination id */
const std::string& PeerId() const { return peerId; }
void PeerId(const std::string& id) { peerId = id; }
/* complete id */
uint32_t PacketId();
/* complete id */
uint32_t PacketId();
/* id parts */
uint8_t PacketVersion();
uint8_t PacketClass();
uint8_t PacketType();
uint8_t PacketSubType();
/* id parts */
uint8_t PacketVersion();
uint8_t PacketClass();
uint8_t PacketType();
uint8_t PacketSubType();
/* For Service Packets */
RsItem(uint8_t ver, uint16_t service, uint8_t subtype);
uint16_t PacketService(); /* combined Packet class/type (mid 16bits) */
typedef enum { CONTROL_QUEUE, DATA_QUEUE } QueueType ;
virtual QueueType queueType() const { return CONTROL_QUEUE ; }
/* For Service Packets */
RsItem(uint8_t ver, uint16_t service, uint8_t subtype);
uint16_t PacketService(); /* combined Packet class/type (mid 16bits) */
inline uint8_t priority_level() const { return _priority_level ;}
inline void setPriorityLevel(uint8_t l) { _priority_level = l ;}
private:
uint32_t type;
std::string peerId;
uint32_t type;
std::string peerId;
uint8_t _priority_level ;
};
@ -172,31 +173,29 @@ std::ostream &printIndent(std::ostream &out, uint16_t indent);
class RsRawItem: public RsItem
{
public:
RsRawItem(uint32_t t, uint32_t size)
:RsItem(t), len(size), _queue_type(RsItem::CONTROL_QUEUE)
{ data = malloc(len);}
RsRawItem(uint32_t t, uint32_t size)
:RsItem(t), len(size)
{
data = malloc(len);
}
virtual ~RsRawItem()
{
if (data)
free(data);
data = NULL;
len = 0;
}
virtual ~RsRawItem()
{
if (data)
free(data);
data = NULL;
len = 0;
}
uint32_t getRawLength() { return len; }
void * getRawData() { return data; }
uint32_t getRawLength() { return len; }
void *getRawData() { return data; }
virtual void clear() { return; } /* what can it do? */
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
virtual RsItem::QueueType queueType() const { return _queue_type ;}
void setQueueType(const RsItem::QueueType& t) { _queue_type = t ;}
virtual void clear() { return; } /* what can it do? */
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
private:
void *data;
uint32_t len;
RsItem::QueueType _queue_type ;
void *data;
uint32_t len;
};

View file

@ -37,7 +37,9 @@ class RsStatusItem: public RsItem
RsStatusItem()
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_STATUS,
RS_PKT_SUBTYPE_DEFAULT)
{ return; }
{
setPriorityLevel(QOS_PRIORITY_RS_STATUS_ITEM);
}
virtual ~RsStatusItem();
virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);

View file

@ -40,7 +40,8 @@ const uint8_t RS_PKT_SUBTYPE_VOIP_PONG = 0x02;
class RsVoipItem: public RsItem
{
public:
RsVoipItem(uint8_t chat_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_VOIP,chat_subtype) {}
RsVoipItem(uint8_t chat_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_VOIP,chat_subtype)
{ setPriorityLevel(QOS_PRIORITY_RS_VOIP_PING) ;} // should be refined later.
virtual ~RsVoipItem() {};
virtual void clear() {};