diff --git a/libretroshare/src/pgp/rscertificate.h b/libretroshare/src/pgp/rscertificate.h index cc3a60224..f1faab2fa 100644 --- a/libretroshare/src/pgp/rscertificate.h +++ b/libretroshare/src/pgp/rscertificate.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include class RsPeerDetails ; diff --git a/libretroshare/src/pqi/p3historymgr.cc b/libretroshare/src/pqi/p3historymgr.cc index 2566dee4f..cbd623cfd 100644 --- a/libretroshare/src/pqi/p3historymgr.cc +++ b/libretroshare/src/pqi/p3historymgr.cc @@ -63,7 +63,7 @@ p3HistoryMgr::~p3HistoryMgr() /***** p3HistoryMgr *****/ -void p3HistoryMgr::addMessage(bool incoming, const std::string &chatPeerId, const std::string &peerId, const RsChatMsgItem *chatItem) +void p3HistoryMgr::addMessage(bool incoming, const RsPeerId &chatPeerId, const RsPeerId &peerId, const RsChatMsgItem *chatItem) { uint32_t addMsgId = 0; @@ -78,7 +78,7 @@ void p3HistoryMgr::addMessage(bool incoming, const std::string &chatPeerId, cons { RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/ - if (mPublicEnable == false && chatPeerId.empty()) { + if (mPublicEnable == false && chatPeerId.isNull()) { // public chat not enabled return; } @@ -87,12 +87,12 @@ void p3HistoryMgr::addMessage(bool incoming, const std::string &chatPeerId, cons if (cli) { - if (mLobbyEnable == false && !chatPeerId.empty()) // lobby chat not enabled + if (mLobbyEnable == false && !chatPeerId.isNull()) // lobby chat not enabled return; } else { - if (mPrivateEnable == false && !chatPeerId.empty()) // private chat not enabled + if (mPrivateEnable == false && !chatPeerId.isNull()) // private chat not enabled return; } @@ -112,7 +112,7 @@ void p3HistoryMgr::addMessage(bool incoming, const std::string &chatPeerId, cons item->message = chatItem->message ; //librs::util::ConvertUtf16ToUtf8(chatItem->message, item->message); - std::map >::iterator mit = mMessages.find(item->chatPeerId); + std::map >::iterator mit = mMessages.find(item->chatPeerId); if (mit != mMessages.end()) { item->msgId = nextMsgId++; mit->second.insert(std::make_pair(item->msgId, item)); @@ -120,7 +120,7 @@ void p3HistoryMgr::addMessage(bool incoming, const std::string &chatPeerId, cons // check the limit uint32_t limit; - if (chatPeerId.empty()) + if (chatPeerId.isNull()) limit = mPublicSaveCount; else if (cli) limit = mLobbySaveCount; @@ -159,7 +159,7 @@ void p3HistoryMgr::cleanOldMessages() time_t now = time(NULL) ; bool changed = false ; - for(std::map >::iterator mit = mMessages.begin(); mit != mMessages.end();) + for(std::map >::iterator mit = mMessages.begin(); mit != mMessages.end();) { if (mMaxStorageDurationSeconds > 0) { @@ -183,7 +183,7 @@ void p3HistoryMgr::cleanOldMessages() if(mit->second.empty()) { - std::map >::iterator mit2 = mit ; + std::map >::iterator mit2 = mit ; ++mit2 ; std::cerr << " removing peer id " << mit->first << ", since it has no messages" << std::endl; mMessages.erase(mit) ; @@ -216,7 +216,7 @@ bool p3HistoryMgr::saveList(bool& cleanup, std::list& saveData) mHistoryMtx.lock(); /********** STACK LOCKED MTX ******/ - std::map >::iterator mit; + std::map >::iterator mit; std::map::iterator lit; for (mit = mMessages.begin(); mit != mMessages.end(); mit++) { for (lit = mit->second.begin(); lit != mit->second.end(); lit++) { @@ -287,7 +287,7 @@ bool p3HistoryMgr::loadList(std::list& load) for (it = load.begin(); it != load.end(); it++) { if (NULL != (msgItem = dynamic_cast(*it))) { - std::map >::iterator mit = mMessages.find(msgItem->chatPeerId); + std::map >::iterator mit = mMessages.find(msgItem->chatPeerId); msgItem->msgId = nextMsgId++; std::cerr << "Loading msg history item: peer id=" << msgItem->chatPeerId << "), msg id =" << msgItem->msgId << std::endl; @@ -371,7 +371,7 @@ static void convertMsg(const RsHistoryMsgItem* item, HistoryMsg &msg) msg.message = item->message; } -bool p3HistoryMgr::getMessages(const std::string &chatPeerId, std::list &msgs, uint32_t loadCount) +bool p3HistoryMgr::getMessages(const RsPeerId &chatPeerId, std::list &msgs, uint32_t loadCount) { msgs.clear(); @@ -379,20 +379,20 @@ bool p3HistoryMgr::getMessages(const std::string &chatPeerId, std::list >::iterator mit = mMessages.find(chatPeerId); + std::map >::iterator mit = mMessages.find(chatPeerId); if (mit != mMessages.end()) { @@ -418,7 +418,7 @@ bool p3HistoryMgr::getMessage(uint32_t msgId, HistoryMsg &msg) { RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/ - std::map >::iterator mit; + std::map >::iterator mit; for (mit = mMessages.begin(); mit != mMessages.end(); mit++) { std::map::iterator lit = mit->second.find(msgId); if (lit != mit->second.end()) { @@ -430,14 +430,14 @@ bool p3HistoryMgr::getMessage(uint32_t msgId, HistoryMsg &msg) return false; } -void p3HistoryMgr::clear(const std::string &chatPeerId) +void p3HistoryMgr::clear(const RsPeerId &chatPeerId) { { RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/ std::cerr << "********** p3History::clear()called for peer id " << chatPeerId << std::endl; - std::map >::iterator mit = mMessages.find(chatPeerId); + std::map >::iterator mit = mMessages.find(chatPeerId); if (mit == mMessages.end()) { return; } @@ -465,7 +465,7 @@ void p3HistoryMgr::removeMessages(const std::list &msgIds) { RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/ - std::map >::iterator mit; + std::map >::iterator mit; for (mit = mMessages.begin(); mit != mMessages.end(); ++mit) { iit = ids.begin(); while (iit != ids.end()) { diff --git a/libretroshare/src/pqi/p3historymgr.h b/libretroshare/src/pqi/p3historymgr.h index 038d1bbac..70f07bb67 100644 --- a/libretroshare/src/pqi/p3historymgr.h +++ b/libretroshare/src/pqi/p3historymgr.h @@ -48,13 +48,13 @@ public: /******** p3HistoryMgr *********/ - void addMessage(bool incoming, const std::string &chatPeerId, const std::string &peerId, const RsChatMsgItem *chatItem); + void addMessage(bool incoming, const RsPeerId &chatPeerId, const RsPeerId &peerId, const RsChatMsgItem *chatItem); /********* RsHistory ***********/ - bool getMessages(const std::string &chatPeerId, std::list &msgs, uint32_t loadCount); + bool getMessages(const RsPeerId &chatPeerId, std::list &msgs, uint32_t loadCount); bool getMessage(uint32_t msgId, HistoryMsg &msg); - void clear(const std::string &chatPeerId); + void clear(const RsPeerId &chatPeerId); void removeMessages(const std::list &msgIds); virtual bool getEnable(uint32_t chat_type); @@ -73,7 +73,7 @@ public: private: uint32_t nextMsgId; - std::map > mMessages; + std::map > mMessages; // Removes messages stored for more than mMaxMsgStorageDurationSeconds seconds. // This avoids the stored list to grow crazy with time. diff --git a/libretroshare/src/retroshare/rshistory.h b/libretroshare/src/retroshare/rshistory.h index 2c6f8366e..034b2da68 100644 --- a/libretroshare/src/retroshare/rshistory.h +++ b/libretroshare/src/retroshare/rshistory.h @@ -33,6 +33,7 @@ extern RsHistory *rsHistory; #include #include #include +#include "retroshare/rstypes.h" //! data object for message history /*! @@ -55,9 +56,9 @@ public: public: uint32_t msgId; - std::string chatPeerId; + RsPeerId chatPeerId; bool incoming; - std::string peerId; + RsPeerId peerId; std::string peerName; uint32_t sendTime; uint32_t recvTime; @@ -71,10 +72,10 @@ public: class RsHistory { public: - virtual bool getMessages(const std::string &chatPeerId, std::list &msgs, uint32_t loadCount) = 0; + virtual bool getMessages(const RsPeerId &chatPeerId, std::list &msgs, uint32_t loadCount) = 0; virtual bool getMessage(uint32_t msgId, HistoryMsg &msg) = 0; virtual void removeMessages(const std::list &msgIds) = 0; - virtual void clear(const std::string &chatPeerId) = 0; + virtual void clear(const RsPeerId &chatPeerId) = 0; virtual bool getEnable(uint32_t chat_type) = 0; virtual void setEnable(uint32_t chat_type, bool enable) = 0; diff --git a/libretroshare/src/retroshare/rsids.h b/libretroshare/src/retroshare/rsids.h index 29899f165..c66c9aadd 100644 --- a/libretroshare/src/retroshare/rsids.h +++ b/libretroshare/src/retroshare/rsids.h @@ -36,7 +36,7 @@ #include #include -template class t_RsGenericIdType +template class t_RsGenericIdType { public: t_RsGenericIdType() @@ -55,9 +55,9 @@ template class t_RsGeneric // Random initialization. Can be useful for testing. // - static t_RsGenericIdType random() + static t_RsGenericIdType random() { - t_RsGenericIdType id ; + t_RsGenericIdType id ; for(uint32_t i=0;i class t_RsGeneric // Converts to a std::string using cached value. // - std::string toStdString(bool upper_case = true) const ; const unsigned char *toByteArray() const { return &bytes[0] ; } static const uint32_t SIZE_IN_BYTES = ID_SIZE_IN_BYTES ; - inline bool operator==(const t_RsGenericIdType& fp) const { return !memcmp(bytes,fp.bytes,ID_SIZE_IN_BYTES) ; } - inline bool operator!=(const t_RsGenericIdType& fp) const { return !!memcmp(bytes,fp.bytes,ID_SIZE_IN_BYTES); } - inline bool operator< (const t_RsGenericIdType& fp) const { return (memcmp(bytes,fp.bytes,ID_SIZE_IN_BYTES) < 0) ; } + inline bool operator==(const t_RsGenericIdType& fp) const { return !memcmp(bytes,fp.bytes,ID_SIZE_IN_BYTES) ; } + inline bool operator!=(const t_RsGenericIdType& fp) const { return !!memcmp(bytes,fp.bytes,ID_SIZE_IN_BYTES); } + inline bool operator< (const t_RsGenericIdType& fp) const { return (memcmp(bytes,fp.bytes,ID_SIZE_IN_BYTES) < 0) ; } inline bool isNull() const { @@ -85,15 +84,39 @@ template class t_RsGeneric return true ; } - friend std::ostream& operator<<(std::ostream& out,const t_RsGenericIdType& id) + friend std::ostream& operator<<(std::ostream& out,const t_RsGenericIdType& id) { - return out << id.toStdString() ; + return out << id.toStdString(UPPER_CASE) ; + } + + inline std::string toStdString() const { return toStdString(UPPER_CASE) ; } + + inline uint32_t serial_size() const { return SIZE_IN_BYTES ; } + bool serialise(void *data,uint32_t pktsize,uint32_t& offset) + { + if(offset + SIZE_IN_BYTES >= pktsize) + return false ; + + memcpy(&((uint8_t*)data)[offset],bytes,SIZE_IN_BYTES) ; + offset += SIZE_IN_BYTES ; + return true ; + } + bool deserialise(void *data,uint32_t pktsize,uint32_t& offset) + { + if(offset + SIZE_IN_BYTES >= pktsize) + return false ; + + memcpy(bytes,&((uint8_t*)data)[offset],SIZE_IN_BYTES) ; + offset += SIZE_IN_BYTES ; + return true ; } private: + std::string toStdString(bool upper_case) const ; + unsigned char bytes[ID_SIZE_IN_BYTES] ; }; -template std::string t_RsGenericIdType::toStdString(bool upper_case) const +template std::string t_RsGenericIdType::toStdString(bool upper_case) const { static const char outh[16] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' } ; static const char outl[16] = { '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f' } ; @@ -115,7 +138,7 @@ template std::string t_RsG return res ; } -template t_RsGenericIdType::t_RsGenericIdType(const std::string& s) +template t_RsGenericIdType::t_RsGenericIdType(const std::string& s) { try { @@ -149,7 +172,7 @@ template t_RsGenericIdType } } -template t_RsGenericIdType::t_RsGenericIdType(const unsigned char *mem) +template t_RsGenericIdType::t_RsGenericIdType(const unsigned char *mem) { if(mem == NULL) memset(bytes,0,ID_SIZE_IN_BYTES) ; @@ -169,8 +192,8 @@ static const uint32_t RS_GENERIC_ID_PGP_ID_TYPE = 0x80339f4f ; static const uint32_t RS_GENERIC_ID_SHA1_ID_TYPE = 0x9540284e ; static const uint32_t RS_GENERIC_ID_PGP_FINGERPRINT_TYPE = 0x102943e3 ; -typedef t_RsGenericIdType< SSL_ID_SIZE , RS_GENERIC_ID_SSL_ID_TYPE> SSLIdType ; -typedef t_RsGenericIdType< PGP_KEY_ID_SIZE , RS_GENERIC_ID_PGP_ID_TYPE> PGPIdType; -typedef t_RsGenericIdType< SHA1_SIZE , RS_GENERIC_ID_SHA1_ID_TYPE> Sha1CheckSum ; -typedef t_RsGenericIdType< PGP_KEY_FINGERPRINT_SIZE, RS_GENERIC_ID_PGP_FINGERPRINT_TYPE> PGPFingerprintType ; +typedef t_RsGenericIdType< SSL_ID_SIZE , false, RS_GENERIC_ID_SSL_ID_TYPE> SSLIdType ; +typedef t_RsGenericIdType< PGP_KEY_ID_SIZE , true, RS_GENERIC_ID_PGP_ID_TYPE> PGPIdType; +typedef t_RsGenericIdType< SHA1_SIZE , false, RS_GENERIC_ID_SHA1_ID_TYPE> Sha1CheckSum ; +typedef t_RsGenericIdType< PGP_KEY_FINGERPRINT_SIZE, true, RS_GENERIC_ID_PGP_FINGERPRINT_TYPE> PGPFingerprintType ; diff --git a/libretroshare/src/retroshare/rsmsgs.h b/libretroshare/src/retroshare/rsmsgs.h index 70b0a38cc..319ecb84b 100644 --- a/libretroshare/src/retroshare/rsmsgs.h +++ b/libretroshare/src/retroshare/rsmsgs.h @@ -92,13 +92,13 @@ class MessageInfo public: MessageInfo() {} std::string msgId; - std::string srcId; + RsPeerId srcId; unsigned int msgflags; - std::list msgto; - std::list msgcc; - std::list msgbcc; + std::list msgto; + std::list msgcc; + std::list msgbcc; std::string title; std::string msg; @@ -119,7 +119,7 @@ class MsgInfoSummary MsgInfoSummary() {} std::string msgId; - std::string srcId; + RsPeerId srcId; uint32_t msgflags; @@ -170,7 +170,7 @@ public: class ChatInfo { public: - std::string rsid; + RsPeerId rsid; std::string peer_nickname; unsigned int chatflags; uint32_t sendTime; @@ -182,7 +182,7 @@ class ChatLobbyInvite { public: ChatLobbyId lobby_id ; - std::string peer_id ; + RsPeerId peer_id ; std::string lobby_name ; std::string lobby_topic ; uint32_t lobby_privacy_level ; @@ -196,7 +196,7 @@ class VisibleChatLobbyRecord ChatLobbyId lobby_id ; // unique id of the lobby std::string lobby_name ; // name to use for this lobby std::string lobby_topic ; // topic to use for this lobby - std::set participating_friends ; // list of direct friend who participate. + std::set participating_friends ; // list of direct friend who participate. uint32_t total_number_of_peers ; // total number of particpating peers. Might not be time_t last_report_time ; // last time the lobby was reported. @@ -210,7 +210,7 @@ class ChatLobbyInfo ChatLobbyId lobby_id ; // unique id of the lobby std::string lobby_name ; // name to use for this lobby std::string lobby_topic ; // topic to use for this lobby - std::set participating_friends ; // list of direct friend who participate. Used to broadcast sent messages. + std::set participating_friends ; // list of direct friend who participate. Used to broadcast sent messages. std::string nick_name ; // nickname to use for this lobby uint32_t lobby_privacy_level ; // see RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC / RS_CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE @@ -222,7 +222,7 @@ struct DistantChatInviteInfo { std::string hash ; // hash to contact the invite and refer to it. std::string encrypted_radix64_string ; // encrypted radix string used to for the chat link - std::string destination_pgp_id ; // pgp is of the destination of the chat link + PGPIdType destination_pgp_id ; // pgp is of the destination of the chat link time_t time_of_validity ; // time when te invite becomes unusable uint32_t invite_flags ; // used to keep track of wether signature was ok or not. }; @@ -237,7 +237,7 @@ extern RsMsgs *rsMsgs; struct DistantOfflineMessengingInvite { - std::string issuer_pgp_id ; + PGPIdType issuer_pgp_id ; std::string hash ; time_t time_of_validity ; }; @@ -290,29 +290,29 @@ virtual bool createDistantOfflineMessengingInvite(time_t validity_time_stamp, st virtual bool getDistantOfflineMessengingInvites(std::vector& invites) = 0 ; virtual void enableDistantMessaging(bool b) = 0; virtual bool distantMessagingEnabled() = 0; -virtual bool getDistantMessageHash(const std::string& pgp_id, std::string& hash) = 0; +virtual bool getDistantMessageHash(const PGPIdType& pgp_id, std::string& hash) = 0; /****************************************/ /* Chat */ /****************************************/ virtual bool sendPublicChat(const std::string& msg) = 0; -virtual bool sendPrivateChat(const std::string& id, const std::string& msg) = 0; +virtual bool sendPrivateChat(const RsPeerId& id, const std::string& msg) = 0; virtual int getPublicChatQueueCount() = 0; virtual bool getPublicChatQueue(std::list &chats) = 0; virtual int getPrivateChatQueueCount(bool incoming) = 0; -virtual bool getPrivateChatQueueIds(bool incoming, std::list &ids) = 0; -virtual bool getPrivateChatQueue(bool incoming, const std::string& id, std::list &chats) = 0; -virtual bool clearPrivateChatQueue(bool incoming, const std::string& id) = 0; +virtual bool getPrivateChatQueueIds(bool incoming, std::list &ids) = 0; +virtual bool getPrivateChatQueue(bool incoming, const RsPeerId& id, std::list &chats) = 0; +virtual bool clearPrivateChatQueue(bool incoming, const RsPeerId& id) = 0; -virtual void sendStatusString(const std::string& id,const std::string& status_string) = 0 ; +virtual void sendStatusString(const RsPeerId& id,const std::string& status_string) = 0 ; virtual void sendGroupChatStatusString(const std::string& status_string) = 0 ; virtual void setCustomStateString(const std::string& status_string) = 0 ; virtual std::string getCustomStateString() = 0 ; -virtual std::string getCustomStateString(const std::string& peer_id) = 0 ; +virtual std::string getCustomStateString(const RsPeerId& peer_id) = 0 ; // get avatar data for peer pid -virtual void getAvatarData(const std::string& pid,unsigned char *& data,int& size) = 0 ; +virtual void getAvatarData(const RsPeerId& pid,unsigned char *& data,int& size) = 0 ; // set own avatar data virtual void setOwnAvatarData(const unsigned char *data,int size) = 0 ; virtual void getOwnAvatarData(unsigned char *& data,int& size) = 0 ; @@ -322,11 +322,11 @@ virtual void getOwnAvatarData(unsigned char *& data,int& size) = 0 ; /****************************************/ virtual bool joinVisibleChatLobby(const ChatLobbyId& lobby_id) = 0 ; -virtual bool isLobbyId(const std::string& virtual_peer_id,ChatLobbyId& lobby_id) = 0; -virtual bool getVirtualPeerId(const ChatLobbyId& lobby_id,std::string& vpid) = 0; +virtual bool isLobbyId(const RsPeerId& virtual_peer_id,ChatLobbyId& lobby_id) = 0; +virtual bool getVirtualPeerId(const ChatLobbyId& lobby_id,RsPeerId& vpid) = 0; virtual void getChatLobbyList(std::list& cl_info) = 0; virtual void getListOfNearbyChatLobbies(std::vector& public_lobbies) = 0 ; -virtual void invitePeerToLobby(const ChatLobbyId& lobby_id,const std::string& peer_id) = 0; +virtual void invitePeerToLobby(const ChatLobbyId& lobby_id,const RsPeerId& peer_id) = 0; virtual bool acceptLobbyInvite(const ChatLobbyId& id) = 0 ; virtual void denyLobbyInvite(const ChatLobbyId& id) = 0 ; virtual void getPendingChatLobbyInvites(std::list& invites) = 0; @@ -337,17 +337,17 @@ virtual bool setDefaultNickNameForChatLobby(const std::string& nick) = 0; virtual bool getDefaultNickNameForChatLobby(std::string& nick) = 0 ; virtual void setLobbyAutoSubscribe(const ChatLobbyId& lobby_id, const bool autoSubscribe) = 0 ; virtual bool getLobbyAutoSubscribe(const ChatLobbyId& lobby_id) = 0 ; -virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::string& lobby_topic,const std::list& invited_friends,uint32_t lobby_privacy_type) = 0 ; +virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::string& lobby_topic,const std::list& invited_friends,uint32_t lobby_privacy_type) = 0 ; /****************************************/ /* Distant chat */ /****************************************/ -virtual bool createDistantChatInvite(const std::string& pgp_id,time_t time_of_validity,std::string& encrypted_string) = 0 ; +virtual bool createDistantChatInvite(const PGPIdType& pgp_id,time_t time_of_validity,std::string& encrypted_string) = 0 ; virtual bool getDistantChatInviteList(std::vector& invites) = 0; virtual bool initiateDistantChatConnexion(const std::string& encrypted_string,time_t validity_time,std::string& hash,uint32_t& error_code) = 0; virtual bool initiateDistantChatConnexion(const std::string& hash,uint32_t& error_code) = 0; -virtual bool getDistantChatStatus(const std::string& hash,uint32_t& status,std::string& pgp_id) = 0; +virtual bool getDistantChatStatus(const std::string& hash,uint32_t& status,PGPIdType& pgp_id) = 0; virtual bool closeDistantChatConnexion(const std::string& hash) = 0; virtual bool removeDistantChatInvite(const std::string& hash) = 0 ; diff --git a/libretroshare/src/rsserver/p3history.cc b/libretroshare/src/rsserver/p3history.cc index 68e4c134d..a7a225ae2 100644 --- a/libretroshare/src/rsserver/p3history.cc +++ b/libretroshare/src/rsserver/p3history.cc @@ -44,7 +44,7 @@ uint32_t p3History::getMaxStorageDuration() { return mHistoryMgr->getMaxStorageDuration() ; } -bool p3History::getMessages(const std::string &chatPeerId, std::list &msgs, const uint32_t loadCount) +bool p3History::getMessages(const RsPeerId &chatPeerId, std::list &msgs, const uint32_t loadCount) { return mHistoryMgr->getMessages(chatPeerId, msgs, loadCount); } @@ -59,7 +59,7 @@ void p3History::removeMessages(const std::list &msgIds) mHistoryMgr->removeMessages(msgIds); } -void p3History::clear(const std::string &chatPeerId) +void p3History::clear(const RsPeerId &chatPeerId) { mHistoryMgr->clear(chatPeerId); } diff --git a/libretroshare/src/rsserver/p3history.h b/libretroshare/src/rsserver/p3history.h index 50b2b4a80..9a4bc8837 100644 --- a/libretroshare/src/rsserver/p3history.h +++ b/libretroshare/src/rsserver/p3history.h @@ -41,10 +41,10 @@ public: p3History(p3HistoryMgr* historyMgr); virtual ~p3History(); - virtual bool getMessages(const std::string &chatPeerId, std::list &msgs, uint32_t loadCount); + virtual bool getMessages(const RsPeerId &chatPeerId, std::list &msgs, uint32_t loadCount); virtual bool getMessage(uint32_t msgId, HistoryMsg &msg); virtual void removeMessages(const std::list &msgIds); - virtual void clear(const std::string &chatPeerId); + virtual void clear(const RsPeerId &chatPeerId); virtual bool getEnable(uint32_t chat_type); virtual void setEnable(uint32_t chat_type, bool enable); virtual uint32_t getSaveCount(uint32_t chat_type); diff --git a/libretroshare/src/rsserver/p3msgs.cc b/libretroshare/src/rsserver/p3msgs.cc index c49ac332d..da5faf51f 100644 --- a/libretroshare/src/rsserver/p3msgs.cc +++ b/libretroshare/src/rsserver/p3msgs.cc @@ -116,7 +116,7 @@ bool p3Msgs::distantMessagingEnabled() { return mMsgSrv->distantMessagingEnabled(); } -bool p3Msgs::getDistantMessageHash(const std::string& pgp_id,std::string& hash) +bool p3Msgs::getDistantMessageHash(const PGPIdType& pgp_id,std::string& hash) { return mMsgSrv->getDistantMessageHash(pgp_id,hash); } @@ -218,7 +218,7 @@ bool p3Msgs::sendPublicChat(const std::string& msg) return mChatSrv -> sendPublicChat(msg); } -bool p3Msgs::sendPrivateChat(const std::string& id, const std::string& msg) +bool p3Msgs::sendPrivateChat(const RsPeerId& id, const std::string& msg) { /* send a message to peer */ return mChatSrv -> sendPrivateChat(id, msg); @@ -229,7 +229,7 @@ void p3Msgs::sendGroupChatStatusString(const std::string& status_string) mChatSrv->sendGroupChatStatusString(status_string); } -void p3Msgs::sendStatusString(const std::string& peer_id, const std::string& status_string) +void p3Msgs::sendStatusString(const RsPeerId& peer_id, const std::string& status_string) { mChatSrv->sendStatusString(peer_id, status_string); } @@ -249,17 +249,17 @@ int p3Msgs::getPrivateChatQueueCount(bool incoming) return mChatSrv->getPrivateChatQueueCount(incoming); } -bool p3Msgs::getPrivateChatQueueIds(bool incoming, std::list &ids) +bool p3Msgs::getPrivateChatQueueIds(bool incoming, std::list &ids) { return mChatSrv->getPrivateChatQueueIds(incoming, ids); } -bool p3Msgs::getPrivateChatQueue(bool incoming, const std::string& id, std::list &chats) +bool p3Msgs::getPrivateChatQueue(bool incoming, const RsPeerId& id, std::list &chats) { return mChatSrv->getPrivateChatQueue(incoming, id, chats); } -bool p3Msgs::clearPrivateChatQueue(bool incoming, const std::string& id) +bool p3Msgs::clearPrivateChatQueue(bool incoming, const RsPeerId& id) { return mChatSrv->clearPrivateChatQueue(incoming, id); } @@ -274,12 +274,12 @@ void p3Msgs::setOwnAvatarData(const unsigned char *data,int size) mChatSrv->setOwnAvatarJpegData(data,size) ; } -void p3Msgs::getAvatarData(const std::string& pid,unsigned char *& data,int& size) +void p3Msgs::getAvatarData(const RsPeerId& pid,unsigned char *& data,int& size) { mChatSrv->getAvatarJpegData(pid,data,size) ; } -std::string p3Msgs::getCustomStateString(const std::string& peer_id) +std::string p3Msgs::getCustomStateString(const RsPeerId& peer_id) { return mChatSrv->getCustomStateString(peer_id) ; } @@ -294,11 +294,11 @@ void p3Msgs::setCustomStateString(const std::string& state_string) mChatSrv->setOwnCustomStateString(state_string) ; } -bool p3Msgs::getVirtualPeerId(const ChatLobbyId& id,std::string& peer_id) +bool p3Msgs::getVirtualPeerId(const ChatLobbyId& id,RsPeerId& peer_id) { return mChatSrv->getVirtualPeerId(id,peer_id) ; } -bool p3Msgs::isLobbyId(const std::string& peer_id,ChatLobbyId& id) +bool p3Msgs::isLobbyId(const RsPeerId& peer_id,ChatLobbyId& id) { return mChatSrv->isLobbyId(peer_id,id) ; } @@ -307,7 +307,7 @@ void p3Msgs::getChatLobbyList(std::list& linfos) { mChatSrv->getChatLobbyList(linfos) ; } -void p3Msgs::invitePeerToLobby(const ChatLobbyId& lobby_id, const std::string& peer_id) +void p3Msgs::invitePeerToLobby(const ChatLobbyId& lobby_id, const RsPeerId& peer_id) { mChatSrv->invitePeerToLobby(lobby_id,peer_id) ; } @@ -343,7 +343,7 @@ void p3Msgs::getListOfNearbyChatLobbies(std::vector& pub mChatSrv->getListOfNearbyChatLobbies(public_lobbies) ; } -ChatLobbyId p3Msgs::createChatLobby(const std::string& lobby_name,const std::string& lobby_topic,const std::list& invited_friends,uint32_t privacy_type) +ChatLobbyId p3Msgs::createChatLobby(const std::string& lobby_name,const std::string& lobby_topic,const std::list& invited_friends,uint32_t privacy_type) { return mChatSrv->createChatLobby(lobby_name,lobby_topic,invited_friends,privacy_type) ; } @@ -371,7 +371,7 @@ void p3Msgs::getPendingChatLobbyInvites(std::list& invites) { mChatSrv->getPendingChatLobbyInvites(invites) ; } -bool p3Msgs::createDistantChatInvite(const std::string& pgp_id,time_t time_of_validity,std::string& encrypted_string) +bool p3Msgs::createDistantChatInvite(const PGPIdType& pgp_id,time_t time_of_validity,std::string& encrypted_string) { return mChatSrv->createDistantChatInvite(pgp_id,time_of_validity,encrypted_string) ; } @@ -387,7 +387,7 @@ bool p3Msgs::initiateDistantChatConnexion(const std::string& hash,uint32_t& erro { return mChatSrv->initiateDistantChatConnexion(hash,error_code) ; } -bool p3Msgs::getDistantChatStatus(const std::string& hash,uint32_t& status,std::string& pgp_id) +bool p3Msgs::getDistantChatStatus(const std::string& hash,uint32_t& status,PGPIdType& pgp_id) { return mChatSrv->getDistantChatStatus(hash,status,pgp_id) ; } diff --git a/libretroshare/src/rsserver/p3msgs.h b/libretroshare/src/rsserver/p3msgs.h index 531d5eabb..211363f3c 100644 --- a/libretroshare/src/rsserver/p3msgs.h +++ b/libretroshare/src/rsserver/p3msgs.h @@ -85,12 +85,12 @@ class p3Msgs: public RsMsgs virtual void enableDistantMessaging(bool b) ; virtual bool distantMessagingEnabled() ; - virtual bool getDistantMessageHash(const std::string& pgp_id,std::string& hash) ; + virtual bool getDistantMessageHash(const PGPIdType& pgp_id,std::string& hash) ; /*! * gets avatar from peer, image data in jpeg format */ - virtual void getAvatarData(const std::string& pid,unsigned char *& data,int& size); + virtual void getAvatarData(const RsPeerId& pid,unsigned char *& data,int& size); /*! * sets clients avatar, image data should be in jpeg format @@ -115,7 +115,7 @@ class p3Msgs: public RsMsgs /*! * retrieves peer's custom status */ - virtual std::string getCustomStateString(const std::string& peer_id) ; + virtual std::string getCustomStateString(const RsPeerId& peer_id) ; /*! @@ -127,7 +127,7 @@ class p3Msgs: public RsMsgs * chat is sent to specifc peer * @param id peer to send chat msg to */ - virtual bool sendPrivateChat(const std::string& id, const std::string& msg); + virtual bool sendPrivateChat(const RsPeerId& id, const std::string& msg); /*! * returns the count of messages in public or private queue @@ -149,24 +149,24 @@ class p3Msgs: public RsMsgs /*! * @param id's of available private chat messages */ - virtual bool getPrivateChatQueueIds(bool incoming, std::list &ids); + virtual bool getPrivateChatQueueIds(bool incoming, std::list &ids); /*! * @param chats ref to list of received private chats is stored here */ - virtual bool getPrivateChatQueue(bool incoming, const std::string& id, std::list &chats); + virtual bool getPrivateChatQueue(bool incoming, const RsPeerId& id, std::list &chats); /*! * @param clear private chat queue */ - virtual bool clearPrivateChatQueue(bool incoming, const std::string& id); + virtual bool clearPrivateChatQueue(bool incoming, const RsPeerId& id); /*! * sends immediate status string to a specific peer, e.g. in a private chat * @param peer_id peer to send status string to * @param status_string immediate status to send */ - virtual void sendStatusString(const std::string& peer_id, const std::string& status_string) ; + virtual void sendStatusString(const RsPeerId& peer_id, const std::string& status_string) ; /*! * sends immediate status to all peers @@ -178,10 +178,10 @@ class p3Msgs: public RsMsgs virtual bool joinVisibleChatLobby(const ChatLobbyId& id) ; virtual void getListOfNearbyChatLobbies(std::vector& public_lobbies) ; - virtual bool getVirtualPeerId(const ChatLobbyId& id,std::string& vpid) ; - virtual bool isLobbyId(const std::string& virtual_peer_id,ChatLobbyId& lobby_id) ; + virtual bool getVirtualPeerId(const ChatLobbyId& id,RsPeerId& vpid) ; + virtual bool isLobbyId(const RsPeerId& virtual_peer_id,ChatLobbyId& lobby_id) ; virtual void getChatLobbyList(std::list >&) ; - virtual void invitePeerToLobby(const ChatLobbyId&, const std::string&) ; + virtual void invitePeerToLobby(const ChatLobbyId&, const RsPeerId&) ; virtual bool acceptLobbyInvite(const ChatLobbyId& id) ; virtual void denyLobbyInvite(const ChatLobbyId& id) ; virtual void getPendingChatLobbyInvites(std::list& invites) ; @@ -192,13 +192,13 @@ class p3Msgs: public RsMsgs virtual bool getDefaultNickNameForChatLobby(std::string& nick) ; virtual void setLobbyAutoSubscribe(const ChatLobbyId& lobby_id, const bool autoSubscribe); virtual bool getLobbyAutoSubscribe(const ChatLobbyId& lobby_id); - virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::string& lobby_topic,const std::list& invited_friends,uint32_t privacy_type) ; + virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::string& lobby_topic,const std::list& invited_friends,uint32_t privacy_type) ; - virtual bool createDistantChatInvite(const std::string& pgp_id,time_t time_of_validity,std::string& encrypted_string) ; + virtual bool createDistantChatInvite(const PGPIdType& pgp_id,time_t time_of_validity,std::string& encrypted_string) ; virtual bool getDistantChatInviteList(std::vector& invites); virtual bool initiateDistantChatConnexion(const std::string& encrypted_string,time_t validity_time,std::string& hash,uint32_t& error_code) ; virtual bool initiateDistantChatConnexion(const std::string& hash,uint32_t& error_code) ; - virtual bool getDistantChatStatus(const std::string& hash,uint32_t& status,std::string& pgp_id) ; + virtual bool getDistantChatStatus(const std::string& hash,uint32_t& status,PGPIdType& pgp_id) ; virtual bool closeDistantChatConnexion(const std::string& hash) ; virtual bool removeDistantChatInvite(const std::string& hash) ; diff --git a/libretroshare/src/serialiser/rsconfigitems.cc b/libretroshare/src/serialiser/rsconfigitems.cc index a6b288b9e..eb7bbe50f 100644 --- a/libretroshare/src/serialiser/rsconfigitems.cc +++ b/libretroshare/src/serialiser/rsconfigitems.cc @@ -1184,7 +1184,7 @@ std::ostream &RsPeerGroupItem::print(std::ostream &out, uint16_t indent) printIndent(out, int_Indent); out << "groupFlag: " << flag << std::endl; - std::list::iterator it; + std::list::iterator it; for (it = peerIds.begin(); it != peerIds.end(); it++) { printIndent(out, int_Indent); out << "peerId: " << *it << std::endl; @@ -1222,9 +1222,9 @@ uint32_t RsPeerConfigSerialiser::sizeGroup(RsPeerGroupItem *i) s += GetTlvStringSize(i->name); s += 4; /* flag */ - std::list::iterator it; + std::list::iterator it; for (it = i->peerIds.begin(); it != i->peerIds.end(); it++) { - s += GetTlvStringSize(*it); + s += PGPIdType::SIZE_IN_BYTES ; } return s; @@ -1260,9 +1260,9 @@ bool RsPeerConfigSerialiser::serialiseGroup(RsPeerGroupItem *item, void *data, u ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, item->name); ok &= setRawUInt32(data, tlvsize, &offset, item->flag); - std::list::iterator it; + std::list::iterator it; for (it = item->peerIds.begin(); it != item->peerIds.end(); it++) { - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PEERID, *it); + ok &= setRawPGPId(data, tlvsize, &offset, *it); } if(offset != tlvsize) @@ -1313,11 +1313,10 @@ RsPeerGroupItem *RsPeerConfigSerialiser::deserialiseGroup(void *data, uint32_t * ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->name); ok &= getRawUInt32(data, rssize, &offset, &(item->flag)); - std::string peerId; - while (offset != rssize) { - peerId.erase(); - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PEERID, peerId); + PGPIdType peerId; + while (offset != rssize) + { + ok &= getRawPGPId(data, rssize, &offset, peerId); item->peerIds.push_back(peerId); } diff --git a/libretroshare/src/serialiser/rshistoryitems.cc b/libretroshare/src/serialiser/rshistoryitems.cc index 023fdc81c..2ecbf591b 100644 --- a/libretroshare/src/serialiser/rshistoryitems.cc +++ b/libretroshare/src/serialiser/rshistoryitems.cc @@ -104,9 +104,9 @@ uint32_t RsHistorySerialiser::sizeHistoryMsgItem(RsHistoryMsgItem* item) { uint32_t s = 8; /* header */ s += 2; /* version */ - s += GetTlvStringSize(item->chatPeerId); + s += item->chatPeerId.serial_size(); s += 1; /* incoming */ - s += GetTlvStringSize(item->peerId); + s += item->peerId.serial_size(); s += GetTlvStringSize(item->peerName); s += 4; /* sendTime */ s += 4; /* recvTime */ @@ -140,10 +140,10 @@ bool RsHistorySerialiser::serialiseHistoryMsgItem(RsHistoryMsgItem* item, void* /* add mandatory parts first */ ok &= setRawUInt16(data, tlvsize, &offset, 0); // version - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_LOCATION, item->chatPeerId); + ok &= item->chatPeerId.serialise(data, tlvsize, offset) ; uint8_t dummy = item->incoming ? 1 : 0; ok &= setRawUInt8(data, tlvsize, &offset, dummy); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PEERID, item->peerId); + ok &= item->peerId.serialise(data, tlvsize, offset) ; ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, item->peerName); ok &= setRawUInt32(data, tlvsize, &offset, item->sendTime); ok &= setRawUInt32(data, tlvsize, &offset, item->recvTime); @@ -194,11 +194,11 @@ RsHistoryMsgItem *RsHistorySerialiser::deserialiseHistoryMsgItem(void *data, uin /* get mandatory parts first */ uint16_t version = 0; ok &= getRawUInt16(data, rssize, &offset, &version); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_LOCATION, item->chatPeerId); + ok &= item->chatPeerId.deserialise(data, rssize, offset) ; uint8_t dummy; ok &= getRawUInt8(data, rssize, &offset, &dummy); item->incoming = (dummy == 1); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PEERID, item->peerId); + ok &= item->peerId.deserialise(data, rssize, offset) ; ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->peerName); ok &= getRawUInt32(data, rssize, &offset, &(item->sendTime)); ok &= getRawUInt32(data, rssize, &offset, &(item->recvTime)); diff --git a/libretroshare/src/serialiser/rshistoryitems.h b/libretroshare/src/serialiser/rshistoryitems.h index fb194d8fa..039bf095f 100644 --- a/libretroshare/src/serialiser/rshistoryitems.h +++ b/libretroshare/src/serialiser/rshistoryitems.h @@ -28,6 +28,7 @@ #include "serialiser/rsserviceids.h" #include "serialiser/rsserial.h" +#include "retroshare/rstypes.h" /**************************************************************************/ @@ -40,9 +41,9 @@ public: virtual void clear(); std::ostream& print(std::ostream &out, uint16_t indent = 0); - std::string chatPeerId; // empty for global chat + RsPeerId chatPeerId; // empty for global chat bool incoming; - std::string peerId; + RsPeerId peerId; std::string peerName; uint32_t sendTime; uint32_t recvTime; diff --git a/libretroshare/src/serialiser/rsmsgitems.cc b/libretroshare/src/serialiser/rsmsgitems.cc index bd3ef1bcb..538f84f81 100644 --- a/libretroshare/src/serialiser/rsmsgitems.cc +++ b/libretroshare/src/serialiser/rsmsgitems.cc @@ -418,7 +418,7 @@ uint32_t RsPrivateChatMsgConfigItem::serial_size() { uint32_t s = 8; /* header */ s += 4; /* version */ - s += GetTlvStringSize(configPeerId); + s += configPeerId.serial_size(); s += 4; /* chatFlags */ s += 4; /* configFlags */ s += 4; /* sendTime */ @@ -432,7 +432,7 @@ uint32_t RsPrivateChatDistantInviteConfigItem::serial_size() uint32_t s = 8; /* header */ s += GetTlvStringSize(hash); s += GetTlvStringSize(encrypted_radix64_string); - s += GetTlvStringSize(destination_pgp_id); + s += destination_pgp_id.serial_size(); s += 16; /* aes_key */ s += 4; /* time_of_validity */ s += 4; /* last_hit_time */ @@ -807,7 +807,7 @@ bool RsPrivateChatMsgConfigItem::serialise(void *data, uint32_t& pktsize) /* add mandatory parts first */ ok &= setRawUInt32(data, tlvsize, &offset, 0); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PEERID, configPeerId); + ok &= configPeerId.serialise(data, tlvsize, offset) ; ok &= setRawUInt32(data, tlvsize, &offset, chatFlags); ok &= setRawUInt32(data, tlvsize, &offset, configFlags); ok &= setRawUInt32(data, tlvsize, &offset, sendTime); @@ -847,7 +847,7 @@ bool RsPrivateChatDistantInviteConfigItem::serialise(void *data, uint32_t& pktsi /* add mandatory parts first */ ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_KEY, hash); ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_LINK, encrypted_radix64_string); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GPGID, destination_pgp_id); + ok &= destination_pgp_id.serialise(data, tlvsize, offset); memcpy(&((unsigned char *)data)[offset],aes_key,16) ; offset += 16 ; @@ -1229,7 +1229,7 @@ RsPrivateChatMsgConfigItem::RsPrivateChatMsgConfigItem(void *data,uint32_t /*siz /* get mandatory parts first */ uint32_t version = 0; ok &= getRawUInt32(data, rssize, &offset, &version); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PEERID, configPeerId); + ok &= configPeerId.deserialise(data, rssize, offset); ok &= getRawUInt32(data, rssize, &offset, &chatFlags); ok &= getRawUInt32(data, rssize, &offset, &configFlags); ok &= getRawUInt32(data, rssize, &offset, &sendTime); @@ -1254,7 +1254,7 @@ RsPrivateChatDistantInviteConfigItem::RsPrivateChatDistantInviteConfigItem(void /* get mandatory parts first */ ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_KEY, hash); ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_LINK, encrypted_radix64_string); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_GPGID, destination_pgp_id); + ok &= destination_pgp_id.serialise(data, rssize, offset); memcpy(aes_key,&((unsigned char*)data)[offset],16) ; offset += 16 ; @@ -1296,7 +1296,7 @@ RsChatLobbyConfigItem::RsChatLobbyConfigItem(void *data,uint32_t /*size*/) } /* set data from RsChatMsgItem to RsPrivateChatMsgConfigItem */ -void RsPrivateChatMsgConfigItem::set(RsChatMsgItem *ci, const std::string &/*peerId*/, uint32_t confFlags) +void RsPrivateChatMsgConfigItem::set(RsChatMsgItem *ci, const RsPeerId& /*peerId*/, uint32_t confFlags) { PeerId(ci->PeerId()); configPeerId = ci->PeerId(); @@ -1982,7 +1982,7 @@ uint32_t RsMsgSrcId::serial_size(bool) uint32_t s = 8; /* header */ s += 4; - s += GetTlvStringSize(srcId); + s += srcId.serial_size() ; return s; } @@ -2011,7 +2011,7 @@ bool RsMsgSrcId::serialise(void *data, uint32_t& pktsize,bool config) offset += 8; ok &= setRawUInt32(data, tlvsize, &offset, msgId); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PEERID, srcId); + ok &= srcId.serialise(data, tlvsize, offset) ; if (offset != tlvsize) { @@ -2056,7 +2056,7 @@ RsMsgSrcId* RsMsgSerialiser::deserialiseMsgSrcIdItem(void* data, uint32_t* pktsi /* get mandatory parts first */ ok &= getRawUInt32(data, rssize, &offset, &(item->msgId)); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PEERID, item->srcId); + ok &= item->srcId.deserialise(data, rssize, offset); if (offset != rssize) { diff --git a/libretroshare/src/serialiser/rsmsgitems.h b/libretroshare/src/serialiser/rsmsgitems.h index 119e7a805..7d08ba317 100644 --- a/libretroshare/src/serialiser/rsmsgitems.h +++ b/libretroshare/src/serialiser/rsmsgitems.h @@ -28,6 +28,7 @@ #include +#include "retroshare/rstypes.h" #include "serialiser/rsserviceids.h" #include "serialiser/rsserial.h" #include "serialiser/rstlvtypes.h" @@ -308,11 +309,11 @@ class RsPrivateChatMsgConfigItem: public RsChatItem virtual uint32_t serial_size() ; // deserialise is handled using a constructor /* set data from RsChatMsgItem to RsPrivateChatMsgConfigItem */ - void set(RsChatMsgItem *ci, const std::string &peerId, uint32_t confFlags); + void set(RsChatMsgItem *ci, const RsPeerId &peerId, uint32_t confFlags); /* get data from RsPrivateChatMsgConfigItem to RsChatMsgItem */ void get(RsChatMsgItem *ci); - std::string configPeerId; + RsPeerId configPeerId; uint32_t chatFlags; uint32_t configFlags; uint32_t sendTime; @@ -335,7 +336,7 @@ class RsPrivateChatDistantInviteConfigItem: public RsChatItem unsigned char aes_key[16] ; std::string hash ; std::string encrypted_radix64_string ; - std::string destination_pgp_id ; + PGPIdType destination_pgp_id ; uint32_t time_of_validity ; uint32_t last_hit_time ; uint32_t flags ; @@ -545,7 +546,7 @@ class RsMsgSrcId : public RsMessageItem // uint32_t msgId; - std::string srcId; + RsPeerId srcId; }; class RsPublicMsgInviteConfigItem : public RsMessageItem { diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index 9602e1dcf..782a1538d 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -153,12 +153,12 @@ int p3ChatService::sendPublicChat(const std::string &msg) { /* go through all the peers */ - std::list ids; - std::list::iterator it; + std::list ids; + std::list::iterator it; mLinkMgr->getOnlineList(ids); /* add in own id -> so get reflection */ - std::string ownId = mLinkMgr->getOwnId(); + RsPeerId ownId = mLinkMgr->getOwnId(); ids.push_back(ownId); #ifdef CHAT_DEBUG @@ -184,7 +184,7 @@ int p3ChatService::sendPublicChat(const std::string &msg) #endif if (*it == ownId) { - mHistoryMgr->addMessage(false, "", ownId, ci); + mHistoryMgr->addMessage(false, RsPeerId(), ownId, ci); } sendItem(ci); } @@ -242,7 +242,7 @@ class p3ChatService::AvatarInfo void p3ChatService::sendGroupChatStatusString(const std::string& status_string) { - std::list ids; + std::list ids; mLinkMgr->getOnlineList(ids); #ifdef CHAT_DEBUG @@ -250,7 +250,7 @@ void p3ChatService::sendGroupChatStatusString(const std::string& status_string) std::cerr << std::endl; #endif - for(std::list::iterator it = ids.begin(); it != ids.end(); ++it) + for(std::list::iterator it = ids.begin(); it != ids.end(); ++it) { RsChatStatusItem *cs = new RsChatStatusItem ; @@ -263,7 +263,7 @@ void p3ChatService::sendGroupChatStatusString(const std::string& status_string) } } -void p3ChatService::sendStatusString( const std::string& id , const std::string& status_string) +void p3ChatService::sendStatusString( const RsPeerId& id , const std::string& status_string) { ChatLobbyId lobby_id ; if(isLobbyId(id,lobby_id)) @@ -291,8 +291,12 @@ void p3ChatService::sendPrivateChatItem(RsChatItem *item) { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ - if(_distant_chat_peers.find(item->PeerId()) != _distant_chat_peers.end()) - found = true ; + for(std::map::const_iterator it=_distant_chat_peers.begin();it!=_distant_chat_peers.end();++it) + if( it->second.virtual_peer_id == item->PeerId()) // _distant_chat_peers.find(item->PeerId()) !=_distant_chat_peers.end()) + { + found = true ; + break ; + } } if(found) @@ -363,7 +367,7 @@ void p3ChatService::checkSizeAndSendMessage(RsChatLobbyMsgItem *msg) sendItem(msg) ; } -bool p3ChatService::getVirtualPeerId(const ChatLobbyId& id,std::string& vpid) +bool p3ChatService::getVirtualPeerId(const ChatLobbyId& id,ChatLobbyVirtualPeerId& vpid) { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ @@ -409,7 +413,7 @@ void p3ChatService::locked_printDebugInfo() const std::cerr << " Participating friends: " << std::endl; - for(std::set::const_iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2) + for(std::set::const_iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2) std::cerr << " " << *it2 << std::endl; std::cerr << " Participating nick names: " << std::endl; @@ -421,7 +425,7 @@ void p3ChatService::locked_printDebugInfo() const std::cerr << "Recorded lobby names: " << std::endl; - for( std::map::const_iterator it(_lobby_ids.begin()) ;it!=_lobby_ids.end();++it) + for( std::map::const_iterator it(_lobby_ids.begin()) ;it!=_lobby_ids.end();++it) std::cerr << " \"" << it->first << "\" id = " << std::hex << it->second << std::dec << std::endl; std::cerr << "Visible public lobbies: " << std::endl; @@ -429,7 +433,7 @@ void p3ChatService::locked_printDebugInfo() const for( std::map::const_iterator it(_visible_lobbies.begin()) ;it!=_visible_lobbies.end();++it) { std::cerr << " " << std::hex << it->first << " name = " << std::dec << it->second.lobby_name << it->second.lobby_topic << std::endl; - for(std::set::const_iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2) + for(std::set::const_iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2) std::cerr << " With friend: " << *it2 << std::endl; } @@ -439,11 +443,11 @@ void p3ChatService::locked_printDebugInfo() const std::cerr << " \"" << std::hex << it->first << "\" flags = " << it->second << std::dec << std::endl; } -bool p3ChatService::isLobbyId(const std::string& virtual_peer_id,ChatLobbyId& lobby_id) +bool p3ChatService::isLobbyId(const RsPeerId& virtual_peer_id,ChatLobbyId& lobby_id) { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ - std::map::const_iterator it(_lobby_ids.find(virtual_peer_id)) ; + std::map::const_iterator it(_lobby_ids.find(virtual_peer_id)) ; if(it != _lobby_ids.end()) { @@ -455,20 +459,21 @@ bool p3ChatService::isLobbyId(const std::string& virtual_peer_id,ChatLobbyId& lo return false ; } -bool p3ChatService::isOnline(const std::string& id) +bool p3ChatService::isOnline(const RsPeerId& id) { // check if the id is a tunnel id or a peer id. uint32_t status ; - std::string pgp_id ; + PGPIdType pgp_id ; - if(!getDistantChatStatus(id,status,pgp_id)) + std::string hash ; + if(findHashForVirtualPeerId(id,hash) && getDistantChatStatus(hash,status,pgp_id)) + return true ; + else return mLinkMgr->isOnline(id) ; - - return true ; } -bool p3ChatService::sendPrivateChat(const std::string &id, const std::string &msg) +bool p3ChatService::sendPrivateChat(const RsPeerId &id, const std::string &msg) { // look into ID. Is it a peer, or a chat lobby? @@ -508,7 +513,7 @@ bool p3ChatService::sendPrivateChat(const std::string &id, const std::string { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ - std::map::iterator it = _avatars.find(id) ; + std::map::iterator it = _avatars.find(id) ; if(it == _avatars.end()) { @@ -543,7 +548,7 @@ bool p3ChatService::sendPrivateChat(const std::string &id, const std::string { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ - std::map::iterator it = _state_strings.find(id) ; + std::map::iterator it = _state_strings.find(id) ; if(it == _state_strings.end()) { @@ -575,7 +580,7 @@ bool p3ChatService::locked_checkAndRebuildPartialMessage_deprecated(RsChatMsgIte { // Check is the item is ending an incomplete item. // - std::map::iterator it = _pendingPartialMessages.find(ci->PeerId()) ; + std::map::iterator it = _pendingPartialMessages.find(ci->PeerId()) ; bool ci_is_incomplete = ci->chatFlags & RS_CHAT_FLAG_PARTIAL_MESSAGE ; @@ -720,14 +725,14 @@ class MsgCounter }; -bool p3ChatService::locked_bouncingObjectCheck(RsChatLobbyBouncingObject *obj,const std::string& peer_id,uint32_t lobby_count) +bool p3ChatService::locked_bouncingObjectCheck(RsChatLobbyBouncingObject *obj,const RsPeerId& peer_id,uint32_t lobby_count) { static std::map > message_counts ; std::ostringstream os ; os << obj->lobby_id ; - std::string pid = peer_id + "_" + os.str() ; + std::string pid = peer_id.toStdString() + "_" + os.str() ; // Check for the number of peers in the lobby. First look into visible lobbies, because the number // of peers there is more accurate. If non existant (because it's a private lobby), take the count from @@ -1079,7 +1084,7 @@ void p3ChatService::handleRecvChatAvatarItem(RsChatAvatarItem *ca) #ifdef CHAT_DEBUG std::cerr << "Received avatar data for peer " << ca->PeerId() << ". Notifying." << std::endl ; #endif - RsServer::notify()->notifyPeerHasNewAvatar(ca->PeerId()) ; + RsServer::notify()->notifyPeerHasNewAvatar(ca->PeerId().toStdString()) ; } bool p3ChatService::checkForMessageSecurity(RsChatMsgItem *ci) @@ -1131,7 +1136,7 @@ bool p3ChatService::checkForMessageSecurity(RsChatMsgItem *ci) // std::cout << "handleRecvChatMsgItem: " << ci->message << std::endl; std::cout << "**********" << std::endl; - std::cout << "********** entity attack by " << ci->PeerId().c_str() << std::endl; + std::cout << "********** entity attack by " << ci->PeerId().toStdString().c_str() << std::endl; std::cout << "**********" << std::endl; ci->message = "**** This message (from peer id " + rsPeers->getPeerName(ci->PeerId()) + ") has been removed because it contains the string \"lobby_id,virtual_peer_id) ; cli->PeerId(virtual_peer_id) ; name = cli->nick; @@ -1256,7 +1261,7 @@ bool p3ChatService::handleRecvChatMsgItem(RsChatMsgItem *ci) ci->chatFlags &= ~RS_CHAT_FLAG_AVATAR_AVAILABLE ; } - std::map::const_iterator it = _avatars.find(ci->PeerId()) ; + std::map::const_iterator it = _avatars.find(ci->PeerId()) ; #ifdef CHAT_DEBUG std::cerr << "p3chatservice:: avatar requested from above. " << std::endl ; @@ -1276,11 +1281,11 @@ bool p3ChatService::handleRecvChatMsgItem(RsChatMsgItem *ci) if (ci->chatFlags & RS_CHAT_FLAG_PRIVATE) { /* notify private chat message */ - RsServer::notify()->AddPopupMessage(popupChatFlag, ci->PeerId(), name, message); + RsServer::notify()->AddPopupMessage(popupChatFlag, ci->PeerId().toStdString(), name, message); } else { /* notify public chat message */ - RsServer::notify()->AddPopupMessage(RS_POPUP_GROUPCHAT, ci->PeerId(), "", message); - RsServer::notify()->AddFeedItem(RS_FEED_ITEM_CHAT_NEW, ci->PeerId(), message, ""); + RsServer::notify()->AddPopupMessage(RS_POPUP_GROUPCHAT, ci->PeerId().toStdString(), "", message); + RsServer::notify()->AddFeedItem(RS_FEED_ITEM_CHAT_NEW, ci->PeerId().toStdString(), message, ""); } { @@ -1303,7 +1308,7 @@ bool p3ChatService::handleRecvChatMsgItem(RsChatMsgItem *ci) if (ci->PeerId() != mLinkMgr->getOwnId()) { /* not from loop back */ - mHistoryMgr->addMessage(true, "", ci->PeerId(), ci); + mHistoryMgr->addMessage(true, RsPeerId(), ci->PeerId(), ci); } } } /* UNLOCK */ @@ -1331,7 +1336,7 @@ void p3ChatService::handleRecvChatStatusItem(RsChatStatusItem *cs) else if(cs->flags & RS_CHAT_FLAG_CUSTOM_STATE) // Check if new custom string is available at peer's. { // If so, send a request to get the custom string. receiveStateString(cs->PeerId(),cs->status_string) ; // store it - RsServer::notify()->notifyCustomState(cs->PeerId(), cs->status_string) ; + RsServer::notify()->notifyCustomState(cs->PeerId().toStdString(), cs->status_string) ; } else if(cs->flags & RS_CHAT_FLAG_CUSTOM_STATE_AVAILABLE) { @@ -1342,13 +1347,13 @@ void p3ChatService::handleRecvChatStatusItem(RsChatStatusItem *cs) } else if(cs->flags & RS_CHAT_FLAG_PRIVATE) { - RsServer::notify()->notifyChatStatus(cs->PeerId(),cs->status_string,true) ; + RsServer::notify()->notifyChatStatus(cs->PeerId().toStdString(),cs->status_string,true) ; if(cs->flags & RS_CHAT_FLAG_CLOSING_DISTANT_CONNECTION) markDistantChatAsClosed(cs->PeerId()) ; } else if(cs->flags & RS_CHAT_FLAG_PUBLIC) - RsServer::notify()->notifyChatStatus(cs->PeerId(),cs->status_string,false) ; + RsServer::notify()->notifyChatStatus(cs->PeerId().toStdString(),cs->status_string,false) ; } void p3ChatService::getListOfNearbyChatLobbies(std::vector& visible_lobbies) @@ -1366,10 +1371,10 @@ void p3ChatService::getListOfNearbyChatLobbies(std::vector MIN_DELAY_BETWEEN_PUBLIC_LOBBY_REQ + last_visible_lobby_info_request_time) { - std::list ids ; + std::list ids ; mLinkMgr->getOnlineList(ids); - for(std::list::const_iterator it(ids.begin());it!=ids.end();++it) + for(std::list::const_iterator it(ids.begin());it!=ids.end();++it) { #ifdef CHAT_DEBUG std::cerr << " asking list of public lobbies to " << *it << std::endl; @@ -1436,7 +1441,7 @@ int p3ChatService::getPrivateChatQueueCount(bool incoming) return privateOutgoingList.size(); } -bool p3ChatService::getPrivateChatQueueIds(bool incoming, std::list &ids) +bool p3ChatService::getPrivateChatQueueIds(bool incoming, std::list &ids) { ids.clear(); @@ -1467,7 +1472,7 @@ bool p3ChatService::getPrivateChatQueueIds(bool incoming, std::list return true; } -bool p3ChatService::getPrivateChatQueue(bool incoming, const std::string &id, std::list &chats) +bool p3ChatService::getPrivateChatQueue(bool incoming, const RsPeerId &id, std::list &chats) { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ @@ -1498,7 +1503,7 @@ bool p3ChatService::getPrivateChatQueue(bool incoming, const std::string &id, st return (chats.size() > 0); } -bool p3ChatService::clearPrivateChatQueue(bool incoming, const std::string &id) +bool p3ChatService::clearPrivateChatQueue(bool incoming, const RsPeerId &id) { bool changed = false; @@ -1569,7 +1574,7 @@ void p3ChatService::initRsChatInfo(RsChatMsgItem *c, ChatInfo &i) void p3ChatService::setOwnCustomStateString(const std::string& s) { - std::list onlineList; + std::list onlineList; { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ @@ -1578,7 +1583,7 @@ void p3ChatService::setOwnCustomStateString(const std::string& s) #endif _custom_status_string = s ; - for(std::map::iterator it(_state_strings.begin());it!=_state_strings.end();++it) + for(std::map::iterator it(_state_strings.begin());it!=_state_strings.end();++it) it->second._own_is_new = true ; mLinkMgr->getOnlineList(onlineList); @@ -1587,7 +1592,7 @@ void p3ChatService::setOwnCustomStateString(const std::string& s) RsServer::notify()->notifyOwnStatusMessageChanged() ; // alert your online peers to your newly set status - std::list::iterator it(onlineList.begin()); + std::list::iterator it(onlineList.begin()); for(; it != onlineList.end(); it++){ RsChatStatusItem *cs = new RsChatStatusItem(); @@ -1619,7 +1624,7 @@ void p3ChatService::setOwnAvatarJpegData(const unsigned char *data,int size) _own_avatar = new AvatarInfo(data,size) ; // set the info that our avatar is new, for all peers - for(std::map::iterator it(_avatars.begin());it!=_avatars.end();++it) + for(std::map::iterator it(_avatars.begin());it!=_avatars.end();++it) it->second->_own_is_new = true ; } IndicateConfigChanged(); @@ -1632,7 +1637,7 @@ void p3ChatService::setOwnAvatarJpegData(const unsigned char *data,int size) } -void p3ChatService::receiveStateString(const std::string& id,const std::string& s) +void p3ChatService::receiveStateString(const RsPeerId& id,const std::string& s) { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ #ifdef CHAT_DEBUG @@ -1696,13 +1701,13 @@ void p3ChatService::getOwnAvatarJpegData(unsigned char *& data,int& size) } } -std::string p3ChatService::getCustomStateString(const std::string& peer_id) +std::string p3ChatService::getCustomStateString(const RsPeerId& peer_id) { { // should be a Mutex here. RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ - std::map::iterator it = _state_strings.find(peer_id) ; + std::map::iterator it = _state_strings.find(peer_id) ; // has it. Return it strait away. // @@ -1717,13 +1722,13 @@ std::string p3ChatService::getCustomStateString(const std::string& peer_id) return std::string() ; } -void p3ChatService::getAvatarJpegData(const std::string& peer_id,unsigned char *& data,int& size) +void p3ChatService::getAvatarJpegData(const RsPeerId& peer_id,unsigned char *& data,int& size) { { // should be a Mutex here. RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ - std::map::const_iterator it = _avatars.find(peer_id) ; + std::map::const_iterator it = _avatars.find(peer_id) ; #ifdef CHAT_DEBUG std::cerr << "p3chatservice:: avatar for peer " << peer_id << " requested from above. " << std::endl ; @@ -1750,7 +1755,7 @@ void p3ChatService::getAvatarJpegData(const std::string& peer_id,unsigned char * sendAvatarRequest(peer_id); } -void p3ChatService::sendAvatarRequest(const std::string& peer_id) +void p3ChatService::sendAvatarRequest(const RsPeerId& peer_id) { // Doesn't have avatar. Request it. // @@ -1769,7 +1774,7 @@ void p3ChatService::sendAvatarRequest(const std::string& peer_id) sendPrivateChatItem(ci); } -void p3ChatService::sendCustomStateRequest(const std::string& peer_id){ +void p3ChatService::sendCustomStateRequest(const RsPeerId& peer_id){ RsChatStatusItem* cs = new RsChatStatusItem; @@ -1806,7 +1811,7 @@ RsChatAvatarItem *p3ChatService::makeOwnAvatarItem() } -void p3ChatService::sendAvatarJpegData(const std::string& peer_id) +void p3ChatService::sendAvatarJpegData(const RsPeerId& peer_id) { #ifdef CHAT_DEBUG std::cerr << "p3chatservice: sending requested for peer " << peer_id << ", data=" << (void*)_own_avatar << std::endl ; @@ -1833,7 +1838,7 @@ void p3ChatService::sendAvatarJpegData(const std::string& peer_id) } } -void p3ChatService::sendCustomState(const std::string& peer_id){ +void p3ChatService::sendCustomState(const RsPeerId& peer_id){ #ifdef CHAT_DEBUG std::cerr << "p3chatservice: sending requested status string for peer " << peer_id << std::endl ; @@ -1847,7 +1852,7 @@ std::cerr << "p3chatservice: sending requested status string for peer " << peer_ bool p3ChatService::loadList(std::list& load) { - std::list ssl_peers; + std::list ssl_peers; mLinkMgr->getFriendList(ssl_peers); for(std::list::const_iterator it(load.begin());it!=load.end();++it) @@ -2069,7 +2074,7 @@ void p3ChatService::statusChange(const std::list &plist) { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ - std::string ownId = mLinkMgr->getOwnId(); + RsPeerId ownId = mLinkMgr->getOwnId(); std::list::iterator cit = privateOutgoingList.begin(); while (cit != privateOutgoingList.end()) { @@ -2115,7 +2120,7 @@ void p3ChatService::statusChange(const std::list &plist) // true: the object is not a duplicate and should be used // false: the object is a duplicate or there is an error, and it should be destroyed. // -bool p3ChatService::bounceLobbyObject(RsChatLobbyBouncingObject *item,const std::string& peer_id) +bool p3ChatService::bounceLobbyObject(RsChatLobbyBouncingObject *item,const RsPeerId& peer_id) { time_t now = time(NULL) ; RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ @@ -2173,7 +2178,7 @@ bool p3ChatService::bounceLobbyObject(RsChatLobbyBouncingObject *item,const std: // Forward to allparticipating friends, except this peer. - for(std::set::const_iterator it(lobby.participating_friends.begin());it!=lobby.participating_friends.end();++it) + for(std::set::const_iterator it(lobby.participating_friends.begin());it!=lobby.participating_friends.end();++it) if((*it)!=peer_id && mLinkMgr->isOnline(*it)) { RsChatLobbyBouncingObject *obj2 = item->duplicate() ; // makes a copy @@ -2248,7 +2253,7 @@ void p3ChatService::sendLobbyStatusItem(const ChatLobbyId& lobby_id,int type,con item.string1 = status_string ; item.sendTime = time(NULL) ; } - std::string ownId = mLinkMgr->getOwnId(); + RsPeerId ownId = mLinkMgr->getOwnId(); bounceLobbyObject(&item,ownId) ; } @@ -2281,7 +2286,7 @@ bool p3ChatService::locked_initLobbyBouncableObject(const ChatLobbyId& lobby_id, return true ; } -bool p3ChatService::sendLobbyChat(const std::string &id, const std::string& msg, const ChatLobbyId& lobby_id) +bool p3ChatService::sendLobbyChat(const RsPeerId &id, const std::string& msg, const ChatLobbyId& lobby_id) { #ifdef CHAT_DEBUG std::cerr << "Sending chat lobby message to lobby " << std::hex << lobby_id << std::dec << std::endl; @@ -2306,7 +2311,7 @@ bool p3ChatService::sendLobbyChat(const std::string &id, const std::string& msg, item.message = msg; } - std::string ownId = rsPeers->getOwnId(); + RsPeerId ownId = rsPeers->getOwnId(); mHistoryMgr->addMessage(false, id, ownId, &item); @@ -2327,7 +2332,8 @@ void p3ChatService::handleConnectionChallenge(RsChatLobbyConnectChallengeItem *i time_t now = time(NULL) ; ChatLobbyId lobby_id ; - std::string ownId = rsPeers->getOwnId(); + const RsPeerId& ownId = rsPeers->getOwnId(); + bool found = false ; { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ @@ -2406,10 +2412,10 @@ void p3ChatService::sendConnectionChallenge(ChatLobbyId lobby_id) // Broadcast to all direct friends - std::list ids ; + std::list ids ; mLinkMgr->getOnlineList(ids); - for(std::list::const_iterator it(ids.begin());it!=ids.end();++it) + for(std::list::const_iterator it(ids.begin());it!=ids.end();++it) { RsChatLobbyConnectChallengeItem *item = new RsChatLobbyConnectChallengeItem ; @@ -2425,16 +2431,16 @@ void p3ChatService::sendConnectionChallenge(ChatLobbyId lobby_id) } } -uint64_t p3ChatService::makeConnexionChallengeCode(const std::string& peer_id,ChatLobbyId lobby_id,ChatLobbyMsgId msg_id) +uint64_t p3ChatService::makeConnexionChallengeCode(const RsPeerId& peer_id,ChatLobbyId lobby_id,ChatLobbyMsgId msg_id) { uint64_t result = 0 ; - for(uint32_t i=0;i> 35 ; result += result << 6 ; - result ^= peer_id[i] * lobby_id ; + result ^= peer_id.toByteArray()[i] * lobby_id ; result += result << 26 ; result ^= result >> 13 ; } @@ -2452,7 +2458,7 @@ void p3ChatService::getChatLobbyList(std::list& cl_infos) for(std::map::const_iterator it(_chat_lobbys.begin());it!=_chat_lobbys.end();++it) cl_infos.push_back(it->second) ; } -void p3ChatService::invitePeerToLobby(const ChatLobbyId& lobby_id, const std::string& peer_id,bool connexion_challenge) +void p3ChatService::invitePeerToLobby(const ChatLobbyId& lobby_id, const RsPeerId& peer_id,bool connexion_challenge) { #ifdef CHAT_DEBUG if(connexion_challenge) @@ -2623,12 +2629,13 @@ bool p3ChatService::acceptLobbyInvite(const ChatLobbyId& lobby_id) return true ; } -std::string p3ChatService::makeVirtualPeerId(ChatLobbyId lobby_id) +ChatLobbyVirtualPeerId p3ChatService::makeVirtualPeerId(ChatLobbyId lobby_id) { - std::string s; - rs_sprintf(s, "Chat Lobby 0x%llx", lobby_id); + uint8_t bytes[RsPeerId::SIZE_IN_BYTES] ; + memset(bytes,0,RsPeerId::SIZE_IN_BYTES) ; + memcpy(bytes,&lobby_id,sizeof(lobby_id)) ; - return s ; + return ChatLobbyVirtualPeerId(bytes) ; } @@ -2655,7 +2662,7 @@ bool p3ChatService::joinVisibleChatLobby(const ChatLobbyId& lobby_id) #ifdef CHAT_DEBUG std::cerr << "Joining public chat lobby " << std::hex << lobby_id << std::dec << std::endl; #endif - std::list invited_friends ; + std::list invited_friends ; { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ @@ -2702,7 +2709,7 @@ bool p3ChatService::joinVisibleChatLobby(const ChatLobbyId& lobby_id) _lobby_ids[entry.virtual_peer_id] = lobby_id ; - for(std::set::const_iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2) + for(std::set::const_iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2) { invited_friends.push_back(*it2) ; entry.participating_friends.insert(*it2) ; @@ -2710,7 +2717,7 @@ bool p3ChatService::joinVisibleChatLobby(const ChatLobbyId& lobby_id) _chat_lobbys[lobby_id] = entry ; } - for(std::list::const_iterator it(invited_friends.begin());it!=invited_friends.end();++it) + for(std::list::const_iterator it(invited_friends.begin());it!=invited_friends.end();++it) invitePeerToLobby(lobby_id,*it) ; RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ; @@ -2719,7 +2726,7 @@ bool p3ChatService::joinVisibleChatLobby(const ChatLobbyId& lobby_id) return true ; } -ChatLobbyId p3ChatService::createChatLobby(const std::string& lobby_name,const std::string& lobby_topic,const std::list& invited_friends,uint32_t privacy_level) +ChatLobbyId p3ChatService::createChatLobby(const std::string& lobby_name,const std::string& lobby_topic,const std::list& invited_friends,uint32_t privacy_level) { #ifdef CHAT_DEBUG std::cerr << "Creating a new Chat lobby !!" << std::endl; @@ -2754,7 +2761,7 @@ ChatLobbyId p3ChatService::createChatLobby(const std::string& lobby_name,const s _chat_lobbys[lobby_id] = entry ; } - for(std::list::const_iterator it(invited_friends.begin());it!=invited_friends.end();++it) + for(std::list::const_iterator it(invited_friends.begin());it!=invited_friends.end();++it) invitePeerToLobby(lobby_id,*it) ; RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ; @@ -2778,7 +2785,7 @@ void p3ChatService::handleFriendUnsubscribeLobby(RsChatLobbyUnsubscribeItem *ite return ; } - for(std::set::iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2) + for(std::set::iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2) if(*it2 == item->PeerId()) { #ifdef CHAT_DEBUG @@ -2811,7 +2818,7 @@ void p3ChatService::unsubscribeChatLobby(const ChatLobbyId& id) // send a lobby leaving packet to all friends - for(std::set::const_iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2) + for(std::set::const_iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2) { RsChatLobbyUnsubscribeItem *item = new RsChatLobbyUnsubscribeItem ; @@ -2833,7 +2840,7 @@ void p3ChatService::unsubscribeChatLobby(const ChatLobbyId& id) _chat_lobbys.erase(it) ; - for(std::map::iterator it2(_lobby_ids.begin());it2!=_lobby_ids.end();++it2) + for(std::map::iterator it2(_lobby_ids.begin());it2!=_lobby_ids.end();++it2) if(it2->second == id) { _lobby_ids.erase(it2) ; @@ -3065,7 +3072,7 @@ void p3ChatService::cleanLobbyCaches() sendConnectionChallenge(*it) ; } -bool p3ChatService::handleTunnelRequest(const std::string& hash,const std::string& /*peer_id*/) +bool p3ChatService::handleTunnelRequest(const std::string& hash,const RsPeerId& /*peer_id*/) { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ @@ -3156,7 +3163,7 @@ void p3ChatService::addVirtualPeer(const TurtleFileHash& hash,const TurtleVirtua cs->status_string = "Tunnel is working. You can talk!" ; cs->flags = RS_CHAT_FLAG_PRIVATE | RS_CHAT_FLAG_ACK_DISTANT_CONNECTION; - cs->PeerId(hash); + cs->PeerId(virtual_peer_id); { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ @@ -3201,7 +3208,7 @@ static void printBinaryData(void *data,uint32_t size) #endif void p3ChatService::receiveTurtleData( RsTurtleGenericTunnelItem *gitem,const std::string& hash, - const std::string& virtual_peer_id,RsTurtleGenericTunnelItem::Direction /*direction*/) + const RsPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction /*direction*/) { #ifdef DEBUG_DISTANT_CHAT std::cerr << "p3ChatService::receiveTurtleData(): Received turtle data. " << std::endl; @@ -3285,12 +3292,25 @@ void p3ChatService::receiveTurtleData( RsTurtleGenericTunnelItem *gitem,const st // Setup the virtual peer to be the origin, and pass it on. // - citem->PeerId(hash) ; + citem->PeerId(virtual_peer_id) ; //RsServer::notify()->notifyPeerStatusChanged(hash,RS_STATUS_ONLINE) ; handleIncomingItem(citem) ; // Treats the item, and deletes it } +bool p3ChatService::findHashForVirtualPeerId(const TurtleVirtualPeerId& vpid,std::string& hash) +{ + // Looks costly, but there's very few distant chat peers at a time, so this is not. + // + for(std::map::const_iterator it = _distant_chat_peers.begin();it!=_distant_chat_peers.end();++it) + if(it->second.virtual_peer_id == vpid) + { + hash = it->first ; + return true ; + } + return false ; +} + void p3ChatService::sendTurtleData(RsChatItem *item) { #ifdef DEBUG_DISTANT_CHAT @@ -3311,11 +3331,13 @@ void p3ChatService::sendTurtleData(RsChatItem *item) #endif uint8_t aes_key[DISTANT_CHAT_AES_KEY_SIZE] ; - std::string virtual_peer_id ; + RsPeerId virtual_peer_id = item->PeerId(); + TurtleFileHash hash ; + if(findHashForVirtualPeerId(virtual_peer_id,hash)) { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ - std::map::iterator it = _distant_chat_peers.find(item->PeerId()) ; + std::map::iterator it = _distant_chat_peers.find(hash) ; if(it == _distant_chat_peers.end()) { @@ -3324,9 +3346,14 @@ void p3ChatService::sendTurtleData(RsChatItem *item) return ; } it->second.last_contact = time(NULL) ; - virtual_peer_id = it->second.virtual_peer_id ; memcpy(aes_key,it->second.aes_key,DISTANT_CHAT_AES_KEY_SIZE) ; } + else + { + std::cerr << "(EE) p3ChatService::sendTurtleData(): virtual peer id " << virtual_peer_id << " is unknown!!" << std::endl; + delete[] buff ; + return ; + } #ifdef DEBUG_DISTANT_CHAT std::cerr << "p3ChatService::sendTurtleData(): tunnel found. Encrypting data." << std::endl; #endif @@ -3377,7 +3404,7 @@ void p3ChatService::sendTurtleData(RsChatItem *item) mTurtle->sendTurtleData(virtual_peer_id,gitem) ; } -bool p3ChatService::createDistantChatInvite(const std::string& pgp_id,time_t time_of_validity,std::string& encrypted_radix64_string) +bool p3ChatService::createDistantChatInvite(const PGPIdType& pgp_id,time_t time_of_validity,std::string& encrypted_radix64_string) { // create the invite @@ -3391,19 +3418,13 @@ bool p3ChatService::createDistantChatInvite(const std::string& pgp_id,time_t tim // Create a random hash for that invite. // - unsigned char hash_bytes[DISTANT_CHAT_HASH_SIZE] ; - RAND_bytes( hash_bytes, DISTANT_CHAT_HASH_SIZE) ; - - std::string hash = Sha1CheckSum(hash_bytes).toStdString(false) ; + std::string hash = Sha1CheckSum::random().toStdString() ; #ifdef DEBUG_DISTANT_CHAT std::cerr << "Created new distant chat invite: " << std::endl; std::cerr << " validity time stamp = " << invite.time_of_validity << std::endl; std::cerr << " hash = " << hash << std::endl; - std::cerr << " encryption key = " ; - static const char outl[16] = { '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f' } ; - for(uint32_t j = 0; j < 16; j++) { std::cerr << outl[ (invite.aes_key[j]>>4) ] ; std::cerr << outl[ invite.aes_key[j] & 0xf ] ; } - std::cerr << std::endl; + std::cerr << " encryption key = " << t_GenericIdType(invite.aes_key) << std::endl; #endif // Now encrypt the data to create the link info. We need @@ -3423,7 +3444,7 @@ bool p3ChatService::createDistantChatInvite(const std::string& pgp_id,time_t tim PGPIdType OwnId(AuthGPG::getAuthGPG()->getGPGOwnId()); - memcpy(data ,hash_bytes ,DISTANT_CHAT_HASH_SIZE) ; + memcpy(data ,Sha1CheckSum(hash).toByteArray(),DISTANT_CHAT_HASH_SIZE) ; memcpy(data+DISTANT_CHAT_HASH_SIZE ,invite.aes_key ,DISTANT_CHAT_AES_KEY_SIZE) ; memcpy(data+DISTANT_CHAT_HASH_SIZE+DISTANT_CHAT_AES_KEY_SIZE,OwnId.toByteArray(),PGP_KEY_ID_SIZE) ; @@ -3508,21 +3529,21 @@ bool p3ChatService::initiateDistantChatConnexion(const std::string& encrypted_st return false ; } - bool signature_checked = AuthGPG::getAuthGPG()->VerifySignBin(data,header_size,data+header_size,data_size-header_size,fingerprint.toStdString()) ; + bool signature_checked = AuthGPG::getAuthGPG()->VerifySignBin(data,header_size,data+header_size,data_size-header_size,fingerprint) ; #ifdef DEBUG_DISTANT_CHAT std::cerr << "Signature successfuly verified!" << std::endl; #endif - hash = Sha1CheckSum(data).toStdString(false) ; + hash = Sha1CheckSum(data).toStdString() ; - startClientDistantChatConnection(hash,pgp_id.toStdString(),data+DISTANT_CHAT_HASH_SIZE) ; + startClientDistantChatConnection(hash,pgp_id,data+DISTANT_CHAT_HASH_SIZE) ; // Finally, save the decrypted chat info, so that we can display some info in the GUI in case we want to re-use the link // DistantChatInvite dinvite ; dinvite.encrypted_radix64_string = "" ; // means that it's not issued by us - dinvite.destination_pgp_id = pgp_id.toStdString() ; + dinvite.destination_pgp_id = pgp_id; dinvite.time_of_validity = time_of_validity ; dinvite.last_hit_time = time(NULL) ; dinvite.flags = RS_DISTANT_CHAT_FLAG_SIGNED | (signature_checked ? RS_DISTANT_CHAT_FLAG_SIGNATURE_OK : 0) ; @@ -3555,7 +3576,7 @@ bool p3ChatService::initiateDistantChatConnexion(const std::string& encrypted_st bool p3ChatService::initiateDistantChatConnexion(const std::string& hash,uint32_t& error_code) { - std::string pgp_id ; + PGPIdType pgp_id ; unsigned char aes_key[DISTANT_CHAT_AES_KEY_SIZE] ; { @@ -3582,7 +3603,7 @@ bool p3ChatService::initiateDistantChatConnexion(const std::string& hash,uint32_ return true ; } -void p3ChatService::startClientDistantChatConnection(const std::string& hash,const std::string& pgp_id,const unsigned char *aes_key_buf) +void p3ChatService::startClientDistantChatConnection(const std::string& hash,const PGPIdType& pgp_id,const unsigned char *aes_key_buf) { DistantChatPeerInfo info ; @@ -3654,7 +3675,7 @@ bool p3ChatService::getDistantChatInviteList(std::vector& return true ; } -bool p3ChatService::getDistantChatStatus(const std::string& hash,uint32_t& status,std::string& pgp_id) +bool p3ChatService::getDistantChatStatus(const std::string& hash,uint32_t& status,PGPIdType& pgp_id) { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ @@ -3679,6 +3700,7 @@ bool p3ChatService::closeDistantChatConnexion(const std::string& hash) // - server needs to only close the window and let the tunnel die. But the window should only open if a message arrives. bool is_client = false ; + RsPeerId virtual_peer_id ; { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ @@ -3691,6 +3713,8 @@ bool p3ChatService::closeDistantChatConnexion(const std::string& hash) } if(it->second.direction == RsTurtleGenericTunnelItem::DIRECTION_SERVER) is_client = true ; + + virtual_peer_id = it->second.virtual_peer_id ; } if(is_client) @@ -3701,7 +3725,7 @@ bool p3ChatService::closeDistantChatConnexion(const std::string& hash) cs->status_string = "" ; cs->flags = RS_CHAT_FLAG_PRIVATE | RS_CHAT_FLAG_CLOSING_DISTANT_CONNECTION; - cs->PeerId(hash); + cs->PeerId(virtual_peer_id); sendTurtleData(cs) ; // that needs to be done off-mutex! @@ -3725,10 +3749,17 @@ bool p3ChatService::closeDistantChatConnexion(const std::string& hash) return true ; } -void p3ChatService::markDistantChatAsClosed(const std::string& hash) +void p3ChatService::markDistantChatAsClosed(const RsPeerId& vpid) { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ - std::map::iterator it = _distant_chat_peers.find(hash) ; + + std::string hash ; + if(!findHashForVirtualPeerId(vpid,hash)) + { + std::cerr << "Cannot mark distant chat as closed for vpid " << vpid << ": not found." << std::endl; + return ; + } + std::map::iterator it = _distant_chat_peers.find(hash) ; if(it == _distant_chat_peers.end()) // server side. Nothing to do. { @@ -3742,7 +3773,7 @@ void p3ChatService::markDistantChatAsClosed(const std::string& hash) bool p3ChatService::removeDistantChatInvite(const std::string& hash) { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ - std::map::iterator it = _distant_chat_invites.find(hash) ; + std::map::iterator it = _distant_chat_invites.find(hash) ; if(it == _distant_chat_invites.end()) // server side. Nothing to do. { diff --git a/libretroshare/src/services/p3chatservice.h b/libretroshare/src/services/p3chatservice.h index c95b12f16..2b2509a00 100644 --- a/libretroshare/src/services/p3chatservice.h +++ b/libretroshare/src/services/p3chatservice.h @@ -41,6 +41,8 @@ class p3LinkMgr; class p3HistoryMgr; class p3turtle ; +typedef RsPeerId ChatLobbyVirtualPeerId ; + //!The basic Chat service. /** * @@ -77,13 +79,13 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi * chat is sent to specifc peer * @param id peer to send chat msg to */ - bool sendPrivateChat(const std::string &id, const std::string &msg); + bool sendPrivateChat(const RsPeerId &id, const std::string &msg); /*! * can be used to send 'immediate' status msgs, these status updates are meant for immediate use by peer (not saved by rs) * e.g currently used to update user when a peer 'is typing' during a chat */ - void sendStatusString(const std::string& peer_id,const std::string& status_str) ; + void sendStatusString(const RsPeerId& peer_id,const std::string& status_str) ; /*! * send to all peers online @@ -95,7 +97,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi * this retrieves custom status for a peers, generate a requests to the peer * @param peer_id the id of the peer you want status string for */ - std::string getCustomStateString(const std::string& peer_id) ; + std::string getCustomStateString(const RsPeerId& peer_id) ; /*! * sets the client's custom status, generates 'status available' item sent to all online peers @@ -111,7 +113,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi * its avatar, if not already available. Creates a new unsigned char array. It's the caller's * responsibility to delete this ones used. */ - void getAvatarJpegData(const std::string& peer_id,unsigned char *& data,int& size) ; + void getAvatarJpegData(const RsPeerId& peer_id,unsigned char *& data,int& size) ; /*! * Sets the avatar data and size for client's account @@ -145,12 +147,12 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi /*! * @param id's of available private chat messages */ - bool getPrivateChatQueueIds(bool incoming, std::list &ids); + bool getPrivateChatQueueIds(bool incoming, std::list &ids); /*! * This retrieves all private chat msg items for peer */ - bool getPrivateChatQueue(bool incoming, const std::string &id, std::list &chats); + bool getPrivateChatQueue(bool incoming, const RsPeerId &id, std::list &chats); /*! * Checks message security, especially remove billion laughs attacks @@ -161,15 +163,15 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi /*! * @param clear private chat queue */ - bool clearPrivateChatQueue(bool incoming, const std::string &id); + bool clearPrivateChatQueue(bool incoming, const RsPeerId &id); - bool getVirtualPeerId(const ChatLobbyId& lobby_id, std::string& virtual_peer_id) ; - bool isLobbyId(const std::string& virtual_peer_id, ChatLobbyId& lobby_id) ; + bool getVirtualPeerId(const ChatLobbyId& lobby_id, RsPeerId& virtual_peer_id) ; + bool isLobbyId(const RsPeerId& virtual_peer_id, ChatLobbyId& lobby_id) ; void getChatLobbyList(std::list >& cl_infos) ; bool acceptLobbyInvite(const ChatLobbyId& id) ; void denyLobbyInvite(const ChatLobbyId& id) ; void getPendingChatLobbyInvites(std::list& invites) ; - void invitePeerToLobby(const ChatLobbyId&, const std::string& peer_id,bool connexion_challenge = false) ; + void invitePeerToLobby(const ChatLobbyId&, const RsPeerId& peer_id,bool connexion_challenge = false) ; void unsubscribeChatLobby(const ChatLobbyId& lobby_id) ; bool setNickNameForChatLobby(const ChatLobbyId& lobby_id,const std::string& nick) ; bool getNickNameForChatLobby(const ChatLobbyId& lobby_id,std::string& nick) ; @@ -178,7 +180,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi void setLobbyAutoSubscribe(const ChatLobbyId& lobby_id, const bool autoSubscribe); bool getLobbyAutoSubscribe(const ChatLobbyId& lobby_id); void sendLobbyStatusString(const ChatLobbyId& id,const std::string& status_string) ; - ChatLobbyId createChatLobby(const std::string& lobby_name,const std::string& lobby_topic, const std::list& invited_friends,uint32_t privacy_type) ; + ChatLobbyId createChatLobby(const std::string& lobby_name,const std::string& lobby_topic, const std::list& invited_friends,uint32_t privacy_type) ; void getListOfNearbyChatLobbies(std::vector& public_lobbies) ; bool joinVisibleChatLobby(const ChatLobbyId& id) ; @@ -194,7 +196,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi virtual void saveDone(); virtual bool loadList(std::list& load) ; - bool isOnline(const std::string& id) ; + bool isOnline(const RsPeerId& id) ; private: RsMutex mChatMtx; @@ -211,14 +213,14 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi void addTimeShiftStatistics(int shift) ; /// Send avatar info to peer in jpeg format. - void sendAvatarJpegData(const std::string& peer_id) ; + void sendAvatarJpegData(const RsPeerId& peer_id) ; /// Send custom state info to peer - void sendCustomState(const std::string& peer_id); + void sendCustomState(const RsPeerId& peer_id); /// Receive the avatar in a chat item, with RS_CHAT_RECEIVE_AVATAR flag. void receiveAvatarJpegData(RsChatAvatarItem *ci) ; // new method - void receiveStateString(const std::string& id,const std::string& s) ; + void receiveStateString(const RsPeerId& id,const std::string& s) ; /// methods for handling various Chat items. bool handleRecvChatMsgItem(RsChatMsgItem *item) ; // returns false if the item should be deleted. @@ -229,13 +231,13 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi void handleRecvChatLobbyEventItem(RsChatLobbyEventItem *item) ; /// Checks that the lobby object is not flooding a lobby. - bool locked_bouncingObjectCheck(RsChatLobbyBouncingObject *obj,const std::string& peer_id,uint32_t lobby_count) ; + bool locked_bouncingObjectCheck(RsChatLobbyBouncingObject *obj,const RsPeerId& peer_id,uint32_t lobby_count) ; /// Sends a request for an avatar to the peer of given id - void sendAvatarRequest(const std::string& peer_id) ; + void sendAvatarRequest(const RsPeerId& peer_id) ; /// Send a request for custom status string - void sendCustomStateRequest(const std::string& peer_id); + void sendCustomStateRequest(const RsPeerId& peer_id); /// called as a proxy to sendItem(). Possibly splits item into multiple items of size lower than the maximum item size. void checkSizeAndSendMessage(RsChatLobbyMsgItem *item) ; @@ -246,15 +248,15 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi bool locked_checkAndRebuildPartialMessage_deprecated(RsChatMsgItem*) ; /// receive and handle chat lobby item - bool recvLobbyChat(RsChatLobbyMsgItem*,const std::string& src_peer_id) ; - bool sendLobbyChat(const std::string &id, const std::string&, const ChatLobbyId&) ; + bool recvLobbyChat(RsChatLobbyMsgItem*,const RsPeerId& src_peer_id) ; + bool sendLobbyChat(const RsPeerId &id, const std::string&, const ChatLobbyId&) ; void handleRecvLobbyInvite(RsChatLobbyInviteItem*) ; void checkAndRedirectMsgToLobby(RsChatMsgItem*) ; void handleConnectionChallenge(RsChatLobbyConnectChallengeItem *item) ; void sendConnectionChallenge(ChatLobbyId id) ; void handleFriendUnsubscribeLobby(RsChatLobbyUnsubscribeItem*) ; void cleanLobbyCaches() ; - bool bounceLobbyObject(RsChatLobbyBouncingObject *obj, const std::string& peer_id) ; + bool bounceLobbyObject(RsChatLobbyBouncingObject *obj, const RsPeerId& peer_id) ; void sendLobbyStatusItem(const ChatLobbyId&, int type, const std::string& status_string) ; void sendLobbyStatusPeerLiving(const ChatLobbyId& lobby_id) ; @@ -265,8 +267,8 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi bool locked_initLobbyBouncableObject(const ChatLobbyId& id,RsChatLobbyBouncingObject&) ; - static std::string makeVirtualPeerId(ChatLobbyId) ; - static uint64_t makeConnexionChallengeCode(const std::string& peer_id,ChatLobbyId lobby_id,ChatLobbyMsgId msg_id) ; + static ChatLobbyVirtualPeerId makeVirtualPeerId(ChatLobbyId) ; + static uint64_t makeConnexionChallengeCode(const RsPeerId& peer_id,ChatLobbyId lobby_id,ChatLobbyMsgId msg_id) ; void locked_printDebugInfo() const ; RsChatAvatarItem *makeOwnAvatarItem() ; @@ -280,28 +282,28 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi std::list privateOutgoingList; AvatarInfo *_own_avatar ; - std::map _avatars ; - std::map _pendingPartialMessages ; + std::map _avatars ; + std::map _pendingPartialMessages ; std::map > _pendingPartialLobbyMessages ; // should be used for all chat msgs after version updgrade std::string _custom_status_string ; - std::map _state_strings ; + std::map _state_strings ; class ChatLobbyEntry: public ChatLobbyInfo { public: std::map msg_cache ; - std::string virtual_peer_id ; + RsPeerId virtual_peer_id ; int connexion_challenge_count ; time_t last_connexion_challenge_time ; time_t last_keep_alive_packet_time ; - std::set previously_known_peers ; + std::set previously_known_peers ; uint32_t flags ; }; std::map _chat_lobbys ; std::map _lobby_invites_queue ; std::map _visible_lobbies ; - std::map _lobby_ids ; + std::map _lobby_ids ; std::map _known_lobbies_flags ; // flags for all lobbies, including the ones that are not known. So we can't // store them in _chat_lobbies (subscribed lobbies) nor _visible_lobbies. // Known flags: @@ -325,21 +327,21 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi // 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. // - bool createDistantChatInvite(const std::string& pgp_id,time_t time_of_validity,TurtleFileHash& hash) ; + bool createDistantChatInvite(const PGPIdType& pgp_id,time_t time_of_validity,TurtleFileHash& hash) ; bool getDistantChatInviteList(std::vector& invites) ; bool initiateDistantChatConnexion(const std::string& encrypted_string,time_t time_of_validity,std::string& hash,uint32_t& error_code) ; // from encrypted data bool initiateDistantChatConnexion(const std::string& hash,uint32_t& error_code) ; // from known hash of a decrypted link bool closeDistantChatConnexion(const std::string& hash) ; bool removeDistantChatInvite(const std::string& hash) ; - virtual bool getDistantChatStatus(const std::string& hash,uint32_t& status,std::string& pgp_id) ; + virtual bool getDistantChatStatus(const std::string& hash,uint32_t& status,PGPIdType& pgp_id) ; private: struct DistantChatInvite { unsigned char aes_key[16] ; std::string encrypted_radix64_string ; - std::string destination_pgp_id ; + PGPIdType destination_pgp_id ; time_t time_of_validity ; time_t last_hit_time ; uint32_t flags ; @@ -349,8 +351,8 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi time_t last_contact ; // used to send keep alive packets unsigned char aes_key[16] ; // key to encrypt packets uint32_t status ; // info: do we have a tunnel ? - std::string virtual_peer_id; // given by the turtle router. Identifies the tunnel. - std::string pgp_id ; // pgp id of the peer we're talking to. + RsPeerId virtual_peer_id; // given by the turtle router. Identifies the tunnel. + PGPIdType pgp_id ; // pgp id of the peer we're talking to. RsTurtleGenericTunnelItem::Direction direction ; // specifiec wether we are client(managing the tunnel) or server. }; @@ -361,7 +363,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi // This maps contains the current peers to talk to with distant chat. // - std::map _distant_chat_peers ; + std::map _distant_chat_peers ; // List of items to be sent asap. Used to store items that we cannot pass directly to // sendTurtleData(), because of Mutex protection. @@ -370,12 +372,13 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi // Overloaded from RsTurtleClientService - virtual bool handleTunnelRequest(const std::string& hash,const std::string& peer_id) ; - virtual void receiveTurtleData(RsTurtleGenericTunnelItem *item,const std::string& hash,const std::string& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) ; + virtual bool handleTunnelRequest(const std::string& hash,const RsPeerId& peer_id) ; + virtual void receiveTurtleData(RsTurtleGenericTunnelItem *item,const std::string& hash,const RsPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) ; void addVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&,RsTurtleGenericTunnelItem::Direction dir) ; void removeVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&) ; - void markDistantChatAsClosed(const TurtleFileHash& hash) ; - void startClientDistantChatConnection(const std::string& hash,const std::string& pgp_id,const unsigned char *aes_key_buf) ; + void markDistantChatAsClosed(const TurtleVirtualPeerId& vpid) ; + void startClientDistantChatConnection(const std::string& hash,const PGPIdType& pgp_id,const unsigned char *aes_key_buf) ; + bool findHashForVirtualPeerId(const TurtleVirtualPeerId& pid,std::string& hash) ; // Utility functions diff --git a/libretroshare/src/services/p3msgservice.h b/libretroshare/src/services/p3msgservice.h index 91a81a0c3..e0e902a14 100644 --- a/libretroshare/src/services/p3msgservice.h +++ b/libretroshare/src/services/p3msgservice.h @@ -123,7 +123,7 @@ int checkOutgoingMessages(); struct DistantMessengingContact { time_t last_hit_time ; - std::string virtual_peer_id ; + RsPeerId virtual_peer_id ; uint32_t status ; bool pending_messages ; }; @@ -132,7 +132,7 @@ int checkOutgoingMessages(); void enableDistantMessaging(bool b) ; bool distantMessagingEnabled() ; - bool getDistantMessageHash(const std::string& pgp_id,std::string& hash) ; + bool getDistantMessageHash(const PGPIdType& pgp_id,std::string& hash) ; void sendPrivateMsgItem(RsMsgItem *) ; @@ -150,14 +150,14 @@ int checkOutgoingMessages(); #ifdef GROUTER virtual void receiveGRouterData(RsGRouterGenericDataItem *item, const GRouterKeyId& key) ; #endif - virtual bool handleTunnelRequest(const std::string& hash,const std::string& peer_id) ; - virtual void receiveTurtleData(RsTurtleGenericTunnelItem *item,const std::string& hash,const std::string& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) ; + virtual bool handleTunnelRequest(const std::string& hash,const RsPeerId& peer_id) ; + virtual void receiveTurtleData(RsTurtleGenericTunnelItem *item,const std::string& hash,const RsPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) ; void addVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&,RsTurtleGenericTunnelItem::Direction dir) ; void removeVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&) ; // Utility functions - bool encryptMessage(const std::string& pgp_id,RsMsgItem *msg) ; + bool encryptMessage(const PGPIdType& pgp_id,RsMsgItem *msg) ; void manageDistantPeers() ; void sendTurtleData(const std::string& hash,RsMsgItem *) ; @@ -181,7 +181,7 @@ bool checkAndRebuildPartialMessage(RsMsgItem*) ; void initRsMI(RsMsgItem *msg, MessageInfo &mi); void initRsMIS(RsMsgItem *msg, MsgInfoSummary &mis); -RsMsgItem *initMIRsMsg(MessageInfo &info, const std::string &to); +RsMsgItem *initMIRsMsg(MessageInfo &info, const RsPeerId &to); void initStandardTagTypes();