From f519ae1a0d425d616b7004279def62439034e378 Mon Sep 17 00:00:00 2001 From: drbob Date: Thu, 22 Aug 2013 07:26:13 +0000 Subject: [PATCH] * Added libretroshare internal storage of "Denied Connections" in linkMgr. * Added a couple of missing #defines. * Tweaked dht connect state strings for easy parsing. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6589 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/dht/connectstatebox.cc | 10 ++--- libretroshare/src/dht/p3bitdht_interface.cc | 2 + libretroshare/src/pqi/p3linkmgr.cc | 43 ++++++++++++++++++++- libretroshare/src/pqi/p3linkmgr.h | 9 +++++ libretroshare/src/pqi/pqissl.cc | 1 + libretroshare/src/retroshare/rsdht.h | 1 + libretroshare/src/retroshare/rspeers.h | 5 +++ libretroshare/src/rsserver/p3peers.cc | 8 +++- 8 files changed, 71 insertions(+), 8 deletions(-) diff --git a/libretroshare/src/dht/connectstatebox.cc b/libretroshare/src/dht/connectstatebox.cc index 5a74eeca5..f6a164d03 100644 --- a/libretroshare/src/dht/connectstatebox.cc +++ b/libretroshare/src/dht/connectstatebox.cc @@ -129,19 +129,19 @@ std::string StateAsString(uint32_t state) switch(state) { case CSB_START: - str = "Start"; + str = "Start:"; break; case CSB_TCP_WAIT: - str = "TCP Wait"; + str = "TCP Wait:"; break; case CSB_DIRECT_ATTEMPT: - str = "Direct Attempt"; + str = "Direct Attempt:"; break; case CSB_DIRECT_WAIT: - str = "Direct Wait"; + str = "Direct Wait:"; break; case CSB_PROXY_ATTEMPT: @@ -173,7 +173,7 @@ std::string StateAsString(uint32_t state) break; default: - str = "Unknown State"; + str = "Unknown State:"; break; } diff --git a/libretroshare/src/dht/p3bitdht_interface.cc b/libretroshare/src/dht/p3bitdht_interface.cc index 5a4928627..92f475e5e 100644 --- a/libretroshare/src/dht/p3bitdht_interface.cc +++ b/libretroshare/src/dht/p3bitdht_interface.cc @@ -302,6 +302,8 @@ void convertDhtPeerDetailsToRsDhtNetPeer(RsDhtNetPeer &status, const DhtPeerDeta switch(details.mPeerConnectMode) { default: + status.mPeerConnectMode = RSDHT_TOU_MODE_NONE; + break; case BITDHT_CONNECT_MODE_DIRECT: status.mPeerConnectMode = RSDHT_TOU_MODE_DIRECT; break; diff --git a/libretroshare/src/pqi/p3linkmgr.cc b/libretroshare/src/pqi/p3linkmgr.cc index 144060f1c..dd29e3ae1 100644 --- a/libretroshare/src/pqi/p3linkmgr.cc +++ b/libretroshare/src/pqi/p3linkmgr.cc @@ -104,7 +104,8 @@ peerConnectState::peerConnectState() name(""), state(0), actions(0), source(0), - inConnAttempt(0) + inConnAttempt(0), + wasDeniedConnection(false), deniedTS(false), deniedInConnAttempt(false) { //sockaddr_clear(¤tlocaladdr); //sockaddr_clear(¤tserveraddr); @@ -1036,6 +1037,46 @@ bool p3LinkMgrIMPL::connectResult(const std::string &id, bool success, uint32_t * From various sources */ +// from pqissl, when a connection failed due to security +void p3LinkMgrIMPL::notifyDeniedConnection(const std::string& gpgid,const std::string& sslid,const std::string& sslcn,const struct sockaddr_in &addr, bool incoming) +{ + std::cerr << "p3LinkMgrIMPL::notifyDeniedConnection()"; + std::cerr << " pgpid: " << gpgid; + std::cerr << " sslid: " << sslid; + std::cerr << " sslcn: " << sslcn; + std::cerr << std::endl; + + RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/ + + std::map::iterator it; + it = mFriendList.find(sslid); + if (it == mFriendList.end()) + { + std::cerr << "p3LinkMgrIMPL::notifyDeniedConnection() of NON-FRIEND: " << sslid; + std::cerr << std::endl; + return; + } + + it->second.wasDeniedConnection = true; + it->second.deniedTS = time(NULL); + + if ((!incoming) && it->second.inConnAttempt) + { + it->second.deniedInConnAttempt = true; + it->second.deniedConnectionAttempt = it->second.currentConnAddrAttempt; + + std::cerr << "p3LinkMgrIMPL::notifyDeniedConnection() Denied In Connection Attempt"; + std::cerr << std::endl; + } + else + { + it->second.deniedInConnAttempt = false; + std::cerr << "p3LinkMgrIMPL::notifyDeniedConnection() Denied NOT In Connection Attempt"; + std::cerr << std::endl; + } + return; +} + void p3LinkMgrIMPL::peerStatus(std::string id, const pqiIpAddrSet &addrs, uint32_t type, uint32_t flags, uint32_t source) diff --git a/libretroshare/src/pqi/p3linkmgr.h b/libretroshare/src/pqi/p3linkmgr.h index 5cf0026dd..10b3284bd 100644 --- a/libretroshare/src/pqi/p3linkmgr.h +++ b/libretroshare/src/pqi/p3linkmgr.h @@ -113,6 +113,11 @@ class peerConnectState peerConnectAddress currentConnAddrAttempt; std::list connAddrs; + /* information about denial */ + bool wasDeniedConnection; + time_t deniedTS; + bool deniedInConnAttempt; /* is below valid */ + peerConnectAddress deniedConnectionAttempt; }; @@ -159,6 +164,8 @@ virtual bool connectAttempt(const std::string &id, struct sockaddr_in &raddr, virtual bool connectResult(const std::string &id, bool success, uint32_t flags, struct sockaddr_in remote_peer_address) = 0; virtual bool retryConnect(const std::string &id) = 0; +virtual void notifyDeniedConnection(const std::string& gpgid,const std::string& sslid,const std::string& sslcn,const struct sockaddr_in &addr, bool incoming) = 0; + /* Network Addresses */ virtual bool setLocalAddress(struct sockaddr_in addr) = 0; virtual struct sockaddr_in getLocalAddress() = 0; @@ -216,6 +223,8 @@ virtual bool connectAttempt(const std::string &id, struct sockaddr_in &raddr, virtual bool connectResult(const std::string &id, bool success, uint32_t flags, struct sockaddr_in remote_peer_address); virtual bool retryConnect(const std::string &id); +virtual void notifyDeniedConnection(const std::string& gpgid,const std::string& sslid,const std::string& sslcn,const struct sockaddr_in &addr, bool incoming); + /* Network Addresses */ virtual bool setLocalAddress(struct sockaddr_in addr); virtual struct sockaddr_in getLocalAddress(); diff --git a/libretroshare/src/pqi/pqissl.cc b/libretroshare/src/pqi/pqissl.cc index 57db7b80a..2e37d7583 100644 --- a/libretroshare/src/pqi/pqissl.cc +++ b/libretroshare/src/pqi/pqissl.cc @@ -1177,6 +1177,7 @@ int pqissl::Extract_Failed_SSL_Certificate() std::string sslcn = getX509CNString(peercert->cert_info->subject); AuthSSL::getAuthSSL()->FailedCertificate(peercert, gpgid,sslid,sslcn,remote_addr, false); + mLinkMgr->notifyDeniedConnection(gpgid, sslid, sslcn, remote_addr, false); return 1; } diff --git a/libretroshare/src/retroshare/rsdht.h b/libretroshare/src/retroshare/rsdht.h index 7be2363a5..a691567ba 100644 --- a/libretroshare/src/retroshare/rsdht.h +++ b/libretroshare/src/retroshare/rsdht.h @@ -66,6 +66,7 @@ extern RsDht *rsDht; #define RSDHT_PEERREQ_STOPPED 1 #define RSDHT_PEERREQ_RUNNING 2 +#define RSDHT_TOU_MODE_NONE 0 #define RSDHT_TOU_MODE_DIRECT 1 #define RSDHT_TOU_MODE_PROXY 2 #define RSDHT_TOU_MODE_RELAY 3 diff --git a/libretroshare/src/retroshare/rspeers.h b/libretroshare/src/retroshare/rspeers.h index 4df01a285..ee5df57a9 100644 --- a/libretroshare/src/retroshare/rspeers.h +++ b/libretroshare/src/retroshare/rspeers.h @@ -78,6 +78,7 @@ const ServicePermissionFlags RS_SERVICE_PERM_ALL = RS_SERVICE_PERM_TURTL // ... /* Connect state */ +const uint32_t RS_PEER_CONNECTSTATE_OFFLINE = 0; const uint32_t RS_PEER_CONNECTSTATE_TRYING_TUNNEL = 1; const uint32_t RS_PEER_CONNECTSTATE_TRYING_TCP = 2; const uint32_t RS_PEER_CONNECTSTATE_TRYING_UDP = 3; @@ -224,6 +225,10 @@ class RsPeerDetails uint32_t connectPeriod; bool foundDHT; + /* have we been denied */ + bool wasDeniedConnection; + time_t deniedTS; + /* linkType */ uint32_t linkType; }; diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index 666216d2d..150562db8 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -389,7 +389,7 @@ bool p3Peers::getPeerDetails(const std::string &id, RsPeerDetails &d) /* Finally determine AutoConnect Status */ d.foundDHT = pcs.dht.found; - d.connectState = 0; + d.connectState = RS_PEER_CONNECTSTATE_OFFLINE; d.connectStateString.clear(); @@ -425,6 +425,9 @@ bool p3Peers::getPeerDetails(const std::string &id, RsPeerDetails &d) } } + d.wasDeniedConnection = pcs.wasDeniedConnection; + d.deniedTS = pcs.deniedTS; + return true; } @@ -1178,7 +1181,8 @@ RsPeerDetails::RsPeerDetails() trustLvl(0), validLvl(0),ownsign(false), hasSignedMe(false),accept_connection(false), state(0),localAddr(""),localPort(0),extAddr(""),extPort(0),netMode(0),visState(0), - lastConnect(0),connectState(0),connectStateString(""),connectPeriod(0),foundDHT(false) + lastConnect(0),connectState(0),connectStateString(""),connectPeriod(0),foundDHT(false), + wasDeniedConnection(false), deniedTS(0) { }