Merge pull request #412 from csoler/v0.6-MaxUpRate

V0.6 max up rate
This commit is contained in:
Cyril Soler 2016-06-11 17:58:08 -04:00 committed by GitHub
commit 248d0c42d3
20 changed files with 785 additions and 606 deletions

View file

@ -110,10 +110,6 @@ peerConnectState::peerConnectState()
inConnAttempt(0),
wasDeniedConnection(false), deniedTS(false), deniedInConnAttempt(false)
{
//sockaddr_clear(&currentlocaladdr);
//sockaddr_clear(&currentserveraddr);
return;
}
std::string textPeerConnectState(peerConnectState &state)

View file

@ -129,7 +129,6 @@ class peerConnectState
time_t deniedTS;
bool deniedInConnAttempt; /* is below valid */
peerConnectAddress deniedConnectionAttempt;
};
class p3tunnel;
@ -312,7 +311,7 @@ bool addAddressIfUnique(std::list<peerConnectAddress> &addrList, peerConnectAdd
private:
// These should have there own Mutex Protection,
// These should have their own Mutex Protection,
//p3tunnel *mP3tunnel;
DNSResolver *mDNSResolver ;

View file

@ -2009,6 +2009,10 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
#endif
}
RsPeerBandwidthLimitsItem *pblitem = new RsPeerBandwidthLimitsItem ;
pblitem->peers = mPeerBandwidthLimits ;
saveData.push_back(pblitem) ;
RsPeerServicePermissionItem *sitem = new RsPeerServicePermissionItem ;
for(std::map<RsPgpId,ServicePermissionFlags>::const_iterator it(mFriendsPermissionFlags.begin());it!=mFriendsPermissionFlags.end();++it)
@ -2072,6 +2076,61 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
return true;
}
bool p3PeerMgrIMPL::getMaxRates(const RsPeerId& pid,uint32_t& maxUp,uint32_t& maxDn)
{
RsPgpId pgp_id ;
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
std::map<RsPeerId, peerState>::const_iterator it = mFriendList.find(pid) ;
if(it == mFriendList.end())
return false ;
pgp_id = it->second.gpg_id ;
}
return getMaxRates(pgp_id,maxUp,maxDn) ;
}
bool p3PeerMgrIMPL::getMaxRates(const RsPgpId& pid,uint32_t& maxUp,uint32_t& maxDn)
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
std::map<RsPgpId,PeerBandwidthLimits>::const_iterator it2 = mPeerBandwidthLimits.find(pid) ;
if(it2 != mPeerBandwidthLimits.end())
{
maxUp = it2->second.max_up_rate_kbs ;
maxDn = it2->second.max_dl_rate_kbs ;
return true ;
}
else
{
maxUp = 0;
maxDn = 0;
return false ;
}
}
bool p3PeerMgrIMPL::setMaxRates(const RsPgpId& pid,uint32_t maxUp,uint32_t maxDn)
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
PeerBandwidthLimits& p(mPeerBandwidthLimits[pid]) ;
if(maxUp == p.max_up_rate_kbs && maxDn == p.max_dl_rate_kbs)
return true ;
std::cerr << "Updating max rates for peer " << pid << " to " << maxUp << " kB/s (up), " << maxDn << " kB/s (dn)" << std::endl;
p.max_up_rate_kbs = maxUp ;
p.max_dl_rate_kbs = maxDn ;
IndicateConfigChanged();
return true ;
}
void p3PeerMgrIMPL::saveDone()
{
/* clean up the save List */
@ -2256,6 +2315,18 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
continue;
}
RsPeerBandwidthLimitsItem *pblitem = dynamic_cast<RsPeerBandwidthLimitsItem*>(*it) ;
if(pblitem)
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
#ifdef PEER_DEBUG
std::cerr << "Loaded service permission item: " << std::endl;
#endif
mPeerBandwidthLimits = pblitem->peers ;
}
RsPeerServicePermissionItem *sitem = dynamic_cast<RsPeerServicePermissionItem*>(*it) ;
if(sitem)

View file

@ -102,6 +102,8 @@ class peerState
std::string location;
std::string name;
uint32_t maxUpRate ;
uint32_t maxDnRate ;
};
class RsPeerGroupItem;
@ -207,6 +209,9 @@ virtual uint32_t getHiddenType(const RsPeerId &ssl_id) = 0;
virtual int getFriendCount(bool ssl, bool online) = 0;
virtual bool setMaxRates(const RsPgpId& pid,uint32_t maxUp,uint32_t maxDn)=0;
virtual bool getMaxRates(const RsPgpId& pid,uint32_t& maxUp,uint32_t& maxDn)=0;
virtual bool getMaxRates(const RsPeerId& pid,uint32_t& maxUp,uint32_t& maxDn)=0;
/************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
@ -321,6 +326,9 @@ virtual int getFriendCount(bool ssl, bool online);
// Single Use Function... shouldn't be here. used by p3serverconfig.cc
virtual bool haveOnceConnected();
virtual bool setMaxRates(const RsPgpId& pid,uint32_t maxUp,uint32_t maxDn);
virtual bool getMaxRates(const RsPgpId& pid,uint32_t& maxUp,uint32_t& maxDn);
virtual bool getMaxRates(const RsPeerId& pid,uint32_t& maxUp,uint32_t& maxDn);
/************************************************************************************************/
/* Extra IMPL Functions (used by p3LinkMgr, p3NetMgr + Setup) */
@ -392,6 +400,7 @@ private:
std::list<RsItem *> saveCleanupList; /* TEMPORARY LIST WHEN SAVING */
std::map<RsPgpId, ServicePermissionFlags> mFriendsPermissionFlags ; // permission flags for each gpg key
std::map<RsPgpId, PeerBandwidthLimits> mPeerBandwidthLimits ; // bandwidth limits for each gpg key
struct sockaddr_storage mProxyServerAddressTor;
struct sockaddr_storage mProxyServerAddressI2P;

View file

@ -27,6 +27,7 @@
#include "util/rsdebug.h"
#include "util/rsstring.h"
#include "retroshare/rspeers.h"
#include <stdlib.h>
#include <time.h>
@ -115,25 +116,25 @@ int pqihandler::tick()
#endif
}
// static time_t last_print_time = 0 ;
// time_t now = time(NULL) ;
// if(now > last_print_time + 3)
// {
// std::map<uint16_t,uint32_t> per_service_count ;
// std::vector<uint32_t> per_priority_count ;
//
// ExtractOutQueueStatistics(per_service_count,per_priority_count) ;
//
// std::cerr << "PQIHandler outqueues: " << std::endl;
//
// for(std::map<uint16_t,uint32_t>::const_iterator it=per_service_count.begin();it!=per_service_count.end();++it)
// std::cerr << " " << std::hex << it->first << std::dec << " " << it->second << std::endl;
//
// for(int i=0;i<per_priority_count.size();++i)
// std::cerr << " " << i << " : " << per_priority_count[i] << std::endl;
//
// last_print_time = now ;
// }
static time_t last_print_time = 0 ;
time_t now = time(NULL) ;
if(now > last_print_time + 5)
{
// every 5 secs, update the max rates for all modules
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
for(std::map<RsPeerId, SearchModule *>::iterator it = mods.begin(); it != mods.end(); ++it)
{
// This is rather inelegant, but pqihandler has searchModules that are dynamically allocated, so the max rates
// need to be updated from inside.
uint32_t maxUp,maxDn ;
rsPeers->getPeerMaximumRates(it->first,maxUp,maxDn);
it->second->pqi->setRateCap(maxDn,maxUp);// mind the order! Dn first, than Up.
}
last_print_time = now ;
}
UpdateRates();
return moreToTick;
@ -277,144 +278,6 @@ int pqihandler::SendRsRawItem(RsRawItem *ns)
return queueOutRsItem(ns) ;
}
#ifdef TO_BE_REMOVED
// inputs. This is a very basic
// system that is completely biased and slow...
// someone please fix.
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
// THIS CODE SHOULD BE ABLE TO BE REMOVED!
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
int pqihandler::locked_GetItems()
{
std::map<RsPeerId, SearchModule *>::iterator it;
RsItem *item;
int count = 0;
// loop through modules....
for(it = mods.begin(); it != mods.end(); ++it)
{
SearchModule *mod = (it -> second);
// check security... is output allowed.
if(0 < secpolicy_check((it -> second) -> sp,
0, PQI_INCOMING)) // PQI_ITEM_TYPE_ITEM, PQI_INCOMING))
{
// if yes... attempt to read.
while((item = (mod -> pqi) -> GetItem()) != NULL)
{
static int ntimes =0 ;
// if(++ntimes < 20)
{
std::cerr << "pqihandler::locked_GetItems() pqi->GetItem()";
std::cerr << " should never happen anymore!";
std::cerr << std::endl;
}
#ifdef RSITEM_DEBUG
std::string out;
rs_sprintf(out, "pqihandler::GetItems() Incoming Item from: %p\n", mod -> pqi);
item -> print_string(out);
pqioutput(PQL_DEBUG_BASIC,
pqihandlerzone, out);
#endif
if (item->PeerId() != (mod->pqi)->PeerId())
{
/* ERROR */
pqioutput(PQL_ALERT,
pqihandlerzone, "ERROR PeerIds dont match!");
item->PeerId(mod->pqi->PeerId());
}
locked_SortnStoreItem(item);
count++;
}
}
else
{
// not allowed to recieve from here....
while((item = (mod -> pqi) -> GetItem()) != NULL)
{
std::string out;
rs_sprintf(out, "pqihandler::GetItems() Incoming Item from: %p\n", mod -> pqi);
item -> print_string(out);
out += "\nItem Not Allowed (Sec Pol). deleting!";
pqioutput(PQL_DEBUG_BASIC,
pqihandlerzone, out);
delete item;
}
}
}
return count;
}
void pqihandler::locked_SortnStoreItem(RsItem *item)
{
/* get class type / subtype out of the item */
uint8_t vers = item -> PacketVersion();
/* whole Version reserved for SERVICES/CACHES */
if (vers == RS_PKT_VERSION_SERVICE)
{
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone,
"SortnStore -> Service");
in_service.push_back(item);
item = NULL;
return;
}
std::cerr << "pqihandler::locked_SortnStoreItem() : unhandled item! Will be deleted. This is certainly a bug." << std::endl;
if (vers != RS_PKT_VERSION1)
{
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, "SortnStore -> Invalid VERSION! Deleting!");
delete item;
item = NULL;
return;
}
if (item)
{
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, "SortnStore -> Deleting Unsorted Item");
delete item;
}
return;
}
RsRawItem *pqihandler::GetRsRawItem()
{
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
if (in_service.size() != 0)
{
RsRawItem *fi = dynamic_cast<RsRawItem *>(in_service.front());
if (!fi) { delete in_service.front(); }
in_service.pop_front();
return fi;
}
return NULL;
}
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
// ABOVE CODE SHOULD BE ABLE TO BE REMOVED!
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
#endif
static const float MIN_RATE = 0.01; // 10 B/s
int pqihandler::ExtractTrafficInfo(std::list<RSTrafficClue>& out_lst,std::list<RSTrafficClue>& in_lst)
{
in_lst.clear() ;
@ -640,6 +503,7 @@ int pqihandler::UpdateRates()
for(it = mods.begin(); it != mods.end(); ++it)
{
SearchModule *mod = (it -> second);
mod -> pqi -> setMaxRate(true, in_max_bw);
mod -> pqi -> setMaxRate(false, out_max_bw);
}
@ -649,18 +513,10 @@ int pqihandler::UpdateRates()
for(it = mods.begin(); it != mods.end(); ++it)
{
SearchModule *mod = (it -> second);
if (mod -> pqi -> getMaxRate(false) < max_out_effective) {
mod -> pqi -> setMaxRate(false, max_out_effective);
}
if (mod -> pqi -> getMaxRate(false) > avail_out) {
mod -> pqi -> setMaxRate(false, avail_out);
}
if (mod -> pqi -> getMaxRate(true) < max_in_effective) {
mod -> pqi -> setMaxRate(true, max_in_effective);
}
if (mod -> pqi -> getMaxRate(true) > avail_in) {
mod -> pqi -> setMaxRate(true, avail_in);
}
if (mod -> pqi -> getMaxRate(false) < max_out_effective) mod -> pqi -> setMaxRate(false, max_out_effective);
if (mod -> pqi -> getMaxRate(false) > avail_out) mod -> pqi -> setMaxRate(false, avail_out);
if (mod -> pqi -> getMaxRate(true) < max_in_effective) mod -> pqi -> setMaxRate(true, max_in_effective);
if (mod -> pqi -> getMaxRate(true) > avail_in) mod -> pqi -> setMaxRate(true, avail_in);
}
return 1;

View file

@ -39,6 +39,8 @@
class SearchModule
{
public:
SearchModule() : pqi(NULL) {}
RsPeerId peerid ;
PQInterface *pqi;
};
@ -71,9 +73,13 @@ class pqihandler: public P3Interface, public pqiPublisher
#endif
// rate control.
//void setMaxRate(const RsPeerId& pid,bool in, uint32_t val_kBs);
void setMaxRate(bool in, float val);
float getMaxRate(bool in);
void setMaxRates(const RsPeerId& pid,bool in,float val) ;
float getMaxRates(const RsPeerId& pid,bool in) ;
void getCurrentRates(float &in, float &out);
// TESTING INTERFACE.

View file

@ -293,8 +293,8 @@ public:
/* Data Rate Control - to be moved here */
virtual int SetMaxDataRates( int downKb, int upKb ) = 0;
virtual int GetMaxDataRates( int &inKb, int &outKb ) = 0;
virtual int GetCurrentDataRates( float &inKb, float &outKb ) = 0;
virtual int GetCurrentDataRates( float &inKb, float &outKb ) = 0;
};
#endif

View file

@ -428,6 +428,10 @@ public:
virtual ServicePermissionFlags servicePermissionFlags(const RsPgpId& gpg_id) = 0;
virtual ServicePermissionFlags servicePermissionFlags(const RsPeerId& ssl_id) = 0;
virtual void setServicePermissionFlags(const RsPgpId& gpg_id,const ServicePermissionFlags& flags) = 0;
virtual bool setPeerMaximumRates(const RsPgpId& pid,uint32_t maxUploadRate,uint32_t maxDownloadRate) =0;
virtual bool getPeerMaximumRates(const RsPeerId& pid,uint32_t& maxUploadRate,uint32_t& maxDownloadRate) =0;
virtual bool getPeerMaximumRates(const RsPgpId& pid,uint32_t& maxUploadRate,uint32_t& maxDownloadRate) =0;
};
#endif

View file

@ -118,6 +118,15 @@ class Condition
std::string name;
};
class PeerBandwidthLimits
{
public:
PeerBandwidthLimits() : max_up_rate_kbs(0), max_dl_rate_kbs(0) {}
uint32_t max_up_rate_kbs ;
uint32_t max_dl_rate_kbs ;
};
//class SearchRequest // unused stuff.
//{
// public:

View file

@ -241,6 +241,20 @@ bool p3Peers::isFriend(const RsPeerId &ssl_id)
return mPeerMgr->isFriend(ssl_id);
}
bool p3Peers::getPeerMaximumRates(const RsPeerId& pid,uint32_t& maxUploadRate,uint32_t& maxDownloadRate)
{
return mPeerMgr->getMaxRates(pid,maxUploadRate,maxDownloadRate) ;
}
bool p3Peers::getPeerMaximumRates(const RsPgpId& pid,uint32_t& maxUploadRate,uint32_t& maxDownloadRate)
{
return mPeerMgr->getMaxRates(pid,maxUploadRate,maxDownloadRate) ;
}
bool p3Peers::setPeerMaximumRates(const RsPgpId& pid,uint32_t maxUploadRate,uint32_t maxDownloadRate)
{
return mPeerMgr->setMaxRates(pid,maxUploadRate,maxDownloadRate) ;
}
bool p3Peers::haveSecretKey(const RsPgpId& id)
{
return AuthGPG::getAuthGPG()->haveSecretKey(id);
@ -352,8 +366,7 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
rs_sprintf_append(toto, " %ld sec", time(NULL) - it->mSeenTime);
d.ipAddressList.push_back(toto);
}
for(it = ps.ipAddrs.mExt.mAddrs.begin();
it != ps.ipAddrs.mExt.mAddrs.end(); ++it)
for(it = ps.ipAddrs.mExt.mAddrs.begin(); it != ps.ipAddrs.mExt.mAddrs.end(); ++it)
{
std::string toto;
toto += "E:";
@ -388,7 +401,6 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
d.vs_disc = ps.vs_disc;
d.vs_dht = ps.vs_dht;
/* Translate */
peerConnectState pcs;
if (!mLinkMgr->getFriendNetStatus(id, pcs))
@ -414,14 +426,10 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
}
d.state = 0;
if (pcs.state & RS_PEER_S_FRIEND)
d.state |= RS_PEER_STATE_FRIEND;
if (pcs.state & RS_PEER_S_ONLINE)
d.state |= RS_PEER_STATE_ONLINE;
if (pcs.state & RS_PEER_S_CONNECTED)
d.state |= RS_PEER_STATE_CONNECTED;
if (pcs.state & RS_PEER_S_UNREACHABLE)
d.state |= RS_PEER_STATE_UNREACHABLE;
if (pcs.state & RS_PEER_S_FRIEND) d.state |= RS_PEER_STATE_FRIEND;
if (pcs.state & RS_PEER_S_ONLINE) d.state |= RS_PEER_STATE_ONLINE;
if (pcs.state & RS_PEER_S_CONNECTED) d.state |= RS_PEER_STATE_CONNECTED;
if (pcs.state & RS_PEER_S_UNREACHABLE) d.state |= RS_PEER_STATE_UNREACHABLE;
d.actAsServer = pcs.actAsServer;
@ -433,7 +441,6 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
d.connectState = RS_PEER_CONNECTSTATE_OFFLINE;
d.connectStateString.clear();
if (pcs.inConnAttempt)
{
if (pcs.currentConnAddrAttempt.type & RS_NET_CONN_TCP_ALL) {

View file

@ -139,6 +139,9 @@ public:
virtual ServicePermissionFlags servicePermissionFlags(const RsPeerId & ssl_id);
virtual void setServicePermissionFlags(const RsPgpId& gpg_id,const ServicePermissionFlags& flags);
virtual bool setPeerMaximumRates(const RsPgpId& pid,uint32_t maxUploadRate,uint32_t maxDownloadRate);
virtual bool getPeerMaximumRates(const RsPgpId& pid,uint32_t& maxUploadRate,uint32_t& maxDownloadRate);
virtual bool getPeerMaximumRates(const RsPeerId& pid,uint32_t& maxUploadRate,uint32_t& maxDownloadRate);
private:
p3LinkMgr *mLinkMgr;

View file

@ -503,7 +503,6 @@ bool p3ServerConfig::switchToOperatingMode(uint32_t opMode)
return true;
}
/* handle data rates.
* Mutex must be handled at the lower levels: TODO */

View file

@ -880,7 +880,6 @@ uint32_t RsPeerConfigSerialiser::sizeNet(RsPeerNetItem *i)
s += 2; /* domain_port */
return s;
}
bool RsPeerConfigSerialiser::serialiseNet(RsPeerNetItem *item, void *data, uint32_t *size)
@ -1028,6 +1027,160 @@ RsPeerNetItem *RsPeerConfigSerialiser::deserialiseNet(void *data, uint32_t *size
return item;
}
/****************************************************************************/
uint32_t RsPeerConfigSerialiser::sizePeerBandwidthLimits(RsPeerBandwidthLimitsItem *i)
{
uint32_t s = 8; /* header */
s += 4; // number of elements
s += i->peers.size() * (4 + 4 + RsPgpId::SIZE_IN_BYTES) ;
return s;
}
bool RsPeerConfigSerialiser::serialisePeerBandwidthLimits(RsPeerBandwidthLimitsItem *item, void *data, uint32_t *size)
{
uint32_t tlvsize = RsPeerConfigSerialiser::sizePeerBandwidthLimits(item);
uint32_t offset = 0;
#ifdef RSSERIAL_DEBUG
std::cerr << "RsPeerConfigSerialiser::serialiseNet() tlvsize: " << tlvsize << std::endl;
#endif
if(*size < tlvsize)
{
#ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsPeerConfigSerialiser::serialiseNet() ERROR not enough space" << std::endl;
#endif
return false; /* not enough space */
}
*size = tlvsize;
bool ok = true;
// serialise header
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG
std::cerr << "RsPeerConfigSerialiser::serialiseNet() Header: " << ok << std::endl;
std::cerr << "RsPeerConfigSerialiser::serialiseNet() Header test: " << tlvsize << std::endl;
#endif
/* skip the header */
offset += 8;
ok &= setRawUInt32(data, tlvsize, &offset, item->peers.size()); /* Mandatory */
for(std::map<RsPgpId,PeerBandwidthLimits>::const_iterator it(item->peers.begin());it!=item->peers.end();++it)
{
ok &= it->first.serialise(data,tlvsize,offset);
ok &= setRawUInt32(data, tlvsize, &offset, it->second.max_up_rate_kbs); /* Mandatory */
ok &= setRawUInt32(data, tlvsize, &offset, it->second.max_dl_rate_kbs); /* Mandatory */
}
if(offset != tlvsize)
{
#ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsPeerConfigSerialiser::serialiseNet() Size Error! " << std::endl;
#endif
ok = false;
}
return ok;
}
RsPeerBandwidthLimitsItem *RsPeerConfigSerialiser::deserialisePeerBandwidthLimits(void *data, uint32_t *size)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
#ifdef RSSERIAL_DEBUG
std::cerr << "RsPeerConfigSerialiser::deserialiseNet() rssize: " << rssize << std::endl;
#endif
if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) ||
(RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) ||
(RS_PKT_TYPE_PEER_CONFIG != getRsItemType(rstype)) ||
(RS_PKT_SUBTYPE_PEER_BANDLIMITS != getRsItemSubType(rstype)))
{
#ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsPeerConfigSerialiser::deserialiseNet() ERROR Type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsPeerConfigSerialiser::deserialiseNet() ERROR not enough data" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsPeerBandwidthLimitsItem *item = new RsPeerBandwidthLimitsItem();
/* skip the header */
offset += 8;
/* get mandatory parts first */
uint32_t n ;
ok &= getRawUInt32(data, rssize, &offset, &n) ;
for(uint32_t i=0;i<n;++i)
{
RsPgpId pgpid ;
ok &= pgpid.deserialise(data,rssize,offset) ;
PeerBandwidthLimits p ;
ok &= getRawUInt32(data, rssize, &offset, &(p.max_up_rate_kbs)); /* Mandatory */
ok &= getRawUInt32(data, rssize, &offset, &(p.max_dl_rate_kbs)); /* Mandatory */
item->peers[pgpid] = p ;
}
if (offset != rssize)
{
#ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsPeerConfigSerialiser::deserialiseNet() ERROR size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
return item;
}
std::ostream &RsPeerBandwidthLimitsItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsPeerBandwidthLimitsItem", indent);
uint16_t int_Indent = indent + 2;
for(std::map<RsPgpId,PeerBandwidthLimits>::const_iterator it(peers.begin());it!=peers.end();++it)
{
printIndent(out, int_Indent);
out << it->first << " : " << it->second.max_up_rate_kbs << " (up) " << it->second.max_dl_rate_kbs << " (dn)" << std::endl;
}
printRsItemEnd(out, "RsPeerStunItem", indent);
return out;
}
/****************************************************************************/
RsPeerStunItem::~RsPeerStunItem()

View file

@ -54,6 +54,7 @@ const uint8_t RS_PKT_SUBTYPE_PEER_STUN = 0x02;
const uint8_t RS_PKT_SUBTYPE_PEER_NET = 0x03;
const uint8_t RS_PKT_SUBTYPE_PEER_GROUP = 0x04;
const uint8_t RS_PKT_SUBTYPE_PEER_PERMISSIONS = 0x05;
const uint8_t RS_PKT_SUBTYPE_PEER_BANDLIMITS = 0x06;
/* FILE CONFIG SUBTYPES */
const uint8_t RS_PKT_SUBTYPE_FILE_TRANSFER = 0x01;
@ -61,6 +62,8 @@ const uint8_t RS_PKT_SUBTYPE_FILE_ITEM = 0x02;
/**************************************************************************/
#warning should make these items use a clean serialise code, and all derive from the same item type.
class RsPeerNetItem: public RsItem
{
public:
@ -97,6 +100,7 @@ std::ostream &print(std::ostream &out, uint16_t indent = 0);
uint16_t domain_port;
};
// This item should be merged with the next item, but that is not backward compatible.
class RsPeerServicePermissionItem : public RsItem
{
public:
@ -114,7 +118,21 @@ class RsPeerServicePermissionItem : public RsItem
std::vector<RsPgpId> pgp_ids ;
std::vector<ServicePermissionFlags> service_flags ;
};
class RsPeerBandwidthLimitsItem : public RsItem
{
public:
RsPeerBandwidthLimitsItem() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_PEER_BANDLIMITS) {}
virtual ~RsPeerBandwidthLimitsItem() {}
virtual void clear()
{
peers.clear() ;
}
std::ostream &print(std::ostream &out, uint16_t indent = 0);
/* Mandatory */
std::map<RsPgpId,PeerBandwidthLimits> peers ;
};
class RsPeerGroupItem : public RsItem
{
@ -183,6 +201,10 @@ virtual uint32_t sizeGroup(RsPeerGroupItem *);
virtual bool serialiseGroup (RsPeerGroupItem *item, void *data, uint32_t *size);
virtual RsPeerGroupItem * deserialiseGroup(void *data, uint32_t *size);
virtual uint32_t sizePeerBandwidthLimits(RsPeerBandwidthLimitsItem *);
virtual bool serialisePeerBandwidthLimits (RsPeerBandwidthLimitsItem *item, void *data, uint32_t *size);
virtual RsPeerBandwidthLimitsItem *deserialisePeerBandwidthLimits(void *data, uint32_t *size);
virtual uint32_t sizePermissions(RsPeerServicePermissionItem *);
virtual bool serialisePermissions (RsPeerServicePermissionItem *item, void *data, uint32_t *size);
virtual RsPeerServicePermissionItem * deserialisePermissions(void *data, uint32_t *size);

View file

@ -103,9 +103,6 @@ ConfCertDialog::ConfCertDialog(const RsPeerId& id, const RsPgpId &pgp_id, QWidge
connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(close()));
connect(ui._shouldAddSignatures_CB, SIGNAL(toggled(bool)), this, SLOT(loadInvitePage()));
//connect(ui.denyFriendButton, SIGNAL(clicked()), this, SLOT(denyFriend()));
//connect(ui._shouldAddSignatures_CB_2, SIGNAL(toggled(bool)), this, SLOT(loadInvitePage()));
ui.avatar->setFrameType(AvatarWidget::NORMAL_FRAME);
MainWindow *w = MainWindow::getInstance();
@ -115,33 +112,17 @@ ConfCertDialog::ConfCertDialog(const RsPeerId& id, const RsPgpId &pgp_id, QWidge
}
ConfCertDialog::~ConfCertDialog()
{
// if(peerId.isNull())
{
QMap<RsPeerId, ConfCertDialog*>::iterator it = instances_ssl.find(peerId);
if (it != instances_ssl.end())
instances_ssl.erase(it);
}
// else
{
QMap<RsPgpId, ConfCertDialog*>::iterator it = instances_pgp.find(pgpId);
if (it != instances_pgp.end())
instances_pgp.erase(it);
}
QMap<RsPgpId, ConfCertDialog*>::iterator it2 = instances_pgp.find(pgpId);
if (it2 != instances_pgp.end())
instances_pgp.erase(it2);
}
void ConfCertDialog::setServiceFlags()
{
ServicePermissionFlags flags(0) ;
if( ui._direct_transfer_CB->isChecked()) flags = flags | RS_NODE_PERM_DIRECT_DL ;
if( ui._allow_push_CB->isChecked()) flags = flags | RS_NODE_PERM_ALLOW_PUSH ;
if( ui._require_WL_CB->isChecked()) flags = flags | RS_NODE_PERM_REQUIRE_WL ;
rsPeers->setServicePermissionFlags(pgpId,flags) ;
}
void ConfCertDialog::loadAll()
{
for(QMap<RsPeerId, ConfCertDialog*>::iterator it = instances_ssl.begin(); it != instances_ssl.end(); ++it) it.value()->load();
@ -161,10 +142,6 @@ void ConfCertDialog::load()
return;
}
ui._direct_transfer_CB->setChecked( detail.service_perm_flags & RS_NODE_PERM_DIRECT_DL ) ;
ui._allow_push_CB->setChecked( detail.service_perm_flags & RS_NODE_PERM_ALLOW_PUSH) ;
ui._require_WL_CB->setChecked( detail.service_perm_flags & RS_NODE_PERM_REQUIRE_WL) ;
//ui.pgpfingerprint->setText(QString::fromUtf8(detail.name.c_str()));
ui.peerid->setText(QString::fromStdString(detail.id.toStdString()));
@ -397,8 +374,6 @@ void ConfCertDialog::applyDialog()
}
}
setServiceFlags() ;
loadAll();
close();
}

View file

@ -76,11 +76,7 @@ private:
private slots:
void applyDialog();
//void makeFriend();
//void denyFriend();
//void signGPGKey();
void loadInvitePage();
void setServiceFlags();
void showHelpDialog();
/** Called when a child window requests the given help <b>topic</b>. */

View file

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>678</width>
<height>727</height>
<width>742</width>
<height>915</height>
</rect>
</property>
<property name="windowTitle">
@ -35,6 +35,7 @@
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<zorder>stabWidget</zorder>
</widget>
</item>
<item row="1" column="0">
@ -60,7 +61,7 @@
<item row="0" column="0">
<widget class="QTabWidget" name="stabWidget">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="icon">
@ -407,6 +408,13 @@
<string>Retroshare Certificate</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Use this certificate to make friends:</string>
</property>
</widget>
</item>
<item>
<widget class="QTextEdit" name="userCertificateText"/>
</item>
@ -436,60 +444,6 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_4">
<attribute name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/admin-16.png</normaloff>:/images/admin-16.png</iconset>
</attribute>
<attribute name="title">
<string>Options</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0" colspan="2">
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>196</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="_direct_transfer_CB">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;justify&quot;&gt;Retroshare periodically checks your friend lists for browsable files matching your transfers, to establish a direct transfer. In this case, your friend knows you're downloading the file.&lt;/p&gt;&lt;p align=&quot;justify&quot;&gt;To prevent this behavior for this friend only, uncheck this box. You can still perform a direct transfer if you explicitly ask for it, by e.g. downloading from your friend's file list. &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Use as direct source, when available</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="_allow_push_CB">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This option allows you to automatically download a file that is recommended in an message coming from this node. This can be used for instance to send files between your own nodes.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Auto-download recommended files from this node</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="_require_WL_CB">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Peers that have this option cannot connect if their connection address is not in the whitelist. This protects you from traffic forwarding attacks. When used, rejected peers will be reported by &amp;quot;security feed items&amp;quot; in the News Feed section. From there, you can whitelist/blacklist their IP.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Require white list clearance</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>

View file

@ -145,44 +145,23 @@ void PGPKeyDialog::load()
ui.make_friend_button->setToolTip("") ;
}
//ui._direct_transfer_CB->setChecked( detail.service_perm_flags & RS_NODE_PERM_DIRECT_DL ) ;
//ui._allow_push_CB->setChecked( detail.service_perm_flags & RS_NODE_PERM_ALLOW_PUSH) ;
ui.name->setText(QString::fromUtf8(detail.name.c_str()));
//ui.peerid->setText(QString::fromStdString(detail.id.toStdString()));
//RetroShareLink link;
//link.createPerson(detail.gpg_id);
//ui.rsid->setText(QString::fromStdString(detail.gpg_id.toStdString())) ;
ui.pgpfingerprint->setText(misc::fingerPrintStyleSplit(QString::fromStdString(detail.fpr.toStdString())));
//ui.rsid->setToolTip(link.title());
//ui.avatar->setId(pgpId.toStdString(), true);
// ui.rsid->show();
// ui.peerid->hide();
// ui.label_id->hide();
// ui.label_rsid->show();
ui.pgpfingerprint->show();
ui.pgpfingerprint_label->show();
// ui.loc->hide();
// ui.label_loc->hide();
// ui.statusline->hide();
// ui.label_status->hide();
// ui.lastcontact->hide();
// ui.label_last_contact->hide();
// ui.version->hide();
// ui.label_version->hide();
// ui.groupBox_4->hide();
// ui.crypto_info->hide();
// ui.crypto_label->hide();
ui._direct_transfer_CB->setChecked( detail.service_perm_flags & RS_NODE_PERM_DIRECT_DL ) ;
ui._allow_push_CB->setChecked( detail.service_perm_flags & RS_NODE_PERM_ALLOW_PUSH) ;
ui._require_WL_CB->setChecked( detail.service_perm_flags & RS_NODE_PERM_REQUIRE_WL) ;
// ui.groupBox->hide();
// ui.tabWidget->hide();
uint32_t max_upload_speed = 0 ;
uint32_t max_download_speed = 0 ;
rsPeers->getPeerMaximumRates(pgpId,max_upload_speed,max_download_speed);
ui.maxUploadSpeed_SB->setValue(max_upload_speed) ;
ui.maxDownloadSpeed_SB->setValue(max_download_speed) ;
if (detail.gpg_id == rsPeers->getGPGOwnId())
{
@ -323,7 +302,6 @@ void PGPKeyDialog::loadKeyPage()
ui.userCertificateText_2->setToolTip(helptext) ;
}
void PGPKeyDialog::applyDialog()
{
std::cerr << "PGPKeyDialog::applyDialog() called" << std::endl ;
@ -343,6 +321,19 @@ void PGPKeyDialog::applyDialog()
if(ui.trustlevel_CB->currentIndex() != detail.trustLvl)
rsPeers->trustGPGCertificate(pgpId, ui.trustlevel_CB->currentIndex());
uint32_t max_upload_speed = ui.maxUploadSpeed_SB->value() ;
uint32_t max_download_speed = ui.maxDownloadSpeed_SB->value();
rsPeers->setPeerMaximumRates(pgpId,max_upload_speed,max_download_speed);
ServicePermissionFlags flags(0) ;
if( ui._direct_transfer_CB->isChecked()) flags = flags | RS_NODE_PERM_DIRECT_DL ;
if( ui._allow_push_CB->isChecked()) flags = flags | RS_NODE_PERM_ALLOW_PUSH ;
if( ui._require_WL_CB->isChecked()) flags = flags | RS_NODE_PERM_REQUIRE_WL ;
rsPeers->setServicePermissionFlags(pgpId,flags) ;
//setServiceFlags() ;
loadAll();

View file

@ -27,7 +27,7 @@
<item>
<widget class="QTabWidget" name="stabWidget">
<property name="currentIndex">
<number>1</number>
<number>2</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
@ -295,6 +295,23 @@ p, li { white-space: pre-wrap; }
<string>ASCII format</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QTextBrowser" name="textBrowser">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Below is the node's PGP key. It identifies the node and all its locations. A &amp;quot;Retroshare certificate&amp;quot; that you can exchange in order to make friends, is in the the &amp;quot;details&amp;quot; of each separate location.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QTextEdit" name="userCertificateText_2">
<property name="sizePolicy">
@ -321,6 +338,115 @@ p, li { white-space: pre-wrap; }
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Options</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>These options apply to all locations of the same node:</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="_direct_transfer_CB">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;justify&quot;&gt;Retroshare periodically checks your friend lists for browsable files matching your transfers, to establish a direct transfer. In this case, your friend knows you're downloading the file.&lt;/p&gt;&lt;p align=&quot;justify&quot;&gt;To prevent this behavior for this friend only, uncheck this box. You can still perform a direct transfer if you explicitly ask for it, by e.g. downloading from your friend's file list. This setting is applied to all locations of the same node.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Use as direct source, when available</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="_allow_push_CB">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This option allows you to automatically download a file that is recommended in an message coming from this node. This can be used for instance to send files between your own nodes. Applied to all locations of the same node.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Auto-download recommended files from this node</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="_require_WL_CB">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Peers that have this option cannot connect if their connection address is not in the whitelist. This protects you from traffic forwarding attacks. When used, rejected peers will be reported by &amp;quot;security feed items&amp;quot; in the News Feed section. From there, you can whitelist/blacklist their IP. Applies to all locations of the same node.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Require white list clearance</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Max upload speed (0=unlimited)</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Max download speed (0=unlimited)</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QSpinBox" name="maxUploadSpeed_SB">
<property name="suffix">
<string> kB/s</string>
</property>
<property name="maximum">
<number>10000</number>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="maxDownloadSpeed_SB">
<property name="suffix">
<string> kB/s</string>
</property>
<property name="maximum">
<number>10000</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>274</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
<item>
@ -334,6 +460,9 @@ p, li { white-space: pre-wrap; }
</widget>
</item>
</layout>
<zorder>stabWidget</zorder>
<zorder>headerFrame</zorder>
<zorder>buttonBox</zorder>
</widget>
<customwidgets>
<customwidget>