--- Merging r4753 through r4779 from /svnroot/retroshare/branches/v0.5-dhtmods

Merging Dht Relay improvements into the trunk. These changes should finally make relays functional.
There are still some service changes required to reduce the traffic over relays.

Summary of Changes
---------------------

 * Changed the way proxy/relay peers are selected in bdConnection. (needs more work).
 * Added LinkType to peer info in p3LinkMgr & rspeers.h interface.
 * Added getConnectionType() to p3PeerMgr. This defaults to FRIEND for the moment.
 * Provide information about Bandwidth, Transport and Peer Type via LinkType().
 * Added RateCap() to limit traffic over Relay connections.
 * Set Internal Rate to 75% of Relay Limit to account for transport overhead.
 * Added various #include "util/rswin.h" to fix compile errors with standard ssl package.
 * Removed Local variables (mConnectProxyAddr, etc) which were hiding Class Variables.
 * Cleaned up bits in pqissl.cc and p3linkmgr.cc
 * Increased UDP Relay Packet size (max transport of 1400 bytes per UDP packet)
 * Modified checkRelay() to use Low Pass Filter to calculate Relay Bandwidth.
 * Improved udprelay debugging.
 * increased (x2) Relay Lifetimes - this is so that enough useful data can be transported (1meg).
 * Added LOCALNET_TESTING code to rsinit.cc. This allows Port Restrictions to simulate firewalls.
 * more debugging and minor bugfixes.




git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4780 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2012-01-11 11:54:28 +00:00
commit fc949ce5d0
34 changed files with 690 additions and 130 deletions

View file

@ -43,7 +43,9 @@ const int p3connectzone = 3431;
#include "serialiser/rsconfigitems.h"
#include "pqi/pqinotify.h"
#include "retroshare/rsiface.h"
#include "retroshare/rspeers.h"
#include <sstream>
@ -208,6 +210,28 @@ bool p3LinkMgrIMPL::isOnline(const std::string &ssl_id)
return false;
}
uint32_t p3LinkMgrIMPL::getLinkType(const std::string &ssl_id)
{
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
std::map<std::string, peerConnectState>::iterator it;
it = mFriendList.find(ssl_id);
if (it == mFriendList.end())
{
return 0;
}
if (it->second.state & RS_PEER_S_CONNECTED)
{
return it->second.linkType;
}
return 0;
}
void p3LinkMgrIMPL::getOnlineList(std::list<std::string> &ssl_peers)
{
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
@ -654,11 +678,82 @@ bool p3LinkMgrIMPL::connectAttempt(const std::string &id, struct sockaddr_in &ra
srcaddr = it->second.currentConnAddrAttempt.srcaddr;
bandwidth = it->second.currentConnAddrAttempt.bandwidth;
/********* Setup LinkType parameters **********/
#define TRICKLE_LIMIT 2001 // 2kb
#define LOW_BANDWIDTH_LIMIT 5001 // 5kb
it->second.linkType = 0;
if (type & RS_NET_CONN_TCP_ALL)
{
it->second.linkType |= RS_NET_CONN_TRANS_TCP_UNKNOWN;
}
else if (type & RS_NET_CONN_UDP_ALL)
{
if (flags & RS_CB_FLAG_MODE_UDP_DIRECT)
{
it->second.linkType |= RS_NET_CONN_TRANS_UDP_DIRECT;
}
else if (flags & RS_CB_FLAG_MODE_UDP_PROXY)
{
it->second.linkType |= RS_NET_CONN_TRANS_UDP_PROXY;
}
else if (flags & RS_CB_FLAG_MODE_UDP_RELAY)
{
it->second.linkType |= RS_NET_CONN_TRANS_UDP_RELAY;
}
else
{
it->second.linkType |= RS_NET_CONN_TRANS_UDP_UNKNOWN;
}
}
else if (type & RS_NET_CONN_TUNNEL)
{
it->second.linkType |= RS_NET_CONN_TRANS_TUNNEL;
}
else
{
it->second.linkType |= RS_NET_CONN_TRANS_UNKNOWN;
}
if (flags & RS_CB_FLAG_MODE_UDP_RELAY)
{
if (bandwidth < TRICKLE_LIMIT)
{
it->second.linkType |= RS_NET_CONN_SPEED_TRICKLE;
}
else if (bandwidth < LOW_BANDWIDTH_LIMIT)
{
it->second.linkType |= RS_NET_CONN_SPEED_LOW;
}
else
{
it->second.linkType |= RS_NET_CONN_SPEED_NORMAL;
}
}
else
{
it->second.linkType |= RS_NET_CONN_SPEED_NORMAL;
}
uint32_t connType = mPeerMgr->getConnectionType(id);
it->second.linkType |= connType;
/********* Setup LinkType parameters **********/
// TEMP DEBUG.
std::cerr << "p3LinkMgrIMPL::connectAttempt() found an address: id: " << id << std::endl;
std::cerr << " laddr: " << rs_inet_ntoa(raddr.sin_addr) << " lport: " << ntohs(raddr.sin_port) << " delay: " << delay << " period: " << period;
std::cerr << " type: " << type << std::endl;
std::cerr << "p3LinkMgrIMPL::connectAttempt() set LinkType to: " << it->second.linkType << std::endl;
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgrIMPL::connectAttempt() found an address: id: " << id << std::endl;
std::cerr << " laddr: " << rs_inet_ntoa(addr.sin_addr) << " lport: " << ntohs(addr.sin_port) << " delay: " << delay << " period: " << period;
std::cerr << " type: " << type << std::endl;
std::cerr << "p3LinkMgrIMPL::connectAttempt() set LinkType to: " << it->second.linkType << std::endl;
#endif
if (raddr.sin_addr.s_addr == 0 || raddr.sin_port == 0) {
#ifdef LINKMGR_DEBUG
@ -1485,9 +1580,7 @@ bool p3LinkMgrIMPL::retryConnectTCP(const std::string &id)
std::map<std::string, peerConnectState>::iterator it;
if (mFriendList.end() != (it = mFriendList.find(id)))
{
locked_ConnectAttempt_CurrentAddresses(&(it->second), &lAddr, &eAddr);
locked_ConnectAttempt_HistoricalAddresses(&(it->second), histAddrs);
uint16_t dynPort = ntohs(eAddr.sin_port);
if (!dynPort)
@ -1497,6 +1590,8 @@ bool p3LinkMgrIMPL::retryConnectTCP(const std::string &id)
locked_ConnectAttempt_AddDynDNS(&(it->second), dyndns, dynPort);
}
locked_ConnectAttempt_HistoricalAddresses(&(it->second), histAddrs);
//locked_ConnectAttempt_AddTunnel(&(it->second));
/* finish it off */