From f60f3627bb2e15deb5f208e2d35b02a8aa46abba Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 17 Mar 2013 23:26:26 +0000 Subject: [PATCH] dropping chat lobby messages from more than 10 minutes in the future (sorry Marty) git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6239 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/services/p3chatservice.cc | 25 ++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index e9af41a1a..bc738eef2 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -803,16 +803,24 @@ void p3ChatService::handleRecvChatLobbyEventItem(RsChatLobbyEventItem *item) #ifdef CHAT_DEBUG std::cerr << "Received ChatLobbyEvent item of type " << (int)(item->event_type) << ", and string=" << item->string1 << std::endl; #endif + time_t now = time(NULL) ; - if(time(NULL)+100 > (time_t) item->sendTime + MAX_KEEP_MSG_RECORD) // the message is older than the max cache keep minus 100 seconds ! It's too old, and is going to make an echo! + if(now+100 > (time_t) item->sendTime + MAX_KEEP_MSG_RECORD) // the message is older than the max cache keep minus 100 seconds ! It's too old, and is going to make an echo! { - std::cerr << "Received severely outdated lobby event item! Dropping it!" << std::endl; + std::cerr << "Received severely outdated lobby event item (" << now - (time_t)item->sendTime << " in the past)! Dropping it!" << std::endl; + std::cerr << "Message item is:" << std::endl; + item->print(std::cerr) ; + std::cerr << std::endl; + return ; + } + if(now+600 < (time_t) item->sendTime) // the message is from the future more than 10 minutes + { + std::cerr << "Received event item from the future (" << (time_t)item->sendTime - now << " seconds in the future)! Dropping it!" << std::endl; std::cerr << "Message item is:" << std::endl; item->print(std::cerr) ; std::cerr << std::endl; return ; } - if(! bounceLobbyObject(item,item->PeerId())) return ; @@ -920,13 +928,20 @@ bool p3ChatService::handleRecvChatMsgItem(RsChatMsgItem *ci) if(now+100 > (time_t) cli->sendTime + MAX_KEEP_MSG_RECORD) // the message is older than the max cache keep plus 100 seconds ! It's too old, and is going to make an echo! { - std::cerr << "Received severely outdated message!Dropping it!" << std::endl; + std::cerr << "Received severely outdated lobby event item (" << now - (time_t)cli->sendTime << " in the past)! Dropping it!" << std::endl; + std::cerr << "Message item is:" << std::endl; + cli->print(std::cerr) ; + std::cerr << std::endl; + return false ; + } + if(now+600 < (time_t) cli->sendTime) // the message is from the future. Drop it. more than 10 minutes + { + std::cerr << "Received event item from the future (" << (time_t)cli->sendTime - now << " seconds in the future)! Dropping it!" << std::endl; std::cerr << "Message item is:" << std::endl; cli->print(std::cerr) ; std::cerr << std::endl; return false ; } - if(!bounceLobbyObject(cli,cli->PeerId())) // forwards the message to friends, keeps track of subscribers, etc. return false;