fixed some cleaning of remotely closed tunnels in GxsTunnelService

This commit is contained in:
csoler 2015-12-03 00:34:13 -05:00
parent 81b196d38d
commit b198f1a007
2 changed files with 106 additions and 93 deletions

View File

@ -194,8 +194,19 @@ void p3GxsTunnelService::flush()
time_t now = time(NULL) ;
for(std::map<RsGxsTunnelId,GxsTunnelPeerInfo>::iterator it(_gxs_tunnel_contacts.begin());it!=_gxs_tunnel_contacts.end();++it)
for(std::map<RsGxsTunnelId,GxsTunnelPeerInfo>::iterator it(_gxs_tunnel_contacts.begin());it!=_gxs_tunnel_contacts.end();)
{
// Remove any tunnel that was remotely closed, since we cannot use it anymore.
if(it->second.status == RS_GXS_TUNNEL_STATUS_REMOTELY_CLOSED && it->second.last_contact + 20 < now)
{
std::map<RsGxsTunnelId,GxsTunnelPeerInfo>::iterator tmp = it ;
++tmp ;
_gxs_tunnel_contacts.erase(it) ;
it=tmp ;
continue ;
}
if(it->second.last_contact+20+GXS_TUNNEL_KEEP_ALIVE_TIMEOUT < now && it->second.status == RS_GXS_TUNNEL_STATUS_CAN_TALK)
{
#ifdef DEBUG_GXS_TUNNEL
@ -233,6 +244,7 @@ void p3GxsTunnelService::flush()
std::cerr << "(II) GxsTunnelService:: Sending keep alive packet to gxs id " << it->first << std::endl;
#endif
}
++it ;
}
}
@ -1418,6 +1430,7 @@ bool p3GxsTunnelService::closeExistingTunnel(const RsGxsTunnelId& tunnel_id, uin
TurtleFileHash hash ;
TurtleVirtualPeerId vpid ;
bool close_tunnel = false ;
int direction ;
{
RsStackMutex stack(mGxsTunnelMtx); /********** STACK LOCKED MTX ******/
std::map<RsGxsTunnelId,GxsTunnelPeerInfo>::iterator it = _gxs_tunnel_contacts.find(tunnel_id) ;
@ -1432,9 +1445,6 @@ bool p3GxsTunnelService::closeExistingTunnel(const RsGxsTunnelId& tunnel_id, uin
}
vpid = it->second.virtual_peer_id ;
if(it->second.direction == RsTurtleGenericTunnelItem::DIRECTION_CLIENT) // nothing more to do for server side.
return true ;
std::map<TurtleVirtualPeerId, GxsTunnelDHInfo>::const_iterator it2 = _gxs_tunnel_virtual_peer_ids.find(vpid) ;
if(it2 != _gxs_tunnel_virtual_peer_ids.end())
@ -1451,14 +1461,14 @@ bool p3GxsTunnelService::closeExistingTunnel(const RsGxsTunnelId& tunnel_id, uin
}
it->second.client_services.erase(it3) ;
direction = it->second.direction ;
if(it->second.client_services.empty())
close_tunnel = true ;
}
if(!close_tunnel)
return true ;
if(close_tunnel && direction == RsTurtleGenericTunnelItem::DIRECTION_SERVER) // nothing more to do for server side.
{
// send a status item saying that we're closing the connection
#ifdef DEBUG_GXS_TUNNEL
std::cerr << " Sending a ACK to close the tunnel since we're managing it and it's not used by any service. tunnel id=." << tunnel_id << std::endl;
@ -1475,6 +1485,9 @@ bool p3GxsTunnelService::closeExistingTunnel(const RsGxsTunnelId& tunnel_id, uin
std::cerr << " This is client side. Stopping tunnel manageement for tunnel_id " << tunnel_id << std::endl;
#endif
mTurtle->stopMonitoringTunnels( hash ) ; // still valid if the hash is null
}
if(close_tunnel)
{
RsStackMutex stack(mGxsTunnelMtx); /********** STACK LOCKED MTX ******/
std::map<RsGxsTunnelId,GxsTunnelPeerInfo>::iterator it = _gxs_tunnel_contacts.find(tunnel_id) ;

View File

@ -104,7 +104,7 @@ void PopupDistantChatDialog::updateDisplay()
{
case RS_DISTANT_CHAT_STATUS_UNKNOWN: //std::cerr << "Unknown hash. Error!" << std::endl;
_status_label->setPixmap(QPixmap(IMAGE_GRY_LED)) ;
msg = tr("Hash Error. No tunnel.");
msg = tr("Chat remotely closed. Please close this window.");
_status_label->setToolTip(msg) ;
getChatWidget()->updateStatusString("%1", msg, true);
getChatWidget()->blockSending(tr("Can't send message, because there is no tunnel."));