Skip to content

Commit 85a5c64

Browse files
committed
distributed-chat: add chat history sharing preference and restrict protocol responses
1 parent 852da09 commit 85a5c64

5 files changed

Lines changed: 60 additions & 0 deletions

File tree

src/chat/distributedchat.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ DistributedChatService::DistributedChatService(uint32_t serv_type,p3ServiceContr
6666
{
6767
_time_shift_average = 0.0f ;
6868
_should_reset_lobby_counts = false ;
69+
_allow_history_sharing = false ;
6970
last_visible_lobby_info_request_time = 0 ;
7071
}
7172

@@ -2149,6 +2150,15 @@ void DistributedChatService::addToSaveList(std::list<RsItem*>& list) const
21492150
list.push_back(vitem);
21502151
}
21512152

2153+
/* Save Allow History Sharing */
2154+
{
2155+
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ;
2156+
RsTlvKeyValue kv;
2157+
kv.key = "ALLOW_HISTORY_SHARING";
2158+
kv.value = _allow_history_sharing ? "1" : "0";
2159+
vitem->tlvkvs.pairs.push_back(kv);
2160+
list.push_back(vitem);
2161+
}
21522162
}
21532163

21542164
bool DistributedChatService::processLoadListItem(const RsItem *item)
@@ -2174,6 +2184,12 @@ bool DistributedChatService::processLoadListItem(const RsItem *item)
21742184
return true;
21752185
}
21762186

2187+
if( kit->key == "ALLOW_HISTORY_SHARING" )
2188+
{
2189+
_allow_history_sharing = (kit->value == "1") ;
2190+
return true;
2191+
}
2192+
21772193
if( kit->key.compare(0, strldID.length(), strldID) == 0)
21782194
{
21792195
#ifdef DEBUG_CHAT_LOBBIES
@@ -2324,6 +2340,13 @@ void DistributedChatService::handleRecvLobbyHistoryProbe(RsChatLobbyHistoryProbe
23242340
}
23252341
}
23262342

2343+
// Check if we allow sharing history
2344+
if(!_allow_history_sharing)
2345+
{
2346+
std::cerr << "handleRecvLobbyHistoryProbe(): history sharing is disabled. Ignoring." << std::endl;
2347+
return ;
2348+
}
2349+
23272350
// Retrieve our local history for this lobby
23282351
std::list<HistoryMsg> msgs ;
23292352
mHistMgr->getMessages(ChatId(item->lobby_id), msgs, 0) ; // 0 = get all available
@@ -2408,6 +2431,13 @@ void DistributedChatService::handleRecvLobbyHistoryRequest(RsChatLobbyHistoryReq
24082431
}
24092432
}
24102433

2434+
// Check if we allow sharing history
2435+
if(!_allow_history_sharing)
2436+
{
2437+
std::cerr << "handleRecvLobbyHistoryRequest(): history sharing is disabled. Ignoring." << std::endl;
2438+
return ;
2439+
}
2440+
24112441
// Retrieve local history
24122442
std::list<HistoryMsg> msgs ;
24132443
mHistMgr->getMessages(ChatId(item->lobby_id), msgs, item->max_count) ;

src/chat/distributedchat.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ class DistributedChatService
8787
// Lobby history retrieval protocol
8888
bool requestLobbyHistory(const ChatLobbyId& lobby_id) ;
8989
bool requestLobbyHistoryFromPeer(const ChatLobbyId& lobby_id, const RsPeerId& peer_id, uint32_t max_count, uint32_t oldest_ts) ;
90+
void allowHistorySharing(bool allow) { _allow_history_sharing = allow; triggerConfigSave(); }
91+
bool isHistorySharingAllowed() const { return _allow_history_sharing; }
9092

9193
protected:
9294
bool handleRecvItem(RsChatItem *) ;
@@ -171,6 +173,7 @@ class DistributedChatService
171173
rstime_t last_lobby_challenge_time ; // prevents bruteforce attack
172174
rstime_t last_visible_lobby_info_request_time ; // allows to ask for updates
173175
bool _should_reset_lobby_counts ;
176+
bool _allow_history_sharing ;
174177
RsGxsId _default_identity;
175178
std::map<ChatLobbyId,RsGxsId> _lobby_default_identity;
176179

src/chat/p3chatservice.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,17 @@ bool p3ChatService::requestLobbyHistoryFromPeer(const ChatLobbyId& lobby_id, con
564564
return DistributedChatService::requestLobbyHistoryFromPeer(lobby_id, peer_id, max_count, oldest_ts) ;
565565
}
566566

567+
bool p3ChatService::allowHistorySharing(bool allow)
568+
{
569+
DistributedChatService::allowHistorySharing(allow) ;
570+
return true ;
571+
}
572+
573+
bool p3ChatService::isHistorySharingAllowed() const
574+
{
575+
return DistributedChatService::isHistorySharingAllowed() ;
576+
}
577+
567578

568579
void p3ChatService::sendChatItem(RsChatItem *item)
569580
{

src/chat/p3chatservice.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ class p3ChatService :
141141
virtual bool requestLobbyHistory(const ChatLobbyId& lobby_id) override;
142142
virtual bool requestLobbyHistoryFromPeer(const ChatLobbyId& lobby_id, const RsPeerId& peer_id, uint32_t max_count, uint32_t oldest_ts) override;
143143

144+
virtual bool allowHistorySharing(bool allow) override;
145+
virtual bool isHistorySharingAllowed() const override;
146+
144147
/** methods that will call the DistantChatService parent
145148
*/
146149
virtual bool setDistantChatPermissionFlags(uint32_t flags) override;

src/retroshare/rschats.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,19 @@ class RsChats
634634
*/
635635
virtual bool requestLobbyHistoryFromPeer(const ChatLobbyId& lobby_id, const RsPeerId& peer_id, uint32_t max_count, uint32_t oldest_ts) = 0 ;
636636

637+
/**
638+
* @brief allowHistorySharing enable or disable sharing of chat history with friends
639+
* @param[in] allow set to true to allow sharing, false to disallow
640+
* @return true on success
641+
*/
642+
virtual bool allowHistorySharing(bool allow) = 0 ;
643+
644+
/**
645+
* @brief isHistorySharingAllowed check if history sharing is allowed
646+
* @return true if sharing is allowed, false otherwise
647+
*/
648+
virtual bool isHistorySharingAllowed() const = 0 ;
649+
637650
/**
638651
* @brief createChatLobby create a new chat lobby
639652
* @jsonapi{development}

0 commit comments

Comments
 (0)