Enabled distant chat system.

Added system to collect and create chat invites from pgp keys.
Finished the GUI (some layouts need fixing, especially the link creation window).
Still needed: QoS on generic turtle data items. Will need a new item class for any anyway.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6433 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2013-06-16 14:39:44 +00:00
parent 94b78a8444
commit 69bf523c7a
18 changed files with 485 additions and 377 deletions

View file

@ -156,6 +156,7 @@ public:
#define RS_DISTANT_CHAT_ERROR_DECRYPTION_FAILED 0x0001
#define RS_DISTANT_CHAT_ERROR_SIGNATURE_MISMATCH 0x0002
#define RS_DISTANT_CHAT_ERROR_UNKNOWN_KEY 0x0003
#define RS_DISTANT_CHAT_ERROR_UNKNOWN_HASH 0x0004
class ChatInfo
{
@ -328,9 +329,11 @@ virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::str
virtual bool createDistantChatInvite(const std::string& pgp_id,time_t time_of_validity,std::string& encrypted_string) = 0 ;
virtual bool getDistantChatInviteList(std::vector<DistantChatInviteInfo>& invites) = 0;
virtual bool initiateDistantChatConnexion(const std::string& encrypted_string,std::string& hash,uint32_t& error_code) = 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 closeDistantChatConnexion(const std::string& hash) = 0;
virtual bool removeDistantChatInvite(const std::string& hash) = 0 ;
};

View file

@ -352,9 +352,13 @@ bool p3Msgs::getDistantChatInviteList(std::vector<DistantChatInviteInfo>& invite
{
return mChatSrv->getDistantChatInviteList(invites) ;
}
bool p3Msgs::initiateDistantChatConnexion(const std::string& encrypted_str,std::string& hash,uint32_t& error_code)
bool p3Msgs::initiateDistantChatConnexion(const std::string& encrypted_str,time_t validity_time,std::string& hash,uint32_t& error_code)
{
return mChatSrv->initiateDistantChatConnexion(encrypted_str,hash,error_code) ;
return mChatSrv->initiateDistantChatConnexion(encrypted_str,validity_time,hash,error_code) ;
}
bool p3Msgs::initiateDistantChatConnexion(const std::string& hash,uint32_t& error_code)
{
return mChatSrv->initiateDistantChatConnexion(hash,error_code) ;
}
bool p3Msgs::getDistantChatStatus(const std::string& hash,uint32_t& status,std::string& pgp_id)
{
@ -364,4 +368,8 @@ bool p3Msgs::closeDistantChatConnexion(const std::string& hash)
{
return mChatSrv->closeDistantChatConnexion(hash) ;
}
bool p3Msgs::removeDistantChatInvite(const std::string& hash)
{
return mChatSrv->removeDistantChatInvite(hash) ;
}

View file

@ -189,9 +189,11 @@ class p3Msgs: public RsMsgs
virtual bool createDistantChatInvite(const std::string& pgp_id,time_t time_of_validity,std::string& encrypted_string) ;
virtual bool getDistantChatInviteList(std::vector<DistantChatInviteInfo>& invites);
virtual bool initiateDistantChatConnexion(const std::string& encrypted_string,std::string& hash,uint32_t& error_code) ;
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 closeDistantChatConnexion(const std::string& hash) ;
virtual bool removeDistantChatInvite(const std::string& hash) ;
private:

View file

@ -49,6 +49,7 @@
* #define CHAT_DEBUG 1
* #define DEBUG_DISTANT_CHAT 1
****/
#define DEBUG_DISTANT_CHAT 1
static const int CONNECTION_CHALLENGE_MAX_COUNT = 20 ; // sends a connexion challenge every 20 messages
static const time_t CONNECTION_CHALLENGE_MAX_MSG_AGE = 30 ; // maximum age of a message to be used in a connexion challenge
@ -3233,10 +3234,8 @@ bool p3ChatService::createDistantChatInvite(const std::string& pgp_id,time_t tim
return true ;
}
bool p3ChatService::initiateDistantChatConnexion(const std::string& encrypted_str,std::string& hash,uint32_t& error_code)
bool p3ChatService::initiateDistantChatConnexion(const std::string& encrypted_str,time_t time_of_validity,std::string& hash,uint32_t& error_code)
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
// Un-radix the string.
//
char *encrypted_data_bin = NULL ;
@ -3283,19 +3282,87 @@ bool p3ChatService::initiateDistantChatConnexion(const std::string& encrypted_st
#ifdef DEBUG_DISTANT_CHAT
std::cerr << "Signature successfuly verified!" << std::endl;
#endif
hash = t_RsGenericIdType<DISTANT_CHAT_HASH_SIZE>(data).toStdString(false) ;
startClientDistantChatConnection(hash,pgp_id.toStdString(),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.time_of_validity = time_of_validity ;
dinvite.last_hit_time = time(NULL) ;
memcpy(dinvite.aes_key,data+DISTANT_CHAT_HASH_SIZE,DISTANT_CHAT_AES_KEY_SIZE) ;
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
_distant_chat_invites[hash] = dinvite ;
}
#ifdef DEBUG_DISTANT_CHAT
std::cerr << "Saving info for decrypted link, for later use:" << std::endl;
std::cerr << " destination pgp id: " << dinvite.destination_pgp_id << std::endl;
std::cerr << " validity : " << dinvite.time_of_validity << std::endl;
std::cerr << " last hit time : " << dinvite.last_hit_time << std::endl;
#endif
delete[] data ;
// And notify about chatting.
error_code = RS_DISTANT_CHAT_ERROR_NO_ERROR ;
getPqiNotify()->AddPopupMessage(RS_POPUP_CHAT, hash, "Distant peer", "Conversation starts...");
// Save config, since a new invite was added.
//
IndicateConfigChanged() ;
return true ;
}
bool p3ChatService::initiateDistantChatConnexion(const std::string& hash,uint32_t& error_code)
{
std::string pgp_id ;
unsigned char aes_key[DISTANT_CHAT_AES_KEY_SIZE] ;
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
std::map<std::string,DistantChatInvite>::iterator it = _distant_chat_invites.find(hash) ;
if(it == _distant_chat_invites.end())
{
error_code = RS_DISTANT_CHAT_ERROR_UNKNOWN_HASH ;
return false ;
}
it->second.last_hit_time = time(NULL) ;
pgp_id = it->second.destination_pgp_id;
memcpy(aes_key,it->second.aes_key,DISTANT_CHAT_AES_KEY_SIZE) ;
}
startClientDistantChatConnection(hash,pgp_id,aes_key) ;
getPqiNotify()->AddPopupMessage(RS_POPUP_CHAT, hash, "Distant peer", "Conversation starts...");
error_code = RS_DISTANT_CHAT_ERROR_NO_ERROR ;
return true ;
}
void p3ChatService::startClientDistantChatConnection(const std::string& hash,const std::string& pgp_id,const unsigned char *aes_key_buf)
{
DistantChatPeerInfo info ;
info.last_contact = time(NULL) ;
info.status = RS_DISTANT_CHAT_STATUS_TUNNEL_DN ;
info.pgp_id = pgp_id.toStdString() ;
info.pgp_id = pgp_id ;
info.direction = RsTurtleGenericTunnelItem::DIRECTION_SERVER ;
memcpy(info.aes_key,data+DISTANT_CHAT_HASH_SIZE,DISTANT_CHAT_AES_KEY_SIZE) ;
memcpy(info.aes_key,aes_key_buf,DISTANT_CHAT_AES_KEY_SIZE) ;
_distant_chat_peers[hash] = info ;
delete[] data ;
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
_distant_chat_peers[hash] = info ;
}
// Now ask the turtle router to manage a tunnel for that hash.
@ -3304,13 +3371,6 @@ bool p3ChatService::initiateDistantChatConnexion(const std::string& encrypted_st
#endif
mTurtle->monitorTunnels(hash,this) ;
// And notify about chatting.
error_code = RS_DISTANT_CHAT_ERROR_NO_ERROR ;
getPqiNotify()->AddPopupMessage(RS_POPUP_CHAT, hash, "Distant peer", "Conversation starts...");
return true ;
}
void p3ChatService::cleanDistantChatInvites()
@ -3445,7 +3505,23 @@ void p3ChatService::markDistantChatAsClosed(const std::string& hash)
it->second.status = RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED ;
}
bool p3ChatService::removeDistantChatInvite(const std::string& hash)
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
std::map<std::string,DistantChatInvite>::iterator it = _distant_chat_invites.find(hash) ;
if(it == _distant_chat_invites.end()) // server side. Nothing to do.
{
std::cerr << "Cannot find distant chat invite for hash " << hash << std::endl;
return false;
}
_distant_chat_invites.erase(it) ;
IndicateConfigChanged() ;
return true ;
}

View file

@ -312,8 +312,10 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi
//
bool createDistantChatInvite(const std::string& pgp_id,time_t time_of_validity,TurtleFileHash& hash) ;
bool getDistantChatInviteList(std::vector<DistantChatInviteInfo>& invites) ;
bool initiateDistantChatConnexion(const std::string& encrypted_string,std::string& hash,uint32_t& error_code) ;
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) ;
@ -352,6 +354,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi
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) ;
// Utility functions