mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-05 04:44:19 -04:00
merged with upstream/master
This commit is contained in:
commit
5d9272055f
2052 changed files with 8495 additions and 3638 deletions
132
libretroshare/src/retroshare/rsgxstunnel.h
Normal file
132
libretroshare/src/retroshare/rsgxstunnel.h
Normal file
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* libretroshare/src/services: rsgrouter.h
|
||||
*
|
||||
* Services for RetroShare.
|
||||
*
|
||||
* Copyright 2013 by Cyril Soler
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library 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 GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "csoler@users.sourceforge.net".
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "util/rsdir.h"
|
||||
#include "retroshare/rsids.h"
|
||||
#include "retroshare/rsturtle.h"
|
||||
#include "retroshare/rsgxsifacetypes.h"
|
||||
|
||||
class RsGxsTunnelService
|
||||
{
|
||||
public:
|
||||
typedef GXSTunnelId RsGxsTunnelId ;
|
||||
|
||||
enum {
|
||||
RS_GXS_TUNNEL_ERROR_NO_ERROR = 0x0000,
|
||||
RS_GXS_TUNNEL_ERROR_UNKNOWN_GXS_ID = 0x0001
|
||||
};
|
||||
|
||||
enum {
|
||||
RS_GXS_TUNNEL_STATUS_UNKNOWN = 0x00,
|
||||
RS_GXS_TUNNEL_STATUS_TUNNEL_DN = 0x01,
|
||||
RS_GXS_TUNNEL_STATUS_CAN_TALK = 0x02,
|
||||
RS_GXS_TUNNEL_STATUS_REMOTELY_CLOSED = 0x03
|
||||
};
|
||||
|
||||
class RsGxsTunnelClientService
|
||||
{
|
||||
public:
|
||||
// The client should derive this in order to handle notifications from the tunnel service.
|
||||
// This cannot be ignored because the client needs to know when the tunnel is active.
|
||||
|
||||
virtual void notifyTunnelStatus(const RsGxsTunnelId& tunnel_id,uint32_t tunnel_status) =0;
|
||||
|
||||
// Data obtained from the corresponding GXS id. The memory ownership is transferred to the client, which
|
||||
// is responsible to free it using free() once used.
|
||||
|
||||
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
|
||||
{
|
||||
public:
|
||||
// Tunnel information
|
||||
|
||||
RsGxsTunnelId tunnel_id ;
|
||||
RsGxsId destination_gxs_id ; // GXS Id we're talking to
|
||||
RsGxsId source_gxs_id ; // GXS Id we're using to talk
|
||||
uint32_t tunnel_status ; // active, requested, DH pending, etc.
|
||||
uint32_t total_size_sent ; // total bytes sent through that tunnel since openned (including management).
|
||||
uint32_t total_size_received ; // total bytes received through that tunnel since openned (including management).
|
||||
|
||||
// Data packets
|
||||
|
||||
uint32_t pending_data_packets; // number of packets not acknowledged by other side, still on their way. Should be 0 unless something bad happens.
|
||||
uint32_t total_data_packets_sent ; // total number of data packets sent (does not include tunnel management)
|
||||
uint32_t total_data_packets_received ; // total number of data packets received (does not include tunnel management)
|
||||
};
|
||||
|
||||
// This is the interface file for the secured tunnel service
|
||||
//
|
||||
//===================================================//
|
||||
// Debugging info //
|
||||
//===================================================//
|
||||
|
||||
virtual bool getTunnelsInfo(std::vector<GxsTunnelInfo>& infos) =0;
|
||||
virtual bool getTunnelInfo(const RsGxsTunnelId& tunnel_id,GxsTunnelInfo& info) =0;
|
||||
|
||||
// retrieve the routing probabilities
|
||||
|
||||
//===================================================//
|
||||
// Communication to other services. //
|
||||
//===================================================//
|
||||
|
||||
// Register a new client service. The service ID needs to be unique, and it's the coder's resonsibility to use an ID that is not used elsewhere
|
||||
// for the same purpose.
|
||||
|
||||
virtual bool registerClientService(uint32_t service_id,RsGxsTunnelClientService *service) =0;
|
||||
|
||||
// Asks for a tunnel. The service will request it to turtle router, and exchange a AES key using DH.
|
||||
// When the tunnel is secured, the client---here supplied as argument---will be notified. He can
|
||||
// then send data into the tunnel. The same tunnel may be used by different clients.
|
||||
// The service id is passed on so that the client is notified when the tunnel is up.
|
||||
|
||||
virtual bool requestSecuredTunnel(const RsGxsId& to_id,const RsGxsId& from_id,RsGxsTunnelId& tunnel_id,uint32_t service_id,uint32_t& error_code) =0 ;
|
||||
|
||||
// Data is sent through the established tunnel, possibly multiple times, until reception is acknowledged. If the tunnel does not exist, the item is rejected and
|
||||
// an error is issued. In any case, the memory ownership of the data is *not* transferred to the tunnel service, so the client should delete it afterwards, if needed.
|
||||
|
||||
virtual bool sendData(const RsGxsTunnelId& tunnel_id, uint32_t client_service_id, const uint8_t *data, uint32_t data_size) =0;
|
||||
|
||||
// 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.
|
||||
|
||||
virtual bool closeExistingTunnel(const RsGxsTunnelId& to_id,uint32_t service_id) =0;
|
||||
|
||||
//===================================================//
|
||||
// Routage feedback from other services //
|
||||
//===================================================//
|
||||
|
||||
};
|
||||
|
||||
// To access the GRouter from anywhere
|
||||
//
|
||||
extern RsGxsTunnelService *rsGxsTunnel ;
|
|
@ -209,15 +209,17 @@ static const int SHA1_SIZE = 20 ;
|
|||
|
||||
// These constants are random, but should be different, in order to make the various IDs incompatible with each other.
|
||||
//
|
||||
static const uint32_t RS_GENERIC_ID_SSL_ID_TYPE = 0x0001 ;
|
||||
static const uint32_t RS_GENERIC_ID_PGP_ID_TYPE = 0x0002 ;
|
||||
static const uint32_t RS_GENERIC_ID_SHA1_ID_TYPE = 0x0003 ;
|
||||
static const uint32_t RS_GENERIC_ID_PGP_FINGERPRINT_TYPE = 0x0004 ;
|
||||
static const uint32_t RS_GENERIC_ID_GXS_GROUP_ID_TYPE = 0x0005 ;
|
||||
static const uint32_t RS_GENERIC_ID_GXS_ID_TYPE = 0x0006 ;
|
||||
static const uint32_t RS_GENERIC_ID_GXS_MSG_ID_TYPE = 0x0007 ;
|
||||
static const uint32_t RS_GENERIC_ID_GXS_CIRCLE_ID_TYPE = 0x0008 ;
|
||||
static const uint32_t RS_GENERIC_ID_GROUTER_ID_TYPE = 0x0009 ;
|
||||
static const uint32_t RS_GENERIC_ID_SSL_ID_TYPE = 0x0001 ;
|
||||
static const uint32_t RS_GENERIC_ID_PGP_ID_TYPE = 0x0002 ;
|
||||
static const uint32_t RS_GENERIC_ID_SHA1_ID_TYPE = 0x0003 ;
|
||||
static const uint32_t RS_GENERIC_ID_PGP_FINGERPRINT_TYPE = 0x0004 ;
|
||||
static const uint32_t RS_GENERIC_ID_GXS_GROUP_ID_TYPE = 0x0005 ;
|
||||
static const uint32_t RS_GENERIC_ID_GXS_ID_TYPE = 0x0006 ;
|
||||
static const uint32_t RS_GENERIC_ID_GXS_MSG_ID_TYPE = 0x0007 ;
|
||||
static const uint32_t RS_GENERIC_ID_GXS_CIRCLE_ID_TYPE = 0x0008 ;
|
||||
static const uint32_t RS_GENERIC_ID_GROUTER_ID_TYPE = 0x0009 ;
|
||||
static const uint32_t RS_GENERIC_ID_GXS_TUNNEL_ID_TYPE = 0x0010 ;
|
||||
static const uint32_t RS_GENERIC_ID_GXS_DISTANT_CHAT_ID_TYPE = 0x0011 ;
|
||||
|
||||
typedef t_RsGenericIdType< SSL_ID_SIZE , false, RS_GENERIC_ID_SSL_ID_TYPE> SSLIdType ;
|
||||
typedef t_RsGenericIdType< PGP_KEY_ID_SIZE , true, RS_GENERIC_ID_PGP_ID_TYPE> PGPIdType ;
|
||||
|
@ -227,4 +229,6 @@ typedef t_RsGenericIdType< PGP_KEY_FINGERPRINT_SIZE, true, RS_GENERIC_ID_PGP_F
|
|||
typedef t_RsGenericIdType< CERT_SIGN_LEN , false, RS_GENERIC_ID_GXS_GROUP_ID_TYPE > GXSGroupId ;
|
||||
typedef t_RsGenericIdType< CERT_SIGN_LEN , false, RS_GENERIC_ID_GXS_ID_TYPE > GXSId ;
|
||||
typedef t_RsGenericIdType< CERT_SIGN_LEN , false, RS_GENERIC_ID_GXS_CIRCLE_ID_TYPE > GXSCircleId ;
|
||||
typedef t_RsGenericIdType< SSL_ID_SIZE , false, RS_GENERIC_ID_GXS_TUNNEL_ID_TYPE > GXSTunnelId ;
|
||||
typedef t_RsGenericIdType< SSL_ID_SIZE , false, RS_GENERIC_ID_GXS_DISTANT_CHAT_ID_TYPE > DistantChatPeerId ;
|
||||
|
||||
|
|
|
@ -99,9 +99,6 @@ typedef uint64_t ChatLobbyId ;
|
|||
typedef uint64_t ChatLobbyMsgId ;
|
||||
typedef std::string ChatLobbyNickName ;
|
||||
|
||||
typedef RsPeerId DistantChatPeerId ;
|
||||
//typedef GRouterKeyId DistantMsgPeerId ;
|
||||
|
||||
typedef uint64_t MessageId ;
|
||||
|
||||
|
||||
|
@ -253,12 +250,10 @@ public:
|
|||
#define RS_CHAT_PRIVATE 0x0002
|
||||
#define RS_CHAT_AVATAR_AVAILABLE 0x0004
|
||||
|
||||
#define RS_DISTANT_CHAT_STATUS_UNKNOWN 0x0000
|
||||
#define RS_DISTANT_CHAT_STATUS_TUNNEL_DN 0x0001
|
||||
#define RS_DISTANT_CHAT_STATUS_TUNNEL_OK 0x0002
|
||||
#define RS_DISTANT_CHAT_STATUS_CAN_TALK 0x0003
|
||||
#define RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED 0x0004
|
||||
#define RS_DISTANT_CHAT_STATUS_WAITING_DH 0x0005
|
||||
#define RS_DISTANT_CHAT_STATUS_UNKNOWN 0x0000
|
||||
#define RS_DISTANT_CHAT_STATUS_TUNNEL_DN 0x0001
|
||||
#define RS_DISTANT_CHAT_STATUS_CAN_TALK 0x0002
|
||||
#define RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED 0x0003
|
||||
|
||||
#define RS_DISTANT_CHAT_ERROR_NO_ERROR 0x0000
|
||||
#define RS_DISTANT_CHAT_ERROR_DECRYPTION_FAILED 0x0001
|
||||
|
@ -275,9 +270,13 @@ public:
|
|||
#define RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_EVERYBODY 0x0001
|
||||
#define RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_CONTACT_LIST 0x0002
|
||||
|
||||
#define RS_DISTANT_CHAT_CONTACT_PERMISSION_FLAG_NONE 0x0000
|
||||
#define RS_DISTANT_CHAT_CONTACT_PERMISSION_FLAG_EVERYBODY 0x0001
|
||||
#define RS_DISTANT_CHAT_CONTACT_PERMISSION_FLAG_CONTACT_LIST 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
|
||||
// neighbour peer, distant peer, chatlobby, broadcast
|
||||
|
@ -286,8 +285,8 @@ class ChatId
|
|||
public:
|
||||
ChatId();
|
||||
explicit ChatId(RsPeerId id);
|
||||
explicit ChatId(RsGxsId id);
|
||||
explicit ChatId(ChatLobbyId id);
|
||||
explicit ChatId(DistantChatPeerId id);
|
||||
explicit ChatId(std::string str);
|
||||
static ChatId makeBroadcastId();
|
||||
|
||||
|
@ -299,13 +298,14 @@ public:
|
|||
|
||||
bool isNotSet() const;
|
||||
bool isPeerId() const;
|
||||
bool isGxsId() const;
|
||||
bool isDistantChatId() const;
|
||||
bool isLobbyId() const;
|
||||
bool isBroadcast() const;
|
||||
|
||||
RsPeerId toPeerId() const;
|
||||
RsGxsId toGxsId() const;
|
||||
ChatLobbyId toLobbyId() const;
|
||||
DistantChatPeerId toDistantChatId() const;
|
||||
|
||||
// for the very specific case of transfering a status string
|
||||
// from the chatservice to the gui,
|
||||
|
@ -321,7 +321,7 @@ private:
|
|||
|
||||
Type type;
|
||||
RsPeerId peer_id;
|
||||
RsGxsId gxs_id;
|
||||
DistantChatPeerId distant_chat_id;
|
||||
ChatLobbyId lobby_id;
|
||||
};
|
||||
|
||||
|
@ -382,15 +382,6 @@ class ChatLobbyInfo
|
|||
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);
|
||||
|
||||
class RsMsgs;
|
||||
|
@ -491,9 +482,9 @@ virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const RsGxsId&
|
|||
/* Distant chat */
|
||||
/****************************************/
|
||||
|
||||
virtual bool initiateDistantChatConnexion(const RsGxsId& to_pid,const RsGxsId& from_pid,uint32_t& error_code) = 0;
|
||||
virtual bool getDistantChatStatus(const RsGxsId& gxs_id,uint32_t& status, RsGxsId *from_gxs_id = NULL) = 0;
|
||||
virtual bool closeDistantChatConnexion(const RsGxsId& pid) = 0;
|
||||
virtual bool initiateDistantChatConnexion(const RsGxsId& to_pid,const RsGxsId& from_pid,DistantChatPeerId& pid,uint32_t& error_code) = 0;
|
||||
virtual bool getDistantChatStatus(const DistantChatPeerId& pid,DistantChatPeerInfo& info)=0;
|
||||
virtual bool closeDistantChatConnexion(const DistantChatPeerId& pid)=0;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -42,12 +42,14 @@ class p3Service ;
|
|||
class RsServiceControl ;
|
||||
class RsReputations ;
|
||||
class RsTurtle ;
|
||||
class RsGxsTunnelService ;
|
||||
class RsDht ;
|
||||
class RsDisc ;
|
||||
class RsMsgs ;
|
||||
class RsGxsForums;
|
||||
class RsGxsChannels;
|
||||
class RsNotify;
|
||||
class RsServiceControl;
|
||||
class p3LinkMgr ;
|
||||
class MainPage ;
|
||||
class QIcon ;
|
||||
|
@ -74,6 +76,12 @@ class RsGcxs;
|
|||
class PgpAuxUtils;
|
||||
class p3Config;
|
||||
|
||||
namespace resource_api
|
||||
{
|
||||
class ResourceRouter;
|
||||
class StateTokenServer;
|
||||
}
|
||||
|
||||
// Plugin API version. Not used yet, but will be in the future the
|
||||
// main value that decides for compatibility.
|
||||
//
|
||||
|
@ -107,6 +115,8 @@ public:
|
|||
RsUtil::inited_ptr<RsDisc> mDisc;
|
||||
RsUtil::inited_ptr<RsDht> mDht;
|
||||
RsUtil::inited_ptr<RsNotify> mNotify;
|
||||
RsUtil::inited_ptr<RsServiceControl> mServiceControl;
|
||||
RsUtil::inited_ptr<RsPluginHandler> mPluginHandler;
|
||||
|
||||
// gxs
|
||||
std::string mGxsDir;
|
||||
|
@ -117,6 +127,7 @@ public:
|
|||
RsUtil::inited_ptr<PgpAuxUtils> mPgpAuxUtils;
|
||||
RsUtil::inited_ptr<RsGxsForums> mGxsForums;
|
||||
RsUtil::inited_ptr<RsGxsChannels> mGxsChannels;
|
||||
RsUtil::inited_ptr<RsGxsTunnelService> mGxsTunnels;
|
||||
RsUtil::inited_ptr<RsReputations> mReputations;
|
||||
};
|
||||
|
||||
|
@ -145,6 +156,12 @@ class RsPlugin
|
|||
virtual p3Config *p3_config() const { return NULL ; }
|
||||
virtual uint16_t rs_service_id() const { return 0 ; }
|
||||
|
||||
|
||||
// creates a new resource api handler object. ownership is transferred to the caller.
|
||||
// the caller should supply a statetokenserver, and keep it valid until destruction
|
||||
// the plugin should return a entry point name. this is to make the entry point name independent from file names
|
||||
virtual resource_api::ResourceRouter* new_resource_api_handler(const RsPlugInInterfaces& ifaces, resource_api::StateTokenServer* sts, std::string &entrypoint) const { return 0;}
|
||||
|
||||
// Shutdown
|
||||
virtual void stop() {}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue