updated GUI for new distant chat

This commit is contained in:
csoler 2015-11-26 20:40:06 -05:00
parent 26f4523f5f
commit a2e0f4196b
17 changed files with 215 additions and 1214 deletions

File diff suppressed because it is too large Load diff

View file

@ -25,33 +25,34 @@
#pragma once #pragma once
#include <turtle/turtleclientservice.h>
#include <chat/rschatitems.h> #include <chat/rschatitems.h>
#include <retroshare/rsmsgs.h> #include <retroshare/rsmsgs.h>
#include <retroshare/rsgxstunnel.h>
class RsGixs ; class RsGixs ;
static const uint32_t DISTANT_CHAT_AES_KEY_SIZE = 16 ; static const uint32_t DISTANT_CHAT_AES_KEY_SIZE = 16 ;
class DistantChatService: public RsTurtleClientService class DistantChatService: public RsGxsTunnelService::RsGxsTunnelClientService
{ {
public: public:
DistantChatService(RsGixs *pids) // So, public interface only uses DistandChatPeerId, but internally, this is converted into a RsGxsTunnelService::RsGxsTunnelId
: mGixs(pids), mDistantChatMtx("distant chat")
DistantChatService(RsGixs *pids) : mDistantChatMtx("distant chat")
{ {
mTurtle = NULL ; mGxsTunnels = NULL ;
} }
void flush() ; virtual void connectToGxsTunnelService(RsGxsTunnelService *tunnel_service) ;
virtual void connectToTurtleRouter(p3turtle *) ;
// Creates the invite if the public key of the distant peer is available. // 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. // Om success, stores the invite in the map above, so that we can respond to tunnel requests.
// //
bool initiateDistantChatConnexion(const RsGxsId& to_gxs_id,const RsGxsId &from_gxs_id, uint32_t &error_code) ; bool initiateDistantChatConnexion(const RsGxsId& to_gxs_id, const RsGxsId &from_gxs_id, DistantChatPeerId& dcpid, uint32_t &error_code) ;
bool closeDistantChatConnexion(const RsGxsId& pid) ; bool closeDistantChatConnexion(const DistantChatPeerId &tunnel_id) ;
virtual bool getDistantChatStatus(const RsGxsId &gxs_id,uint32_t &status, RsGxsId *from_gxs_id=NULL) ;
virtual bool getDistantChatStatus(const DistantChatPeerId &tunnel_id, DistantChatPeerInfo& cinfo) ;
// derived in p3ChatService // derived in p3ChatService
virtual void handleIncomingItem(RsItem *) = 0; virtual void handleIncomingItem(RsItem *) = 0;
@ -62,78 +63,26 @@ public:
void handleRecvChatStatusItem(RsChatStatusItem *cs) ; void handleRecvChatStatusItem(RsChatStatusItem *cs) ;
private: private:
class DistantChatPeerInfo struct DistantChatContact
{ {
public: RsGxsId from_id ;
DistantChatPeerInfo() : last_contact(0), last_keep_alive_sent(0), status(0), direction(0) RsGxsId to_id ;
{
memset(aes_key, 0, DISTANT_CHAT_AES_KEY_SIZE);
}
time_t last_contact ; // used to keep track of working connexion
time_t last_keep_alive_sent ; // last time we sent a keep alive packet.
unsigned char aes_key[DISTANT_CHAT_AES_KEY_SIZE] ;
uint32_t status ; // info: do we have a tunnel ?
RsPeerId virtual_peer_id; // given by the turtle router. Identifies the tunnel.
RsGxsId own_gxs_id ; // gxs id we're using to talk.
RsTurtleGenericTunnelItem::Direction direction ; // specifiec wether we are client(managing the tunnel) or server.
}; };
class DistantChatDHInfo
{
public:
DistantChatDHInfo() : dh(0), direction(0), status(0) {}
DH *dh ;
RsGxsId gxs_id ;
RsTurtleGenericTunnelItem::Direction direction ;
uint32_t status ;
TurtleFileHash hash ;
};
// This maps contains the current peers to talk to with distant chat. // This maps contains the current peers to talk to with distant chat.
// //
std::map<RsGxsId, DistantChatPeerInfo> _distant_chat_contacts ; // current peers we can talk to std::map<DistantChatPeerId, DistantChatContact> mDistantChatContacts ; // current peers we can talk to
std::map<RsPeerId,DistantChatDHInfo> _distant_chat_virtual_peer_ids ; // current virtual peers. Used to figure out tunnels, etc.
// List of items to be sent asap. Used to store items that we cannot pass directly to // Overloaded from RsGxsTunnelClientService
// sendTurtleData(), because of Mutex protection.
std::list<RsChatItem*> pendingDistantChatItems ; virtual void notifyTunnelStatus(const RsGxsTunnelService::RsGxsTunnelId& tunnel_id,uint32_t tunnel_status) ;
virtual void receiveData(const RsGxsTunnelService::RsGxsTunnelId& id,unsigned char *data,uint32_t data_size) ;
// Overloaded from RsTurtleClientService // Utility functions.
virtual bool handleTunnelRequest(const RsFileHash &hash,const RsPeerId& peer_id) ;
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 RsGxsId &gxs_id) ; void markDistantChatAsClosed(const RsGxsId &gxs_id) ;
void startClientDistantChatConnection(const RsGxsId &to_gxs_id,const RsGxsId& from_gxs_id) ; void startClientDistantChatConnection(const RsGxsId &to_gxs_id,const RsGxsId& from_gxs_id) ;
void locked_restartDHSession(const RsPeerId &virtual_peer_id, const RsGxsId &own_gxs_id) ;
//bool getHashFromVirtualPeerId(const TurtleVirtualPeerId& pid,RsFileHash& hash) ; RsGxsTunnelService *mGxsTunnels ;
static TurtleFileHash hashFromGxsId(const RsGxsId& destination) ;
static RsGxsId gxsIdFromHash(const TurtleFileHash& sum) ;
void handleRecvDHPublicKey(RsChatDHPublicKeyItem *item) ;
bool locked_sendDHPublicKey(const DH *dh, const RsGxsId &own_gxs_id, const RsPeerId &virtual_peer_id) ;
bool locked_initDHSessionKey(DH *&dh);
DistantChatPeerId virtualPeerIdFromHash(const TurtleFileHash& hash ) ; // ... and to a hash for p3turtle
// Utility functions
void sendTurtleData(RsChatItem *) ;
void sendEncryptedTurtleData(const uint8_t *buff,uint32_t rssize,const RsGxsId &gxs_id) ;
bool handleEncryptedData(const uint8_t *data_bytes,uint32_t data_size,const TurtleFileHash& hash,const RsPeerId& virtual_peer_id) ;
static TurtleFileHash hashFromVirtualPeerId(const DistantChatPeerId& peerId) ; // converts IDs so that we can talk to RsPeerId from outside
p3turtle *mTurtle ;
RsGixs *mGixs ;
RsMutex mDistantChatMtx ; RsMutex mDistantChatMtx ;
}; };

View file

@ -86,7 +86,7 @@ int p3ChatService::tick()
receiveChatQueue(); receiveChatQueue();
DistributedChatService::flush() ; DistributedChatService::flush() ;
DistantChatService::flush() ; //DistantChatService::flush() ;
return 0; return 0;
} }
@ -285,9 +285,12 @@ void p3ChatService::checkSizeAndSendMessage(RsChatMsgItem *msg)
bool p3ChatService::isOnline(const RsPeerId& pid) bool p3ChatService::isOnline(const RsPeerId& pid)
{ {
// check if the id is a tunnel id or a peer id. // check if the id is a tunnel id or a peer id.
uint32_t status ; uint32_t status ;
if(getDistantChatStatus(RsGxsId(pid),status)) DistantChatPeerInfo dcpinfo;
return status == RS_DISTANT_CHAT_STATUS_CAN_TALK ;
if(getDistantChatStatus(DistantChatPeerId(pid),dcpinfo))
return dcpinfo.status == RS_DISTANT_CHAT_STATUS_CAN_TALK ;
else else
return mServiceCtrl->isPeerConnected(getServiceInfo().mServiceType, pid); return mServiceCtrl->isPeerConnected(getServiceInfo().mServiceType, pid);
} }
@ -767,6 +770,7 @@ void p3ChatService::handleRecvChatStatusItem(RsChatStatusItem *cs)
#endif #endif
uint32_t status; uint32_t status;
DistantChatPeerInfo dcpinfo;
if(cs->flags & RS_CHAT_FLAG_REQUEST_CUSTOM_STATE) // no state here just a request. if(cs->flags & RS_CHAT_FLAG_REQUEST_CUSTOM_STATE) // no state here just a request.
sendCustomState(cs->PeerId()) ; sendCustomState(cs->PeerId()) ;
@ -782,9 +786,9 @@ void p3ChatService::handleRecvChatStatusItem(RsChatStatusItem *cs)
#endif #endif
sendCustomStateRequest(cs->PeerId()) ; sendCustomStateRequest(cs->PeerId()) ;
} }
else if(DistantChatService::getDistantChatStatus(RsGxsId(cs->PeerId()), status)) else if(DistantChatService::getDistantChatStatus(DistantChatPeerId(cs->PeerId()), dcpinfo))
{ {
RsServer::notify()->notifyChatStatus(ChatId(RsGxsId(cs->PeerId())), cs->status_string) ; RsServer::notify()->notifyChatStatus(ChatId(DistantChatPeerId(cs->PeerId())), cs->status_string) ;
} }
else if(cs->flags & RS_CHAT_FLAG_PRIVATE) else if(cs->flags & RS_CHAT_FLAG_PRIVATE)
{ {
@ -817,8 +821,9 @@ void p3ChatService::initChatMessage(RsChatMsgItem *c, ChatMessage &m)
} }
uint32_t status; uint32_t status;
if(DistantChatService::getDistantChatStatus(RsGxsId(c->PeerId()), status)) DistantChatPeerInfo dcpinfo;
m.chat_id = ChatId(RsGxsId(c->PeerId())); if(DistantChatService::getDistantChatStatus(DistantChatPeerId(c->PeerId()), dcpinfo))
m.chat_id = ChatId(DistantChatPeerId(c->PeerId()));
if (c -> chatFlags & RS_CHAT_FLAG_PRIVATE) if (c -> chatFlags & RS_CHAT_FLAG_PRIVATE)
m.chatflags |= RS_CHAT_PRIVATE; m.chatflags |= RS_CHAT_PRIVATE;

View file

@ -53,11 +53,6 @@ static const uint32_t RS_GXS_TUNNEL_DH_STATUS_UNINITIALIZED = 0x0000 ;
static const uint32_t RS_GXS_TUNNEL_DH_STATUS_HALF_KEY_DONE = 0x0001 ; static const uint32_t RS_GXS_TUNNEL_DH_STATUS_HALF_KEY_DONE = 0x0001 ;
static const uint32_t RS_GXS_TUNNEL_DH_STATUS_KEY_AVAILABLE = 0x0002 ; static const uint32_t RS_GXS_TUNNEL_DH_STATUS_KEY_AVAILABLE = 0x0002 ;
static const uint32_t RS_GXS_TUNNEL_STATUS_UNKNOWN = 0x00 ;
static const uint32_t RS_GXS_TUNNEL_STATUS_CAN_TALK = 0x01 ;
static const uint32_t RS_GXS_TUNNEL_STATUS_TUNNEL_DN = 0x02 ;
static const uint32_t RS_GXS_TUNNEL_STATUS_REMOTELY_CLOSED = 0x03 ;
static const uint32_t RS_GXS_TUNNEL_DELAY_BETWEEN_RESEND = 10 ; // re-send every 10 secs. static const uint32_t RS_GXS_TUNNEL_DELAY_BETWEEN_RESEND = 10 ; // re-send every 10 secs.
static const uint32_t GXS_TUNNEL_ENCRYPTION_HMAC_SIZE = SHA_DIGEST_LENGTH ; static const uint32_t GXS_TUNNEL_ENCRYPTION_HMAC_SIZE = SHA_DIGEST_LENGTH ;
@ -1126,8 +1121,7 @@ void p3GxsTunnelService::startClientGxsTunnelConnection(const RsGxsId& to_gxs_id
RsFileHash hash = randomHashFromDestinationGxsId(to_gxs_id) ; RsFileHash hash = randomHashFromDestinationGxsId(to_gxs_id) ;
RsGxsTunnelId tnl_id = makeGxsTunnelId(from_gxs_id,to_gxs_id) ; tunnel_id = makeGxsTunnelId(from_gxs_id,to_gxs_id) ;
tunnel_id = tnl_id ;
{ {
RsStackMutex stack(mGxsTunnelMtx); /********** STACK LOCKED MTX ******/ RsStackMutex stack(mGxsTunnelMtx); /********** STACK LOCKED MTX ******/

View file

@ -227,8 +227,6 @@ private:
bool handleEncryptedData(const uint8_t *data_bytes,uint32_t data_size,const TurtleFileHash& hash,const RsPeerId& virtual_peer_id) ; bool handleEncryptedData(const uint8_t *data_bytes,uint32_t data_size,const TurtleFileHash& hash,const RsPeerId& virtual_peer_id) ;
static TurtleFileHash hashFromVirtualPeerId(const DistantChatPeerId& peerId) ; // converts IDs so that we can talk to RsPeerId from outside
// local data // local data
p3turtle *mTurtle ; p3turtle *mTurtle ;

View file

@ -232,6 +232,10 @@ std::ostream& RsChatAvatarItem::print(std::ostream &out, uint16_t indent)
return out; return out;
} }
RsGxsTunnelDHPublicKeyItem::~RsGxsTunnelDHPublicKeyItem()
{
BN_free(public_key) ;
}
RsItem *RsChatSerialiser::deserialise(void *data, uint32_t *pktsize) RsItem *RsChatSerialiser::deserialise(void *data, uint32_t *pktsize)
{ {
uint32_t rstype = getRsItemId(data); uint32_t rstype = getRsItemId(data);

View file

@ -130,10 +130,10 @@ class RsGxsTunnelDataAckItem: public RsGxsTunnelItem
class RsGxsTunnelDHPublicKeyItem: public RsGxsTunnelItem class RsGxsTunnelDHPublicKeyItem: public RsGxsTunnelItem
{ {
public: public:
RsGxsTunnelDHPublicKeyItem() :RsGxsTunnelItem(RS_PKT_SUBTYPE_DISTANT_CHAT_DH_PUBLIC_KEY) {} RsGxsTunnelDHPublicKeyItem() :RsGxsTunnelItem(RS_PKT_SUBTYPE_GXS_TUNNEL_DH_PUBLIC_KEY) {}
RsGxsTunnelDHPublicKeyItem(void *data,uint32_t size) ; // deserialization RsGxsTunnelDHPublicKeyItem(void *data,uint32_t size) ; // deserialization
virtual ~RsGxsTunnelDHPublicKeyItem() { BN_free(public_key) ; } virtual ~RsGxsTunnelDHPublicKeyItem() ;
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ? virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ?

View file

@ -104,9 +104,9 @@ void p3HistoryMgr::addMessage(const ChatMessage& cm)
peerName = cm.chat_id.toGxsId().toStdString(); peerName = cm.chat_id.toGxsId().toStdString();
} else { } else {
uint32_t status; uint32_t status;
RsGxsId from_gxs_id; DistantChatPeerInfo dcpinfo;
if (rsMsgs->getDistantChatStatus(cm.chat_id.toGxsId(), status, &from_gxs_id)) if (rsMsgs->getDistantChatStatus(cm.chat_id.toPeerId(), dcpinfo))
peerName = from_gxs_id.toStdString(); peerName = cm.chat_id.toPeerId().toStdString();
} }
enabled = true; enabled = true;
} }

View file

@ -36,6 +36,11 @@ public:
static const uint32_t RS_GXS_TUNNEL_ERROR_NO_ERROR = 0x0000 ; static const uint32_t RS_GXS_TUNNEL_ERROR_NO_ERROR = 0x0000 ;
static const uint32_t RS_GXS_TUNNEL_ERROR_UNKNOWN_GXS_ID = 0x0001 ; static const uint32_t RS_GXS_TUNNEL_ERROR_UNKNOWN_GXS_ID = 0x0001 ;
static const uint32_t RS_GXS_TUNNEL_STATUS_UNKNOWN = 0x00 ;
static const uint32_t RS_GXS_TUNNEL_STATUS_CAN_TALK = 0x01 ;
static const uint32_t RS_GXS_TUNNEL_STATUS_TUNNEL_DN = 0x02 ;
static const uint32_t RS_GXS_TUNNEL_STATUS_REMOTELY_CLOSED = 0x03 ;
typedef GXSTunnelId RsGxsTunnelId ; typedef GXSTunnelId RsGxsTunnelId ;
class RsGxsTunnelClientService class RsGxsTunnelClientService
@ -50,6 +55,10 @@ public:
// is responsible to free it using free() once used. // is responsible to free it using free() once used.
virtual void receiveData(const RsGxsTunnelId& id,unsigned char *data,uint32_t data_size) =0; virtual void receiveData(const RsGxsTunnelId& id,unsigned char *data,uint32_t data_size) =0;
// Used by the creator of the service to supply a pointer to the GXS tunnel service for it to be able to send data etc.
virtual void connectToGxsTunnelService(RsGxsTunnelService *tunnel_service) =0;
}; };
class GxsTunnelInfo class GxsTunnelInfo
@ -77,6 +86,7 @@ public:
//===================================================// //===================================================//
virtual bool getGxsTunnelsInfo(std::vector<GxsTunnelInfo>& infos) =0; virtual bool getGxsTunnelsInfo(std::vector<GxsTunnelInfo>& infos) =0;
virtual bool getGxsTunnelInfo(const RsGxsTunnelId& tunnel_id,GxsTunnelInfo& info) =0;
// retrieve the routing probabilities // retrieve the routing probabilities
@ -103,7 +113,7 @@ public:
// Removes any established tunnel to this GXS id. This makes the tunnel refuse further data, but the tunnel will be however kept alive // Removes any established tunnel to this GXS id. This makes the tunnel refuse further data, but the tunnel will be however kept alive
// until all pending data is flushed. All clients attached to the tunnel will be notified that the tunnel gets closed. // until all pending data is flushed. All clients attached to the tunnel will be notified that the tunnel gets closed.
virtual bool closeExistingTunnel(const RsGxsId& to_id) =0; virtual bool closeExistingTunnel(const RsGxsTunnelId& to_id) =0;
//===================================================// //===================================================//
// Routage feedback from other services // // Routage feedback from other services //

View file

@ -100,7 +100,6 @@ typedef uint64_t ChatLobbyMsgId ;
typedef std::string ChatLobbyNickName ; typedef std::string ChatLobbyNickName ;
typedef RsPeerId DistantChatPeerId ; typedef RsPeerId DistantChatPeerId ;
//typedef GRouterKeyId DistantMsgPeerId ;
typedef uint64_t MessageId ; typedef uint64_t MessageId ;
@ -269,6 +268,14 @@ public:
#define RS_DISTANT_CHAT_FLAG_SIGNED 0x0001 #define RS_DISTANT_CHAT_FLAG_SIGNED 0x0001
#define RS_DISTANT_CHAT_FLAG_SIGNATURE_OK 0x0002 #define RS_DISTANT_CHAT_FLAG_SIGNATURE_OK 0x0002
struct DistantChatPeerInfo
{
RsGxsId to_id ;
RsGxsId own_id ;
DistantChatPeerId peer_id ; // this is the tunnel id actually
uint32_t status ; // see the values in rsmsgs.h
};
// Identifier for an chat endpoint like // Identifier for an chat endpoint like
// neighbour peer, distant peer, chatlobby, broadcast // neighbour peer, distant peer, chatlobby, broadcast
class ChatId class ChatId
@ -372,15 +379,6 @@ class ChatLobbyInfo
time_t last_activity ; // last recorded activity. Useful for removing dead lobbies. time_t last_activity ; // last recorded activity. Useful for removing dead lobbies.
}; };
struct DistantChatInviteInfo
{
DistantChatPeerId pid ; // pid to contact the invite and refer to it.
std::string encrypted_radix64_string ; // encrypted radix string used to for the chat link
RsPgpId 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.
};
std::ostream &operator<<(std::ostream &out, const Rs::Msgs::MessageInfo &info); std::ostream &operator<<(std::ostream &out, const Rs::Msgs::MessageInfo &info);
class RsMsgs; class RsMsgs;
@ -481,9 +479,9 @@ virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const RsGxsId&
/* Distant chat */ /* Distant chat */
/****************************************/ /****************************************/
virtual bool initiateDistantChatConnexion(const RsGxsId& to_pid,const RsGxsId& from_pid,uint32_t& error_code) = 0; virtual bool initiateDistantChatConnexion(const RsGxsId& to_pid,const RsGxsId& from_pid,DistantChatPeerId& pid,uint32_t& error_code) = 0;
virtual bool getDistantChatStatus(const RsGxsId& gxs_id,uint32_t& status, RsGxsId *from_gxs_id = NULL) = 0; virtual bool getDistantChatStatus(const DistantChatPeerId& pid,DistantChatPeerInfo& info)=0;
virtual bool closeDistantChatConnexion(const RsGxsId& pid) = 0; virtual bool closeDistantChatConnexion(const DistantChatPeerId& pid)=0;
}; };

View file

@ -523,15 +523,15 @@ void p3Msgs::getPendingChatLobbyInvites(std::list<ChatLobbyInvite>& invites)
{ {
mChatSrv->getPendingChatLobbyInvites(invites) ; mChatSrv->getPendingChatLobbyInvites(invites) ;
} }
bool p3Msgs::initiateDistantChatConnexion(const RsGxsId& to_gxs_id,const RsGxsId& from_gxs_id,uint32_t& error_code) bool p3Msgs::initiateDistantChatConnexion(const RsGxsId& to_gxs_id,const RsGxsId& from_gxs_id,DistantChatPeerId& pid,uint32_t& error_code)
{ {
return mChatSrv->initiateDistantChatConnexion(to_gxs_id,from_gxs_id,error_code) ; return mChatSrv->initiateDistantChatConnexion(to_gxs_id,from_gxs_id,pid,error_code) ;
} }
bool p3Msgs::getDistantChatStatus(const RsGxsId &gxs_id,uint32_t &status,RsGxsId *from_gxs_id) bool p3Msgs::getDistantChatStatus(const DistantChatPeerId& pid,DistantChatPeerInfo& info)
{ {
return mChatSrv->getDistantChatStatus(gxs_id,status,from_gxs_id) ; return mChatSrv->getDistantChatStatus(pid,info) ;
} }
bool p3Msgs::closeDistantChatConnexion(const RsGxsId& pid) bool p3Msgs::closeDistantChatConnexion(const DistantChatPeerId &pid)
{ {
return mChatSrv->closeDistantChatConnexion(pid) ; return mChatSrv->closeDistantChatConnexion(pid) ;
} }

View file

@ -155,9 +155,9 @@ class p3Msgs: public RsMsgs
virtual bool getLobbyAutoSubscribe(const ChatLobbyId& lobby_id); virtual bool getLobbyAutoSubscribe(const ChatLobbyId& lobby_id);
virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const RsGxsId& lobby_identity,const std::string& lobby_topic,const std::set<RsPeerId>& invited_friends,ChatLobbyFlags privacy_type) ; virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const RsGxsId& lobby_identity,const std::string& lobby_topic,const std::set<RsPeerId>& invited_friends,ChatLobbyFlags privacy_type) ;
virtual bool initiateDistantChatConnexion(const RsGxsId& to_gxs_id,const RsGxsId& from_gxs_id,uint32_t& error_code) ; virtual bool initiateDistantChatConnexion(const RsGxsId& to_gxs_id, const RsGxsId& from_gxs_id, DistantChatPeerId &pid, uint32_t& error_code) ;
virtual bool getDistantChatStatus(const RsGxsId& gxs_id,uint32_t& status, RsGxsId *from_gxs_id=NULL) ; virtual bool getDistantChatStatus(const DistantChatPeerId& gxs_id,DistantChatPeerInfo& info);
virtual bool closeDistantChatConnexion(const RsGxsId &pid) ; virtual bool closeDistantChatConnexion(const DistantChatPeerId &pid) ;
private: private:

View file

@ -56,6 +56,8 @@
#include <openssl/rand.h> #include <openssl/rand.h>
#include <fcntl.h> #include <fcntl.h>
#include <gxstunnel/p3gxstunnel.h>
#define ENABLE_GROUTER #define ENABLE_GROUTER
#if (defined(__unix__) || defined(unix)) && !defined(USG) #if (defined(__unix__) || defined(unix)) && !defined(USG)
@ -1472,13 +1474,16 @@ int RsServer::StartupRetroShare()
pqih -> addService(tr,true); pqih -> addService(tr,true);
pqih -> addService(ftserver,true); pqih -> addService(ftserver,true);
p3GxsTunnelService *gxs_tunnels = new p3GxsTunnelService() ;
rsGxsTunnels = gxs_tunnels;
rsDisc = mDisc; rsDisc = mDisc;
rsMsgs = new p3Msgs(msgSrv, chatSrv); rsMsgs = new p3Msgs(msgSrv, chatSrv);
// connect components to turtle router. // connect components to turtle router.
ftserver->connectToTurtleRouter(tr) ; ftserver->connectToTurtleRouter(tr) ;
chatSrv->connectToTurtleRouter(tr) ; chatSrv->connectToxsTunnelService(gxs_tunnels) ;
gr->connectToTurtleRouter(tr) ; gr->connectToTurtleRouter(tr) ;
#ifdef ENABLE_GROUTER #ifdef ENABLE_GROUTER
msgSrv->connectToGlobalRouter(gr) ; msgSrv->connectToGlobalRouter(gr) ;
@ -1491,7 +1496,6 @@ int RsServer::StartupRetroShare()
pqih -> addService(chatSrv,true); pqih -> addService(chatSrv,true);
pqih -> addService(mStatusSrv,true); pqih -> addService(mStatusSrv,true);
// set interfaces for plugins // set interfaces for plugins
// //
RsPlugInInterfaces interfaces; RsPlugInInterfaces interfaces;

View file

@ -104,10 +104,9 @@ void ChatDialog::init(ChatId id, const QString &title)
ChatLobbyDialog* cld = new ChatLobbyDialog(id.toLobbyId()); ChatLobbyDialog* cld = new ChatLobbyDialog(id.toLobbyId());
cld->init(); cld->init();
cd = cld; cd = cld;
} else if(id.isGxsId()) { } else if(id.isGxsTunnelId()) {
PopupDistantChatDialog* pdcd = new PopupDistantChatDialog(); PopupDistantChatDialog* pdcd = new PopupDistantChatDialog(id.toGxsTunnelId());
QString peer_name = pdcd->getPeerName(id) ; pdcd->init() ;
pdcd->init(id.toGxsId(), tr("Talking to")+" "+peer_name) ;
cd = pdcd; cd = pdcd;
} else { } else {
RsPeerDetails sslDetails; RsPeerDetails sslDetails;

View file

@ -553,8 +553,9 @@ void ChatLobbyDialog::distantChatParticipant()
rsMsgs->getIdentityForChatLobby(lobbyId, own_id); rsMsgs->getIdentityForChatLobby(lobbyId, own_id);
uint32_t error_code ; uint32_t error_code ;
RsGxsTunnelService::RsGxsTunnelId tunnel_id;
if(! rsMsgs->initiateDistantChatConnexion(gxs_id,own_id,error_code)) if(! rsMsgs->initiateDistantChatConnexion(gxs_id,own_id,tunnel_id,error_code))
{ {
QString error_str ; QString error_str ;
switch(error_code) switch(error_code)

View file

@ -43,9 +43,11 @@ PopupDistantChatDialog::~PopupDistantChatDialog()
delete _update_timer ; delete _update_timer ;
} }
PopupDistantChatDialog::PopupDistantChatDialog(QWidget *parent, Qt::WindowFlags flags) PopupDistantChatDialog::PopupDistantChatDialog(const RsGxsTunnelService::RsGxsTunnelId& tunnel_id,QWidget *parent, Qt::WindowFlags flags)
: PopupChatDialog(parent,flags) : PopupChatDialog(parent,flags)
{ {
_tunnel_id = tunnel_id ;
_status_label = new QLabel ; _status_label = new QLabel ;
_update_timer = new QTimer ; _update_timer = new QTimer ;
@ -58,19 +60,19 @@ PopupDistantChatDialog::PopupDistantChatDialog(QWidget *parent, Qt::WindowFlags
updateDisplay() ; updateDisplay() ;
} }
void PopupDistantChatDialog::init(const RsGxsId &gxs_id,const QString & title) void PopupDistantChatDialog::init()
{ {
_pid = gxs_id ; RsGxsTunnelService::GxsTunnelInfo tinfo;
PopupChatDialog::init(ChatId(gxs_id), title) ;
RsGxsId own_gxs_id ; if(!rsGxsTunnels->getDistantChatStatus(tunnel_id,tinfo))
uint32_t status ; return ;
// do not use setOwnId, because we don't want the user to change the GXS avatar from the chat window PopupChatDialog::init(ChatId(tinfo.destination_gxs_id), title) ;
// Do not use setOwnId, because we don't want the user to change the GXS avatar from the chat window
// it will not be transmitted. // it will not be transmitted.
if(rsMsgs->getDistantChatStatus(gxs_id,status,&own_gxs_id)) ui.ownAvatarWidget->setId(ChatId(tinfo.source_gxs_id));
ui.ownAvatarWidget->setId(ChatId(own_gxs_id));
} }
void PopupDistantChatDialog::updateDisplay() void PopupDistantChatDialog::updateDisplay()
@ -85,15 +87,15 @@ void PopupDistantChatDialog::updateDisplay()
// make sure about the tunnel status // make sure about the tunnel status
// //
uint32_t status= RS_DISTANT_CHAT_STATUS_UNKNOWN; RsGxsTunnelService::GxsTunnelInfo tinfo;
rsMsgs->getDistantChatStatus(_pid,status) ; rsMsgs->getDistantChatStatus(_tunnel_id,tinfo) ;
ui.avatarWidget->setId(ChatId(_pid)); ui.avatarWidget->setId(ChatId(tinfo.destination_gxs_id));
QString msg; QString msg;
switch(status) switch(tinfo.tunnel_status)
{ {
case RS_DISTANT_CHAT_STATUS_UNKNOWN: //std::cerr << "Unknown hash. Error!" << std::endl; case RsGxsTunnelService::RS_DISTANT_CHAT_STATUS_UNKNOWN: //std::cerr << "Unknown hash. Error!" << std::endl;
_status_label->setPixmap(QPixmap(IMAGE_GRY_LED)) ; _status_label->setPixmap(QPixmap(IMAGE_GRY_LED)) ;
msg = tr("Hash Error. No tunnel."); msg = tr("Hash Error. No tunnel.");
_status_label->setToolTip(msg) ; _status_label->setToolTip(msg) ;
@ -101,7 +103,7 @@ void PopupDistantChatDialog::updateDisplay()
getChatWidget()->blockSending(tr("Can't send message, because there is no tunnel.")); getChatWidget()->blockSending(tr("Can't send message, because there is no tunnel."));
setPeerStatus(RS_STATUS_OFFLINE) ; setPeerStatus(RS_STATUS_OFFLINE) ;
break ; break ;
case RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED: std::cerr << "Chat remotely closed. " << std::endl; case RsGxsTunnelService::RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED: std::cerr << "Chat remotely closed. " << std::endl;
_status_label->setPixmap(QPixmap(IMAGE_RED_LED)) ; _status_label->setPixmap(QPixmap(IMAGE_RED_LED)) ;
_status_label->setToolTip(QObject::tr("Distant peer has closed the chat")) ; _status_label->setToolTip(QObject::tr("Distant peer has closed the chat")) ;
@ -110,7 +112,7 @@ void PopupDistantChatDialog::updateDisplay()
setPeerStatus(RS_STATUS_OFFLINE) ; setPeerStatus(RS_STATUS_OFFLINE) ;
break ; break ;
case RS_DISTANT_CHAT_STATUS_TUNNEL_DN: //std::cerr << "Tunnel asked. Waiting for reponse. " << std::endl; case RsGxsTunnelService::RS_DISTANT_CHAT_STATUS_TUNNEL_DN: //std::cerr << "Tunnel asked. Waiting for reponse. " << std::endl;
_status_label->setPixmap(QPixmap(IMAGE_RED_LED)) ; _status_label->setPixmap(QPixmap(IMAGE_RED_LED)) ;
msg = QObject::tr("Tunnel is pending..."); msg = QObject::tr("Tunnel is pending...");
_status_label->setToolTip(msg) ; _status_label->setToolTip(msg) ;
@ -118,15 +120,7 @@ void PopupDistantChatDialog::updateDisplay()
getChatWidget()->blockSending(msg); getChatWidget()->blockSending(msg);
setPeerStatus(RS_STATUS_OFFLINE) ; setPeerStatus(RS_STATUS_OFFLINE) ;
break ; break ;
case RS_DISTANT_CHAT_STATUS_TUNNEL_OK: //std::cerr << "Tunnel is ok. " << std::endl; case RsGxsTunnelService::RS_DISTANT_CHAT_STATUS_CAN_TALK: //std::cerr << "Tunnel is ok and data is transmitted." << std::endl;
_status_label->setPixmap(QPixmap(IMAGE_YEL_LED)) ;
msg = QObject::tr("Secured tunnel established. Waiting for ACK...");
_status_label->setToolTip(msg) ;
getChatWidget()->updateStatusString("%1", msg, true);
getChatWidget()->blockSending(msg);
setPeerStatus(RS_STATUS_ONLINE) ;
break ;
case RS_DISTANT_CHAT_STATUS_CAN_TALK: //std::cerr << "Tunnel is ok and data is transmitted." << std::endl;
_status_label->setPixmap(QPixmap(IMAGE_GRN_LED)) ; _status_label->setPixmap(QPixmap(IMAGE_GRN_LED)) ;
msg = QObject::tr("Secured tunnel is working. You can talk!"); msg = QObject::tr("Secured tunnel is working. You can talk!");
_status_label->setToolTip(msg) ; _status_label->setToolTip(msg) ;
@ -148,7 +142,7 @@ void PopupDistantChatDialog::closeEvent(QCloseEvent *e)
QString msg = tr("Closing this window will end the conversation, notify the peer and remove the encrypted tunnel.") ; QString msg = tr("Closing this window will end the conversation, notify the peer and remove the encrypted tunnel.") ;
if(QMessageBox::Ok == QMessageBox::critical(NULL,tr("Kill the tunnel?"),msg, QMessageBox::Ok | QMessageBox::Cancel)) if(QMessageBox::Ok == QMessageBox::critical(NULL,tr("Kill the tunnel?"),msg, QMessageBox::Ok | QMessageBox::Cancel))
rsMsgs->closeDistantChatConnexion(_pid) ; rsMsgs->closeDistantChatConnexion(_tunnel_id) ;
else else
{ {
e->ignore() ; e->ignore() ;
@ -163,23 +157,26 @@ void PopupDistantChatDialog::closeEvent(QCloseEvent *e)
QString PopupDistantChatDialog::getPeerName(const ChatId &id) const QString PopupDistantChatDialog::getPeerName(const ChatId &id) const
{ {
RsGxsTunnelService::GxsTunnelInfo tinfo;
rsMsgs->getDistantChatStatus(_tunnel_id,tinfo) ;
RsIdentityDetails details ; RsIdentityDetails details ;
if(rsIdentity->getIdDetails(id.toGxsId(),details)) if(rsIdentity->getIdDetails(destination_gxs_id,details))
return QString::fromUtf8( details.mNickname.c_str() ) ; return QString::fromUtf8( details.mNickname.c_str() ) ;
else else
return QString::fromStdString(id.toGxsId().toStdString()) ; return QString::fromStdString(destination_gxs_id.toStdString()) ;
} }
QString PopupDistantChatDialog::getOwnName() const QString PopupDistantChatDialog::getOwnName() const
{ {
uint32_t status= RS_DISTANT_CHAT_STATUS_UNKNOWN; RsGxsTunnelService::GxsTunnelInfo tinfo;
RsGxsId from_gxs_id ;
rsMsgs->getDistantChatStatus(_pid,status,&from_gxs_id) ; rsMsgs->getDistantChatStatus(_tunnel_id,tinfo) ;
RsIdentityDetails details ; RsIdentityDetails details ;
if(rsIdentity->getIdDetails(from_gxs_id,details)) if(rsIdentity->getIdDetails(source_gxs_id,details))
return QString::fromUtf8( details.mNickname.c_str() ) ; return QString::fromUtf8( details.mNickname.c_str() ) ;
else else
return QString::fromStdString(from_gxs_id.toStdString()) ; return QString::fromStdString(source_gxs_id.toStdString()) ;
} }

View file

@ -22,6 +22,7 @@
#pragma once #pragma once
#include <retroshare/rsgxstunnel.h>
#include "PopupChatDialog.h" #include "PopupChatDialog.h"
class QTimer ; class QTimer ;
@ -33,7 +34,7 @@ class PopupDistantChatDialog: public PopupChatDialog
protected: protected:
/** Default constructor */ /** Default constructor */
PopupDistantChatDialog(QWidget *parent = 0, Qt::WindowFlags flags = 0); PopupDistantChatDialog(const RsGxsTunnelService::RsGxsTunnelId &tunnel_id, QWidget *parent = 0, Qt::WindowFlags flags = 0);
/** Default destructor */ /** Default destructor */
virtual ~PopupDistantChatDialog(); virtual ~PopupDistantChatDialog();
@ -48,7 +49,7 @@ class PopupDistantChatDialog: public PopupChatDialog
private: private:
QTimer *_update_timer ; QTimer *_update_timer ;
RsGxsId _pid ; RsGxsTunnelService::RsGxsTunnelId _tunnel_id ;
QLabel *_status_label ; QLabel *_status_label ;
friend class ChatDialog; friend class ChatDialog;