added backend for distant message and distant chat filtering based on contact list

This commit is contained in:
csoler 2015-12-25 22:37:06 -05:00
parent f5c2aa31e3
commit 140205108a
20 changed files with 373 additions and 180 deletions

View File

@ -25,6 +25,7 @@
#include <unistd.h> #include <unistd.h>
#include <sstream>
#include "openssl/rand.h" #include "openssl/rand.h"
#include "openssl/dh.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; 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) 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; std::cerr << "DistantChatService::notifyTunnelStatus(): got notification " << std::hex << tunnel_status << std::dec << " for tunnel " << tunnel_id << std::endl;
@ -138,8 +150,6 @@ void DistantChatService::receiveData(const RsGxsTunnelService::RsGxsTunnelId &tu
std::cerr << " received: " << RsUtil::BinToHex(data,data_size) << std::endl; std::cerr << " received: " << RsUtil::BinToHex(data,data_size) << std::endl;
std::cerr << " deserialising..." << 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 // 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. // receives the first item.
{ {
@ -149,12 +159,17 @@ void DistantChatService::receiveData(const RsGxsTunnelService::RsGxsTunnelId &tu
if(!mGxsTunnels->getTunnelInfo(tunnel_id,tinfo)) if(!mGxsTunnels->getTunnelInfo(tunnel_id,tinfo))
return ; 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)]) ; DistantChatContact& contact(mDistantChatContacts[DistantChatPeerId(tunnel_id)]) ;
contact.to_id = tinfo.destination_gxs_id ; contact.to_id = tinfo.destination_gxs_id ;
contact.from_id = tinfo.source_gxs_id ; contact.from_id = tinfo.source_gxs_id ;
} }
RsItem *item = RsChatSerialiser().deserialise(data,&data_size) ;
if(item != NULL) 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.
@ -243,4 +258,62 @@ bool DistantChatService::closeDistantChatConnexion(const DistantChatPeerId &tunn
return true ; 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 ;
}

View File

@ -42,11 +42,12 @@ public:
DistantChatService() : mDistantChatMtx("distant chat") DistantChatService() : mDistantChatMtx("distant chat")
{ {
mGxsTunnels = NULL ; mGxsTunnels = NULL ;
mDistantChatPermissions = RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_FILTER_NONE ; // default: accept everyone
} }
// Overloaded methods from RsGxsTunnelClientService virtual void triggerConfigSave()=0 ;
bool processLoadListItem(const RsItem *item) ;
virtual void connectToGxsTunnelService(RsGxsTunnelService *tunnel_service) ; void addToSaveList(std::list<RsItem*>& list) const;
// Creates the invite if the public key of the distant peer is available. // Creates the invite if the public key of the distant peer is available.
// Om success, stores the invite in the map above, so that we can respond to tunnel requests. // Om success, stores the invite in the map above, so that we can respond to tunnel requests.
@ -54,6 +55,14 @@ public:
bool initiateDistantChatConnexion(const RsGxsId& to_gxs_id, const RsGxsId &from_gxs_id, DistantChatPeerId& dcpid, uint32_t &error_code) ; bool initiateDistantChatConnexion(const RsGxsId& to_gxs_id, const RsGxsId &from_gxs_id, DistantChatPeerId& dcpid, uint32_t &error_code) ;
bool closeDistantChatConnexion(const DistantChatPeerId &tunnel_id) ; bool closeDistantChatConnexion(const DistantChatPeerId &tunnel_id) ;
// Sets flags to only allow connexion from some people.
uint32_t getDistantChatPermissionFlags() ;
bool setDistantChatPermissionFlags(uint32_t flags) ;
// Returns the status of a distant chat contact. The contact is defined by the tunnel id (turned into a DistantChatPeerId) because
// each pair of talking GXS id needs to be treated separately
virtual bool getDistantChatStatus(const DistantChatPeerId &tunnel_id, DistantChatPeerInfo& cinfo) ; virtual bool getDistantChatStatus(const DistantChatPeerId &tunnel_id, DistantChatPeerInfo& cinfo) ;
// derived in p3ChatService, so as to pass down some info // derived in p3ChatService, so as to pass down some info
@ -74,8 +83,17 @@ private:
// //
std::map<DistantChatPeerId, DistantChatContact> mDistantChatContacts ; // current peers we can talk to std::map<DistantChatPeerId, DistantChatContact> mDistantChatContacts ; // current peers we can talk to
// Permission handling
uint32_t mDistantChatPermissions ;
// Overloaded from RsGxsTunnelClientService // Overloaded from RsGxsTunnelClientService
public:
virtual void connectToGxsTunnelService(RsGxsTunnelService *tunnel_service) ;
private:
virtual bool acceptDataFromPeer(const RsGxsId& gxs_id) ;
virtual void notifyTunnelStatus(const RsGxsTunnelService::RsGxsTunnelId& tunnel_id,uint32_t tunnel_status) ; virtual void notifyTunnelStatus(const RsGxsTunnelService::RsGxsTunnelId& tunnel_id,uint32_t tunnel_status) ;
virtual void receiveData(const RsGxsTunnelService::RsGxsTunnelId& id,unsigned char *data,uint32_t data_size) ; virtual void receiveData(const RsGxsTunnelService::RsGxsTunnelId& id,unsigned char *data,uint32_t data_size) ;
@ -84,6 +102,5 @@ private:
void markDistantChatAsClosed(const DistantChatPeerId& dcpid) ; void markDistantChatAsClosed(const DistantChatPeerId& dcpid) ;
RsGxsTunnelService *mGxsTunnels ; RsGxsTunnelService *mGxsTunnels ;
RsMutex mDistantChatMtx ; RsMutex mDistantChatMtx ;
}; };

View File

@ -1192,11 +1192,8 @@ bool p3ChatService::loadList(std::list<RsItem*>& load)
continue; continue;
} }
if(DistributedChatService::processLoadListItem(*it)) DistributedChatService::processLoadListItem(*it) ;
{ DistantChatService::processLoadListItem(*it) ;
delete *it;
continue;
}
// delete unknown items // delete unknown items
delete *it; delete *it;
@ -1238,6 +1235,7 @@ bool p3ChatService::saveList(bool& cleanup, std::list<RsItem*>& list)
} }
DistributedChatService::addToSaveList(list) ; DistributedChatService::addToSaveList(list) ;
DistantChatService::addToSaveList(list) ;
return true; return true;
} }

View File

@ -73,6 +73,10 @@ class GRouterClientService
// 2 - call pt->registerTunnelService(this), so that the TR knows that service and can send back information to it. // 2 - call pt->registerTunnelService(this), so that the TR knows that service and can send back information to it.
// //
virtual void connectToGlobalRouter(p3GRouter *pt) = 0 ; virtual void connectToGlobalRouter(p3GRouter *pt) = 0 ;
// should be derived to determine wether the client accepts data from this peer or not. If not, the data is dropped.
virtual bool acceptDataFromPeer(const RsGxsId& gxs_id) =0;
}; };

View File

@ -1661,10 +1661,13 @@ void p3GRouter::handleIncomingDataItem(RsGRouterGenericDataItem *data_item)
std::cerr << " notyfying client." << std::endl; std::cerr << " notyfying client." << std::endl;
#endif #endif
if(client->acceptDataFromPeer(decrypted_item->signature.keyId))
{
client->receiveGRouterData(decrypted_item->destination_key,decrypted_item->signature.keyId,service_id,decrypted_item->data_bytes,decrypted_item->data_size); client->receiveGRouterData(decrypted_item->destination_key,decrypted_item->signature.keyId,service_id,decrypted_item->data_bytes,decrypted_item->data_size);
decrypted_item->data_bytes = NULL ; decrypted_item->data_bytes = NULL ;
decrypted_item->data_size = 0 ; decrypted_item->data_size = 0 ;
}
delete decrypted_item ; delete decrypted_item ;
} }

View File

@ -327,6 +327,8 @@ void p3GxsTunnelService::handleRecvTunnelDataItem(const RsGxsTunnelId& tunnel_id
#endif #endif
RsGxsTunnelClientService *service = NULL ; RsGxsTunnelClientService *service = NULL ;
RsGxsId peer_from ;
{ {
RS_STACK_MUTEX(mGxsTunnelMtx); /********** STACK LOCKED MTX ******/ RS_STACK_MUTEX(mGxsTunnelMtx); /********** STACK LOCKED MTX ******/
std::map<uint32_t,RsGxsTunnelClientService *>::const_iterator it = mRegisteredServices.find(item->service_id) ; std::map<uint32_t,RsGxsTunnelClientService *>::const_iterator it = mRegisteredServices.find(item->service_id) ;
@ -341,9 +343,13 @@ void p3GxsTunnelService::handleRecvTunnelDataItem(const RsGxsTunnelId& tunnel_id
std::map<RsGxsTunnelId,GxsTunnelPeerInfo>::iterator it2 = _gxs_tunnel_contacts.find(tunnel_id) ; std::map<RsGxsTunnelId,GxsTunnelPeerInfo>::iterator it2 = _gxs_tunnel_contacts.find(tunnel_id) ;
if(it2 != _gxs_tunnel_contacts.end()) if(it2 != _gxs_tunnel_contacts.end())
{
it2->second.client_services.insert(item->service_id) ; it2->second.client_services.insert(item->service_id) ;
peer_from = it2->second.to_gxs_id ;
}
} }
if(service->acceptDataFromPeer(peer_from))
service->receiveData(tunnel_id,item->data,item->data_size) ; service->receiveData(tunnel_id,item->data,item->data_size) ;
item->data = NULL ; // avoids deletion, since the client has the memory now item->data = NULL ; // avoids deletion, since the client has the memory now

View File

@ -63,6 +63,10 @@ public:
// Used by the creator of the service to supply a pointer to the GXS tunnel service for it to be able to send data etc. // Used by the creator of the service to supply a pointer to the GXS tunnel service for it to be able to send data etc.
virtual void connectToGxsTunnelService(RsGxsTunnelService *tunnel_service) =0; virtual void connectToGxsTunnelService(RsGxsTunnelService *tunnel_service) =0;
// Gives feedback about type of data that is allowed in. For security reasons, this always needs to be re-derived (Clients can return true on default)
virtual bool acceptDataFromPeer(const RsGxsId& gxs_id) = 0 ;
}; };
class GxsTunnelInfo class GxsTunnelInfo

View File

@ -250,6 +250,7 @@ virtual bool getRecognTagRequest(const RsGxsId &id, const std::string &comment,
uint16_t tag_class, uint16_t tag_type, std::string &tag) = 0; uint16_t tag_class, uint16_t tag_type, std::string &tag) = 0;
virtual bool setAsRegularContact(const RsGxsId& id,bool is_a_contact) = 0 ; virtual bool setAsRegularContact(const RsGxsId& id,bool is_a_contact) = 0 ;
virtual bool isARegularContact(const RsGxsId& id) = 0 ;
// Specific RsIdentity Functions.... // Specific RsIdentity Functions....
/* Specific Service Data */ /* Specific Service Data */

View File

@ -264,11 +264,11 @@ public:
#define RS_DISTANT_CHAT_FLAG_SIGNED 0x0001 #define RS_DISTANT_CHAT_FLAG_SIGNED 0x0001
#define RS_DISTANT_CHAT_FLAG_SIGNATURE_OK 0x0002 #define RS_DISTANT_CHAT_FLAG_SIGNATURE_OK 0x0002
// flags to define who we accept to talk to // flags to define who we accept to talk to. Each flag *removes* some people.
#define RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_NONE 0x0000 #define RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_FILTER_NONE 0x0000
#define RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_EVERYBODY 0x0001 #define RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_FILTER_NON_CONTACTS 0x0001
#define RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_CONTACT_LIST 0x0002 #define RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_FILTER_EVERYBODY 0x0002
struct DistantChatPeerInfo struct DistantChatPeerInfo
{ {
@ -482,6 +482,9 @@ virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const RsGxsId&
/* Distant chat */ /* Distant chat */
/****************************************/ /****************************************/
virtual uint32_t getDistantChatPermissionFlags()=0 ;
virtual bool setDistantChatPermissionFlags(uint32_t flags)=0 ;
virtual bool initiateDistantChatConnexion(const RsGxsId& to_pid,const RsGxsId& from_pid,DistantChatPeerId& pid,uint32_t& error_code) = 0; virtual bool initiateDistantChatConnexion(const RsGxsId& to_pid,const RsGxsId& from_pid,DistantChatPeerId& pid,uint32_t& error_code) = 0;
virtual bool getDistantChatStatus(const DistantChatPeerId& pid,DistantChatPeerInfo& info)=0; virtual bool getDistantChatStatus(const DistantChatPeerId& pid,DistantChatPeerInfo& info)=0;
virtual bool closeDistantChatConnexion(const DistantChatPeerId& pid)=0; virtual bool closeDistantChatConnexion(const DistantChatPeerId& pid)=0;

View File

@ -537,4 +537,12 @@ bool p3Msgs::closeDistantChatConnexion(const DistantChatPeerId &pid)
{ {
return mChatSrv->closeDistantChatConnexion(pid) ; return mChatSrv->closeDistantChatConnexion(pid) ;
} }
bool p3Msgs::setDistantChatPermissionFlags(uint32_t flags)
{
return mChatSrv->setDistantChatPermissionFlags(flags) ;
}
uint32_t p3Msgs::getDistantChatPermissionFlags()
{
return mChatSrv->getDistantChatPermissionFlags() ;
}

View File

@ -159,6 +159,9 @@ class p3Msgs: public RsMsgs
virtual bool getDistantChatStatus(const DistantChatPeerId& gxs_id,DistantChatPeerInfo& info); virtual bool getDistantChatStatus(const DistantChatPeerId& gxs_id,DistantChatPeerInfo& info);
virtual bool closeDistantChatConnexion(const DistantChatPeerId &pid) ; virtual bool closeDistantChatConnexion(const DistantChatPeerId &pid) ;
virtual uint32_t getDistantChatPermissionFlags() ;
virtual bool setDistantChatPermissionFlags(uint32_t flags) ;
private: private:
p3MsgService *mMsgSrv; p3MsgService *mMsgSrv;

View File

@ -212,6 +212,13 @@ uint32_t p3IdService::idAuthenPolicy()
return policy; return policy;
} }
bool p3IdService::isARegularContact(const RsGxsId& id)
{
RsStackMutex stack(mIdMtx);
return mContacts.find(id) != mContacts.end() ;
}
bool p3IdService::setAsRegularContact(const RsGxsId& id,bool b) bool p3IdService::setAsRegularContact(const RsGxsId& id,bool b)
{ {
std::set<RsGxsId>::iterator it = mContacts.find(id) ; std::set<RsGxsId>::iterator it = mContacts.find(id) ;

View File

@ -266,6 +266,7 @@ virtual bool getRecognTagRequest(const RsGxsId &id, const std::string &comment,
uint16_t tag_class, uint16_t tag_type, std::string &tag); uint16_t tag_class, uint16_t tag_type, std::string &tag);
virtual bool setAsRegularContact(const RsGxsId& id,bool is_a_contact) ; virtual bool setAsRegularContact(const RsGxsId& id,bool is_a_contact) ;
virtual bool isARegularContact(const RsGxsId& id) ;
/**************** RsGixs Implementation ***************/ /**************** RsGixs Implementation ***************/

View File

@ -87,6 +87,7 @@ p3MsgService::p3MsgService(p3ServiceControl *sc, p3IdService *id_serv)
mShouldEnableDistantMessaging = true ; mShouldEnableDistantMessaging = true ;
mDistantMessagingEnabled = false ; mDistantMessagingEnabled = false ;
mDistantMessagePermissions = RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_FILTER_NONE ;
/* Initialize standard tag types */ /* Initialize standard tag types */
if(sc) if(sc)
@ -469,6 +470,10 @@ bool p3MsgService::saveList(bool& cleanup, std::list<RsItem*>& itemList)
kv.value = mShouldEnableDistantMessaging?"YES":"NO" ; kv.value = mShouldEnableDistantMessaging?"YES":"NO" ;
vitem->tlvkvs.pairs.push_back(kv) ; vitem->tlvkvs.pairs.push_back(kv) ;
kv.key = "DISTANT_MESSAGE_PERMISSION_FLAGS" ;
kv.value = RsUtil::NumberToString(mDistantMessagePermissions) ;
vitem->tlvkvs.pairs.push_back(kv) ;
itemList.push_back(vitem) ; itemList.push_back(vitem) ;
return true; return true;
@ -598,6 +603,7 @@ bool p3MsgService::loadList(std::list<RsItem*>& load)
if(NULL != (vitem = dynamic_cast<RsConfigKeyValueSet*>(*it))) if(NULL != (vitem = dynamic_cast<RsConfigKeyValueSet*>(*it)))
for(std::list<RsTlvKeyValue>::const_iterator kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); ++kit) for(std::list<RsTlvKeyValue>::const_iterator kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); ++kit)
{
if(kit->key == "DISTANT_MESSAGES_ENABLED") if(kit->key == "DISTANT_MESSAGES_ENABLED")
{ {
#ifdef MSG_DEBUG #ifdef MSG_DEBUG
@ -605,6 +611,25 @@ bool p3MsgService::loadList(std::list<RsItem*>& load)
#endif #endif
mShouldEnableDistantMessaging = (kit->value == "YES") ; mShouldEnableDistantMessaging = (kit->value == "YES") ;
} }
if(kit->key == "DISTANT_MESSAGE_PERMISSION_FLAGS")
{
#ifdef MSG_DEBUG
std::cerr << "Loaded distant message permission flags: " << kit->value << std::endl ;
#endif
if (!kit->value.empty())
{
std::istringstream is(kit->value) ;
uint32_t tmp ;
is >> tmp ;
if(tmp < 3)
mDistantMessagePermissions = tmp ;
else
std::cerr << "(EE) Invalid value read for DistantMessagePermission flags in config: " << tmp << std::endl;
}
}
}
} }
@ -1791,6 +1816,32 @@ void p3MsgService::notifyDataStatus(const GRouterMsgPropagationId& id,uint32_t d
RsServer::notify()->notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_ADD); RsServer::notify()->notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_ADD);
IndicateConfigChanged() ; IndicateConfigChanged() ;
} }
bool p3MsgService::acceptDataFromPeer(const RsGxsId& to_gxs_id)
{
if(mDistantMessagePermissions & RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_FILTER_NON_CONTACTS)
return (rsIdentity!=NULL) && rsIdentity->isARegularContact(to_gxs_id) ;
if(mDistantMessagePermissions & RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_FILTER_EVERYBODY)
return false ;
return true ;
}
void p3MsgService::setDistantMessagingPermissionFlags(uint32_t flags)
{
if(flags != mDistantMessagePermissions)
{
mDistantMessagePermissions = flags ;
IndicateConfigChanged() ;
}
}
uint32_t p3MsgService::getDistantMessagingPermissionFlags()
{
return mDistantMessagePermissions ;
}
void p3MsgService::receiveGRouterData(const RsGxsId& destination_key, const RsGxsId& signing_key,GRouterServiceId& client_id,uint8_t *data,uint32_t data_size) void p3MsgService::receiveGRouterData(const RsGxsId& destination_key, const RsGxsId& signing_key,GRouterServiceId& client_id,uint8_t *data,uint32_t data_size)
{ {
std::cerr << "p3MsgService::receiveGRouterData(): received message item of size " << data_size << ", for key " << destination_key << std::endl; std::cerr << "p3MsgService::receiveGRouterData(): received message item of size " << data_size << ", for key " << destination_key << std::endl;

View File

@ -126,8 +126,9 @@ class p3MsgService: public p3Service, public p3Config, public pqiServiceMonitor,
}; };
void enableDistantMessaging(bool b) ; void enableDistantMessaging(bool b) ;
bool distantMessagingEnabled() ; bool distantMessagingEnabled() ;
void setDistantMessagingPermissionFlags(uint32_t flags) {}
uint32_t getDistantMessagingPermissionFlags() { return 0 ;} void setDistantMessagingPermissionFlags(uint32_t flags) ;
uint32_t getDistantMessagingPermissionFlags() ;
private: private:
void sendDistantMsgItem(RsMsgItem *msgitem) ; void sendDistantMsgItem(RsMsgItem *msgitem) ;
@ -139,6 +140,7 @@ class p3MsgService: public p3Service, public p3Config, public pqiServiceMonitor,
// Overloaded from GRouterClientService // Overloaded from GRouterClientService
virtual bool acceptDataFromPeer(const RsGxsId& gxs_id) ;
virtual void receiveGRouterData(const RsGxsId& destination_key,const RsGxsId& signing_key, GRouterServiceId &client_id, uint8_t *data, uint32_t data_size) ; virtual void receiveGRouterData(const RsGxsId& destination_key,const RsGxsId& signing_key, GRouterServiceId &client_id, uint8_t *data, uint32_t data_size) ;
virtual void notifyDataStatus(const GRouterMsgPropagationId& msg_id,uint32_t data_status) ; virtual void notifyDataStatus(const GRouterMsgPropagationId& msg_id,uint32_t data_status) ;
@ -205,6 +207,7 @@ class p3MsgService: public p3Service, public p3Config, public pqiServiceMonitor,
std::string config_dir; std::string config_dir;
bool mDistantMessagingEnabled ; bool mDistantMessagingEnabled ;
uint32_t mDistantMessagePermissions ;
bool mShouldEnableDistantMessaging ; bool mShouldEnableDistantMessaging ;
}; };

View File

@ -27,6 +27,7 @@
#include "util/rsprint.h" #include "util/rsprint.h"
#include "util/rsstring.h" #include "util/rsstring.h"
#include <iomanip> #include <iomanip>
#include <sstream>
#include <openssl/sha.h> #include <openssl/sha.h>
#include <sys/time.h> #include <sys/time.h>
@ -35,6 +36,15 @@
#include <sys/timeb.h> #include <sys/timeb.h>
#endif #endif
std::string RsUtil::NumberToString(uint64_t n)
{
std::ostringstream os ;
os << n ;
os.flush() ;
return os.str();
}
std::string RsUtil::BinToHex(const std::string &bin) std::string RsUtil::BinToHex(const std::string &bin)
{ {
return BinToHex(bin.c_str(), bin.length()); return BinToHex(bin.c_str(), bin.length());

View File

@ -36,6 +36,7 @@ namespace RsUtil {
std::string BinToHex(const std::string &bin); std::string BinToHex(const std::string &bin);
std::string BinToHex(const char *arr, const uint32_t len); std::string BinToHex(const char *arr, const uint32_t len);
std::string BinToHex(const unsigned char *arr, const uint32_t len); std::string BinToHex(const unsigned char *arr, const uint32_t len);
std::string NumberToString(uint64_t n);
std::string HashId(const std::string &id, bool reverse = false); std::string HashId(const std::string &id, bool reverse = false);
//std::string AccurateTimeString(); //std::string AccurateTimeString();

View File

@ -64,13 +64,13 @@ void MessagePage::distantMsgsComboBoxChanged(int i)
{ {
switch(i) switch(i)
{ {
case 0: rsMail->setDistantMessagingPermissionFlags(RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_EVERYBODY |RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_CONTACT_LIST) ; case 0: rsMail->setDistantMessagingPermissionFlags(RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_FILTER_NONE) ;
break ; break ;
case 1: rsMail->setDistantMessagingPermissionFlags(RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_CONTACT_LIST) ; case 1: rsMail->setDistantMessagingPermissionFlags(RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_FILTER_NON_CONTACTS) ;
break ; break ;
case 2: rsMail->setDistantMessagingPermissionFlags(RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_NONE) ; case 2: rsMail->setDistantMessagingPermissionFlags(RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_FILTER_EVERYBODY) ;
break ; break ;
@ -123,9 +123,9 @@ MessagePage::load()
uint32_t flags = rsMail->getDistantMessagingPermissionFlags() ; uint32_t flags = rsMail->getDistantMessagingPermissionFlags() ;
if(flags == (RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_CONTACT_LIST | RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_EVERYBODY)) if(flags & RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_FILTER_EVERYBODY)
ui.comboBox->setCurrentIndex(2); ui.comboBox->setCurrentIndex(2);
else if(flags == RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_CONTACT_LIST) else if(flags & RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_FILTER_NON_CONTACTS)
ui.comboBox->setCurrentIndex(1); ui.comboBox->setCurrentIndex(1);
else else
ui.comboBox->setCurrentIndex(0); ui.comboBox->setCurrentIndex(0);