2018-05-21 14:50:38 -04:00
|
|
|
/*******************************************************************************
|
|
|
|
* libretroshare/src/chat: distantchat.h *
|
|
|
|
* *
|
|
|
|
* libretroshare: retroshare core library *
|
|
|
|
* *
|
|
|
|
* Copyright 2014 by Cyril Soler <csoler@users.sourceforge.net> *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
2018-05-28 16:03:39 -04:00
|
|
|
* it under the terms of the GNU Lesser General Public License as *
|
2018-05-21 14:50:38 -04:00
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
2018-05-28 16:03:39 -04:00
|
|
|
* GNU Lesser General Public License for more details. *
|
2018-05-21 14:50:38 -04:00
|
|
|
* *
|
2018-05-28 16:03:39 -04:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License *
|
2018-05-21 14:50:38 -04:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2014-11-08 09:55:29 -05:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2014-11-11 11:10:54 -05:00
|
|
|
#include <chat/rschatitems.h>
|
|
|
|
#include <retroshare/rsmsgs.h>
|
2015-11-26 20:40:06 -05:00
|
|
|
#include <retroshare/rsgxstunnel.h>
|
2014-11-11 11:10:54 -05:00
|
|
|
|
2015-03-14 10:33:23 -04:00
|
|
|
class RsGixs ;
|
2014-11-08 09:55:29 -05:00
|
|
|
|
|
|
|
static const uint32_t DISTANT_CHAT_AES_KEY_SIZE = 16 ;
|
|
|
|
|
2019-04-28 12:10:17 -04:00
|
|
|
/**
|
|
|
|
* Public interface only uses DistandChatPeerId, but internally, this is
|
|
|
|
* converted into a RsGxsTunnelId
|
|
|
|
*/
|
2015-11-26 20:40:06 -05:00
|
|
|
class DistantChatService: public RsGxsTunnelService::RsGxsTunnelClientService
|
2014-11-08 09:55:29 -05:00
|
|
|
{
|
2014-11-17 16:56:41 -05:00
|
|
|
public:
|
2015-12-27 21:10:20 -05:00
|
|
|
DistantChatService() ;
|
2014-11-08 09:55:29 -05:00
|
|
|
|
2015-12-25 22:37:06 -05:00
|
|
|
virtual void triggerConfigSave()=0 ;
|
|
|
|
bool processLoadListItem(const RsItem *item) ;
|
|
|
|
void addToSaveList(std::list<RsItem*>& list) const;
|
2015-11-28 14:55:56 -05:00
|
|
|
|
2017-03-01 17:07:53 -05:00
|
|
|
/**
|
|
|
|
* Creates the invite if the public key of the distant peer is available.
|
|
|
|
* On 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,
|
|
|
|
DistantChatPeerId& dcpid,
|
|
|
|
uint32_t &error_code,
|
|
|
|
bool notify = true );
|
2015-11-26 20:40:06 -05:00
|
|
|
bool closeDistantChatConnexion(const DistantChatPeerId &tunnel_id) ;
|
|
|
|
|
2015-12-25 22:37:06 -05:00
|
|
|
// Sets flags to only allow connexion from some people.
|
|
|
|
|
|
|
|
uint32_t getDistantChatPermissionFlags() ;
|
|
|
|
bool setDistantChatPermissionFlags(uint32_t flags) ;
|
|
|
|
|
|
|
|
// Returns the status of a distant chat contact. The contact is defined by the tunnel id (turned into a DistantChatPeerId) because
|
|
|
|
// each pair of talking GXS id needs to be treated separately
|
|
|
|
|
2015-11-26 20:40:06 -05:00
|
|
|
virtual bool getDistantChatStatus(const DistantChatPeerId &tunnel_id, DistantChatPeerInfo& cinfo) ;
|
2014-11-08 09:55:29 -05:00
|
|
|
|
2015-11-30 00:02:44 -05:00
|
|
|
// derived in p3ChatService, so as to pass down some info
|
2014-11-17 16:56:41 -05:00
|
|
|
virtual void handleIncomingItem(RsItem *) = 0;
|
2016-04-21 22:07:50 -04:00
|
|
|
virtual bool handleRecvChatMsgItem(RsChatMsgItem *& ci)=0 ;
|
2014-11-08 09:55:29 -05:00
|
|
|
|
2014-11-17 16:56:41 -05:00
|
|
|
bool handleOutgoingItem(RsChatItem *) ;
|
|
|
|
bool handleRecvItem(RsChatItem *) ;
|
|
|
|
void handleRecvChatStatusItem(RsChatStatusItem *cs) ;
|
2014-11-08 09:55:29 -05:00
|
|
|
|
2014-11-17 16:56:41 -05:00
|
|
|
private:
|
2015-11-26 20:40:06 -05:00
|
|
|
struct DistantChatContact
|
2014-11-17 16:56:41 -05:00
|
|
|
{
|
2015-11-26 20:40:06 -05:00
|
|
|
RsGxsId from_id ;
|
|
|
|
RsGxsId to_id ;
|
2014-11-17 16:56:41 -05:00
|
|
|
};
|
|
|
|
// This maps contains the current peers to talk to with distant chat.
|
|
|
|
//
|
2015-11-26 20:40:06 -05:00
|
|
|
std::map<DistantChatPeerId, DistantChatContact> mDistantChatContacts ; // current peers we can talk to
|
2014-11-08 09:55:29 -05:00
|
|
|
|
2015-12-25 22:37:06 -05:00
|
|
|
// Permission handling
|
|
|
|
|
|
|
|
uint32_t mDistantChatPermissions ;
|
|
|
|
|
2015-11-26 20:40:06 -05:00
|
|
|
// Overloaded from RsGxsTunnelClientService
|
|
|
|
|
2015-12-25 22:37:06 -05:00
|
|
|
public:
|
|
|
|
virtual void connectToGxsTunnelService(RsGxsTunnelService *tunnel_service) ;
|
|
|
|
|
|
|
|
private:
|
2019-04-28 12:10:17 -04:00
|
|
|
virtual bool acceptDataFromPeer(
|
|
|
|
const RsGxsId& gxs_id, const RsGxsTunnelId& tunnel_id,
|
|
|
|
bool am_I_client_side);
|
|
|
|
virtual void notifyTunnelStatus(
|
|
|
|
const RsGxsTunnelId& tunnel_id, uint32_t tunnel_status);
|
|
|
|
virtual void receiveData(
|
|
|
|
const RsGxsTunnelId& id, unsigned char* data, uint32_t data_size );
|
2014-11-08 09:55:29 -05:00
|
|
|
|
2015-11-26 20:40:06 -05:00
|
|
|
// Utility functions.
|
|
|
|
|
2015-11-28 14:55:56 -05:00
|
|
|
void markDistantChatAsClosed(const DistantChatPeerId& dcpid) ;
|
2014-11-08 09:55:29 -05:00
|
|
|
|
2015-11-26 20:40:06 -05:00
|
|
|
RsGxsTunnelService *mGxsTunnels ;
|
2014-11-17 16:56:41 -05:00
|
|
|
RsMutex mDistantChatMtx ;
|
2014-11-08 09:55:29 -05:00
|
|
|
};
|