mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-14 08:59:50 -05:00
fixed connection type detection and other small things
This commit is contained in:
parent
8725aab180
commit
bfcf43f0e1
@ -1631,12 +1631,23 @@ bool p3LinkMgrIMPL::retryConnectTCP(const RsPeerId &id)
|
|||||||
/* then we just have one connect attempt via the Proxy */
|
/* then we just have one connect attempt via the Proxy */
|
||||||
if (mPeerMgr->getProxyAddress(id, proxy_addr, domain_addr, domain_port))
|
if (mPeerMgr->getProxyAddress(id, proxy_addr, domain_addr, domain_port))
|
||||||
{
|
{
|
||||||
|
/* check if it's a valid proxy address */
|
||||||
|
uint32_t type = mPeerMgr->hiddenDomainToHiddenType(domain_addr);
|
||||||
|
if (type & (~RS_HIDDEN_TYPE_MASK))
|
||||||
|
{
|
||||||
|
#ifdef LINKMGR_DEBUG
|
||||||
|
std::cerr << "p3LinkMgrIMPL::retryConnectTCP() domain (" << domain_addr << ") is invalid hidden type (" << type << ") -> return false";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
|
||||||
std::map<RsPeerId, peerConnectState>::iterator it;
|
std::map<RsPeerId, peerConnectState>::iterator it;
|
||||||
if (mFriendList.end() != (it = mFriendList.find(id)))
|
if (mFriendList.end() != (it = mFriendList.find(id)))
|
||||||
{
|
{
|
||||||
locked_ConnectAttempt_ProxyAddress(&(it->second), proxy_addr, domain_addr, domain_port);
|
locked_ConnectAttempt_ProxyAddress(&(it->second), type, proxy_addr, domain_addr, domain_port);
|
||||||
return locked_ConnectAttempt_Complete(&(it->second));
|
return locked_ConnectAttempt_Complete(&(it->second));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2018,7 +2029,7 @@ void p3LinkMgrIMPL::locked_ConnectAttempt_AddDynDNS(peerConnectState *peer, std
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void p3LinkMgrIMPL::locked_ConnectAttempt_ProxyAddress(peerConnectState *peer, const struct sockaddr_storage &proxy_addr, const std::string &domain_addr, uint16_t domain_port)
|
void p3LinkMgrIMPL::locked_ConnectAttempt_ProxyAddress(peerConnectState *peer, const uint32_t type, const struct sockaddr_storage &proxy_addr, const std::string &domain_addr, uint16_t domain_port)
|
||||||
{
|
{
|
||||||
#ifdef LINKMGR_DEBUG
|
#ifdef LINKMGR_DEBUG
|
||||||
std::cerr << "p3LinkMgrIMPL::locked_ConnectAttempt_ProxyAddress() trying address: " << domain_addr << ":" << domain_port << std::endl;
|
std::cerr << "p3LinkMgrIMPL::locked_ConnectAttempt_ProxyAddress() trying address: " << domain_addr << ":" << domain_port << std::endl;
|
||||||
@ -2026,19 +2037,21 @@ void p3LinkMgrIMPL::locked_ConnectAttempt_ProxyAddress(peerConnectState *peer,
|
|||||||
peerConnectAddress pca;
|
peerConnectAddress pca;
|
||||||
pca.addr = proxy_addr;
|
pca.addr = proxy_addr;
|
||||||
|
|
||||||
switch (mPeerMgr->hiddenDomainToHiddenType(domain_addr)) {
|
switch (type) {
|
||||||
case RS_HIDDEN_TYPE_I2P:
|
case RS_HIDDEN_TYPE_I2P:
|
||||||
pca.type = RS_NET_CONN_TCP_HIDDEN_I2P;
|
pca.type = RS_NET_CONN_TCP_HIDDEN_I2P;
|
||||||
break;
|
break;
|
||||||
case RS_HIDDEN_TYPE_UNKNOWN:
|
|
||||||
default:
|
|
||||||
#ifdef LINKMGR_DEBUG
|
|
||||||
std::cerr << "p3LinkMgrIMPL::locked_ConnectAttempt_ProxyAddress() hidden type of addr: " << domain_addr << " is unkown -> fallback to tor" << std::endl;
|
|
||||||
#endif
|
|
||||||
/* the type should be set! since this connection involves a proxy -> fallback to tor */
|
|
||||||
case RS_HIDDEN_TYPE_TOR:
|
case RS_HIDDEN_TYPE_TOR:
|
||||||
pca.type = RS_NET_CONN_TCP_HIDDEN_TOR;
|
pca.type = RS_NET_CONN_TCP_HIDDEN_TOR;
|
||||||
break;
|
break;
|
||||||
|
case RS_HIDDEN_TYPE_UNKNOWN:
|
||||||
|
default:
|
||||||
|
/**** THIS CASE SHOULD NOT BE TRIGGERED - since this function is called only with a valid hidden type****/
|
||||||
|
std::cerr << "p3LinkMgrIMPL::locked_ConnectAttempt_ProxyAddress() hidden type of addr: " << domain_addr << " is unkown -> THIS SHOULD NEVER HAPPEN!" << std::endl;
|
||||||
|
std::cerr << " - peer : " << peer->id << "(" << peer->name << ")" << std::endl;
|
||||||
|
std::cerr << " - proxy: " << sockaddr_storage_tostring(proxy_addr) << std::endl;
|
||||||
|
std::cerr << " - addr : " << domain_addr << ":" << domain_port << std::endl;
|
||||||
|
pca.type = RS_NET_CONN_TCP_UNKNOW_TOPOLOGY;
|
||||||
}
|
}
|
||||||
|
|
||||||
//for the delay, we add a random time and some more time when the friend list is big
|
//for the delay, we add a random time and some more time when the friend list is big
|
||||||
|
@ -303,7 +303,7 @@ void locked_ConnectAttempt_CurrentAddresses(peerConnectState *peer, const struc
|
|||||||
void locked_ConnectAttempt_HistoricalAddresses(peerConnectState *peer, const pqiIpAddrSet &ipAddrs);
|
void locked_ConnectAttempt_HistoricalAddresses(peerConnectState *peer, const pqiIpAddrSet &ipAddrs);
|
||||||
void locked_ConnectAttempt_AddDynDNS(peerConnectState *peer, std::string dyndns, uint16_t dynPort);
|
void locked_ConnectAttempt_AddDynDNS(peerConnectState *peer, std::string dyndns, uint16_t dynPort);
|
||||||
void locked_ConnectAttempt_AddTunnel(peerConnectState *peer);
|
void locked_ConnectAttempt_AddTunnel(peerConnectState *peer);
|
||||||
void locked_ConnectAttempt_ProxyAddress(peerConnectState *peer, const struct sockaddr_storage &proxy_addr, const std::string &domain_addr, uint16_t domain_port);
|
void locked_ConnectAttempt_ProxyAddress(peerConnectState *peer, const uint32_t type, const struct sockaddr_storage &proxy_addr, const std::string &domain_addr, uint16_t domain_port);
|
||||||
|
|
||||||
bool locked_ConnectAttempt_Complete(peerConnectState *peer);
|
bool locked_ConnectAttempt_Complete(peerConnectState *peer);
|
||||||
|
|
||||||
|
@ -74,7 +74,8 @@ const uint32_t PEER_IP_CONNECT_STATE_MAX_LIST_SIZE = 4;
|
|||||||
#define MIN_RETRY_PERIOD 140
|
#define MIN_RETRY_PERIOD 140
|
||||||
|
|
||||||
static const std::string kConfigDefaultProxyServerIpAddr = "127.0.0.1";
|
static const std::string kConfigDefaultProxyServerIpAddr = "127.0.0.1";
|
||||||
static const uint16_t kConfigDefaultProxyServerPort = 9050; // standard port.
|
static const uint16_t kConfigDefaultProxyServerPortTor = 9050; // standard port.
|
||||||
|
static const uint16_t kConfigDefaultProxyServerPortI2P = 9051; // there is no standard port though
|
||||||
|
|
||||||
static const std::string kConfigKeyExtIpFinder = "USE_EXTR_IP_FINDER";
|
static const std::string kConfigKeyExtIpFinder = "USE_EXTR_IP_FINDER";
|
||||||
static const std::string kConfigKeyProxyServerIpAddrTor = "PROXY_SERVER_IPADDR";
|
static const std::string kConfigKeyProxyServerIpAddrTor = "PROXY_SERVER_IPADDR";
|
||||||
@ -137,13 +138,13 @@ p3PeerMgrIMPL::p3PeerMgrIMPL(const RsPeerId& ssl_own_id, const RsPgpId& gpg_own_
|
|||||||
sockaddr_storage_ipv4_aton(mProxyServerAddressTor,
|
sockaddr_storage_ipv4_aton(mProxyServerAddressTor,
|
||||||
kConfigDefaultProxyServerIpAddr.c_str());
|
kConfigDefaultProxyServerIpAddr.c_str());
|
||||||
sockaddr_storage_ipv4_setport(mProxyServerAddressTor,
|
sockaddr_storage_ipv4_setport(mProxyServerAddressTor,
|
||||||
kConfigDefaultProxyServerPort);
|
kConfigDefaultProxyServerPortTor);
|
||||||
// I2P
|
// I2P
|
||||||
sockaddr_storage_clear(mProxyServerAddressI2P);
|
sockaddr_storage_clear(mProxyServerAddressI2P);
|
||||||
sockaddr_storage_ipv4_aton(mProxyServerAddressI2P,
|
sockaddr_storage_ipv4_aton(mProxyServerAddressI2P,
|
||||||
kConfigDefaultProxyServerIpAddr.c_str());
|
kConfigDefaultProxyServerIpAddr.c_str());
|
||||||
sockaddr_storage_ipv4_setport(mProxyServerAddressI2P,
|
sockaddr_storage_ipv4_setport(mProxyServerAddressI2P,
|
||||||
kConfigDefaultProxyServerPort);
|
kConfigDefaultProxyServerPortI2P);
|
||||||
|
|
||||||
mProxyServerStatusTor = RS_NET_PROXY_STATUS_UNKNOWN ;
|
mProxyServerStatusTor = RS_NET_PROXY_STATUS_UNKNOWN ;
|
||||||
mProxyServerStatusI2P = RS_NET_PROXY_STATUS_UNKNOWN;
|
mProxyServerStatusI2P = RS_NET_PROXY_STATUS_UNKNOWN;
|
||||||
@ -199,6 +200,7 @@ bool p3PeerMgrIMPL::forceHiddenNode()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
mOwnState.hiddenNode = true;
|
mOwnState.hiddenNode = true;
|
||||||
|
mOwnState.hiddenType = hiddenDomainToHiddenType(mOwnState.hiddenDomain);
|
||||||
|
|
||||||
// force external address - otherwise its invalid.
|
// force external address - otherwise its invalid.
|
||||||
sockaddr_storage_clear(mOwnState.serveraddr);
|
sockaddr_storage_clear(mOwnState.serveraddr);
|
||||||
@ -1984,9 +1986,9 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
|
|||||||
// DEFAULTS.
|
// DEFAULTS.
|
||||||
bool useExtAddrFinder = true;
|
bool useExtAddrFinder = true;
|
||||||
std::string proxyIpAddressTor = kConfigDefaultProxyServerIpAddr;
|
std::string proxyIpAddressTor = kConfigDefaultProxyServerIpAddr;
|
||||||
uint16_t proxyPortTor = kConfigDefaultProxyServerPort;
|
uint16_t proxyPortTor = kConfigDefaultProxyServerPortTor;
|
||||||
std::string proxyIpAddressI2P = kConfigDefaultProxyServerIpAddr;
|
std::string proxyIpAddressI2P = kConfigDefaultProxyServerIpAddr;
|
||||||
uint16_t proxyPortI2P = kConfigDefaultProxyServerPort + 1;
|
uint16_t proxyPortI2P = kConfigDefaultProxyServerPortI2P;
|
||||||
|
|
||||||
if (load.empty()) {
|
if (load.empty()) {
|
||||||
std::cerr << "p3PeerMgrIMPL::loadList() list is empty, it may be a configuration problem." << std::endl;
|
std::cerr << "p3PeerMgrIMPL::loadList() list is empty, it may be a configuration problem." << std::endl;
|
||||||
|
@ -91,11 +91,19 @@ pqiperson * pqisslpersongrp::locked_createPerson(const RsPeerId& id, pqilistener
|
|||||||
|
|
||||||
pqiconnect *pqisc = new pqiconnect(pqip, rss, pqis);
|
pqiconnect *pqisc = new pqiconnect(pqip, rss, pqis);
|
||||||
|
|
||||||
if (mPeerMgr->isHidden(RS_HIDDEN_TYPE_I2P) | mPeerMgr->isHiddenPeer(id, RS_HIDDEN_TYPE_I2P))
|
/* first select type based on peer */
|
||||||
|
if (mPeerMgr->isHiddenPeer(id, RS_HIDDEN_TYPE_I2P)) {
|
||||||
pqip -> addChildInterface(PQI_CONNECT_HIDDEN_I2P_TCP, pqisc);
|
pqip -> addChildInterface(PQI_CONNECT_HIDDEN_I2P_TCP, pqisc);
|
||||||
else
|
} else if (mPeerMgr->isHiddenPeer(id, RS_HIDDEN_TYPE_TOR)) {
|
||||||
/* default tor */
|
|
||||||
pqip -> addChildInterface(PQI_CONNECT_HIDDEN_TOR_TCP, pqisc);
|
pqip -> addChildInterface(PQI_CONNECT_HIDDEN_TOR_TCP, pqisc);
|
||||||
|
} else {
|
||||||
|
/* peer is not a hidden one but we are */
|
||||||
|
/* select type based on ourselves */
|
||||||
|
if (mPeerMgr->isHidden(RS_HIDDEN_TYPE_I2P))
|
||||||
|
pqip -> addChildInterface(PQI_CONNECT_HIDDEN_I2P_TCP, pqisc);
|
||||||
|
else
|
||||||
|
pqip -> addChildInterface(PQI_CONNECT_HIDDEN_TOR_TCP, pqisc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -68,6 +68,8 @@ const uint32_t RS_HIDDEN_TYPE_NONE = 0x0000;
|
|||||||
const uint32_t RS_HIDDEN_TYPE_UNKNOWN = 0x0001;
|
const uint32_t RS_HIDDEN_TYPE_UNKNOWN = 0x0001;
|
||||||
const uint32_t RS_HIDDEN_TYPE_TOR = 0x0002;
|
const uint32_t RS_HIDDEN_TYPE_TOR = 0x0002;
|
||||||
const uint32_t RS_HIDDEN_TYPE_I2P = 0x0004;
|
const uint32_t RS_HIDDEN_TYPE_I2P = 0x0004;
|
||||||
|
/* mask to match all valid hidden types */
|
||||||
|
const uint32_t RS_HIDDEN_TYPE_MASK = RS_HIDDEN_TYPE_I2P | RS_HIDDEN_TYPE_TOR;
|
||||||
|
|
||||||
/* Visibility */
|
/* Visibility */
|
||||||
const uint32_t RS_VS_DISC_OFF = 0x0000;
|
const uint32_t RS_VS_DISC_OFF = 0x0000;
|
||||||
|
@ -437,26 +437,80 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
|
|||||||
}
|
}
|
||||||
else if (pcs.state & RS_PEER_S_CONNECTED)
|
else if (pcs.state & RS_PEER_S_CONNECTED)
|
||||||
{
|
{
|
||||||
if (mPeerMgr->isHidden(RS_HIDDEN_TYPE_TOR) || isProxyAddress(RS_HIDDEN_TYPE_TOR, pcs.connectaddr))
|
/* peer is connected - determine how and set proper connectState */
|
||||||
{
|
if(mPeerMgr->isHidden())
|
||||||
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_TOR;
|
{
|
||||||
}
|
/* hidden location */
|
||||||
else if (mPeerMgr->isHidden(RS_HIDDEN_TYPE_I2P) || isProxyAddress(RS_HIDDEN_TYPE_I2P, pcs.connectaddr))
|
/* use connection direction to determine connection type */
|
||||||
{
|
if(pcs.actAsServer)
|
||||||
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_I2P;
|
{
|
||||||
}
|
/* incoming connection */
|
||||||
else if (pcs.connecttype == RS_NET_CONN_TCP_ALL)
|
/* use own type to set connectState */
|
||||||
{
|
if (mPeerMgr->isHidden(RS_HIDDEN_TYPE_TOR))
|
||||||
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_TCP;
|
{
|
||||||
}
|
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_TOR;
|
||||||
else if (pcs.connecttype == RS_NET_CONN_UDP_ALL)
|
}
|
||||||
{
|
else if (mPeerMgr->isHidden(RS_HIDDEN_TYPE_I2P))
|
||||||
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_UDP;
|
{
|
||||||
}
|
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_I2P;
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_UNKNOWN;
|
{
|
||||||
}
|
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* outgoing connection */
|
||||||
|
/* use peer hidden type to set connectState */
|
||||||
|
if (ps.hiddenType == RS_HIDDEN_TYPE_TOR)
|
||||||
|
{
|
||||||
|
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_TOR;
|
||||||
|
}
|
||||||
|
else if (ps.hiddenType == RS_HIDDEN_TYPE_I2P)
|
||||||
|
{
|
||||||
|
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_I2P;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (ps.hiddenType & RS_HIDDEN_TYPE_MASK)
|
||||||
|
{
|
||||||
|
/* hidden peer */
|
||||||
|
/* use hidden type to set connectState */
|
||||||
|
if (ps.hiddenType == RS_HIDDEN_TYPE_TOR)
|
||||||
|
{
|
||||||
|
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_TOR;
|
||||||
|
}
|
||||||
|
else if (ps.hiddenType == RS_HIDDEN_TYPE_I2P)
|
||||||
|
{
|
||||||
|
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_I2P;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* peer and we are normal nodes */
|
||||||
|
/* use normal detection to set connectState */
|
||||||
|
if (pcs.connecttype == RS_NET_CONN_TCP_ALL)
|
||||||
|
{
|
||||||
|
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_TCP;
|
||||||
|
}
|
||||||
|
else if (pcs.connecttype == RS_NET_CONN_UDP_ALL)
|
||||||
|
{
|
||||||
|
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_UDP;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
d.wasDeniedConnection = pcs.wasDeniedConnection;
|
d.wasDeniedConnection = pcs.wasDeniedConnection;
|
||||||
|
Loading…
Reference in New Issue
Block a user