diff --git a/libretroshare/src/pqi/p3linkmgr.cc b/libretroshare/src/pqi/p3linkmgr.cc index b6315a42d..a7be8ecb6 100644 --- a/libretroshare/src/pqi/p3linkmgr.cc +++ b/libretroshare/src/pqi/p3linkmgr.cc @@ -110,10 +110,6 @@ peerConnectState::peerConnectState() inConnAttempt(0), wasDeniedConnection(false), deniedTS(false), deniedInConnAttempt(false) { - //sockaddr_clear(¤tlocaladdr); - //sockaddr_clear(¤tserveraddr); - - return; } std::string textPeerConnectState(peerConnectState &state) diff --git a/libretroshare/src/pqi/p3linkmgr.h b/libretroshare/src/pqi/p3linkmgr.h index 0565cd740..926874b47 100644 --- a/libretroshare/src/pqi/p3linkmgr.h +++ b/libretroshare/src/pqi/p3linkmgr.h @@ -129,7 +129,6 @@ class peerConnectState time_t deniedTS; bool deniedInConnAttempt; /* is below valid */ peerConnectAddress deniedConnectionAttempt; - }; class p3tunnel; diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index 64e2e7171..f114d5ecb 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -1999,6 +1999,9 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list& 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); @@ -2016,7 +2019,7 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list& saveData) sitem->pgp_ids.push_back(it->first) ; sitem->service_flags.push_back(it->second) ; } - + saveData.push_back(sitem) ; saveCleanupList.push_back(sitem); @@ -2072,6 +2075,29 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list& 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::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 */ @@ -2144,6 +2170,8 @@ bool p3PeerMgrIMPL::loadList(std::list& load) addFriend(peer_id, peer_pgp_id, pitem->netMode, pitem->vs_disc, pitem->vs_dht, pitem->lastContact, RS_NODE_PERM_ALL); setLocation(pitem->peerId, pitem->location); } + + setMaxRates(pitem->peerId,pitem->maxUploadRate,pitem->maxDownloadRate) ; if (pitem->netMode == RS_NET_MODE_HIDDEN) { diff --git a/libretroshare/src/pqi/p3peermgr.h b/libretroshare/src/pqi/p3peermgr.h index 08984219e..7e3af89c1 100644 --- a/libretroshare/src/pqi/p3peermgr.h +++ b/libretroshare/src/pqi/p3peermgr.h @@ -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) */ diff --git a/libretroshare/src/retroshare/rsflags.h b/libretroshare/src/retroshare/rsflags.h index 90bb54e49..500ed42d4 100644 --- a/libretroshare/src/retroshare/rsflags.h +++ b/libretroshare/src/retroshare/rsflags.h @@ -61,7 +61,7 @@ template 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 diff --git a/libretroshare/src/retroshare/rspeers.h b/libretroshare/src/retroshare/rspeers.h index 51f95f77c..d636c7a36 100644 --- a/libretroshare/src/retroshare/rspeers.h +++ b/libretroshare/src/retroshare/rspeers.h @@ -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 diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index dc86e8194..120ff0a17 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -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); @@ -296,17 +304,17 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d) d.hiddenNodeAddress = ps.hiddenDomain; d.hiddenNodePort = ps.hiddenPort; 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 = ""; @@ -341,10 +349,10 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d) } d.dyndns = ps.dyndns; - + std::list::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:"; @@ -362,33 +369,32 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d) d.ipAddressList.push_back(toto); } } - + 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,8 +520,8 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d) d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_UNKNOWN; } } - } - + } + d.wasDeniedConnection = pcs.wasDeniedConnection; d.deniedTS = pcs.deniedTS; diff --git a/libretroshare/src/rsserver/p3peers.h b/libretroshare/src/rsserver/p3peers.h index d7b621f09..cd5219728 100644 --- a/libretroshare/src/rsserver/p3peers.h +++ b/libretroshare/src/rsserver/p3peers.h @@ -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; diff --git a/libretroshare/src/serialiser/rsconfigitems.cc b/libretroshare/src/serialiser/rsconfigitems.cc index 90abd8c0a..2692774d5 100644 --- a/libretroshare/src/serialiser/rsconfigitems.cc +++ b/libretroshare/src/serialiser/rsconfigitems.cc @@ -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 diff --git a/libretroshare/src/serialiser/rsconfigitems.h b/libretroshare/src/serialiser/rsconfigitems.h index 4c14e1747..6771ea4f2 100644 --- a/libretroshare/src/serialiser/rsconfigitems.h +++ b/libretroshare/src/serialiser/rsconfigitems.h @@ -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 diff --git a/retroshare-gui/src/gui/connect/ConfCertDialog.cpp b/retroshare-gui/src/gui/connect/ConfCertDialog.cpp index 5bbb45369..c8a129e3a 100644 --- a/retroshare-gui/src/gui/connect/ConfCertDialog.cpp +++ b/retroshare-gui/src/gui/connect/ConfCertDialog.cpp @@ -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::iterator it = instances_ssl.find(peerId); - if (it != instances_ssl.end()) - instances_ssl.erase(it); - } -// else - { - QMap::iterator it = instances_pgp.find(pgpId); - if (it != instances_pgp.end()) - instances_pgp.erase(it); - } + QMap::iterator it = instances_ssl.find(peerId); + if (it != instances_ssl.end()) + instances_ssl.erase(it); + + QMap::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())); diff --git a/retroshare-gui/src/gui/connect/ConfCertDialog.ui b/retroshare-gui/src/gui/connect/ConfCertDialog.ui index 4a79121b9..3aeb420e0 100644 --- a/retroshare-gui/src/gui/connect/ConfCertDialog.ui +++ b/retroshare-gui/src/gui/connect/ConfCertDialog.ui @@ -6,8 +6,8 @@ 0 0 - 678 - 727 + 742 + 915 @@ -18,15 +18,24 @@ :/images/logo/logo_16.png:/images/logo/logo_16.png + + 0 + + + 0 + + + 0 + + + 0 + 6 0 - - 0 - @@ -60,7 +69,7 @@ - 0 + 2 @@ -444,8 +453,90 @@ Options - - + + + + + <html><head/><body><p align="justify">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.</p><p align="justify">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.</p></body></html> + + + Use as direct source, when available + + + + + + + <html><head/><body><p>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.</p></body></html> + + + Auto-download recommended files from this node + + + + + + + <html><head/><body><p>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 &quot;security feed items&quot; in the News Feed section. From there, you can whitelist/blacklist their IP. Applies to all locations of the same node.</p></body></html> + + + Require white list clearance + + + + + + + + + + + Max upload speed (0=unlimited) + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Max download speed (0=unlimited) + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + kB/s + + + 10000 + + + + + + + kB/s + + + 10000 + + + + + + + + Qt::Vertical @@ -458,36 +549,6 @@ - - - - <html><head/><body><p align="justify">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.</p><p align="justify">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. </p></body></html> - - - Use as direct source, when available - - - - - - - <html><head/><body><p>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.</p></body></html> - - - Auto-download recommended files from this node - - - - - - - <html><head/><body><p>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 &quot;security feed items&quot; in the News Feed section. From there, you can whitelist/blacklist their IP.</p></body></html> - - - Require white list clearance - - -