fixed connection type detection and other small things

This commit is contained in:
sehraf 2015-09-15 16:18:46 +02:00
parent 8725aab180
commit bfcf43f0e1
6 changed files with 117 additions and 38 deletions

View File

@ -1631,12 +1631,23 @@ bool p3LinkMgrIMPL::retryConnectTCP(const RsPeerId &id)
/* then we just have one connect attempt via the Proxy */
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 *******/
std::map<RsPeerId, peerConnectState>::iterator it;
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));
}
}
@ -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
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;
pca.addr = proxy_addr;
switch (mPeerMgr->hiddenDomainToHiddenType(domain_addr)) {
switch (type) {
case RS_HIDDEN_TYPE_I2P:
pca.type = RS_NET_CONN_TCP_HIDDEN_I2P;
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:
pca.type = RS_NET_CONN_TCP_HIDDEN_TOR;
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

View File

@ -303,7 +303,7 @@ void locked_ConnectAttempt_CurrentAddresses(peerConnectState *peer, const struc
void locked_ConnectAttempt_HistoricalAddresses(peerConnectState *peer, const pqiIpAddrSet &ipAddrs);
void locked_ConnectAttempt_AddDynDNS(peerConnectState *peer, std::string dyndns, uint16_t dynPort);
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);

View File

@ -74,7 +74,8 @@ const uint32_t PEER_IP_CONNECT_STATE_MAX_LIST_SIZE = 4;
#define MIN_RETRY_PERIOD 140
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 kConfigKeyProxyServerIpAddrTor = "PROXY_SERVER_IPADDR";
@ -137,13 +138,13 @@ p3PeerMgrIMPL::p3PeerMgrIMPL(const RsPeerId& ssl_own_id, const RsPgpId& gpg_own_
sockaddr_storage_ipv4_aton(mProxyServerAddressTor,
kConfigDefaultProxyServerIpAddr.c_str());
sockaddr_storage_ipv4_setport(mProxyServerAddressTor,
kConfigDefaultProxyServerPort);
kConfigDefaultProxyServerPortTor);
// I2P
sockaddr_storage_clear(mProxyServerAddressI2P);
sockaddr_storage_ipv4_aton(mProxyServerAddressI2P,
kConfigDefaultProxyServerIpAddr.c_str());
sockaddr_storage_ipv4_setport(mProxyServerAddressI2P,
kConfigDefaultProxyServerPort);
kConfigDefaultProxyServerPortI2P);
mProxyServerStatusTor = RS_NET_PROXY_STATUS_UNKNOWN ;
mProxyServerStatusI2P = RS_NET_PROXY_STATUS_UNKNOWN;
@ -199,6 +200,7 @@ bool p3PeerMgrIMPL::forceHiddenNode()
#endif
}
mOwnState.hiddenNode = true;
mOwnState.hiddenType = hiddenDomainToHiddenType(mOwnState.hiddenDomain);
// force external address - otherwise its invalid.
sockaddr_storage_clear(mOwnState.serveraddr);
@ -1984,9 +1986,9 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
// DEFAULTS.
bool useExtAddrFinder = true;
std::string proxyIpAddressTor = kConfigDefaultProxyServerIpAddr;
uint16_t proxyPortTor = kConfigDefaultProxyServerPort;
uint16_t proxyPortTor = kConfigDefaultProxyServerPortTor;
std::string proxyIpAddressI2P = kConfigDefaultProxyServerIpAddr;
uint16_t proxyPortI2P = kConfigDefaultProxyServerPort + 1;
uint16_t proxyPortI2P = kConfigDefaultProxyServerPortI2P;
if (load.empty()) {
std::cerr << "p3PeerMgrIMPL::loadList() list is empty, it may be a configuration problem." << std::endl;

View File

@ -91,12 +91,20 @@ pqiperson * pqisslpersongrp::locked_createPerson(const RsPeerId& id, pqilistener
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);
} else if (mPeerMgr->isHiddenPeer(id, RS_HIDDEN_TYPE_TOR)) {
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
/* default tor */
pqip -> addChildInterface(PQI_CONNECT_HIDDEN_TOR_TCP, pqisc);
}
}
else
{
#ifdef PQISTREAMER_DEBUG

View File

@ -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_TOR = 0x0002;
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 */
const uint32_t RS_VS_DISC_OFF = 0x0000;

View File

@ -437,15 +437,68 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
}
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())
{
/* hidden location */
/* use connection direction to determine connection type */
if(pcs.actAsServer)
{
/* incoming connection */
/* use own type to set connectState */
if (mPeerMgr->isHidden(RS_HIDDEN_TYPE_TOR))
{
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_TOR;
}
else if (mPeerMgr->isHidden(RS_HIDDEN_TYPE_I2P) || isProxyAddress(RS_HIDDEN_TYPE_I2P, pcs.connectaddr))
else if (mPeerMgr->isHidden(RS_HIDDEN_TYPE_I2P))
{
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_I2P;
}
else if (pcs.connecttype == RS_NET_CONN_TCP_ALL)
else
{
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;
}
@ -458,6 +511,7 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_UNKNOWN;
}
}
}
d.wasDeniedConnection = pcs.wasDeniedConnection;
d.deniedTS = pcs.deniedTS;