mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-11 10:35:22 -04:00
added backend for distant message and distant chat filtering based on contact list
This commit is contained in:
parent
f5c2aa31e3
commit
140205108a
20 changed files with 373 additions and 180 deletions
|
@ -25,6 +25,7 @@
|
|||
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sstream>
|
||||
|
||||
#include "openssl/rand.h"
|
||||
#include "openssl/dh.h"
|
||||
|
@ -108,6 +109,17 @@ void DistantChatService::handleRecvChatStatusItem(RsChatStatusItem *cs)
|
|||
std::cerr << "DistantChatService::handleRecvChatStatusItem(): received keep alive packet for inactive chat! peerId=" << cs->PeerId() << std::endl;
|
||||
}
|
||||
|
||||
bool DistantChatService::acceptDataFromPeer(const RsGxsId& gxs_id)
|
||||
{
|
||||
if(mDistantChatPermissions & RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_FILTER_NON_CONTACTS)
|
||||
return (rsIdentity!=NULL) && rsIdentity->isARegularContact(gxs_id) ;
|
||||
|
||||
if(mDistantChatPermissions & RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_FILTER_EVERYBODY)
|
||||
return false ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
void DistantChatService::notifyTunnelStatus(const RsGxsTunnelService::RsGxsTunnelId &tunnel_id, uint32_t tunnel_status)
|
||||
{
|
||||
std::cerr << "DistantChatService::notifyTunnelStatus(): got notification " << std::hex << tunnel_status << std::dec << " for tunnel " << tunnel_id << std::endl;
|
||||
|
@ -137,9 +149,7 @@ void DistantChatService::receiveData(const RsGxsTunnelService::RsGxsTunnelId &tu
|
|||
std::cerr << "DistantChatService::receiveData(): got data of size " << data_size << " for tunnel " << tunnel_id << std::endl;
|
||||
std::cerr << " received: " << RsUtil::BinToHex(data,data_size) << std::endl;
|
||||
std::cerr << " deserialising..." << std::endl;
|
||||
|
||||
RsItem *item = RsChatSerialiser().deserialise(data,&data_size) ;
|
||||
|
||||
|
||||
// always make the contact up to date. This is useful for server side, which doesn't know about the chat until it
|
||||
// receives the first item.
|
||||
{
|
||||
|
@ -149,21 +159,26 @@ void DistantChatService::receiveData(const RsGxsTunnelService::RsGxsTunnelId &tu
|
|||
if(!mGxsTunnels->getTunnelInfo(tunnel_id,tinfo))
|
||||
return ;
|
||||
|
||||
// Check if the data is accepted. We cannot prevent the creation of tunnels at the level of p3GxsTunnels, since tunnels are shared between services.
|
||||
// however,
|
||||
|
||||
DistantChatContact& contact(mDistantChatContacts[DistantChatPeerId(tunnel_id)]) ;
|
||||
|
||||
|
||||
contact.to_id = tinfo.destination_gxs_id ;
|
||||
contact.from_id = tinfo.source_gxs_id ;
|
||||
}
|
||||
|
||||
|
||||
RsItem *item = RsChatSerialiser().deserialise(data,&data_size) ;
|
||||
|
||||
if(item != NULL)
|
||||
{
|
||||
item->PeerId(RsPeerId(tunnel_id)) ; // just in case, but normally this is already done.
|
||||
|
||||
item->PeerId(RsPeerId(tunnel_id)) ; // just in case, but normally this is already done.
|
||||
|
||||
handleIncomingItem(item) ;
|
||||
RsServer::notify()->notifyListChange(NOTIFY_LIST_PRIVATE_INCOMING_CHAT, NOTIFY_TYPE_ADD);
|
||||
}
|
||||
else
|
||||
std::cerr << " (EE) item could not be deserialised!" << std::endl;
|
||||
std::cerr << " (EE) item could not be deserialised!" << std::endl;
|
||||
}
|
||||
|
||||
void DistantChatService::markDistantChatAsClosed(const DistantChatPeerId& dcpid)
|
||||
|
@ -243,4 +258,62 @@ bool DistantChatService::closeDistantChatConnexion(const DistantChatPeerId &tunn
|
|||
return true ;
|
||||
}
|
||||
|
||||
uint32_t DistantChatService::getDistantChatPermissionFlags()
|
||||
{
|
||||
return mDistantChatPermissions ;
|
||||
}
|
||||
bool DistantChatService::setDistantChatPermissionFlags(uint32_t flags)
|
||||
{
|
||||
if(mDistantChatPermissions != flags)
|
||||
{
|
||||
mDistantChatPermissions = flags ;
|
||||
std::cerr << "(II) Changing distant chat permissions to " << flags << ". Existing openned chats will however remain active until closed" << std::endl;
|
||||
triggerConfigSave() ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
void DistantChatService::addToSaveList(std::list<RsItem*>& list) const
|
||||
{
|
||||
/* Save permission flags */
|
||||
|
||||
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ;
|
||||
RsTlvKeyValue kv;
|
||||
kv.key = "DISTANT_CHAT_PERMISSION_FLAGS" ;
|
||||
kv.value = RsUtil::NumberToString(mDistantChatPermissions) ;
|
||||
|
||||
vitem->tlvkvs.pairs.push_back(kv) ;
|
||||
|
||||
list.push_back(vitem) ;
|
||||
}
|
||||
bool DistantChatService::processLoadListItem(const RsItem *item)
|
||||
{
|
||||
const RsConfigKeyValueSet *vitem = NULL ;
|
||||
|
||||
if(NULL != (vitem = dynamic_cast<const RsConfigKeyValueSet*>(item)))
|
||||
for(std::list<RsTlvKeyValue>::const_iterator kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); ++kit)
|
||||
if(kit->key == "DISTANT_CHAT_PERMISSION_FLAGS")
|
||||
{
|
||||
#ifdef DEBUG_DISTANT_CHAT
|
||||
std::cerr << "Loaded distant chat permission flags: " << kit->value << std::endl ;
|
||||
#endif
|
||||
if (!kit->value.empty())
|
||||
{
|
||||
std::istringstream is(kit->value) ;
|
||||
|
||||
uint32_t tmp ;
|
||||
is >> tmp ;
|
||||
|
||||
if(tmp < 3)
|
||||
mDistantChatPermissions = tmp ;
|
||||
else
|
||||
std::cerr << "(EE) Invalid value read for DistantChatPermission flags in config: " << tmp << std::endl;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false ;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue