mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Final core changes required to get relay links working.
* Added LinkType to p3LinkMgr => exposed via rspeers.h * Added ConnectionType to p3PeerMgr. This is dummy default to FRIEND at the moment. * Flag bandwidth limited Relay links as such. * Switched DNS Address connect to in front of historical addresses. * Reverted Flags in p3LinkMgr to what they were. * Added LinkType Flags to rspeers.h * removed getConnectFlags() as it was a bad way to do things. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-dhtmods@4769 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
dc8e596c0f
commit
8267739b02
@ -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 */
|
||||
|
@ -38,47 +38,17 @@
|
||||
class ExtAddrFinder ;
|
||||
class DNSResolver ;
|
||||
|
||||
/******************* FLAGS that are passed to p3LinkMgr *****
|
||||
* TRANSPORT: TCP/UDP/TUNNEL.
|
||||
* TYPE: SERVER / PEER.
|
||||
* LINK QUALITY: LIMITED, NORMAL, HIGH_SPEED.
|
||||
*/
|
||||
|
||||
// CONNECTION
|
||||
const uint32_t RS_NET_CONN_TRANS_MASK = 0x0000ffff;
|
||||
const uint32_t RS_NET_CONN_TRANS_TCP_MASK = 0x0000000f;
|
||||
const uint32_t RS_NET_CONN_TRANS_TCP_UNKNOWN = 0x00000001;
|
||||
const uint32_t RS_NET_CONN_TRANS_TCP_LOCAL = 0x00000002;
|
||||
const uint32_t RS_NET_CONN_TRANS_TCP_EXTERNAL = 0x00000004;
|
||||
|
||||
const uint32_t RS_NET_CONN_TRANS_UDP_MASK = 0x000000f0;
|
||||
const uint32_t RS_NET_CONN_TRANS_UDP_UNKNOWN = 0x00000010;
|
||||
const uint32_t RS_NET_CONN_TRANS_UDP_DIRECT = 0x00000020;
|
||||
const uint32_t RS_NET_CONN_TRANS_UDP_PROXY = 0x00000040;
|
||||
const uint32_t RS_NET_CONN_TRANS_UDP_RELAY = 0x00000080;
|
||||
|
||||
const uint32_t RS_NET_CONN_TRANS_OTHER_MASK = 0x00000f00;
|
||||
const uint32_t RS_NET_CONN_TRANS_TUNNEL = 0x00000100;
|
||||
|
||||
|
||||
const uint32_t RS_NET_CONN_SPEED_MASK = 0x000f0000;
|
||||
const uint32_t RS_NET_CONN_SPEED_UNKNOWN = 0x00000000;
|
||||
const uint32_t RS_NET_CONN_SPEED_LOW = 0x00010000;
|
||||
const uint32_t RS_NET_CONN_SPEED_NORMAL = 0x00020000;
|
||||
const uint32_t RS_NET_CONN_SPEED_HIGH = 0x00040000;
|
||||
|
||||
const uint32_t RS_NET_CONN_QUALITY_MASK = 0x00f00000;
|
||||
const uint32_t RS_NET_CONN_QUALITY_UNKNOWN = 0x00000000;
|
||||
|
||||
// THIS INFO MUST BE SUPPLIED BY PEERMGR....
|
||||
// Don't know if it should be here.
|
||||
const uint32_t RS_NET_CONN_TYPE_MASK = 0x0f000000;
|
||||
const uint32_t RS_NET_CONN_TYPE_UNKNOWN = 0x00000000;
|
||||
const uint32_t RS_NET_CONN_TYPE_ACQUAINTANCE = 0x01000000;
|
||||
const uint32_t RS_NET_CONN_TYPE_FRIEND = 0x02000000;
|
||||
const uint32_t RS_NET_CONN_TYPE_SERVER = 0x04000000;
|
||||
const uint32_t RS_NET_CONN_TYPE_CLIENT = 0x08000000;
|
||||
/* order of attempts ... */
|
||||
const uint32_t RS_NET_CONN_TCP_ALL = 0x000f;
|
||||
const uint32_t RS_NET_CONN_UDP_ALL = 0x00f0;
|
||||
const uint32_t RS_NET_CONN_TUNNEL = 0x0f00;
|
||||
|
||||
const uint32_t RS_NET_CONN_TCP_LOCAL = 0x0001;
|
||||
const uint32_t RS_NET_CONN_TCP_EXTERNAL = 0x0002;
|
||||
const uint32_t RS_NET_CONN_TCP_UNKNOW_TOPOLOGY = 0x0004;
|
||||
const uint32_t RS_NET_CONN_UDP_DHT_SYNC = 0x0010;
|
||||
const uint32_t RS_NET_CONN_UDP_PEER_SYNC = 0x0020; /* coming soon */
|
||||
|
||||
const uint32_t RS_TCP_STD_TIMEOUT_PERIOD = 5; /* 5 seconds! */
|
||||
const uint32_t RS_UDP_STD_TIMEOUT_PERIOD = 80; /* 80 secs, allows UDP TTL to get to 40! - Plenty of time (30+80) = 110 secs */
|
||||
@ -131,6 +101,7 @@ class peerConnectState
|
||||
|
||||
uint32_t state;
|
||||
uint32_t actions;
|
||||
uint32_t linkType;
|
||||
|
||||
uint32_t source; /* most current source */
|
||||
peerAddrInfo dht;
|
||||
@ -174,6 +145,7 @@ virtual const std::string getOwnId() = 0;
|
||||
virtual bool isOnline(const std::string &ssl_id) = 0;
|
||||
virtual void getOnlineList(std::list<std::string> &ssl_peers) = 0;
|
||||
virtual bool getPeerName(const std::string &ssl_id, std::string &name) = 0;
|
||||
virtual uint32_t getLinkType(const std::string &ssl_id) = 0;
|
||||
|
||||
/**************** handle monitors *****************/
|
||||
virtual void addMonitor(pqiMonitor *mon) = 0;
|
||||
@ -230,6 +202,7 @@ virtual const std::string getOwnId();
|
||||
virtual bool isOnline(const std::string &ssl_id);
|
||||
virtual void getOnlineList(std::list<std::string> &ssl_peers);
|
||||
virtual bool getPeerName(const std::string &ssl_id, std::string &name);
|
||||
virtual uint32_t getLinkType(const std::string &ssl_id);
|
||||
|
||||
|
||||
/**************** handle monitors *****************/
|
||||
|
@ -271,6 +271,11 @@ bool p3PeerMgrIMPL::getGpgId(const std::string &ssl_id, std::string &gpgId)
|
||||
return true;
|
||||
}
|
||||
|
||||
// Placeholder until we implement this functionality.
|
||||
uint32_t p3PeerMgrIMPL::getConnectionType(const std::string &sslId)
|
||||
{
|
||||
return RS_NET_CONN_TYPE_FRIEND;
|
||||
}
|
||||
|
||||
|
||||
bool p3PeerMgrIMPL::getFriendNetStatus(const std::string &id, peerState &state)
|
||||
|
@ -183,6 +183,7 @@ virtual bool getOthersNetStatus(const std::string &id, peerState &state) = 0;
|
||||
|
||||
virtual bool getPeerName(const std::string &ssl_id, std::string &name) = 0;
|
||||
virtual bool getGpgId(const std::string &sslId, std::string &gpgId) = 0;
|
||||
virtual uint32_t getConnectionType(const std::string &sslId) = 0;
|
||||
|
||||
|
||||
/************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
|
||||
@ -268,6 +269,7 @@ virtual bool getOthersNetStatus(const std::string &id, peerState &state);
|
||||
|
||||
virtual bool getPeerName(const std::string &ssl_id, std::string &name);
|
||||
virtual bool getGpgId(const std::string &sslId, std::string &gpgId);
|
||||
virtual uint32_t getConnectionType(const std::string &sslId);
|
||||
|
||||
|
||||
/************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
|
||||
|
@ -116,7 +116,7 @@ virtual void setRateCap(float val_in, float val_out)
|
||||
else
|
||||
{
|
||||
std::cerr << "RateInterface::setRateCap() Enabled ";
|
||||
std::cerr << "in: " << bwCap_in << " out: " << bwCap_out" << std::endl;
|
||||
std::cerr << "in: " << bwCap_in << " out: " << bwCap_out << std::endl;
|
||||
bwCapEnabled = true;
|
||||
bwCap_in = val_in;
|
||||
bwCap_out = val_out;
|
||||
@ -319,7 +319,6 @@ virtual int disconnect() = 0;
|
||||
virtual int reset() = 0;
|
||||
virtual std::string PeerId() { return peerId; }
|
||||
virtual int getConnectAddress(struct sockaddr_in &raddr) = 0;
|
||||
virtual int getConnectFlags(uint32_t &flags) = 0;
|
||||
|
||||
virtual bool connect_parameter(uint32_t type, uint32_t value) = 0;
|
||||
virtual bool connect_additional_address(uint32_t /*type*/, struct sockaddr_in */*addr*/) { return false; } // only needed by udp.
|
||||
|
@ -189,7 +189,7 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
|
||||
out << i << " of " << kids.size();
|
||||
out << std::endl;
|
||||
out << " type: " << (it->first);
|
||||
out << " ni: " << (it->second)->ni;
|
||||
//out << " ni: " << (it->second)->ni;
|
||||
out << " in_ni: " << ni;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
|
||||
i++;
|
||||
|
@ -74,8 +74,8 @@ virtual bool connect_parameter(uint32_t type, uint32_t value) { return ni -> co
|
||||
virtual bool connect_additional_address(uint32_t type, struct sockaddr_in *addr) { return ni -> connect_additional_address(type, addr);}
|
||||
|
||||
|
||||
|
||||
virtual int getConnectAddress(struct sockaddr_in &raddr){ return ni->getConnectAddress(raddr); }
|
||||
virtual int getConnectFlags(uint32_t &flags){ return ni->getConnectFlags(flags); }
|
||||
|
||||
// get the contact from the net side!
|
||||
virtual std::string PeerId()
|
||||
@ -138,6 +138,7 @@ int notifyEvent(NetInterface *ni, int event);
|
||||
// PQInterface for rate control overloaded....
|
||||
virtual float getRate(bool in);
|
||||
virtual void setMaxRate(bool in, float val);
|
||||
virtual void setRateCap(float val_in, float val_out);
|
||||
|
||||
pqiconnect *getKid(uint32_t type);
|
||||
|
||||
|
@ -100,7 +100,6 @@ virtual int stoplistening();
|
||||
virtual int reset();
|
||||
virtual int disconnect();
|
||||
virtual int getConnectAddress(struct sockaddr_in &raddr);
|
||||
virtual int getConnectFlags(uint32_t &flags);
|
||||
|
||||
virtual bool connect_parameter(uint32_t type, uint32_t value);
|
||||
|
||||
@ -182,8 +181,6 @@ virtual int net_internal_fcntl_nonblock(int fd) { return unix_fcntl_nonblock(fd)
|
||||
|
||||
int attempt_ts;
|
||||
|
||||
uint32_t mNetConnectFlags; // What info we have about the connection.
|
||||
|
||||
bool sameLAN; /* flag use to allow high-speed transfers */
|
||||
|
||||
int n_read_zero; /* a counter to determine if the connection is really dead */
|
||||
|
@ -279,7 +279,6 @@ int pqissludp::Initiate_Connection()
|
||||
|
||||
// Then send unreachable message.
|
||||
waiting = WAITING_FAIL_INTERFACE;
|
||||
net_unreachable |= net_attempt;
|
||||
}
|
||||
|
||||
out << "Error: Connection Failed: " << tou_err;
|
||||
@ -365,8 +364,6 @@ int pqissludp::Basic_Connection_Complete()
|
||||
out2 << " - " << socket_errorType(err);
|
||||
rslog(RSL_DEBUG_BASIC, pqissludpzone, out2.str());
|
||||
|
||||
net_unreachable |= net_attempt;
|
||||
|
||||
reset();
|
||||
|
||||
// Then send unreachable message.
|
||||
|
@ -68,8 +68,6 @@ virtual int stoplistening();
|
||||
virtual int tick();
|
||||
virtual int reset();
|
||||
|
||||
//virtual int getConnectFlags(uint32_t &flags);
|
||||
|
||||
virtual bool connect_parameter(uint32_t type, uint32_t value);
|
||||
virtual bool connect_additional_address(uint32_t type, struct sockaddr_in *addr);
|
||||
|
||||
|
@ -77,6 +77,47 @@ const int RS_PEER_CERT_CLEANING_CODE_NO_BEGIN_TAG = 0x02 ;
|
||||
const int RS_PEER_CERT_CLEANING_CODE_NO_END_TAG = 0x03 ;
|
||||
const int RS_PEER_CERT_CLEANING_CODE_NO_CHECKSUM = 0x04 ;
|
||||
|
||||
/* LinkType Flags */
|
||||
|
||||
// CONNECTION
|
||||
const uint32_t RS_NET_CONN_TRANS_MASK = 0x0000ffff;
|
||||
const uint32_t RS_NET_CONN_TRANS_TCP_MASK = 0x0000000f;
|
||||
const uint32_t RS_NET_CONN_TRANS_TCP_UNKNOWN = 0x00000001;
|
||||
const uint32_t RS_NET_CONN_TRANS_TCP_LOCAL = 0x00000002;
|
||||
const uint32_t RS_NET_CONN_TRANS_TCP_EXTERNAL = 0x00000004;
|
||||
|
||||
const uint32_t RS_NET_CONN_TRANS_UDP_MASK = 0x000000f0;
|
||||
const uint32_t RS_NET_CONN_TRANS_UDP_UNKNOWN = 0x00000010;
|
||||
const uint32_t RS_NET_CONN_TRANS_UDP_DIRECT = 0x00000020;
|
||||
const uint32_t RS_NET_CONN_TRANS_UDP_PROXY = 0x00000040;
|
||||
const uint32_t RS_NET_CONN_TRANS_UDP_RELAY = 0x00000080;
|
||||
|
||||
const uint32_t RS_NET_CONN_TRANS_OTHER_MASK = 0x00000f00;
|
||||
const uint32_t RS_NET_CONN_TRANS_TUNNEL = 0x00000100;
|
||||
|
||||
const uint32_t RS_NET_CONN_TRANS_UNKNOWN = 0x00001000;
|
||||
|
||||
|
||||
const uint32_t RS_NET_CONN_SPEED_MASK = 0x000f0000;
|
||||
const uint32_t RS_NET_CONN_SPEED_UNKNOWN = 0x00000000;
|
||||
const uint32_t RS_NET_CONN_SPEED_TRICKLE = 0x00010000;
|
||||
const uint32_t RS_NET_CONN_SPEED_LOW = 0x00020000;
|
||||
const uint32_t RS_NET_CONN_SPEED_NORMAL = 0x00040000;
|
||||
const uint32_t RS_NET_CONN_SPEED_HIGH = 0x00080000;
|
||||
|
||||
const uint32_t RS_NET_CONN_QUALITY_MASK = 0x00f00000;
|
||||
const uint32_t RS_NET_CONN_QUALITY_UNKNOWN = 0x00000000;
|
||||
|
||||
// THIS INFO MUST BE SUPPLIED BY PEERMGR....
|
||||
const uint32_t RS_NET_CONN_TYPE_MASK = 0x0f000000;
|
||||
const uint32_t RS_NET_CONN_TYPE_UNKNOWN = 0x00000000;
|
||||
const uint32_t RS_NET_CONN_TYPE_ACQUAINTANCE = 0x01000000;
|
||||
const uint32_t RS_NET_CONN_TYPE_FRIEND = 0x02000000;
|
||||
const uint32_t RS_NET_CONN_TYPE_SERVER = 0x04000000;
|
||||
const uint32_t RS_NET_CONN_TYPE_CLIENT = 0x08000000;
|
||||
|
||||
|
||||
|
||||
/* Groups */
|
||||
#define RS_GROUP_ID_FRIENDS "Friends"
|
||||
#define RS_GROUP_ID_FAMILY "Family"
|
||||
@ -143,6 +184,9 @@ class RsPeerDetails
|
||||
std::string connectStateString; /* Additional string like ip address */
|
||||
uint32_t connectPeriod;
|
||||
bool foundDHT;
|
||||
|
||||
/* linkType */
|
||||
uint32_t linkType;
|
||||
};
|
||||
|
||||
class RsGroupInfo
|
||||
|
@ -391,7 +391,7 @@ bool p3Peers::getPeerDetails(const std::string &id, RsPeerDetails &d)
|
||||
if (pcs.state & RS_PEER_S_UNREACHABLE)
|
||||
d.state |= RS_PEER_STATE_UNREACHABLE;
|
||||
|
||||
|
||||
d.linkType = pcs.linkType;
|
||||
|
||||
/* Finally determine AutoConnect Status */
|
||||
d.foundDHT = pcs.dht.found;
|
||||
|
Loading…
Reference in New Issue
Block a user