* 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
This commit is contained in:
drbob 2013-08-22 07:26:13 +00:00
parent d0c3241be6
commit f519ae1a0d
8 changed files with 71 additions and 8 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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(&currentlocaladdr);
//sockaddr_clear(&currentserveraddr);
@ -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<std::string, peerConnectState>::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)

View File

@ -113,6 +113,11 @@ class peerConnectState
peerConnectAddress currentConnAddrAttempt;
std::list<peerConnectAddress> 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();

View File

@ -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;
}

View File

@ -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

View File

@ -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;
};

View File

@ -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)
{
}