mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
fixed GUI for distant chat: correct display of peer names, chat window on client shows up when chat is openned. Window on server only shows up when first message is received.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7688 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
8480d46eb5
commit
fd20f629dc
@ -45,7 +45,7 @@
|
||||
#include <retroshare/rsids.h>
|
||||
#include "distantchat.h"
|
||||
|
||||
#define DEBUG_DISTANT_CHAT
|
||||
//#define DEBUG_DISTANT_CHAT
|
||||
|
||||
void DistantChatService::connectToTurtleRouter(p3turtle *tr)
|
||||
{
|
||||
@ -250,11 +250,11 @@ void DistantChatService::addVirtualPeer(const TurtleFileHash& hash,const TurtleV
|
||||
//
|
||||
// privateIncomingList.push_back(item) ;
|
||||
|
||||
RsServer::notify()->AddPopupMessage(RS_POPUP_CHAT, virtual_peer_id.toStdString(), "Distant peer", "Conversation starts...");
|
||||
// RsServer::notify()->AddPopupMessage(RS_POPUP_CHAT, virtual_peer_id.toStdString(), "Distant peer", "Conversation starts...");
|
||||
|
||||
// Notify the GUI that the tunnel is up.
|
||||
//
|
||||
RsServer::notify()->notifyChatShow(virtual_peer_id.toStdString()) ;
|
||||
// RsServer::notify()->notifyChatShow(virtual_peer_id.toStdString()) ;
|
||||
}
|
||||
|
||||
void DistantChatService::removeVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualPeerId& virtual_peer_id)
|
||||
@ -610,7 +610,7 @@ bool DistantChatService::locked_sendDHPublicKey(const DistantChatPeerInfo& pinfo
|
||||
|
||||
dhitem->signature = signature ;
|
||||
dhitem->gxs_key = signature_key_public ;
|
||||
dhitem->PeerId(RsPeerId(pinfo.gxs_id)) ;
|
||||
dhitem->PeerId(RsPeerId(pinfo.virtual_peer_id)) ; // special case for DH items
|
||||
|
||||
#ifdef DEBUG_DISTANT_CHAT
|
||||
std::cerr << " Pushing DH session key item to pending distant messages..." << std::endl;
|
||||
@ -680,23 +680,55 @@ void DistantChatService::sendTurtleData(RsChatItem *item)
|
||||
#endif
|
||||
|
||||
uint8_t aes_key[DISTANT_CHAT_AES_KEY_SIZE] ;
|
||||
|
||||
TurtleFileHash hash = hashFromGxsId(RsGxsId(item->PeerId())) ;
|
||||
uint64_t IV ;
|
||||
TurtleVirtualPeerId virtual_peer_id ;
|
||||
|
||||
if(dynamic_cast<RsChatDHPublicKeyItem*>(item))
|
||||
{
|
||||
#ifdef DEBUG_DISTANT_CHAT
|
||||
std::cerr << " Packet is a DH session key. Using Peer Id " << item->PeerId() << " as virtual peer id" << std::endl;
|
||||
#endif
|
||||
RsStackMutex stack(mDistantChatMtx); /********** STACK LOCKED MTX ******/
|
||||
std::map<TurtleFileHash,DistantChatPeerInfo>::iterator it = _distant_chat_peers.find(hash) ;
|
||||
for(std::map<TurtleFileHash,DistantChatPeerInfo>::iterator it = _distant_chat_peers.begin();it!=_distant_chat_peers.end();++it)
|
||||
if(it->second.virtual_peer_id == item->PeerId())
|
||||
{
|
||||
it->second.last_contact = time(NULL) ;
|
||||
break ;
|
||||
}
|
||||
|
||||
if(it == _distant_chat_peers.end())
|
||||
virtual_peer_id = item->PeerId() ;
|
||||
|
||||
#ifdef DEBUG_DISTANT_CHAT
|
||||
std::cerr << " Special item DH session key --> will be sent unencrypted." << std::endl ;
|
||||
#endif
|
||||
memset(aes_key,0,DISTANT_CHAT_AES_KEY_SIZE) ;
|
||||
IV = 0 ;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DEBUG_DISTANT_CHAT
|
||||
std::cerr << " Packet is a normal chat message. Sending to GXS id " << item->PeerId() << std::endl;
|
||||
#endif
|
||||
bool found = false ;
|
||||
|
||||
RsStackMutex stack(mDistantChatMtx); /********** STACK LOCKED MTX ******/
|
||||
for(std::map<TurtleFileHash,DistantChatPeerInfo>::iterator it = _distant_chat_peers.begin();it!=_distant_chat_peers.end();++it)
|
||||
if(it->second.gxs_id == RsGxsId(item->PeerId()))
|
||||
{
|
||||
it->second.last_contact = time(NULL) ;
|
||||
memcpy(aes_key,it->second.aes_key,DISTANT_CHAT_AES_KEY_SIZE) ;
|
||||
virtual_peer_id = it->second.virtual_peer_id ;
|
||||
IV = RSRandom::random_u64() ; // make a random 8 bytes IV
|
||||
found = true ;
|
||||
break ;
|
||||
}
|
||||
|
||||
if(!found)
|
||||
{
|
||||
std::cerr << "(EE) No distant chat info for peer id = " << item->PeerId() << ". Dropping the item!" << std::endl;
|
||||
delete[] buff ;
|
||||
return ;
|
||||
}
|
||||
it->second.last_contact = time(NULL) ;
|
||||
memcpy(aes_key,it->second.aes_key,DISTANT_CHAT_AES_KEY_SIZE) ;
|
||||
virtual_peer_id = it->second.virtual_peer_id ;
|
||||
}
|
||||
#ifdef DEBUG_DISTANT_CHAT
|
||||
std::cerr << "DistantChatService::sendTurtleData(): tunnel found. Encrypting data." << std::endl;
|
||||
@ -706,16 +738,6 @@ void DistantChatService::sendTurtleData(RsChatItem *item)
|
||||
//
|
||||
uint8_t *encrypted_data = new uint8_t[RsAES::get_buffer_size(rssize)];
|
||||
uint32_t encrypted_size = RsAES::get_buffer_size(rssize);
|
||||
uint64_t IV = RSRandom::random_u64() ; // make a random 8 bytes IV
|
||||
|
||||
if(dynamic_cast<RsChatDHPublicKeyItem*>(item) != NULL)
|
||||
{
|
||||
memset(aes_key,0,16) ;
|
||||
IV = 0 ;
|
||||
#ifdef DEBUG_DISTANT_CHAT
|
||||
std::cerr << " Special item DH session key --> will be sent unencrypted." << std::endl ;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef DEBUG_DISTANT_CHAT
|
||||
std::cerr << " Using IV: " << std::hex << IV << std::dec << std::endl;
|
||||
@ -773,8 +795,15 @@ bool DistantChatService::initiateDistantChatConnexion(const RsGxsId& gxs_id,uint
|
||||
|
||||
//
|
||||
startClientDistantChatConnection(hash,gxs_id,own_gxs_id) ;
|
||||
|
||||
error_code = RS_DISTANT_CHAT_ERROR_NO_ERROR ;
|
||||
|
||||
// spawn a status item so as to open the chat window.
|
||||
RsChatMsgItem *item = new RsChatMsgItem;
|
||||
item->message = "Starting distant chat. Please wait for secure tunnel to be established." ;
|
||||
item->chatFlags = RS_CHAT_FLAG_PRIVATE ;
|
||||
item->PeerId(RsPeerId(gxs_id)) ;
|
||||
handleRecvChatMsgItem(item) ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
@ -805,20 +834,6 @@ void DistantChatService::startClientDistantChatConnection(const RsFileHash& hash
|
||||
mTurtle->monitorTunnels(hash,this) ;
|
||||
}
|
||||
|
||||
// DistantChatPeerId DistantChatService::virtualPeerIdFromHash(const TurtleFileHash& hash)
|
||||
// {
|
||||
// RsStackMutex stack(mDistantChatMtx); /********** STACK LOCKED MTX ******/
|
||||
//
|
||||
// std::map<TurtleFileHash,DistantChatPeerInfo>::const_iterator it = _distant_chat_peers.find(hash) ;
|
||||
//
|
||||
// if(it == _distant_chat_peers.end())
|
||||
// {
|
||||
// std::cerr << " (EE) Cannot find hash " << hash << " in distant peers list. Virtual peer id cannot be returned." << std::endl;
|
||||
// return DistantChatPeerId() ;
|
||||
// }
|
||||
// else
|
||||
// return it->second.virtual_peer_id ;
|
||||
// }
|
||||
TurtleFileHash DistantChatService::hashFromGxsId(const RsGxsId& gid)
|
||||
{
|
||||
if(RsGxsId::SIZE_IN_BYTES > Sha1CheckSum::SIZE_IN_BYTES)
|
||||
|
@ -56,6 +56,7 @@ class DistantChatService: public RsTurtleClientService
|
||||
|
||||
// derived in p3ChatService
|
||||
virtual void handleIncomingItem(RsItem *) = 0;
|
||||
virtual bool handleRecvChatMsgItem(RsChatMsgItem *ci)=0 ;
|
||||
|
||||
bool handleOutgoingItem(RsChatItem *) ;
|
||||
bool handleRecvItem(RsChatItem *) ;
|
||||
|
@ -224,8 +224,7 @@ void ChatWidget::init(const RsPeerId &peerId, const QString &title)
|
||||
mChatType = CHATTYPE_LOBBY;
|
||||
} else {
|
||||
uint32_t status;
|
||||
RsGxsId gxs_id;
|
||||
if (rsMsgs->getDistantChatStatus(peerId, gxs_id, status)) {
|
||||
if (rsMsgs->getDistantChatStatus(RsGxsId(peerId), status)) {
|
||||
mChatType = CHATTYPE_DISTANT;
|
||||
} else {
|
||||
mChatType = CHATTYPE_PRIVATE;
|
||||
@ -1299,15 +1298,14 @@ void ChatWidget::updateStatus(const QString &peer_id, int status)
|
||||
|
||||
QString peerName ;
|
||||
uint32_t stts ;
|
||||
RsGxsId gxs_id ;
|
||||
|
||||
if(rsMsgs->getDistantChatStatus(peerId,gxs_id,stts))
|
||||
if(rsMsgs->getDistantChatStatus(RsGxsId(peerId),stts))
|
||||
{
|
||||
RsIdentityDetails details ;
|
||||
if(rsIdentity->getIdDetails(gxs_id,details))
|
||||
if(rsIdentity->getIdDetails(RsGxsId(peerId),details))
|
||||
peerName = QString::fromUtf8( details.mNickname.c_str() ) ;
|
||||
else
|
||||
peerName = QString::fromStdString(gxs_id.toStdString()) ;
|
||||
peerName = QString::fromStdString(peerId.toStdString()) ;
|
||||
}
|
||||
else
|
||||
peerName = QString::fromUtf8(rsPeers->getPeerName(peerId).c_str());
|
||||
|
@ -138,12 +138,10 @@ void PopupDistantChatDialog::closeEvent(QCloseEvent *e)
|
||||
PopupChatDialog::closeEvent(e) ;
|
||||
}
|
||||
|
||||
QString PopupDistantChatDialog::getPeerName(const RsGxsId& id) const
|
||||
QString PopupDistantChatDialog::getPeerName(const RsPeerId& id) const
|
||||
{
|
||||
uint32_t status ;
|
||||
|
||||
if(rsMsgs->getDistantChatStatus(id,status))
|
||||
{
|
||||
RsIdentityDetails details ;
|
||||
|
||||
if(rsIdentity->getIdDetails(RsGxsId(id),details))
|
||||
@ -151,7 +149,4 @@ QString PopupDistantChatDialog::getPeerName(const RsGxsId& id) const
|
||||
else
|
||||
return QString::fromStdString(id.toStdString()) ;
|
||||
}
|
||||
else
|
||||
return ChatDialog::getPeerName(RsPeerId(id)) ;
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ class PopupDistantChatDialog: public PopupChatDialog
|
||||
virtual void init(const RsPeerId &pid, const QString &title);
|
||||
virtual void closeEvent(QCloseEvent *e) ;
|
||||
|
||||
virtual QString getPeerName(const RsGxsId &id) const ;
|
||||
virtual QString getPeerName(const RsPeerId &id) const ;
|
||||
|
||||
protected slots:
|
||||
void updateDisplay() ; // overloads RsAutoUpdatePage
|
||||
|
Loading…
Reference in New Issue
Block a user