mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-14 09:29:30 -04:00
Ported branch commits:
3099: libretroshare/src/tcponudp/udplayer.cc libretroshare/src/tcponudp/udplayer.h libretroshare/src/util/rsnet.cc libretroshare/src/util/rsnet.h moved operator<<(ostream&,sockaddr_in) to rsnet.h, as it is used at different places 3100: libretroshare/src/util/rsdiscspace.cc suppressed debug mode 3101: libretroshare/src/serialiser/rsdiscitems.cc put correct (i.e. non conservative) size for RsDiscReply packets 3102: libretroshare/src/services/p3disc.cc Made a pass on the code in p3disc. Corrected some bugs: - suppressed an unwanted return in packet treatment - prevented sending info to a peer about itself - changed askInfoToAllPeers() such as not to discard info from peers with NODISC flag (because we especially need info for these) - enabled receiving p3disc info even if p3discovery is disabled. Indeed, disabeling p3disc is a measure of protection, so it should limit the export of p3disc info, not the import. - removed test discarding info about dummy friends, because it is useless - don't discard info about peers that have the NODISC flag (meaning that we especially need info for them) - added safety check about received GPG keys. Before we relied on this test being performed by p3ConnMgr::addFriend() - added some debug info 3103: libretroshare/src/ft/ftcontroller.cc removed debug info git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3104 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
f22753a586
commit
0d14351b8a
8 changed files with 257 additions and 224 deletions
|
@ -63,7 +63,6 @@
|
|||
* #define CONTROL_DEBUG 1
|
||||
* #define DEBUG_DWLQUEUE 1
|
||||
*****/
|
||||
#define CONTROL_DEBUG 1
|
||||
|
||||
static const uint32_t SAVE_TRANSFERS_DELAY = 61 ; // save transfer progress every 61 seconds.
|
||||
static const uint32_t INACTIVE_CHUNKS_CHECK_DELAY = 60 ; // time after which an inactive chunk is released
|
||||
|
|
|
@ -347,7 +347,7 @@ bool RsDiscSerialiser::serialiseReply(RsDiscReply *item, void *data, uint32_
|
|||
|
||||
for (pitemIt = item->rsPeerList.begin(); pitemIt!=(item->rsPeerList.end()) && ok; ++pitemIt)
|
||||
{
|
||||
uint32_t size = ~(uint32_t)0; // we must be conservative otherwise the serialiser returns false !!
|
||||
uint32_t size = *pktsize - offset ;//~(uint32_t)0; // we must be conservative otherwise the serialiser returns false !!
|
||||
|
||||
ok &= rss.serialise(&(*pitemIt), (void *) (((char *) data) + offset), &size);
|
||||
|
||||
|
|
|
@ -146,7 +146,6 @@ int p3disc::handleIncoming()
|
|||
{
|
||||
RsDiscAskInfo *inf = NULL;
|
||||
RsDiscReply *dri = NULL;
|
||||
//RsDiscIssuer *dii = NULL;
|
||||
RsDiscVersion *dvi = NULL;
|
||||
RsDiscHeartbeat *dta = NULL;
|
||||
|
||||
|
@ -173,9 +172,9 @@ int p3disc::handleIncoming()
|
|||
}
|
||||
else if (NULL != (dta = dynamic_cast<RsDiscHeartbeat *> (item))) {
|
||||
recvHeartbeatMsg(dta);
|
||||
delete item;
|
||||
return 1;
|
||||
nhandled++ ;
|
||||
}
|
||||
|
||||
delete item;
|
||||
}
|
||||
#ifdef P3DISC_DEBUG
|
||||
|
@ -200,11 +199,11 @@ void p3disc::statusChange(const std::list<pqipeer> &plist)
|
|||
sendOwnVersion(pit->id);
|
||||
sendAllInfoToJustConnectedPeer(pit->id);
|
||||
sendJustConnectedPeerInfoToAllPeer(pit->id);
|
||||
} else if (!(pit->state & RS_PEER_S_FRIEND) && (pit->actions & RS_PEER_MOVED)) {
|
||||
this->removeFriend(pit->id);
|
||||
} else if ((pit->state & RS_PEER_S_FRIEND) && (pit->actions & RS_PEER_NEW)) {
|
||||
this->askInfoToAllPeers(pit->id);
|
||||
}
|
||||
else if (!(pit->state & RS_PEER_S_FRIEND) && (pit->actions & RS_PEER_MOVED))
|
||||
removeFriend(pit->id);
|
||||
else if ((pit->state & RS_PEER_S_FRIEND) && (pit->actions & RS_PEER_NEW))
|
||||
askInfoToAllPeers(pit->id);
|
||||
}
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::statusChange() finished." << std::endl;
|
||||
|
@ -333,7 +332,10 @@ void p3disc::sendPeerDetails(std::string to, std::string about) {
|
|||
std::list<std::string> sslChilds;
|
||||
rsPeers->getSSLChildListOfGPGId(about, sslChilds);
|
||||
bool shouldWeSendGPGKey = false;//the GPG key is send only if we've got a valid friend with DISC enabled
|
||||
for (std::list<std::string>::iterator sslChildIt = sslChilds.begin(); sslChildIt != sslChilds.end(); sslChildIt++) {
|
||||
|
||||
for (std::list<std::string>::iterator sslChildIt = sslChilds.begin(); sslChildIt != sslChilds.end(); sslChildIt++)
|
||||
if(to != *sslChildIt) // We don't send info to a peer about itself, but we allow sending info
|
||||
{ // about peers with the same GPG id.
|
||||
peerConnectState detail;
|
||||
if (!mConnMgr->getFriendNetStatus(*sslChildIt, detail) || detail.visState & RS_VIS_STATE_NODISC) {
|
||||
continue;
|
||||
|
@ -356,10 +358,13 @@ void p3disc::sendPeerDetails(std::string to, std::string about) {
|
|||
di->rsPeerList.push_back(*rsPeerNetItem);
|
||||
}
|
||||
|
||||
|
||||
//send own details
|
||||
if (about == rsPeers->getGPGOwnId()) {
|
||||
if (about == rsPeers->getGPGOwnId())
|
||||
{
|
||||
peerConnectState detail;
|
||||
if (mConnMgr->getOwnNetStatus(detail)) {
|
||||
if (mConnMgr->getOwnNetStatus(detail))
|
||||
{
|
||||
shouldWeSendGPGKey = true;
|
||||
RsPeerNetItem *rsPeerNetItem = new RsPeerNetItem();
|
||||
rsPeerNetItem->clear();
|
||||
|
@ -453,7 +458,8 @@ void p3disc::askInfoToAllPeers(std::string about)
|
|||
|
||||
|
||||
peerConnectState connectState;
|
||||
if (!mConnMgr->getFriendNetStatus(about, connectState) || (connectState.visState & RS_VIS_STATE_NODISC)) {
|
||||
if (!mConnMgr->getFriendNetStatus(about, connectState)) // || (connectState.visState & RS_VIS_STATE_NODISC)) {
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::askInfoToAllPeers() friend disc is off, don't send the request." << std::endl;
|
||||
#endif
|
||||
|
@ -502,11 +508,12 @@ void p3disc::askInfoToAllPeers(std::string about)
|
|||
|
||||
void p3disc::recvPeerDetails(RsDiscReply *item)
|
||||
{
|
||||
// if off discard item.
|
||||
peerConnectState detail;
|
||||
if (!mConnMgr->getOwnNetStatus(detail) || (detail.visState & RS_VIS_STATE_NODISC)) {
|
||||
return;
|
||||
}
|
||||
// discovery is only disabled for sending, not for receiving.
|
||||
// // if off discard item.
|
||||
// peerConnectState detail;
|
||||
// if (!mConnMgr->getOwnNetStatus(detail) || (detail.visState & RS_VIS_STATE_NODISC)) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::recvPeerFriendMsg() From: " << item->PeerId() << " About " << item->aboutId << std::endl;
|
||||
|
@ -525,67 +532,92 @@ void p3disc::recvPeerDetails(RsDiscReply *item)
|
|||
return;
|
||||
}
|
||||
|
||||
for (std::list<RsPeerNetItem>::iterator pitem = item->rsPeerList.begin(); pitem != item->rsPeerList.end(); pitem++) {
|
||||
for (std::list<RsPeerNetItem>::iterator pitem = item->rsPeerList.begin(); pitem != item->rsPeerList.end(); pitem++)
|
||||
{
|
||||
// there's no way we can receive from a peer some info about our own dummy friend
|
||||
//don't update dummy friends
|
||||
if (rsPeers->isDummyFriend(pitem->pid)) {
|
||||
continue;
|
||||
}
|
||||
//if (rsPeers->isDummyFriend(pitem->pid)) {
|
||||
// continue;
|
||||
//}
|
||||
|
||||
addDiscoveryData(item->PeerId(), pitem->pid, pitem->currentlocaladdr, pitem->currentremoteaddr, 0, time(NULL));
|
||||
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::recvPeerFriendMsg() Peer Config Item:" << std::endl;
|
||||
|
||||
pitem->print(std::cerr, 10);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
if (pitem->pid != rsPeers->getOwnId()) {
|
||||
//check that the friend is not a deleted one
|
||||
if (deletedSSLFriendsIds.find(pitem->pid) == deletedSSLFriendsIds.end()) {
|
||||
//|| {
|
||||
mConnMgr->addFriend(pitem->pid, pitem->gpg_id, pitem->netMode, RS_VIS_STATE_NODISC, 0); //add with no disc by default. If friend already exist, it will do nothing
|
||||
} else if (pitem->lastContact > ((uint32_t)deletedSSLFriendsIds[pitem->pid] + 3600*24)) { // the friend was seen up and running 24 hours after we deleted it, we will readd it
|
||||
mConnMgr->addFriend(pitem->pid, pitem->gpg_id, pitem->netMode, RS_VIS_STATE_NODISC, 0); //add with no disc by default. If friend already exist, it will do nothing
|
||||
}
|
||||
if (pitem->pid != rsPeers->getOwnId())
|
||||
{
|
||||
// Apparently, the connect manager won't add a friend if the gpg id is not
|
||||
// trusted. However, this should be tested here for consistency and security
|
||||
// in case of modifications in mConnMgr.
|
||||
//
|
||||
if(AuthGPG::getAuthGPG()->isGPGAccepted(pitem->gpg_id) || pitem->gpg_id == AuthGPG::getAuthGPG()->getGPGOwnId())
|
||||
{
|
||||
// Add with no disc by default. If friend already exists, it will do nothing
|
||||
//
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "--> Adding to friends list " << pitem->pid << " - " << pitem->gpg_id << std::endl;
|
||||
#endif
|
||||
mConnMgr->addFriend(pitem->pid, pitem->gpg_id, pitem->netMode, 0, 0);
|
||||
RsPeerDetails storedDetails;
|
||||
if (rsPeers->getPeerDetails(pitem->pid, storedDetails) //update only if we got a detail
|
||||
&& ((!(storedDetails.state & RS_PEER_CONNECTED) && storedDetails.lastConnect < (pitem->lastContact - 10000))
|
||||
|| item->PeerId() == pitem->pid)) { //update if it's fresh info or if it's from the peer itself
|
||||
//their info is fresher than ours (there is a 10000 seconds margin), update ours
|
||||
|
||||
// Update if know this peer, and if it's not already connected.
|
||||
//
|
||||
if(rsPeers->getPeerDetails(pitem->pid, storedDetails) && !(storedDetails.state & RS_PEER_CONNECTED))
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "Friend is not connected -> updating info" << std::endl;
|
||||
std::cerr << " -> network mode: " << pitem->netMode << std::endl;
|
||||
std::cerr << " -> location: " << pitem->location << std::endl;
|
||||
#endif
|
||||
// Update if it's fresh info or if it's from the peer itself
|
||||
// their info is fresher than ours, update ours
|
||||
//
|
||||
mConnMgr->setNetworkMode(pitem->pid, pitem->netMode);
|
||||
mConnMgr->setLocation(pitem->pid, pitem->location);
|
||||
|
||||
// The info from the peer itself is ultimately trustable, so we can override some info,
|
||||
// such as:
|
||||
// - local and global addresses
|
||||
//
|
||||
if (item->PeerId() == pitem->pid)
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "Info sent by the peer itself -> updating self info:" << std::endl;
|
||||
std::cerr << " -> current local addr = " << pitem->currentlocaladdr << std::endl;
|
||||
std::cerr << " -> current remote addr = " << pitem->currentremoteaddr << std::endl;
|
||||
std::cerr << " -> clearing NODISC flag " << std::endl;
|
||||
#endif
|
||||
mConnMgr->setLocalAddress(pitem->pid, pitem->currentlocaladdr);
|
||||
mConnMgr->setExtAddress(pitem->pid, pitem->currentremoteaddr);
|
||||
if (pitem->dyndns != "") {
|
||||
pitem->visState &= ~RS_VIS_STATE_NODISC ;
|
||||
mConnMgr->setVisState(pitem->pid, pitem->visState);
|
||||
}
|
||||
}
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "Friend is already connected -> not updating" << std::endl;
|
||||
#endif
|
||||
// allways update address list and dns, except if it's ours
|
||||
if (pitem->dyndns != "")
|
||||
mConnMgr->setDynDNS(pitem->pid, pitem->dyndns);
|
||||
}
|
||||
mConnMgr->setNetworkMode(pitem->pid, pitem->netMode);
|
||||
if (item->PeerId() == pitem->pid) {
|
||||
mConnMgr->setVisState(pitem->pid, pitem->visState); //update vistate only if it's from the peer itself
|
||||
}
|
||||
if (storedDetails.location == "") {
|
||||
mConnMgr->setLocation(pitem->pid, pitem->location);
|
||||
}
|
||||
}
|
||||
|
||||
//useless, we will exploit the list in the connect manager
|
||||
// } else {
|
||||
// if (pitem->currentremoteaddr.sin_addr.s_addr != 0 && pitem->currentremoteaddr.sin_port != 0 &&
|
||||
// pitem->currentremoteaddr.sin_addr.s_addr != 1 && pitem->currentremoteaddr.sin_port != 1 &&
|
||||
// std::string(inet_ntoa(pitem->currentremoteaddr.sin_addr)) != "1.1.1.1" &&
|
||||
// (!isLoopbackNet(&pitem->currentremoteaddr.sin_addr)) &&
|
||||
// (!isPrivateNet(&pitem->currentremoteaddr.sin_addr))
|
||||
// ) {
|
||||
// //the current server address given by the peer looks nice, let's use it for our own ext address if needed
|
||||
// sockaddr_in tempAddr;
|
||||
// if (!mConnMgr->getExtFinderExtAddress(tempAddr) && !mConnMgr->getUpnpExtAddress(tempAddr)) {
|
||||
// //don't change the port, just the ip
|
||||
// pitem->currentremoteaddr.sin_port = mConnMgr->ownState.currentserveraddr.sin_port;
|
||||
// mConnMgr->setExtAddress(mConnMgr->getOwnId(), pitem->currentremoteaddr);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
//allways update address list
|
||||
mConnMgr->setAddressList(pitem->pid, pitem->ipAddressList);
|
||||
}
|
||||
#ifdef P3DISC_DEBUG
|
||||
else
|
||||
std::cerr << " skipping unknown gpg id " << pitem->gpg_id << std::endl ;
|
||||
#endif
|
||||
}
|
||||
#ifdef P3DISC_DEBUG
|
||||
else
|
||||
std::cerr << "Skipping info about own id " << pitem->pid << std::endl ;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_NEIGHBOURS, NOTIFY_TYPE_MOD);
|
||||
|
||||
/* cleanup (handled by caller) */
|
||||
|
|
|
@ -89,13 +89,6 @@ class udpPacket
|
|||
};
|
||||
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const struct sockaddr_in &addr)
|
||||
{
|
||||
out << "[" << inet_ntoa(addr.sin_addr) << ":";
|
||||
out << htons(addr.sin_port) << "]";
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
bool operator==(const struct sockaddr_in &addr, const struct sockaddr_in &addr2)
|
||||
{
|
||||
|
|
|
@ -45,7 +45,6 @@
|
|||
#include <list>
|
||||
#include <deque>
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const struct sockaddr_in &addr);
|
||||
bool operator==(const struct sockaddr_in &addr, const struct sockaddr_in &addr2);
|
||||
bool operator<(const struct sockaddr_in &addr, const struct sockaddr_in &addr2);
|
||||
|
||||
|
|
|
@ -38,7 +38,6 @@
|
|||
/*
|
||||
* #define DEBUG_RSDISCSPACE
|
||||
*/
|
||||
#define DEBUG_RSDISCSPACE
|
||||
|
||||
time_t RsDiscSpace::_last_check[3] = { 0,0,0 } ;
|
||||
uint32_t RsDiscSpace::_size_limit_mb = 100 ;
|
||||
|
|
|
@ -140,3 +140,11 @@ bool getIPAddressFromString (const char *addr_str, struct in_addr *addr)
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const struct sockaddr_in &addr)
|
||||
{
|
||||
out << "[" << inet_ntoa(addr.sin_addr) << ":";
|
||||
out << htons(addr.sin_port) << "]";
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <inttypes.h>
|
||||
#include <stdlib.h> /* Included because GCC4.4 wants it */
|
||||
#include <string.h> /* Included because GCC4.4 wants it */
|
||||
#include <iostream>
|
||||
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
#ifndef WINDOWS_SYS
|
||||
|
@ -73,4 +74,6 @@ bool isExternalNet(const struct in_addr *addr);
|
|||
/* convert addresses */
|
||||
bool getIPAddressFromString (const char *addr_str, struct in_addr *addr);
|
||||
|
||||
std::ostream& operator<<(std::ostream& o,const struct sockaddr_in&) ;
|
||||
|
||||
#endif /* RS_UNIVERSAL_NETWORK_HEADER */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue