show if TCP connection is incoming or outgoing (modified patch from sehraf)

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8265 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
electron128 2015-05-16 11:19:53 +00:00
parent 3d3a163a75
commit 66242ce068
10 changed files with 48 additions and 16 deletions

View File

@ -768,7 +768,7 @@ bool p3LinkMgrIMPL::connectAttempt(const RsPeerId &id, struct sockaddr_storage &
*
*/
bool p3LinkMgrIMPL::connectResult(const RsPeerId &id, bool success, uint32_t flags, const struct sockaddr_storage &remote_peer_address)
bool p3LinkMgrIMPL::connectResult(const RsPeerId &id, bool success, bool isIncomingConnection, uint32_t flags, const struct sockaddr_storage &remote_peer_address)
{
bool doDhtAssist = false ;
bool updatePeerAddr = false;
@ -846,6 +846,8 @@ bool p3LinkMgrIMPL::connectResult(const RsPeerId &id, bool success, uint32_t fla
it->second.connecttype = flags;
it->second.connectaddr = remote_peer_address;
it->second.actAsServer = isIncomingConnection;
updateLastContact = true; /* time of connect */
/* only update the peer's address if we were in a connect attempt.

View File

@ -101,7 +101,8 @@ class peerConnectState
bool dhtVisible;
uint32_t connecttype; // RS_NET_CONN_TCP_ALL / RS_NET_CONN_UDP_ALL
time_t lastavailable;
bool actAsServer;
time_t lastavailable;
time_t lastattempt;
std::string name;
@ -111,9 +112,9 @@ class peerConnectState
uint32_t linkType;
uint32_t source; /* most current source */
peerAddrInfo dht;
peerAddrInfo disc;
peerAddrInfo peer;
peerAddrInfo dht;
peerAddrInfo disc;
peerAddrInfo peer;
struct sockaddr_storage connectaddr; // current connection address. Can be local or external.
@ -171,7 +172,7 @@ virtual bool connectAttempt(const RsPeerId &id, struct sockaddr_storage &raddr,
uint32_t &delay, uint32_t &period, uint32_t &type, uint32_t &flags, uint32_t &bandwidth,
std::string &domain_addr, uint16_t &domain_port) = 0;
virtual bool connectResult(const RsPeerId &id, bool success, uint32_t flags, const struct sockaddr_storage &remote_peer_address) = 0;
virtual bool connectResult(const RsPeerId &id, bool success, bool isIncomingConnection, uint32_t flags, const struct sockaddr_storage &remote_peer_address) = 0;
virtual bool retryConnect(const RsPeerId &id) = 0;
virtual void notifyDeniedConnection(const RsPgpId& gpgid,const RsPeerId& sslid,const std::string& sslcn,const struct sockaddr_storage &addr, bool incoming) = 0;
@ -229,7 +230,7 @@ virtual bool connectAttempt(const RsPeerId &id, struct sockaddr_storage &raddr,
uint32_t &delay, uint32_t &period, uint32_t &type, uint32_t &flags, uint32_t &bandwidth,
std::string &domain_addr, uint16_t &domain_port);
virtual bool connectResult(const RsPeerId &id, bool success, uint32_t flags, const struct sockaddr_storage &remote_peer_address);
virtual bool connectResult(const RsPeerId &id, bool success, bool isIncomingConnection, uint32_t flags, const struct sockaddr_storage &remote_peer_address);
virtual bool retryConnect(const RsPeerId &id);
virtual void notifyDeniedConnection(const RsPgpId& gpgid,const RsPeerId& sslid,const std::string& sslcn,const struct sockaddr_storage &addr, bool incoming);

View File

@ -310,9 +310,14 @@ int pqiperson::handleNotifyEvent_locked(NetInterface *ni, int newState, const s
case CONNECT_SUCCESS:
/* notify */
if (pqipg) {
pqipg->notifyConnect(PeerId(), type, true, remote_peer_address);
}
if (pqipg)
{
pqissl *ssl = dynamic_cast<pqissl*>(ni);
if(ssl != NULL)
pqipg->notifyConnect(PeerId(), type, true, ssl->actAsServer(), remote_peer_address);
else
pqipg->notifyConnect(PeerId(), type, true, false, remote_peer_address);
}
if ((active) && (activepqi != pqi)) // already connected - trouble
{
@ -382,7 +387,7 @@ int pqiperson::handleNotifyEvent_locked(NetInterface *ni, int newState, const s
/* notify up */
if (pqipg)
{
pqipg->notifyConnect(PeerId(), type, false, remote_peer_address);
pqipg->notifyConnect(PeerId(), type, false, false, remote_peer_address);
}
return 1;
@ -529,7 +534,7 @@ int pqiperson::connect(uint32_t type, const struct sockaddr_storage &raddr,
#endif
/* notify of fail! */
pqipg->notifyConnect(PeerId(), type, false, raddr);
pqipg->notifyConnect(PeerId(), type, false, false, raddr);
return 0;
}

View File

@ -657,7 +657,7 @@ int pqipersongrp::connectPeer(const RsPeerId& id
return 1;
}
bool pqipersongrp::notifyConnect(const RsPeerId& id, uint32_t ptype, bool success, const struct sockaddr_storage &raddr)
bool pqipersongrp::notifyConnect(const RsPeerId& id, uint32_t ptype, bool success, bool isIncomingConnection, const struct sockaddr_storage &raddr)
{
uint32_t type = 0;
if (ptype == PQI_CONNECT_TCP)
@ -670,7 +670,7 @@ bool pqipersongrp::notifyConnect(const RsPeerId& id, uint32_t ptype, bool suc
}
if (mLinkMgr)
mLinkMgr->connectResult(id, success, type, raddr);
mLinkMgr->connectResult(id, success, isIncomingConnection, type, raddr);
return (NULL != mLinkMgr);
}

View File

@ -88,7 +88,7 @@ virtual bool RecvRsRawItem(RsRawItem *item);
int tagHeartbeatRecvd(const RsPeerId& id);
/*** callback from children ****/
bool notifyConnect(const RsPeerId& id, uint32_t type, bool success, const struct sockaddr_storage &remote_peer_address);
bool notifyConnect(const RsPeerId& id, uint32_t type, bool success, bool isIncomingConnection, const struct sockaddr_storage &remote_peer_address);
//bool notifyConnect(std::string id, uint32_t type, bool success);
// tick interfaces.

View File

@ -367,6 +367,11 @@ void pqissl::getCryptoParams(RsPeerCryptoParams& params)
}
}
bool pqissl::actAsServer()
{
return (bool)ssl_connection->server;
}
/* returns ...
* -1 if inactive.
* 0 if connecting.

View File

@ -125,6 +125,7 @@ public:
int accept(SSL *ssl, int fd, const struct sockaddr_storage &foreign_addr);
void getCryptoParams(RsPeerCryptoParams& params) ;
bool actAsServer();
protected:

View File

@ -216,7 +216,8 @@ class RsPeerDetails
ServicePermissionFlags service_perm_flags ;
/* Network details (only valid if friend) */
uint32_t state;
uint32_t state;
bool actAsServer;
std::string connectAddr ; // current address if connected.
uint16_t connectPort ;

View File

@ -412,6 +412,8 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
if (pcs.state & RS_PEER_S_UNREACHABLE)
d.state |= RS_PEER_STATE_UNREACHABLE;
d.actAsServer = pcs.actAsServer;
d.linkType = pcs.linkType;
/* Finally determine AutoConnect Status */

View File

@ -158,6 +158,7 @@ QString StatusDefs::peerStateString(int peerState)
QString StatusDefs::connectStateString(RsPeerDetails &details)
{
QString stateString;
bool isConnected = false;
switch (details.connectState) {
case 0:
@ -171,18 +172,30 @@ QString StatusDefs::connectStateString(RsPeerDetails &details)
break;
case RS_PEER_CONNECTSTATE_CONNECTED_TCP:
stateString = qApp->translate("StatusDefs", "Connected: TCP");
isConnected = true;
break;
case RS_PEER_CONNECTSTATE_CONNECTED_UDP:
stateString = qApp->translate("StatusDefs", "Connected: UDP");
isConnected = true;
break;
case RS_PEER_CONNECTSTATE_CONNECTED_TOR:
stateString = qApp->translate("StatusDefs", "Connected: TOR");
isConnected = true;
break;
case RS_PEER_CONNECTSTATE_CONNECTED_UNKNOWN:
stateString = qApp->translate("StatusDefs", "Connected: Unknown");
isConnected = true;
break;
}
if(isConnected) {
stateString += " ";
if(details.actAsServer)
stateString += qApp->translate("StatusDefs", "inbound connection");
else
stateString += qApp->translate("StatusDefs", "outbound connection");
}
if (details.connectStateString.empty() == false) {
if (stateString.isEmpty() == false) {
stateString += ": ";
@ -237,6 +250,7 @@ QString StatusDefs::connectStateIpString(RsPeerDetails &details)
case RS_PEER_CONNECTSTATE_TRYING_TCP:
case RS_PEER_CONNECTSTATE_CONNECTED_TCP:
stateString += qApp->translate("StatusDefs", "TCP");
stateString += QString(details.actAsServer ? "-in" : "-out");
break;
case RS_PEER_CONNECTSTATE_TRYING_UDP:
case RS_PEER_CONNECTSTATE_CONNECTED_UDP:
@ -244,6 +258,7 @@ QString StatusDefs::connectStateIpString(RsPeerDetails &details)
break;
case RS_PEER_CONNECTSTATE_CONNECTED_TOR:
stateString += qApp->translate("StatusDefs", "TOR");
stateString += QString(details.actAsServer ? "-in" : "-out");
break;
case RS_PEER_CONNECTSTATE_CONNECTED_UNKNOWN:
stateString += qApp->translate("StatusDefs", "unkown");