mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-21 21:04:32 -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
5 changed files with 139 additions and 130 deletions
|
@ -45,7 +45,7 @@
|
||||||
#include <retroshare/rsids.h>
|
#include <retroshare/rsids.h>
|
||||||
#include "distantchat.h"
|
#include "distantchat.h"
|
||||||
|
|
||||||
#define DEBUG_DISTANT_CHAT
|
//#define DEBUG_DISTANT_CHAT
|
||||||
|
|
||||||
void DistantChatService::connectToTurtleRouter(p3turtle *tr)
|
void DistantChatService::connectToTurtleRouter(p3turtle *tr)
|
||||||
{
|
{
|
||||||
|
@ -250,11 +250,11 @@ void DistantChatService::addVirtualPeer(const TurtleFileHash& hash,const TurtleV
|
||||||
//
|
//
|
||||||
// privateIncomingList.push_back(item) ;
|
// 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.
|
// 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)
|
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->signature = signature ;
|
||||||
dhitem->gxs_key = signature_key_public ;
|
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
|
#ifdef DEBUG_DISTANT_CHAT
|
||||||
std::cerr << " Pushing DH session key item to pending distant messages..." << std::endl;
|
std::cerr << " Pushing DH session key item to pending distant messages..." << std::endl;
|
||||||
|
@ -680,23 +680,55 @@ void DistantChatService::sendTurtleData(RsChatItem *item)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint8_t aes_key[DISTANT_CHAT_AES_KEY_SIZE] ;
|
uint8_t aes_key[DISTANT_CHAT_AES_KEY_SIZE] ;
|
||||||
|
uint64_t IV ;
|
||||||
TurtleFileHash hash = hashFromGxsId(RsGxsId(item->PeerId())) ;
|
|
||||||
TurtleVirtualPeerId virtual_peer_id ;
|
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 ******/
|
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;
|
std::cerr << "(EE) No distant chat info for peer id = " << item->PeerId() << ". Dropping the item!" << std::endl;
|
||||||
delete[] buff ;
|
delete[] buff ;
|
||||||
return ;
|
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
|
#ifdef DEBUG_DISTANT_CHAT
|
||||||
std::cerr << "DistantChatService::sendTurtleData(): tunnel found. Encrypting data." << std::endl;
|
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)];
|
uint8_t *encrypted_data = new uint8_t[RsAES::get_buffer_size(rssize)];
|
||||||
uint32_t encrypted_size = 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
|
#ifdef DEBUG_DISTANT_CHAT
|
||||||
std::cerr << " Using IV: " << std::hex << IV << std::dec << std::endl;
|
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) ;
|
startClientDistantChatConnection(hash,gxs_id,own_gxs_id) ;
|
||||||
|
|
||||||
error_code = RS_DISTANT_CHAT_ERROR_NO_ERROR ;
|
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 ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -805,20 +834,6 @@ void DistantChatService::startClientDistantChatConnection(const RsFileHash& hash
|
||||||
mTurtle->monitorTunnels(hash,this) ;
|
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)
|
TurtleFileHash DistantChatService::hashFromGxsId(const RsGxsId& gid)
|
||||||
{
|
{
|
||||||
if(RsGxsId::SIZE_IN_BYTES > Sha1CheckSum::SIZE_IN_BYTES)
|
if(RsGxsId::SIZE_IN_BYTES > Sha1CheckSum::SIZE_IN_BYTES)
|
||||||
|
|
|
@ -36,7 +36,7 @@ static const uint32_t DISTANT_CHAT_AES_KEY_SIZE = 16 ;
|
||||||
|
|
||||||
class DistantChatService: public RsTurtleClientService
|
class DistantChatService: public RsTurtleClientService
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DistantChatService(p3IdService *pids)
|
DistantChatService(p3IdService *pids)
|
||||||
: mIdService(pids), mDistantChatMtx("distant chat")
|
: mIdService(pids), mDistantChatMtx("distant chat")
|
||||||
{
|
{
|
||||||
|
@ -56,12 +56,13 @@ class DistantChatService: public RsTurtleClientService
|
||||||
|
|
||||||
// derived in p3ChatService
|
// derived in p3ChatService
|
||||||
virtual void handleIncomingItem(RsItem *) = 0;
|
virtual void handleIncomingItem(RsItem *) = 0;
|
||||||
|
virtual bool handleRecvChatMsgItem(RsChatMsgItem *ci)=0 ;
|
||||||
|
|
||||||
bool handleOutgoingItem(RsChatItem *) ;
|
bool handleOutgoingItem(RsChatItem *) ;
|
||||||
bool handleRecvItem(RsChatItem *) ;
|
bool handleRecvItem(RsChatItem *) ;
|
||||||
void handleRecvChatStatusItem(RsChatStatusItem *cs) ;
|
void handleRecvChatStatusItem(RsChatStatusItem *cs) ;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class DistantChatPeerInfo
|
class DistantChatPeerInfo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -224,8 +224,7 @@ void ChatWidget::init(const RsPeerId &peerId, const QString &title)
|
||||||
mChatType = CHATTYPE_LOBBY;
|
mChatType = CHATTYPE_LOBBY;
|
||||||
} else {
|
} else {
|
||||||
uint32_t status;
|
uint32_t status;
|
||||||
RsGxsId gxs_id;
|
if (rsMsgs->getDistantChatStatus(RsGxsId(peerId), status)) {
|
||||||
if (rsMsgs->getDistantChatStatus(peerId, gxs_id, status)) {
|
|
||||||
mChatType = CHATTYPE_DISTANT;
|
mChatType = CHATTYPE_DISTANT;
|
||||||
} else {
|
} else {
|
||||||
mChatType = CHATTYPE_PRIVATE;
|
mChatType = CHATTYPE_PRIVATE;
|
||||||
|
@ -1299,15 +1298,14 @@ void ChatWidget::updateStatus(const QString &peer_id, int status)
|
||||||
|
|
||||||
QString peerName ;
|
QString peerName ;
|
||||||
uint32_t stts ;
|
uint32_t stts ;
|
||||||
RsGxsId gxs_id ;
|
|
||||||
|
|
||||||
if(rsMsgs->getDistantChatStatus(peerId,gxs_id,stts))
|
if(rsMsgs->getDistantChatStatus(RsGxsId(peerId),stts))
|
||||||
{
|
{
|
||||||
RsIdentityDetails details ;
|
RsIdentityDetails details ;
|
||||||
if(rsIdentity->getIdDetails(gxs_id,details))
|
if(rsIdentity->getIdDetails(RsGxsId(peerId),details))
|
||||||
peerName = QString::fromUtf8( details.mNickname.c_str() ) ;
|
peerName = QString::fromUtf8( details.mNickname.c_str() ) ;
|
||||||
else
|
else
|
||||||
peerName = QString::fromStdString(gxs_id.toStdString()) ;
|
peerName = QString::fromStdString(peerId.toStdString()) ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
peerName = QString::fromUtf8(rsPeers->getPeerName(peerId).c_str());
|
peerName = QString::fromUtf8(rsPeers->getPeerName(peerId).c_str());
|
||||||
|
|
|
@ -138,20 +138,15 @@ void PopupDistantChatDialog::closeEvent(QCloseEvent *e)
|
||||||
PopupChatDialog::closeEvent(e) ;
|
PopupChatDialog::closeEvent(e) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PopupDistantChatDialog::getPeerName(const RsGxsId& id) const
|
QString PopupDistantChatDialog::getPeerName(const RsPeerId& id) const
|
||||||
{
|
{
|
||||||
uint32_t status ;
|
uint32_t status ;
|
||||||
|
|
||||||
if(rsMsgs->getDistantChatStatus(id,status))
|
|
||||||
{
|
|
||||||
RsIdentityDetails details ;
|
RsIdentityDetails details ;
|
||||||
|
|
||||||
if(rsIdentity->getIdDetails(RsGxsId(id),details))
|
if(rsIdentity->getIdDetails(RsGxsId(id),details))
|
||||||
return QString::fromUtf8( details.mNickname.c_str() ) ;
|
return QString::fromUtf8( details.mNickname.c_str() ) ;
|
||||||
else
|
else
|
||||||
return QString::fromStdString(id.toStdString()) ;
|
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 init(const RsPeerId &pid, const QString &title);
|
||||||
virtual void closeEvent(QCloseEvent *e) ;
|
virtual void closeEvent(QCloseEvent *e) ;
|
||||||
|
|
||||||
virtual QString getPeerName(const RsGxsId &id) const ;
|
virtual QString getPeerName(const RsPeerId &id) const ;
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void updateDisplay() ; // overloads RsAutoUpdatePage
|
void updateDisplay() ; // overloads RsAutoUpdatePage
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue