added GUI and storage for max up/dn rates per peer

This commit is contained in:
csoler 2016-06-07 21:48:22 -04:00
parent 0e857096c1
commit 20b6745f70
12 changed files with 218 additions and 101 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;

View File

@ -2000,6 +2000,9 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
item->domain_addr = (it->second).hiddenDomain;
item->domain_port = (it->second).hiddenPort;
item->maxUploadRate = it->second.maxUpRate ;
item->maxDownloadRate = it->second.maxDnRate ;
saveData.push_back(item);
saveCleanupList.push_back(item);
#ifdef PEER_DEBUG
@ -2072,6 +2075,29 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
return true;
}
bool p3PeerMgrIMPL::setMaxRates(const RsPeerId& pid,uint32_t maxUp,uint32_t maxDn)
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
/* check if it is a friend */
std::map<RsPeerId, peerState>::iterator it = mFriendList.find(pid) ;
if(mFriendList.end() == it)
return false ;
if(maxUp == it->second.maxUpRate && maxDn == it->second.maxDnRate)
return true ;
std::cerr << "Updating max rates for peer " << pid << " to " << maxUp << " kB/s (up), " << maxDn << " kB/s (dn)" << std::endl;
it->second.maxUpRate = maxUp ;
it->second.maxDnRate = maxDn ;
IndicateConfigChanged();
return true ;
}
void p3PeerMgrIMPL::saveDone()
{
/* clean up the save List */
@ -2145,6 +2171,8 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
setLocation(pitem->peerId, pitem->location);
}
setMaxRates(pitem->peerId,pitem->maxUploadRate,pitem->maxDownloadRate) ;
if (pitem->netMode == RS_NET_MODE_HIDDEN)
{
/* set only the hidden stuff & localAddress */

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,7 @@ virtual uint32_t getHiddenType(const RsPeerId &ssl_id) = 0;
virtual int getFriendCount(bool ssl, bool online) = 0;
virtual bool setMaxRates(const RsPeerId& pid,uint32_t maxR,uint32_t minR)=0;
/************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
@ -321,6 +324,7 @@ 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 RsPeerId& pid,uint32_t maxR,uint32_t minR);
/************************************************************************************************/
/* Extra IMPL Functions (used by p3LinkMgr, p3NetMgr + Setup) */

View File

@ -61,7 +61,7 @@ template<int n> class t_RsFlags32
#define FLAGS_TAG_TRANSFER_REQS 0x4228af
#define FLAGS_TAG_FILE_STORAGE 0x184738
#define FLAGS_TAG_FILE_SEARCH 0xf29ba5
#define FLAGS_TAG_FILE_SEARCH 0xf29ba5
#define FLAGS_TAG_SERVICE_PERM 0x380912
#define FLAGS_TAG_SERVICE_CHAT 0x839042

View File

@ -276,6 +276,9 @@ class RsPeerDetails
/* linkType */
uint32_t linkType;
uint32_t maxRateUp;
uint32_t maxRateDn;
};
// This class is used to get info about crytographic algorithms used with a
@ -428,6 +431,8 @@ 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 RsPeerId& pid,uint32_t maxUploadRate,uint32_t maxDownloadRate) =0;
};
#endif

View File

@ -241,6 +241,11 @@ bool p3Peers::isFriend(const RsPeerId &ssl_id)
return mPeerMgr->isFriend(ssl_id);
}
bool p3Peers::setPeerMaximumRates(const RsPeerId& pid,uint32_t maxUploadRate,uint32_t maxDownloadRate)
{
mPeerMgr->setMaxRates(pid,maxUploadRate,maxDownloadRate) ;
}
bool p3Peers::haveSecretKey(const RsPgpId& id)
{
return AuthGPG::getAuthGPG()->haveSecretKey(id);
@ -272,6 +277,9 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
return false;
}
d.maxRateUp = ps.maxUpRate ;
d.maxRateDn = ps.maxDnRate ;
/* get from gpg (first), to fill in the sign and trust details */
/* don't return now, we've got fill in the ssl and connection info */
getGPGDetails(ps.gpg_id, d);
@ -298,15 +306,15 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
d.hiddenType = ps.hiddenType;
if(sockaddr_storage_isnull(ps.localaddr)) // that happens if the address is not initialised.
{
{
d.localAddr = "INVALID_IP";
d.localPort = 0 ;
}
else
{
}
else
{
d.localAddr = sockaddr_storage_iptostring(ps.localaddr);
d.localPort = sockaddr_storage_port(ps.localaddr);
}
}
d.extAddr = "hidden";
d.extPort = 0;
d.dyndns = "";
@ -344,7 +352,7 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
std::list<pqiIpAddress>::iterator it;
for(it = ps.ipAddrs.mLocal.mAddrs.begin();
it != ps.ipAddrs.mLocal.mAddrs.end(); ++it)
it != ps.ipAddrs.mLocal.mAddrs.end(); ++it)
{
std::string toto;
toto += "L:";
@ -352,8 +360,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:";
@ -366,29 +373,28 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
switch(ps.netMode & RS_NET_MODE_ACTUAL)
{
case RS_NET_MODE_EXT:
d.netMode = RS_NETMODE_EXT;
break;
case RS_NET_MODE_UPNP:
d.netMode = RS_NETMODE_UPNP;
break;
case RS_NET_MODE_UDP:
d.netMode = RS_NETMODE_UDP;
break;
case RS_NET_MODE_HIDDEN:
d.netMode = RS_NETMODE_HIDDEN;
break;
case RS_NET_MODE_UNREACHABLE:
case RS_NET_MODE_UNKNOWN:
default:
d.netMode = RS_NETMODE_UNREACHABLE;
break;
case RS_NET_MODE_EXT:
d.netMode = RS_NETMODE_EXT;
break;
case RS_NET_MODE_UPNP:
d.netMode = RS_NETMODE_UPNP;
break;
case RS_NET_MODE_UDP:
d.netMode = RS_NETMODE_UDP;
break;
case RS_NET_MODE_HIDDEN:
d.netMode = RS_NETMODE_HIDDEN;
break;
case RS_NET_MODE_UNREACHABLE:
case RS_NET_MODE_UNKNOWN:
default:
d.netMode = RS_NETMODE_UNREACHABLE;
break;
}
d.vs_disc = ps.vs_disc;
d.vs_dht = ps.vs_dht;
/* Translate */
peerConnectState pcs;
if (!mLinkMgr->getFriendNetStatus(id, pcs))
@ -414,14 +420,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 +435,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) {
@ -445,7 +446,7 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
}
}
else if (pcs.state & RS_PEER_S_CONNECTED)
{
{
/* peer is connected - determine how and set proper connectState */
if(mPeerMgr->isHidden())
{
@ -519,7 +520,7 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_UNKNOWN;
}
}
}
}
d.wasDeniedConnection = pcs.wasDeniedConnection;
d.deniedTS = pcs.deniedTS;

View File

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

View File

@ -879,6 +879,9 @@ uint32_t RsPeerConfigSerialiser::sizeNet(RsPeerNetItem *i)
s += GetTlvStringSize(i->domain_addr);
s += 2; /* domain_port */
s += 4 ; // max upload rate
s += 4 ; // max dl rate
return s;
}
@ -938,6 +941,9 @@ bool RsPeerConfigSerialiser::serialiseNet(RsPeerNetItem *item, void *data, uint3
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DOMADDR, item->domain_addr);
ok &= setRawUInt16(data, tlvsize, &offset, item->domain_port); /* Mandatory */
ok &= setRawUInt32(data, tlvsize, &offset, item->maxUploadRate); /* Mandatory */
ok &= setRawUInt32(data, tlvsize, &offset, item->maxDownloadRate); /* Mandatory */
if(offset != tlvsize)
{
#ifdef RSSERIAL_ERROR_DEBUG
@ -1015,6 +1021,12 @@ RsPeerNetItem *RsPeerConfigSerialiser::deserialiseNet(void *data, uint32_t *size
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DOMADDR, item->domain_addr);
ok &= getRawUInt16(data, rssize, &offset, &(item->domain_port)); /* Mandatory */
if(offset == rssize) // this allows to load the peer list when max bandwidth rates are missing.
return item ;
ok &= getRawUInt32(data, rssize, &offset, &(item->maxUploadRate)); /* Mandatory */
ok &= getRawUInt32(data, rssize, &offset, &(item->maxDownloadRate)); /* Mandatory */
if (offset != rssize)
{
#ifdef RSSERIAL_ERROR_DEBUG

View File

@ -95,6 +95,9 @@ std::ostream &print(std::ostream &out, uint16_t indent = 0);
// for proxy connection.
std::string domain_addr;
uint16_t domain_port;
uint32_t maxUploadRate ;
uint32_t maxDownloadRate ;
};
class RsPeerServicePermissionItem : public RsItem

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();
@ -116,20 +113,22 @@ 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<RsPeerId, ConfCertDialog*>::iterator it = instances_ssl.find(peerId);
if (it != instances_ssl.end())
instances_ssl.erase(it);
QMap<RsPgpId, ConfCertDialog*>::iterator it = instances_pgp.find(pgpId);
if (it != instances_pgp.end())
instances_pgp.erase(it);
}
void ConfCertDialog::setTransferSpeeds()
{
uint32_t max_upload_speed = ui.maxUploadSpeed_SB->value() ;
uint32_t max_download_speed = ui.maxDownloadSpeed_SB->value();
rsPeers->setPeerMaxTransferRates(peerId,max_download_speed,max_upload_speed);
}
void ConfCertDialog::setServiceFlags()
{
@ -165,6 +164,14 @@ void ConfCertDialog::load()
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) ;
uint32_t max_upload_speed = ui.maxUploadSpeed_SB->value() ;
uint32_t max_download_speed = ui.maxDownloadSpeed_SB->value();
rsPeers->getPeerMaxTransferRates(peerId,max_download_speed,max_upload_speed);
ui.maxUploadSpeed_SB->setValue(max_upload_speed) ;
ui.maxDownloadSpeed_SB->setValue(max_downupload_speed) ;
//ui.pgpfingerprint->setText(QString::fromUtf8(detail.name.c_str()));
ui.peerid->setText(QString::fromStdString(detail.id.toStdString()));

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">
@ -18,15 +18,24 @@
<normaloff>:/images/logo/logo_16.png</normaloff>:/images/logo/logo_16.png</iconset>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="horizontalSpacing">
<number>6</number>
</property>
<property name="verticalSpacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="HeaderFrame" name="headerFrame">
<property name="frameShape">
@ -60,7 +69,7 @@
<item row="0" column="0">
<widget class="QTabWidget" name="stabWidget">
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="icon">
@ -444,8 +453,90 @@
<attribute name="title">
<string>Options</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0" colspan="2">
<layout class="QVBoxLayout" name="verticalLayout_6">
<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>
@ -458,36 +549,6 @@
</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>