From 0bc77d75ae5004b3d867a9fe3de9f4c30ff418f1 Mon Sep 17 00:00:00 2001 From: sehraf Date: Tue, 8 Sep 2015 13:48:30 +0200 Subject: [PATCH] added some error handling --- libretroshare/src/pqi/p3linkmgr.cc | 8 ++++-- libretroshare/src/pqi/p3peermgr.cc | 35 +++++++++++++++++++++----- libretroshare/src/retroshare/rspeers.h | 5 ++-- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/libretroshare/src/pqi/p3linkmgr.cc b/libretroshare/src/pqi/p3linkmgr.cc index 38323cbc2..4fb737198 100644 --- a/libretroshare/src/pqi/p3linkmgr.cc +++ b/libretroshare/src/pqi/p3linkmgr.cc @@ -2030,9 +2030,13 @@ void p3LinkMgrIMPL::locked_ConnectAttempt_ProxyAddress(peerConnectState *peer, case RS_HIDDEN_TYPE_I2P: pca.type = RS_NET_CONN_TCP_HIDDEN_I2P; break; - case RS_HIDDEN_TYPE_TOR: + case RS_HIDDEN_TYPE_UNKNOWN: default: - /* default tor */ +#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; } diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index c40582aca..c1a838d3a 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -483,7 +483,7 @@ uint32_t p3PeerMgrIMPL::hiddenDomainToHiddenType(const std::string &domain) std::cerr << "p3PeerMgrIMPL::hiddenDomainToHiddenType() unknown hidden type: " << domain; std::cerr << std::endl; #endif - return RS_HIDDEN_TYPE_NONE; + return RS_HIDDEN_TYPE_UNKNOWN; } bool p3PeerMgrIMPL::setHiddenDomainPort(const RsPeerId &ssl_id, const std::string &domain_addr, const uint16_t domain_port) @@ -560,13 +560,19 @@ bool p3PeerMgrIMPL::setProxyServerAddress(const uint32_t type, const struct sock } break; case RS_HIDDEN_TYPE_TOR: - default: if (!sockaddr_storage_same(mProxyServerAddressTor,proxy_addr)) { IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/ mProxyServerAddressTor = proxy_addr; } break; + case RS_HIDDEN_TYPE_UNKNOWN: + default: +#ifdef PEER_DEBUG + std::cerr << "p3PeerMgrIMPL::setProxyServerAddress() unknown hidden type " << type << " -> false"; + std::cerr << std::endl; +#endif + return false; } return true; @@ -593,9 +599,15 @@ bool p3PeerMgrIMPL::getProxyServerStatus(const uint32_t type, uint32_t& proxy_st proxy_status = mProxyServerStatusI2P; break; case RS_HIDDEN_TYPE_TOR: - default: proxy_status = mProxyServerStatusTor; break; + case RS_HIDDEN_TYPE_UNKNOWN: + default: +#ifdef PEER_DEBUG + std::cerr << "p3PeerMgrIMPL::getProxyServerStatus() unknown hidden type " << type << " -> false"; + std::cerr << std::endl; +#endif + return false; } return true; @@ -610,9 +622,15 @@ bool p3PeerMgrIMPL::getProxyServerAddress(const uint32_t type, struct sockaddr_s proxy_addr = mProxyServerAddressI2P; break; case RS_HIDDEN_TYPE_TOR: - default: proxy_addr = mProxyServerAddressTor; break; + case RS_HIDDEN_TYPE_UNKNOWN: + default: +#ifdef PEER_DEBUG + std::cerr << "p3PeerMgrIMPL::getProxyServerAddress() unknown hidden type " << type << " -> false"; + std::cerr << std::endl; +#endif + return false; } return true; } @@ -642,10 +660,15 @@ bool p3PeerMgrIMPL::getProxyAddress(const RsPeerId &ssl_id, struct sockaddr_stor proxy_addr = mProxyServerAddressI2P; break; case RS_HIDDEN_TYPE_TOR: - default: - /* default tor */ proxy_addr = mProxyServerAddressTor; break; + case RS_HIDDEN_TYPE_UNKNOWN: + default: +#ifdef PEER_DEBUG + std::cerr << "p3PeerMgrIMPL::getProxyAddress() no valid hidden type (" << it->second.hiddenType << ") for peer id " << ssl_id << " -> false"; + std::cerr << std::endl; +#endif + return false; } return true; } diff --git a/libretroshare/src/retroshare/rspeers.h b/libretroshare/src/retroshare/rspeers.h index aa7423ae9..2c0382134 100644 --- a/libretroshare/src/retroshare/rspeers.h +++ b/libretroshare/src/retroshare/rspeers.h @@ -65,8 +65,9 @@ const uint32_t RS_NETMODE_UNREACHABLE = 0x0005; /* Hidden Type */ const uint32_t RS_HIDDEN_TYPE_NONE = 0x0000; -const uint32_t RS_HIDDEN_TYPE_TOR = 0x0001; -const uint32_t RS_HIDDEN_TYPE_I2P = 0x0002; +const uint32_t RS_HIDDEN_TYPE_UNKNOWN = 0x0001; +const uint32_t RS_HIDDEN_TYPE_TOR = 0x0002; +const uint32_t RS_HIDDEN_TYPE_I2P = 0x0004; /* Visibility */ const uint32_t RS_VS_DISC_OFF = 0x0000;