mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
speed up status display of participants in chatrooms
This commit is contained in:
parent
b4557064a5
commit
4aaae99a52
@ -723,7 +723,6 @@ void DistributedChatService::handleRecvChatLobbyEventItem(RsChatLobbyEventItem *
|
|||||||
if(!(details.mFlags & RS_IDENTITY_FLAGS_PGP_LINKED))
|
if(!(details.mFlags & RS_IDENTITY_FLAGS_PGP_LINKED))
|
||||||
{
|
{
|
||||||
std::cerr << "(WW) Received a lobby msg/item that is not PGP-authed (ID=" << item->signature.keyId << "), whereas the lobby flags require it. Rejecting!" << std::endl;
|
std::cerr << "(WW) Received a lobby msg/item that is not PGP-authed (ID=" << item->signature.keyId << "), whereas the lobby flags require it. Rejecting!" << std::endl;
|
||||||
|
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -798,6 +797,8 @@ void DistributedChatService::handleRecvChatLobbyEventItem(RsChatLobbyEventItem *
|
|||||||
#ifdef DEBUG_CHAT_LOBBIES
|
#ifdef DEBUG_CHAT_LOBBIES
|
||||||
std::cerr << " added nickname " << item->nick << " from lobby " << std::hex << item->lobby_id << std::dec << std::endl;
|
std::cerr << " added nickname " << item->nick << " from lobby " << std::hex << item->lobby_id << std::dec << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
// trigger a keep alive packets so as to inform the new participant of our presence in the chatroom
|
||||||
|
it->second.last_keep_alive_packet_time = 0 ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(item->event_type == RS_CHAT_LOBBY_EVENT_KEEP_ALIVE) // keep alive packet.
|
else if(item->event_type == RS_CHAT_LOBBY_EVENT_KEEP_ALIVE) // keep alive packet.
|
||||||
@ -818,8 +819,10 @@ void DistributedChatService::handleRecvChatLobbyEventItem(RsChatLobbyEventItem *
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RsServer::notify()->notifyChatLobbyEvent(item->lobby_id,item->event_type,item->signature.keyId,item->string1) ;
|
|
||||||
|
RsServer::notify()->notifyChatLobbyEvent(item->lobby_id,item->event_type,item->signature.keyId,item->string1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DistributedChatService::getListOfNearbyChatLobbies(std::vector<VisibleChatLobbyRecord>& visible_lobbies)
|
void DistributedChatService::getListOfNearbyChatLobbies(std::vector<VisibleChatLobbyRecord>& visible_lobbies)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
@ -1131,7 +1134,6 @@ void DistributedChatService::handleConnectionChallenge(RsChatLobbyConnectChallen
|
|||||||
#ifdef DEBUG_CHAT_LOBBIES
|
#ifdef DEBUG_CHAT_LOBBIES
|
||||||
std::cerr << " Lobby_id = 0x" << std::hex << it->first << ", msg_id = 0x" << it2->first << ": code = 0x" << code << std::dec << std::endl ;
|
std::cerr << " Lobby_id = 0x" << std::hex << it->first << ", msg_id = 0x" << it2->first << ": code = 0x" << code << std::dec << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(code == item->challenge_code)
|
if(code == item->challenge_code)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_CHAT_LOBBIES
|
#ifdef DEBUG_CHAT_LOBBIES
|
||||||
@ -1231,6 +1233,7 @@ uint64_t DistributedChatService::makeConnexionChallengeCode(const RsPeerId& peer
|
|||||||
}
|
}
|
||||||
return result ;
|
return result ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DistributedChatService::getChatLobbyList(std::list<ChatLobbyId>& clids)
|
void DistributedChatService::getChatLobbyList(std::list<ChatLobbyId>& clids)
|
||||||
{
|
{
|
||||||
// fill up a dummy list for now.
|
// fill up a dummy list for now.
|
||||||
@ -1242,6 +1245,7 @@ void DistributedChatService::getChatLobbyList(std::list<ChatLobbyId>& clids)
|
|||||||
for(std::map<ChatLobbyId,ChatLobbyEntry>::const_iterator it(_chat_lobbys.begin());it!=_chat_lobbys.end();++it)
|
for(std::map<ChatLobbyId,ChatLobbyEntry>::const_iterator it(_chat_lobbys.begin());it!=_chat_lobbys.end();++it)
|
||||||
clids.push_back(it->first) ;
|
clids.push_back(it->first) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DistributedChatService::getChatLobbyInfo(const ChatLobbyId& id,ChatLobbyInfo& info)
|
bool DistributedChatService::getChatLobbyInfo(const ChatLobbyId& id,ChatLobbyInfo& info)
|
||||||
{
|
{
|
||||||
// fill up a dummy list for now.
|
// fill up a dummy list for now.
|
||||||
@ -1259,6 +1263,7 @@ bool DistributedChatService::getChatLobbyInfo(const ChatLobbyId& id,ChatLobbyInf
|
|||||||
else
|
else
|
||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DistributedChatService::invitePeerToLobby(const ChatLobbyId& lobby_id, const RsPeerId& peer_id,bool connexion_challenge)
|
void DistributedChatService::invitePeerToLobby(const ChatLobbyId& lobby_id, const RsPeerId& peer_id,bool connexion_challenge)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_CHAT_LOBBIES
|
#ifdef DEBUG_CHAT_LOBBIES
|
||||||
@ -1462,6 +1467,7 @@ bool DistributedChatService::acceptLobbyInvite(const ChatLobbyId& lobby_id,const
|
|||||||
entry.connexion_challenge_count = 0 ;
|
entry.connexion_challenge_count = 0 ;
|
||||||
entry.last_activity = now ;
|
entry.last_activity = now ;
|
||||||
entry.last_connexion_challenge_time = now ;
|
entry.last_connexion_challenge_time = now ;
|
||||||
|
entry.joined_lobby_packet_sent = false;
|
||||||
entry.last_keep_alive_packet_time = now ;
|
entry.last_keep_alive_packet_time = now ;
|
||||||
|
|
||||||
_chat_lobbys[lobby_id] = entry ;
|
_chat_lobbys[lobby_id] = entry ;
|
||||||
@ -1587,6 +1593,7 @@ bool DistributedChatService::joinVisibleChatLobby(const ChatLobbyId& lobby_id,co
|
|||||||
entry.connexion_challenge_count = 0 ;
|
entry.connexion_challenge_count = 0 ;
|
||||||
entry.last_activity = now ;
|
entry.last_activity = now ;
|
||||||
entry.last_connexion_challenge_time = now ;
|
entry.last_connexion_challenge_time = now ;
|
||||||
|
entry.joined_lobby_packet_sent = false;
|
||||||
entry.last_keep_alive_packet_time = now ;
|
entry.last_keep_alive_packet_time = now ;
|
||||||
|
|
||||||
for(std::set<RsPeerId>::const_iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2)
|
for(std::set<RsPeerId>::const_iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2)
|
||||||
@ -1596,6 +1603,7 @@ bool DistributedChatService::joinVisibleChatLobby(const ChatLobbyId& lobby_id,co
|
|||||||
}
|
}
|
||||||
_chat_lobbys[lobby_id] = entry ;
|
_chat_lobbys[lobby_id] = entry ;
|
||||||
}
|
}
|
||||||
|
|
||||||
setLobbyAutoSubscribe(lobby_id,true);
|
setLobbyAutoSubscribe(lobby_id,true);
|
||||||
|
|
||||||
triggerConfigSave(); // so that we save the subscribed lobbies
|
triggerConfigSave(); // so that we save the subscribed lobbies
|
||||||
@ -1644,6 +1652,7 @@ ChatLobbyId DistributedChatService::createChatLobby(const std::string& lobby_nam
|
|||||||
entry.connexion_challenge_count = 0 ;
|
entry.connexion_challenge_count = 0 ;
|
||||||
entry.last_activity = now ;
|
entry.last_activity = now ;
|
||||||
entry.last_connexion_challenge_time = now ;
|
entry.last_connexion_challenge_time = now ;
|
||||||
|
entry.joined_lobby_packet_sent = false;
|
||||||
entry.last_keep_alive_packet_time = now ;
|
entry.last_keep_alive_packet_time = now ;
|
||||||
|
|
||||||
_chat_lobbys[lobby_id] = entry ;
|
_chat_lobbys[lobby_id] = entry ;
|
||||||
@ -1753,6 +1762,7 @@ bool DistributedChatService::setDefaultIdentityForChatLobby(const RsGxsId& nick)
|
|||||||
triggerConfigSave() ;
|
triggerConfigSave() ;
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DistributedChatService::getDefaultIdentityForChatLobby(RsGxsId& nick)
|
void DistributedChatService::getDefaultIdentityForChatLobby(RsGxsId& nick)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mDistributedChatMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mDistributedChatMtx); /********** STACK LOCKED MTX ******/
|
||||||
@ -1775,6 +1785,7 @@ RsGxsId DistributedChatService::locked_getDefaultIdentity()
|
|||||||
}
|
}
|
||||||
return _default_identity ;
|
return _default_identity ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DistributedChatService::getIdentityForChatLobby(const ChatLobbyId& lobby_id,RsGxsId& nick)
|
bool DistributedChatService::getIdentityForChatLobby(const ChatLobbyId& lobby_id,RsGxsId& nick)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mDistributedChatMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mDistributedChatMtx); /********** STACK LOCKED MTX ******/
|
||||||
@ -1898,16 +1909,17 @@ void DistributedChatService::cleanLobbyCaches()
|
|||||||
std::list<ChatLobbyId> keep_alive_lobby_ids ;
|
std::list<ChatLobbyId> keep_alive_lobby_ids ;
|
||||||
std::list<ChatLobbyId> changed_lobbies ;
|
std::list<ChatLobbyId> changed_lobbies ;
|
||||||
std::list<ChatLobbyId> send_challenge_lobbies ;
|
std::list<ChatLobbyId> send_challenge_lobbies ;
|
||||||
|
std::list<ChatLobbyId> joined_lobby_ids ;
|
||||||
|
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mDistributedChatMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mDistributedChatMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
rstime_t now = time(NULL) ;
|
rstime_t now = time(NULL) ;
|
||||||
|
|
||||||
// 1 - clean cache of all lobbies and participating nicknames.
|
|
||||||
//
|
|
||||||
for(std::map<ChatLobbyId,ChatLobbyEntry>::iterator it = _chat_lobbys.begin();it!=_chat_lobbys.end();++it)
|
for(std::map<ChatLobbyId,ChatLobbyEntry>::iterator it = _chat_lobbys.begin();it!=_chat_lobbys.end();++it)
|
||||||
{
|
{
|
||||||
|
// 1 - remove old messages
|
||||||
|
//
|
||||||
for(std::map<ChatLobbyMsgId,rstime_t>::iterator it2(it->second.msg_cache.begin());it2!=it->second.msg_cache.end();)
|
for(std::map<ChatLobbyMsgId,rstime_t>::iterator it2(it->second.msg_cache.begin());it2!=it->second.msg_cache.end();)
|
||||||
if(it2->second + MAX_KEEP_MSG_RECORD < now)
|
if(it2->second + MAX_KEEP_MSG_RECORD < now)
|
||||||
{
|
{
|
||||||
@ -1925,6 +1937,8 @@ void DistributedChatService::cleanLobbyCaches()
|
|||||||
|
|
||||||
bool changed = false ;
|
bool changed = false ;
|
||||||
|
|
||||||
|
// 2 - remove inactive nicknames
|
||||||
|
//
|
||||||
for(std::map<RsGxsId,rstime_t>::iterator it2(it->second.gxs_ids.begin());it2!=it->second.gxs_ids.end();)
|
for(std::map<RsGxsId,rstime_t>::iterator it2(it->second.gxs_ids.begin());it2!=it->second.gxs_ids.end();)
|
||||||
if(it2->second + MAX_KEEP_INACTIVE_NICKNAME < now)
|
if(it2->second + MAX_KEEP_INACTIVE_NICKNAME < now)
|
||||||
{
|
{
|
||||||
@ -1944,7 +1958,27 @@ void DistributedChatService::cleanLobbyCaches()
|
|||||||
if(changed)
|
if(changed)
|
||||||
changed_lobbies.push_back(it->first) ;
|
changed_lobbies.push_back(it->first) ;
|
||||||
|
|
||||||
// 3 - send lobby keep-alive packets to all lobbies
|
// 3 - send a joined_lobby packet if a participating friend is connected, we do that only once
|
||||||
|
//
|
||||||
|
if (!it->second.joined_lobby_packet_sent)
|
||||||
|
{
|
||||||
|
bool oneParticipatingFriendIsConnected = false;
|
||||||
|
for(std::set<RsPeerId>::const_iterator fit(it->second.participating_friends.begin());fit!=it->second.participating_friends.end();++fit)
|
||||||
|
{
|
||||||
|
if(mServControl->isPeerConnected(mServType, *fit))
|
||||||
|
{
|
||||||
|
oneParticipatingFriendIsConnected = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (oneParticipatingFriendIsConnected)
|
||||||
|
{
|
||||||
|
joined_lobby_ids.push_back(it->first) ;
|
||||||
|
it->second.joined_lobby_packet_sent = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4 - send lobby keep-alive packet
|
||||||
//
|
//
|
||||||
if(it->second.last_keep_alive_packet_time + MAX_DELAY_BETWEEN_LOBBY_KEEP_ALIVE < now)
|
if(it->second.last_keep_alive_packet_time + MAX_DELAY_BETWEEN_LOBBY_KEEP_ALIVE < now)
|
||||||
{
|
{
|
||||||
@ -1952,13 +1986,12 @@ void DistributedChatService::cleanLobbyCaches()
|
|||||||
it->second.last_keep_alive_packet_time = now ;
|
it->second.last_keep_alive_packet_time = now ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4 - look at lobby activity and possibly send connection challenge
|
// 5 - look at lobby activity and possibly send connection challenge
|
||||||
//
|
//
|
||||||
if(++it->second.connexion_challenge_count > CONNECTION_CHALLENGE_MAX_COUNT && now > it->second.last_connexion_challenge_time + CONNECTION_CHALLENGE_MIN_DELAY)
|
if(++it->second.connexion_challenge_count > CONNECTION_CHALLENGE_MAX_COUNT && now > it->second.last_connexion_challenge_time + CONNECTION_CHALLENGE_MIN_DELAY)
|
||||||
{
|
{
|
||||||
it->second.connexion_challenge_count = 0 ;
|
it->second.connexion_challenge_count = 0 ;
|
||||||
it->second.last_connexion_challenge_time = now ;
|
it->second.last_connexion_challenge_time = now ;
|
||||||
|
|
||||||
send_challenge_lobbies.push_back(it->first);
|
send_challenge_lobbies.push_back(it->first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1967,12 +2000,12 @@ void DistributedChatService::cleanLobbyCaches()
|
|||||||
//
|
//
|
||||||
|
|
||||||
for(std::map<ChatLobbyId,VisibleChatLobbyRecord>::iterator it(_visible_lobbies.begin());it!=_visible_lobbies.end();)
|
for(std::map<ChatLobbyId,VisibleChatLobbyRecord>::iterator it(_visible_lobbies.begin());it!=_visible_lobbies.end();)
|
||||||
|
{
|
||||||
if(it->second.last_report_time + MAX_KEEP_PUBLIC_LOBBY_RECORD < now && _chat_lobbys.find(it->first)==_chat_lobbys.end()) // this lobby record is too late.
|
if(it->second.last_report_time + MAX_KEEP_PUBLIC_LOBBY_RECORD < now && _chat_lobbys.find(it->first)==_chat_lobbys.end()) // this lobby record is too late.
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_CHAT_LOBBIES
|
#ifdef DEBUG_CHAT_LOBBIES
|
||||||
std::cerr << " removing old public lobby record 0x" << std::hex << it->first << ", time=" << std::dec << now - it->second.last_report_time << " secs ago" << std::endl;
|
std::cerr << " removing old public lobby record 0x" << std::hex << it->first << ", time=" << std::dec << now - it->second.last_report_time << " secs ago" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::map<ChatLobbyMsgId,VisibleChatLobbyRecord>::iterator tmp(it) ;
|
std::map<ChatLobbyMsgId,VisibleChatLobbyRecord>::iterator tmp(it) ;
|
||||||
++tmp ;
|
++tmp ;
|
||||||
_visible_lobbies.erase(it) ;
|
_visible_lobbies.erase(it) ;
|
||||||
@ -1981,7 +2014,9 @@ void DistributedChatService::cleanLobbyCaches()
|
|||||||
else
|
else
|
||||||
++it ;
|
++it ;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// send keep alive
|
||||||
for(std::list<ChatLobbyId>::const_iterator it(keep_alive_lobby_ids.begin());it!=keep_alive_lobby_ids.end();++it)
|
for(std::list<ChatLobbyId>::const_iterator it(keep_alive_lobby_ids.begin());it!=keep_alive_lobby_ids.end();++it)
|
||||||
sendLobbyStatusKeepAlive(*it) ;
|
sendLobbyStatusKeepAlive(*it) ;
|
||||||
|
|
||||||
@ -1989,8 +2024,11 @@ void DistributedChatService::cleanLobbyCaches()
|
|||||||
for(std::list<ChatLobbyId>::const_iterator it(changed_lobbies.begin());it!=changed_lobbies.end();++it)
|
for(std::list<ChatLobbyId>::const_iterator it(changed_lobbies.begin());it!=changed_lobbies.end();++it)
|
||||||
RsServer::notify()->notifyChatLobbyEvent(*it,RS_CHAT_LOBBY_EVENT_KEEP_ALIVE,RsGxsId(),"") ;
|
RsServer::notify()->notifyChatLobbyEvent(*it,RS_CHAT_LOBBY_EVENT_KEEP_ALIVE,RsGxsId(),"") ;
|
||||||
|
|
||||||
|
// send peer joined
|
||||||
|
for(std::list<ChatLobbyId>::const_iterator it(joined_lobby_ids.begin());it!=joined_lobby_ids.end();++it)
|
||||||
|
sendLobbyStatusNewPeer(*it) ;
|
||||||
|
|
||||||
// send connection challenges
|
// send connection challenges
|
||||||
//
|
|
||||||
for(std::list<ChatLobbyId>::const_iterator it(send_challenge_lobbies.begin());it!=send_challenge_lobbies.end();++it)
|
for(std::list<ChatLobbyId>::const_iterator it(send_challenge_lobbies.begin());it!=send_challenge_lobbies.end();++it)
|
||||||
sendConnectionChallenge(*it) ;
|
sendConnectionChallenge(*it) ;
|
||||||
}
|
}
|
||||||
@ -2010,9 +2048,7 @@ void DistributedChatService::addToSaveList(std::list<RsItem*>& list) const
|
|||||||
for(auto it(_chat_lobbys.begin());it!=_chat_lobbys.end();++it)
|
for(auto it(_chat_lobbys.begin());it!=_chat_lobbys.end();++it)
|
||||||
{
|
{
|
||||||
RsSubscribedChatLobbyConfigItem *scli = new RsSubscribedChatLobbyConfigItem;
|
RsSubscribedChatLobbyConfigItem *scli = new RsSubscribedChatLobbyConfigItem;
|
||||||
|
|
||||||
scli->info = it->second; // copies the ChatLobbyInfo part only
|
scli->info = it->second; // copies the ChatLobbyInfo part only
|
||||||
|
|
||||||
list.push_back(scli);
|
list.push_back(scli);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2149,6 +2185,7 @@ bool DistributedChatService::processLoadListItem(const RsItem *item)
|
|||||||
entry.connexion_challenge_count = 0 ;
|
entry.connexion_challenge_count = 0 ;
|
||||||
entry.last_activity = now ;
|
entry.last_activity = now ;
|
||||||
entry.last_connexion_challenge_time = now ;
|
entry.last_connexion_challenge_time = now ;
|
||||||
|
entry.joined_lobby_packet_sent = false ;
|
||||||
entry.last_keep_alive_packet_time = now ;
|
entry.last_keep_alive_packet_time = now ;
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -2163,8 +2200,6 @@ bool DistributedChatService::processLoadListItem(const RsItem *item)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -139,6 +139,7 @@ class DistributedChatService
|
|||||||
RsPeerId virtual_peer_id ;
|
RsPeerId virtual_peer_id ;
|
||||||
int connexion_challenge_count ;
|
int connexion_challenge_count ;
|
||||||
rstime_t last_connexion_challenge_time ;
|
rstime_t last_connexion_challenge_time ;
|
||||||
|
bool joined_lobby_packet_sent;
|
||||||
rstime_t last_keep_alive_packet_time ;
|
rstime_t last_keep_alive_packet_time ;
|
||||||
std::set<RsPeerId> previously_known_peers ;
|
std::set<RsPeerId> previously_known_peers ;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user