mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
improved the logic in distant chat. Now all traffic is referred to by the GXS id of the contact instead of virtual peer id which would change with tunnel route. Work still needed to fix up the GUI
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7687 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
b4ee877c64
commit
8480d46eb5
@ -83,7 +83,7 @@ bool DistantChatService::handleRecvItem(RsChatItem *item)
|
||||
bool DistantChatService::handleOutgoingItem(RsChatItem *item)
|
||||
{
|
||||
for(std::map<TurtleFileHash,DistantChatPeerInfo>::const_iterator it=_distant_chat_peers.begin();it!=_distant_chat_peers.end();++it)
|
||||
if( it->second.virtual_peer_id == item->PeerId())
|
||||
if( it->second.gxs_id == RsGxsId(item->PeerId()))
|
||||
{
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "p3ChatService::sendPrivateChatItem(): sending to " << item->PeerId() << ": interpreted as a distant chat virtual peer id." << std::endl;
|
||||
@ -98,7 +98,7 @@ bool DistantChatService::handleOutgoingItem(RsChatItem *item)
|
||||
void DistantChatService::handleRecvChatStatusItem(RsChatStatusItem *cs)
|
||||
{
|
||||
if(cs->flags & RS_CHAT_FLAG_CLOSING_DISTANT_CONNECTION)
|
||||
markDistantChatAsClosed(cs->PeerId()) ;
|
||||
markDistantChatAsClosed(RsGxsId(cs->PeerId())) ;
|
||||
}
|
||||
|
||||
bool DistantChatService::getHashFromVirtualPeerId(const TurtleVirtualPeerId& vpid,TurtleFileHash& hash)
|
||||
@ -173,28 +173,28 @@ void DistantChatService::addVirtualPeer(const TurtleFileHash& hash,const TurtleV
|
||||
}
|
||||
|
||||
if(dir == RsTurtleGenericTunnelItem::DIRECTION_CLIENT)
|
||||
{
|
||||
RsStackMutex stack(mDistantChatMtx); /********** STACK LOCKED MTX ******/
|
||||
{
|
||||
RsStackMutex stack(mDistantChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
#ifdef DEBUG_DISTANT_CHAT
|
||||
std::cerr << " Side is in direction to client." << std::endl;
|
||||
std::cerr << " Initing encryption parameters from existing distant chat invites." << std::endl;
|
||||
std::cerr << " Side is in direction to client." << std::endl;
|
||||
std::cerr << " Initing encryption parameters from existing distant chat invites." << std::endl;
|
||||
#endif
|
||||
RsGxsId own_gxs_id ;
|
||||
std::list<RsGxsId> own_id_list ;
|
||||
rsIdentity->getOwnIds(own_id_list) ;
|
||||
RsGxsId own_gxs_id ;
|
||||
std::list<RsGxsId> own_id_list ;
|
||||
rsIdentity->getOwnIds(own_id_list) ;
|
||||
|
||||
for(std::list<RsGxsId>::const_iterator it(own_id_list.begin());it!=own_id_list.end();++it)
|
||||
if(hashFromGxsId(*it) == hash)
|
||||
{
|
||||
own_gxs_id = *it ;
|
||||
break ;
|
||||
}
|
||||
if(own_gxs_id.isNull())
|
||||
{
|
||||
std::cerr << "DistantChatService::addVirtualPeer(): cannot find GXS id for hash " << hash << ". This is probably a bug" << std::endl;
|
||||
return ;
|
||||
}
|
||||
for(std::list<RsGxsId>::const_iterator it(own_id_list.begin());it!=own_id_list.end();++it)
|
||||
if(hashFromGxsId(*it) == hash)
|
||||
{
|
||||
own_gxs_id = *it ;
|
||||
break ;
|
||||
}
|
||||
if(own_gxs_id.isNull())
|
||||
{
|
||||
std::cerr << "DistantChatService::addVirtualPeer(): cannot find GXS id for hash " << hash << ". This is probably a bug" << std::endl;
|
||||
return ;
|
||||
}
|
||||
|
||||
// make sure the DH session does not already exist. If so, remove it.
|
||||
std::map<TurtleFileHash,DistantChatPeerInfo>::iterator it = _distant_chat_peers.find(hash) ;
|
||||
@ -208,17 +208,17 @@ void DistantChatService::addVirtualPeer(const TurtleFileHash& hash,const TurtleV
|
||||
}
|
||||
|
||||
DistantChatPeerInfo info ;
|
||||
info.last_contact = now ;
|
||||
info.status = RS_DISTANT_CHAT_STATUS_TUNNEL_OK ;
|
||||
info.virtual_peer_id = virtual_peer_id ;
|
||||
info.gxs_id.clear() ; // unknown yet!
|
||||
info.direction = dir ;
|
||||
info.own_gxs_id = own_gxs_id ;
|
||||
info.dh = NULL ;
|
||||
memset(info.aes_key,0,DISTANT_CHAT_AES_KEY_SIZE) ;
|
||||
info.last_contact = now ;
|
||||
info.status = RS_DISTANT_CHAT_STATUS_TUNNEL_OK ;
|
||||
info.virtual_peer_id = virtual_peer_id ;
|
||||
info.gxs_id.clear() ; // unknown yet!
|
||||
info.direction = dir ;
|
||||
info.own_gxs_id = own_gxs_id ;
|
||||
info.dh = NULL ;
|
||||
memset(info.aes_key,0,DISTANT_CHAT_AES_KEY_SIZE) ;
|
||||
|
||||
_distant_chat_peers[hash] = info ;
|
||||
}
|
||||
_distant_chat_peers[hash] = info ;
|
||||
}
|
||||
|
||||
{
|
||||
// Start a new DH session for this tunnel
|
||||
@ -290,7 +290,7 @@ static void printBinaryData(void *data,uint32_t size)
|
||||
#endif
|
||||
|
||||
void DistantChatService::receiveTurtleData( RsTurtleGenericTunnelItem *gitem,const RsFileHash& hash,
|
||||
const RsPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction)
|
||||
const RsPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction)
|
||||
{
|
||||
#ifdef DEBUG_DISTANT_CHAT
|
||||
std::cerr << "DistantChatService::receiveTurtleData(): Received turtle data. " << std::endl;
|
||||
@ -316,7 +316,8 @@ void DistantChatService::receiveTurtleData( RsTurtleGenericTunnelItem *gitem,con
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
uint8_t aes_key[DISTANT_CHAT_AES_KEY_SIZE] ;
|
||||
uint8_t aes_key[DISTANT_CHAT_AES_KEY_SIZE] ;
|
||||
RsGxsId gxs_id ;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mDistantChatMtx); /********** STACK LOCKED MTX ******/
|
||||
@ -329,7 +330,8 @@ void DistantChatService::receiveTurtleData( RsTurtleGenericTunnelItem *gitem,con
|
||||
}
|
||||
it->second.last_contact = time(NULL) ;
|
||||
memcpy(aes_key,it->second.aes_key,DISTANT_CHAT_AES_KEY_SIZE) ;
|
||||
it->second.status = RS_DISTANT_CHAT_STATUS_CAN_TALK ;
|
||||
it->second.status = RS_DISTANT_CHAT_STATUS_CAN_TALK ;
|
||||
gxs_id = it->second.gxs_id ;
|
||||
}
|
||||
|
||||
// Call the AES crypto module
|
||||
@ -389,7 +391,18 @@ void DistantChatService::receiveTurtleData( RsTurtleGenericTunnelItem *gitem,con
|
||||
|
||||
// Setup the virtual peer to be the origin, and pass it on.
|
||||
//
|
||||
citem->PeerId(virtualPeerIdFromHash(hash)) ;
|
||||
#ifdef DEBUG_DISTANT_CHAT
|
||||
std::cerr << "(II) Setting peer id to " << decrypted_size << std::endl;
|
||||
#endif
|
||||
|
||||
// DH key items are sent even before we know who we speak to, so the virtual peer id is used in this
|
||||
// case only.
|
||||
|
||||
if(dynamic_cast<RsChatDHPublicKeyItem*>(citem) != NULL)
|
||||
citem->PeerId(virtual_peer_id) ;
|
||||
else
|
||||
citem->PeerId(RsPeerId(gxs_id)) ;
|
||||
|
||||
//RsServer::notify()->notifyPeerStatusChanged(hash,RS_STATUS_ONLINE) ;
|
||||
|
||||
handleIncomingItem(citem) ; // Treats the item, and deletes it
|
||||
@ -407,7 +420,7 @@ void DistantChatService::handleRecvDHPublicKey(RsChatDHPublicKeyItem *item)
|
||||
TurtleVirtualPeerId vpid = item->PeerId() ;
|
||||
TurtleFileHash hash ;
|
||||
|
||||
if(getHashFromVirtualPeerId(vpid,hash))
|
||||
if(getHashFromVirtualPeerId(vpid,hash))
|
||||
{
|
||||
#ifdef DEBUG_DISTANT_CHAT
|
||||
std::cerr << " hash = " << hash << std::endl;
|
||||
@ -525,9 +538,9 @@ void DistantChatService::handleRecvDHPublicKey(RsChatDHPublicKeyItem *item)
|
||||
|
||||
RsChatStatusItem *cs = new RsChatStatusItem ;
|
||||
|
||||
cs->status_string = "Tunnel is secured with PFS session. You can talk!" ;
|
||||
cs->status_string = "Tunnel is secured with PFS session. ACK received. You can talk!" ;
|
||||
cs->flags = RS_CHAT_FLAG_PRIVATE | RS_CHAT_FLAG_ACK_DISTANT_CONNECTION;
|
||||
cs->PeerId(vpid);
|
||||
cs->PeerId(RsPeerId(senders_id));
|
||||
|
||||
pendingDistantChatItems.push_back(cs) ;
|
||||
|
||||
@ -597,7 +610,7 @@ bool DistantChatService::locked_sendDHPublicKey(const DistantChatPeerInfo& pinfo
|
||||
|
||||
dhitem->signature = signature ;
|
||||
dhitem->gxs_key = signature_key_public ;
|
||||
dhitem->PeerId(pinfo.virtual_peer_id) ;
|
||||
dhitem->PeerId(RsPeerId(pinfo.gxs_id)) ;
|
||||
|
||||
#ifdef DEBUG_DISTANT_CHAT
|
||||
std::cerr << " Pushing DH session key item to pending distant messages..." << std::endl;
|
||||
@ -668,15 +681,8 @@ void DistantChatService::sendTurtleData(RsChatItem *item)
|
||||
|
||||
uint8_t aes_key[DISTANT_CHAT_AES_KEY_SIZE] ;
|
||||
|
||||
TurtleVirtualPeerId virtual_peer_id = item->PeerId();
|
||||
RsFileHash hash ;
|
||||
|
||||
if(!getHashFromVirtualPeerId(item->PeerId(),hash))
|
||||
{
|
||||
std::cerr << "Cannot get hash from virtual peer id " << item->PeerId() << ". Dropping the chat message." << std::endl;
|
||||
delete[] buff ;
|
||||
return ;
|
||||
}
|
||||
TurtleFileHash hash = hashFromGxsId(RsGxsId(item->PeerId())) ;
|
||||
TurtleVirtualPeerId virtual_peer_id ;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mDistantChatMtx); /********** STACK LOCKED MTX ******/
|
||||
@ -684,12 +690,13 @@ void DistantChatService::sendTurtleData(RsChatItem *item)
|
||||
|
||||
if(it == _distant_chat_peers.end())
|
||||
{
|
||||
std::cerr << "(EE) item is not going into a registered tunnel. Weird. peer id = " << item->PeerId() << std::endl;
|
||||
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) ;
|
||||
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;
|
||||
@ -750,7 +757,6 @@ void DistantChatService::sendTurtleData(RsChatItem *item)
|
||||
|
||||
bool DistantChatService::initiateDistantChatConnexion(const RsGxsId& gxs_id,uint32_t& error_code)
|
||||
{
|
||||
//pid = DistantChatPeerId(gxs_id) ; // the two ids have the same size. Still, I prefer to have 2 different types.
|
||||
TurtleFileHash hash = hashFromGxsId(gxs_id) ;
|
||||
|
||||
// should be a parameter.
|
||||
@ -799,43 +805,42 @@ 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 ;
|
||||
}
|
||||
// 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(DistantChatPeerId::SIZE_IN_BYTES > Sha1CheckSum::SIZE_IN_BYTES)
|
||||
if(RsGxsId::SIZE_IN_BYTES > Sha1CheckSum::SIZE_IN_BYTES)
|
||||
std::cerr << __PRETTY_FUNCTION__ << ": Serious inconsistency error." << std::endl;
|
||||
assert(Sha1CheckSum::SIZE_IN_BYTES >= DistantChatPeerId::SIZE_IN_BYTES) ;
|
||||
|
||||
unsigned char tmp[Sha1CheckSum::SIZE_IN_BYTES] ;
|
||||
memset(tmp,0,Sha1CheckSum::SIZE_IN_BYTES) ;
|
||||
memcpy(tmp,gid.toByteArray(),DistantChatPeerId::SIZE_IN_BYTES) ;
|
||||
assert(Sha1CheckSum::SIZE_IN_BYTES >= RsGxsId::SIZE_IN_BYTES) ;
|
||||
|
||||
return Sha1CheckSum(tmp);
|
||||
unsigned char tmp[Sha1CheckSum::SIZE_IN_BYTES] ;
|
||||
memset(tmp,0,Sha1CheckSum::SIZE_IN_BYTES) ;
|
||||
memcpy(tmp,gid.toByteArray(),RsGxsId::SIZE_IN_BYTES) ;
|
||||
|
||||
return Sha1CheckSum(tmp);
|
||||
}
|
||||
|
||||
bool DistantChatService::getDistantChatStatus(const DistantChatPeerId& pid,RsGxsId& gxs_id,uint32_t& status)
|
||||
bool DistantChatService::getDistantChatStatus(const RsGxsId& gxs_id,uint32_t& status)
|
||||
{
|
||||
RsStackMutex stack(mDistantChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
for(std::map<TurtleFileHash,DistantChatPeerInfo>::const_iterator it = _distant_chat_peers.begin() ; it != _distant_chat_peers.end();++it)
|
||||
if(it->second.virtual_peer_id == pid)
|
||||
if(it->second.gxs_id == gxs_id)
|
||||
{
|
||||
status = it->second.status ;
|
||||
gxs_id = it->second.gxs_id ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
@ -843,7 +848,7 @@ bool DistantChatService::getDistantChatStatus(const DistantChatPeerId& pid,RsGxs
|
||||
return false ;
|
||||
}
|
||||
|
||||
bool DistantChatService::closeDistantChatConnexion(const DistantChatPeerId& pid)
|
||||
bool DistantChatService::closeDistantChatConnexion(const RsGxsId& pid)
|
||||
{
|
||||
// two cases:
|
||||
// - client needs to stop asking for tunnels => remove the hash from the list of tunnelled files
|
||||
@ -858,7 +863,7 @@ bool DistantChatService::closeDistantChatConnexion(const DistantChatPeerId& pid)
|
||||
RsStackMutex stack(mDistantChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
for(std::map<TurtleFileHash,DistantChatPeerInfo>::const_iterator it = _distant_chat_peers.begin() ; it != _distant_chat_peers.end();++it)
|
||||
if(it->second.virtual_peer_id == pid)
|
||||
if(it->second.gxs_id == pid)
|
||||
{
|
||||
if(it->second.direction == RsTurtleGenericTunnelItem::DIRECTION_SERVER)
|
||||
is_client = true ;
|
||||
@ -869,51 +874,51 @@ bool DistantChatService::closeDistantChatConnexion(const DistantChatPeerId& pid)
|
||||
|
||||
if(virtual_peer_id.isNull())
|
||||
{
|
||||
std::cerr << "Cannot close chat associated to virtual peer id " << pid << ": not found." << std::endl;
|
||||
std::cerr << "Cannot close chat associated to GXS Id " << pid << ": not found." << std::endl;
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
|
||||
if(is_client)
|
||||
{
|
||||
// send a status item saying that we're closing the connection
|
||||
{
|
||||
// send a status item saying that we're closing the connection
|
||||
|
||||
RsChatStatusItem *cs = new RsChatStatusItem ;
|
||||
RsChatStatusItem *cs = new RsChatStatusItem ;
|
||||
|
||||
cs->status_string = "" ;
|
||||
cs->flags = RS_CHAT_FLAG_PRIVATE | RS_CHAT_FLAG_CLOSING_DISTANT_CONNECTION;
|
||||
cs->PeerId(virtual_peer_id);
|
||||
cs->status_string = "" ;
|
||||
cs->flags = RS_CHAT_FLAG_PRIVATE | RS_CHAT_FLAG_CLOSING_DISTANT_CONNECTION;
|
||||
cs->PeerId(RsPeerId(pid));
|
||||
|
||||
sendTurtleData(cs) ; // that needs to be done off-mutex!
|
||||
sendTurtleData(cs) ; // that needs to be done off-mutex and before we close the tunnel.
|
||||
|
||||
RsStackMutex stack(mDistantChatMtx); /********** STACK LOCKED MTX ******/
|
||||
RsStackMutex stack(mDistantChatMtx); /********** STACK LOCKED MTX ******/
|
||||
std::map<RsFileHash,DistantChatPeerInfo>::iterator it = _distant_chat_peers.find(hash) ;
|
||||
|
||||
if(it == _distant_chat_peers.end()) // server side. Nothing to do.
|
||||
{
|
||||
std::cerr << "Cannot close chat associated to hash " << hash << ": not found." << std::endl;
|
||||
return false ;
|
||||
}
|
||||
// Client side: Stop tunnels
|
||||
//
|
||||
std::cerr << "This is client side. Stopping tunnel manageement for hash " << hash << std::endl;
|
||||
mTurtle->stopMonitoringTunnels(hash) ;
|
||||
if(it == _distant_chat_peers.end()) // server side. Nothing to do.
|
||||
{
|
||||
std::cerr << "Cannot close chat associated to hash " << hash << ": not found." << std::endl;
|
||||
return false ;
|
||||
}
|
||||
// Client side: Stop tunnels
|
||||
//
|
||||
std::cerr << "This is client side. Stopping tunnel manageement for hash " << hash << std::endl;
|
||||
mTurtle->stopMonitoringTunnels(hash) ;
|
||||
|
||||
// and remove hash from list of current peers.
|
||||
// and remove hash from list of current peers.
|
||||
|
||||
DH_free(it->second.dh) ;
|
||||
_distant_chat_peers.erase(it) ;
|
||||
}
|
||||
DH_free(it->second.dh) ;
|
||||
_distant_chat_peers.erase(it) ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
void DistantChatService::markDistantChatAsClosed(const TurtleVirtualPeerId& vpid)
|
||||
void DistantChatService::markDistantChatAsClosed(const RsGxsId& pid)
|
||||
{
|
||||
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.virtual_peer_id == vpid)
|
||||
if(it->second.gxs_id == pid)
|
||||
it->second.status = RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED ;
|
||||
}
|
||||
|
||||
|
@ -51,8 +51,8 @@ class DistantChatService: public RsTurtleClientService
|
||||
// Om success, stores the invite in the map above, so that we can respond to tunnel requests.
|
||||
//
|
||||
bool initiateDistantChatConnexion(const RsGxsId& gxs_id,uint32_t& error_code) ;
|
||||
bool closeDistantChatConnexion(const DistantChatPeerId& pid) ;
|
||||
virtual bool getDistantChatStatus(const DistantChatPeerId& hash,RsGxsId& gxs_id,uint32_t& status) ;
|
||||
bool closeDistantChatConnexion(const RsGxsId& pid) ;
|
||||
virtual bool getDistantChatStatus(const RsGxsId &gxs_id,uint32_t &status) ;
|
||||
|
||||
// derived in p3ChatService
|
||||
virtual void handleIncomingItem(RsItem *) = 0;
|
||||
@ -95,7 +95,7 @@ class DistantChatService: public RsTurtleClientService
|
||||
virtual void receiveTurtleData(RsTurtleGenericTunnelItem *item,const RsFileHash& 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 TurtleVirtualPeerId& vpid) ;
|
||||
void markDistantChatAsClosed(const RsGxsId &vpid) ;
|
||||
void startClientDistantChatConnection(const RsFileHash& hash,const RsGxsId& to_gxs_id,const RsGxsId& from_gxs_id) ;
|
||||
bool getHashFromVirtualPeerId(const TurtleVirtualPeerId& pid,RsFileHash& hash) ;
|
||||
TurtleFileHash hashFromGxsId(const RsGxsId& pid) ;
|
||||
|
@ -272,15 +272,13 @@ void p3ChatService::checkSizeAndSendMessage(RsChatMsgItem *msg)
|
||||
}
|
||||
|
||||
|
||||
bool p3ChatService::isOnline(const DistantChatPeerId& pid)
|
||||
bool p3ChatService::isOnline(const RsPeerId& pid)
|
||||
{
|
||||
// check if the id is a tunnel id or a peer id.
|
||||
|
||||
uint32_t status ;
|
||||
RsGxsId gxs_id ;
|
||||
|
||||
std::string hash ;
|
||||
if(getDistantChatStatus(pid,gxs_id,status))
|
||||
if(getDistantChatStatus(RsGxsId(pid),status))
|
||||
return status == RS_DISTANT_CHAT_STATUS_CAN_TALK ;
|
||||
else
|
||||
return mServiceCtrl->isPeerConnected(getServiceInfo().mServiceType, pid);
|
||||
|
@ -426,8 +426,8 @@ virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::str
|
||||
/****************************************/
|
||||
|
||||
virtual bool initiateDistantChatConnexion(const RsGxsId& pid,uint32_t& error_code) = 0;
|
||||
virtual bool getDistantChatStatus(const DistantChatPeerId& pid,RsGxsId& gxs_id,uint32_t& status) = 0;
|
||||
virtual bool closeDistantChatConnexion(const DistantChatPeerId& pid) = 0;
|
||||
virtual bool getDistantChatStatus(const RsGxsId& gxs_id,uint32_t& status) = 0;
|
||||
virtual bool closeDistantChatConnexion(const RsGxsId& pid) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
@ -368,11 +368,11 @@ bool p3Msgs::initiateDistantChatConnexion(const RsGxsId& gxs_id,uint32_t& error_
|
||||
{
|
||||
return mChatSrv->initiateDistantChatConnexion(gxs_id,error_code) ;
|
||||
}
|
||||
bool p3Msgs::getDistantChatStatus(const DistantChatPeerId& pid,RsGxsId& gxs_id,uint32_t& status)
|
||||
bool p3Msgs::getDistantChatStatus(const RsGxsId &gxs_id,uint32_t &status)
|
||||
{
|
||||
return mChatSrv->getDistantChatStatus(pid,gxs_id,status) ;
|
||||
return mChatSrv->getDistantChatStatus(gxs_id,status) ;
|
||||
}
|
||||
bool p3Msgs::closeDistantChatConnexion(const DistantChatPeerId& pid)
|
||||
bool p3Msgs::closeDistantChatConnexion(const RsGxsId& pid)
|
||||
{
|
||||
return mChatSrv->closeDistantChatConnexion(pid) ;
|
||||
}
|
||||
|
@ -197,8 +197,8 @@ class p3Msgs: public RsMsgs
|
||||
virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::string& lobby_topic,const std::list<RsPeerId>& invited_friends,uint32_t privacy_type) ;
|
||||
|
||||
virtual bool initiateDistantChatConnexion(const RsGxsId& gxs_id,uint32_t& error_code) ;
|
||||
virtual bool getDistantChatStatus(const DistantChatPeerId& pid,RsGxsId& gxs_id,uint32_t& status) ;
|
||||
virtual bool closeDistantChatConnexion(const DistantChatPeerId& pid) ;
|
||||
virtual bool getDistantChatStatus(const RsGxsId& gxs_id,uint32_t& status) ;
|
||||
virtual bool closeDistantChatConnexion(const RsGxsId &pid) ;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -98,10 +98,9 @@ void ChatDialog::init(const RsPeerId &peerId, const QString &title)
|
||||
}
|
||||
|
||||
uint32_t distant_peer_status ;
|
||||
RsGxsId distant_chat_gxs_id ;
|
||||
|
||||
if(rsMsgs->getDistantChatStatus(peerId,distant_chat_gxs_id,distant_peer_status))
|
||||
chatflags = RS_CHAT_OPEN | RS_CHAT_FOCUS; // use own flags
|
||||
if(rsMsgs->getDistantChatStatus(RsGxsId(peerId),distant_peer_status))
|
||||
chatflags = RS_CHAT_OPEN | RS_CHAT_FOCUS; // use own flags
|
||||
|
||||
if (chatflags & RS_CHAT_OPEN) {
|
||||
if (lobby_id) {
|
||||
@ -118,8 +117,8 @@ void ChatDialog::init(const RsPeerId &peerId, const QString &title)
|
||||
} else if(distant_peer_status > 0) {
|
||||
cd = new PopupDistantChatDialog();
|
||||
chatDialogs[peerId] = cd;
|
||||
QString peer_name = cd->getPeerName(peerId) ;
|
||||
cd->init(peerId, tr("Talking to ")+peer_name+" (GXS id="+QString::fromStdString(distant_chat_gxs_id.toStdString())+")") ;
|
||||
QString peer_name = cd->getPeerName(peerId) ;
|
||||
cd->init(peerId, tr("Talking to ")+peer_name+" (GXS id="+QString::fromStdString(peerId.toStdString())+")") ;
|
||||
|
||||
} else {
|
||||
RsPeerDetails sslDetails;
|
||||
@ -210,10 +209,9 @@ void ChatDialog::init(const RsPeerId &peerId, const QString &title)
|
||||
return;
|
||||
}
|
||||
|
||||
RsGxsId distant_chat_gxs_id ;
|
||||
uint32_t distant_peer_status ;
|
||||
|
||||
if(rsMsgs->getDistantChatStatus(peerId,distant_chat_gxs_id,distant_peer_status))
|
||||
if(rsMsgs->getDistantChatStatus(RsGxsId(peerId),distant_peer_status))
|
||||
{
|
||||
getChat(peerId, forceFocus ? RS_CHAT_OPEN | RS_CHAT_FOCUS : RS_CHAT_OPEN ); // use own flags
|
||||
return ;
|
||||
|
@ -58,9 +58,9 @@ PopupDistantChatDialog::PopupDistantChatDialog(QWidget *parent, Qt::WindowFlags
|
||||
updateDisplay() ;
|
||||
}
|
||||
|
||||
void PopupDistantChatDialog::init(const DistantChatPeerId& pid,const QString & title)
|
||||
void PopupDistantChatDialog::init(const RsPeerId &pid,const QString & title)
|
||||
{
|
||||
_pid = pid ;
|
||||
_pid = RsGxsId(pid) ;
|
||||
PopupChatDialog::init(pid,title) ;
|
||||
}
|
||||
|
||||
@ -77,8 +77,7 @@ void PopupDistantChatDialog::updateDisplay()
|
||||
//
|
||||
|
||||
uint32_t status= RS_DISTANT_CHAT_STATUS_UNKNOWN;
|
||||
RsGxsId gxs_id ;
|
||||
rsMsgs->getDistantChatStatus(_pid,gxs_id,status) ;
|
||||
rsMsgs->getDistantChatStatus(_pid,status) ;
|
||||
|
||||
switch(status)
|
||||
{
|
||||
@ -118,9 +117,8 @@ void PopupDistantChatDialog::closeEvent(QCloseEvent *e)
|
||||
{
|
||||
//std::cerr << "Closing window => closing distant chat for hash " << _pid << std::endl;
|
||||
|
||||
uint32_t status= RS_DISTANT_CHAT_STATUS_UNKNOWN;
|
||||
RsGxsId gxs_id ;
|
||||
rsMsgs->getDistantChatStatus(_pid,gxs_id,status) ;
|
||||
uint32_t status= RS_DISTANT_CHAT_STATUS_UNKNOWN;
|
||||
rsMsgs->getDistantChatStatus(_pid,status) ;
|
||||
|
||||
if(status != RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED)
|
||||
{
|
||||
@ -140,21 +138,20 @@ void PopupDistantChatDialog::closeEvent(QCloseEvent *e)
|
||||
PopupChatDialog::closeEvent(e) ;
|
||||
}
|
||||
|
||||
QString PopupDistantChatDialog::getPeerName(const DistantChatPeerId &id) const
|
||||
QString PopupDistantChatDialog::getPeerName(const RsGxsId& id) const
|
||||
{
|
||||
uint32_t status ;
|
||||
RsGxsId gxs_id ;
|
||||
|
||||
if(rsMsgs->getDistantChatStatus(id,gxs_id,status))
|
||||
if(rsMsgs->getDistantChatStatus(id,status))
|
||||
{
|
||||
RsIdentityDetails details ;
|
||||
|
||||
if(rsIdentity->getIdDetails(gxs_id,details))
|
||||
if(rsIdentity->getIdDetails(RsGxsId(id),details))
|
||||
return QString::fromUtf8( details.mNickname.c_str() ) ;
|
||||
else
|
||||
return QString::fromStdString(gxs_id.toStdString()) ;
|
||||
return QString::fromStdString(id.toStdString()) ;
|
||||
}
|
||||
else
|
||||
return ChatDialog::getPeerName(id) ;
|
||||
return ChatDialog::getPeerName(RsPeerId(id)) ;
|
||||
}
|
||||
|
||||
|
@ -37,17 +37,17 @@ class PopupDistantChatDialog: public PopupChatDialog
|
||||
/** Default destructor */
|
||||
virtual ~PopupDistantChatDialog();
|
||||
|
||||
virtual void init(const DistantChatPeerId &pid, const QString &title);
|
||||
virtual void init(const RsPeerId &pid, const QString &title);
|
||||
virtual void closeEvent(QCloseEvent *e) ;
|
||||
|
||||
virtual QString getPeerName(const DistantChatPeerId& id) const ;
|
||||
virtual QString getPeerName(const RsGxsId &id) const ;
|
||||
|
||||
protected slots:
|
||||
void updateDisplay() ; // overloads RsAutoUpdatePage
|
||||
|
||||
private:
|
||||
QTimer *_update_timer ;
|
||||
DistantChatPeerId _pid ;
|
||||
RsGxsId _pid ;
|
||||
QLabel *_status_label ;
|
||||
|
||||
friend class ChatDialog;
|
||||
|
Loading…
Reference in New Issue
Block a user