2008-07-02 09:19:59 -04:00
|
|
|
/*
|
|
|
|
* libretroshare/src/ft: ftserver.h
|
|
|
|
*
|
|
|
|
* File Transfer for RetroShare.
|
|
|
|
*
|
|
|
|
* Copyright 2008 by Robert Fernie.
|
|
|
|
*
|
|
|
|
* 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 "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FT_SERVER_HEADER
|
|
|
|
#define FT_SERVER_HEADER
|
|
|
|
|
2009-07-12 09:22:31 -04:00
|
|
|
/*
|
2008-07-02 09:19:59 -04:00
|
|
|
* ftServer.
|
|
|
|
*
|
|
|
|
* Top level File Transfer interface.
|
|
|
|
* (replaces old filedexserver)
|
|
|
|
*
|
|
|
|
* sets up the whole File Transfer class structure.
|
|
|
|
* sets up the File Indexing side of cache system too.
|
|
|
|
*
|
|
|
|
* provides rsFiles interface for external control.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <list>
|
|
|
|
#include <iostream>
|
|
|
|
|
2008-08-03 08:45:53 -04:00
|
|
|
#include "ft/ftdata.h"
|
2013-04-01 17:18:58 -04:00
|
|
|
#include "turtle/turtleclientservice.h"
|
2010-08-06 05:40:23 -04:00
|
|
|
#include "retroshare/rsfiles.h"
|
2008-08-09 13:03:24 -04:00
|
|
|
//#include "dbase/cachestrapper.h"
|
2008-07-02 09:19:59 -04:00
|
|
|
|
2008-08-03 08:45:53 -04:00
|
|
|
#include "pqi/pqi.h"
|
2008-07-02 09:19:59 -04:00
|
|
|
#include "pqi/p3cfgmgr.h"
|
|
|
|
|
|
|
|
class p3ConnectMgr;
|
|
|
|
|
|
|
|
class CacheStrapper;
|
2008-08-09 13:03:24 -04:00
|
|
|
class CacheTransfer;
|
|
|
|
|
2014-01-07 17:51:22 -05:00
|
|
|
class pqiNotify; /* needed by FiStore */
|
2008-08-09 13:03:24 -04:00
|
|
|
class ftCacheStrapper;
|
|
|
|
class ftFiStore;
|
|
|
|
class ftFiMonitor;
|
2008-07-02 09:19:59 -04:00
|
|
|
|
2008-07-23 18:01:59 -04:00
|
|
|
class ftController;
|
|
|
|
class ftExtraList;
|
2008-08-03 08:45:53 -04:00
|
|
|
class ftFileSearch;
|
2008-07-02 09:19:59 -04:00
|
|
|
|
2008-08-03 08:45:53 -04:00
|
|
|
class ftDataMultiplex;
|
2009-05-26 17:42:45 -04:00
|
|
|
class p3turtle;
|
2008-08-03 08:45:53 -04:00
|
|
|
|
2009-07-26 11:00:29 -04:00
|
|
|
class ftDwlQueue;
|
|
|
|
|
2011-07-09 14:39:34 -04:00
|
|
|
class p3PeerMgr;
|
|
|
|
class p3LinkMgr;
|
|
|
|
|
2013-04-01 17:18:58 -04:00
|
|
|
class ftServer: public RsFiles, public ftDataSend, public RsTurtleClientService, public RsThread
|
2008-07-02 09:19:59 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2013-04-01 17:18:58 -04:00
|
|
|
/***************************************************************/
|
|
|
|
/******************** Setup ************************************/
|
|
|
|
/***************************************************************/
|
|
|
|
|
|
|
|
ftServer(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr);
|
|
|
|
|
|
|
|
/* Assign important variables */
|
|
|
|
void setConfigDirectory(std::string path);
|
|
|
|
|
|
|
|
void setP3Interface(P3Interface *pqi);
|
|
|
|
|
|
|
|
/* add Config Items (Extra, Controller) */
|
|
|
|
void addConfigComponents(p3ConfigMgr *mgr);
|
|
|
|
|
|
|
|
virtual CacheStrapper *getCacheStrapper();
|
|
|
|
virtual CacheTransfer *getCacheTransfer();
|
|
|
|
|
|
|
|
std::string OwnId();
|
|
|
|
|
|
|
|
/* Final Setup (once everything is assigned) */
|
2014-01-07 17:51:22 -05:00
|
|
|
void SetupFtServer() ;
|
2013-12-27 15:06:47 -05:00
|
|
|
virtual void connectToTurtleRouter(p3turtle *p) ;
|
2013-04-01 17:18:58 -04:00
|
|
|
|
|
|
|
void StartupThreads();
|
|
|
|
void StopThreads();
|
|
|
|
|
|
|
|
/* own thread */
|
|
|
|
virtual void run();
|
|
|
|
|
|
|
|
// Checks that the given hash is well formed. Used to chase
|
|
|
|
// string bugs.
|
|
|
|
static bool checkHash(const std::string& hash,std::string& error_string) ;
|
|
|
|
|
|
|
|
// Implements RsTurtleClientService
|
|
|
|
//
|
2013-04-20 14:56:06 -04:00
|
|
|
virtual bool handleTunnelRequest(const std::string& hash,const std::string& peer_id) ;
|
2013-04-06 05:21:01 -04:00
|
|
|
virtual void receiveTurtleData(RsTurtleGenericTunnelItem *item,const std::string& hash,const std::string& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) ;
|
|
|
|
virtual RsTurtleGenericTunnelItem *deserialiseItem(void *data,uint32_t size) const ;
|
2013-04-01 17:18:58 -04:00
|
|
|
|
2013-04-20 14:56:06 -04:00
|
|
|
void addVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&,RsTurtleGenericTunnelItem::Direction dir) ;
|
2013-04-10 04:52:52 -04:00
|
|
|
void removeVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&) ;
|
|
|
|
|
2013-04-01 17:18:58 -04:00
|
|
|
/***************************************************************/
|
|
|
|
/*************** Control Interface *****************************/
|
|
|
|
/************** (Implements RsFiles) ***************************/
|
|
|
|
/***************************************************************/
|
|
|
|
|
|
|
|
// member access
|
|
|
|
|
|
|
|
ftDataMultiplex *getMultiplexer() const { return mFtDataplex ; }
|
|
|
|
ftController *getController() const { return mFtController ; }
|
|
|
|
|
|
|
|
/***
|
|
|
|
* Control of Downloads
|
|
|
|
***/
|
|
|
|
virtual bool alreadyHaveFile(const std::string& hash, FileInfo &info);
|
|
|
|
virtual bool FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list<std::string>& srcIds);
|
|
|
|
virtual bool FileCancel(const std::string& hash);
|
|
|
|
virtual bool FileControl(const std::string& hash, uint32_t flags);
|
|
|
|
virtual bool FileClearCompleted();
|
|
|
|
virtual bool setDestinationDirectory(const std::string& hash,const std::string& new_path) ;
|
|
|
|
virtual bool setDestinationName(const std::string& hash,const std::string& new_name) ;
|
|
|
|
virtual bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy s) ;
|
|
|
|
virtual void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy) ;
|
|
|
|
virtual FileChunksInfo::ChunkStrategy defaultChunkStrategy() ;
|
|
|
|
virtual uint32_t freeDiskSpaceLimit() const ;
|
|
|
|
virtual void setFreeDiskSpaceLimit(uint32_t size_in_mb) ;
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
* Control of Downloads Priority.
|
|
|
|
***/
|
|
|
|
virtual uint32_t getMinPrioritizedTransfers() ;
|
|
|
|
virtual void setMinPrioritizedTransfers(uint32_t s) ;
|
|
|
|
virtual uint32_t getQueueSize() ;
|
|
|
|
virtual void setQueueSize(uint32_t s) ;
|
|
|
|
virtual bool changeQueuePosition(const std::string hash, QueueMove queue_mv);
|
|
|
|
virtual bool changeDownloadSpeed(const std::string hash, int speed);
|
|
|
|
virtual bool getDownloadSpeed(const std::string hash, int & speed);
|
|
|
|
virtual bool clearDownload(const std::string hash);
|
|
|
|
//virtual void getDwlDetails(std::list<DwlDetails> & details);
|
|
|
|
|
|
|
|
/***
|
|
|
|
* Download/Upload Details
|
|
|
|
***/
|
|
|
|
virtual bool FileDownloads(std::list<std::string> &hashs);
|
|
|
|
virtual bool FileUploads(std::list<std::string> &hashs);
|
|
|
|
virtual bool FileDetails(const std::string &hash, FileSearchFlags hintflags, FileInfo &info);
|
|
|
|
virtual bool FileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info) ;
|
|
|
|
virtual bool FileUploadChunksDetails(const std::string& hash,const std::string& peer_id,CompressedChunkMap& map) ;
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
* Extra List Access
|
|
|
|
***/
|
|
|
|
virtual bool ExtraFileAdd(std::string fname, std::string hash, uint64_t size, uint32_t period, TransferRequestFlags flags);
|
|
|
|
virtual bool ExtraFileRemove(std::string hash, TransferRequestFlags flags);
|
|
|
|
virtual bool ExtraFileHash(std::string localpath, uint32_t period, TransferRequestFlags flags);
|
|
|
|
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info);
|
|
|
|
virtual bool ExtraFileMove(std::string fname, std::string hash, uint64_t size, std::string destpath);
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
* Directory Listing / Search Interface
|
|
|
|
***/
|
|
|
|
virtual int RequestDirDetails(const std::string& uid, const std::string& path, DirDetails &details);
|
|
|
|
virtual int RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags);
|
|
|
|
virtual uint32_t getType(void *ref,FileSearchFlags flags) ;
|
|
|
|
|
|
|
|
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags);
|
|
|
|
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const std::string& peer_id);
|
|
|
|
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags);
|
|
|
|
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const std::string& peer_id);
|
|
|
|
|
|
|
|
/***
|
|
|
|
* Utility Functions
|
|
|
|
***/
|
|
|
|
virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath);
|
|
|
|
virtual void ForceDirectoryCheck();
|
|
|
|
virtual void updateSinceGroupPermissionsChanged() ;
|
|
|
|
virtual bool InDirectoryCheck();
|
2013-06-08 16:03:29 -04:00
|
|
|
virtual bool copyFile(const std::string& source, const std::string& dest);
|
2013-04-01 17:18:58 -04:00
|
|
|
|
|
|
|
/***
|
|
|
|
* Directory Handling
|
|
|
|
***/
|
|
|
|
virtual void setDownloadDirectory(std::string path);
|
|
|
|
virtual void setPartialsDirectory(std::string path);
|
|
|
|
virtual std::string getDownloadDirectory();
|
|
|
|
virtual std::string getPartialsDirectory();
|
|
|
|
|
|
|
|
virtual bool getSharedDirectories(std::list<SharedDirInfo> &dirs);
|
|
|
|
virtual bool setSharedDirectories(std::list<SharedDirInfo> &dirs);
|
|
|
|
virtual bool addSharedDirectory(const SharedDirInfo& dir);
|
|
|
|
virtual bool updateShareFlags(const SharedDirInfo& dir); // updates the flags. The directory should already exist !
|
|
|
|
virtual bool removeSharedDirectory(std::string dir);
|
|
|
|
|
|
|
|
virtual bool getShareDownloadDirectory();
|
|
|
|
virtual bool shareDownloadDirectory(bool share);
|
2008-07-02 09:19:59 -04:00
|
|
|
|
2010-10-31 16:35:31 -04:00
|
|
|
virtual void setRememberHashFilesDuration(uint32_t days) ;
|
|
|
|
virtual uint32_t rememberHashFilesDuration() const ;
|
|
|
|
virtual bool rememberHashFiles() const ;
|
|
|
|
virtual void setRememberHashFiles(bool) ;
|
|
|
|
virtual void clearHashCache() ;
|
2011-03-28 17:52:21 -04:00
|
|
|
virtual void setWatchPeriod(int minutes) ;
|
|
|
|
virtual int watchPeriod() const ;
|
2010-10-31 16:35:31 -04:00
|
|
|
|
2013-04-01 17:18:58 -04:00
|
|
|
/***************************************************************/
|
|
|
|
/*************** Control Interface *****************************/
|
|
|
|
/***************************************************************/
|
|
|
|
|
|
|
|
/***************************************************************/
|
|
|
|
/*************** Data Transfer Interface ***********************/
|
|
|
|
/***************************************************************/
|
|
|
|
public:
|
|
|
|
virtual bool sendData(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
|
|
|
|
virtual bool sendDataRequest(const std::string& peerId, const std::string& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
|
|
|
|
virtual bool sendChunkMapRequest(const std::string& peer_id,const std::string& hash,bool is_client) ;
|
|
|
|
virtual bool sendChunkMap(const std::string& peer_id,const std::string& hash,const CompressedChunkMap& cmap,bool is_client) ;
|
|
|
|
virtual bool sendCRC32MapRequest(const std::string&, const std::string&) ;
|
|
|
|
virtual bool sendCRC32Map(const std::string&, const std::string&, const CRC32Map&) ;
|
|
|
|
virtual bool sendSingleChunkCRCRequest(const std::string& peer_id,const std::string& hash,uint32_t chunk_number) ;
|
|
|
|
virtual bool sendSingleChunkCRC(const std::string& peer_id,const std::string& hash,uint32_t chunk_number,const Sha1CheckSum& crc) ;
|
|
|
|
|
|
|
|
/*************** Internal Transfer Fns *************************/
|
|
|
|
virtual int tick();
|
|
|
|
|
|
|
|
/* Configuration */
|
|
|
|
bool addConfiguration(p3ConfigMgr *cfgmgr);
|
|
|
|
bool ResumeTransfers();
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool handleInputQueues();
|
|
|
|
bool handleCacheData();
|
|
|
|
bool handleFileData();
|
|
|
|
|
|
|
|
/******************* p3 Config Overload ************************/
|
2008-07-02 09:19:59 -04:00
|
|
|
protected:
|
2013-04-01 17:18:58 -04:00
|
|
|
/* Key Functions to be overloaded for Full Configuration */
|
|
|
|
virtual RsSerialiser *setupSerialiser();
|
|
|
|
virtual bool saveList(bool &cleanup, std::list<RsItem *>&);
|
|
|
|
virtual bool loadList(std::list<RsItem *>& load);
|
2008-07-02 09:19:59 -04:00
|
|
|
|
|
|
|
private:
|
2013-04-01 17:18:58 -04:00
|
|
|
bool loadConfigMap(std::map<std::string, std::string> &configMap);
|
|
|
|
/******************* p3 Config Overload ************************/
|
2008-07-02 09:19:59 -04:00
|
|
|
|
2013-04-01 17:18:58 -04:00
|
|
|
/*************************** p3 Config Overload ********************/
|
2008-08-03 08:45:53 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2013-04-01 17:18:58 -04:00
|
|
|
/**** INTERNAL FUNCTIONS ***/
|
|
|
|
//virtual int reScanDirs();
|
|
|
|
//virtual int check_dBUpdate();
|
2008-08-03 08:45:53 -04:00
|
|
|
|
2008-07-02 09:19:59 -04:00
|
|
|
private:
|
|
|
|
|
2013-04-01 17:18:58 -04:00
|
|
|
/* no need for Mutex protection -
|
|
|
|
* as each component is protected independently.
|
|
|
|
*/
|
|
|
|
|
|
|
|
P3Interface *mP3iface; /* XXX THIS NEEDS PROTECTION */
|
2008-07-02 09:19:59 -04:00
|
|
|
|
2013-04-01 17:18:58 -04:00
|
|
|
p3PeerMgr *mPeerMgr;
|
|
|
|
p3LinkMgr *mLinkMgr;
|
2008-08-03 08:45:53 -04:00
|
|
|
|
2013-04-01 17:18:58 -04:00
|
|
|
ftCacheStrapper *mCacheStrapper;
|
|
|
|
ftFiStore *mFiStore;
|
|
|
|
ftFiMonitor *mFiMon;
|
2008-08-03 08:45:53 -04:00
|
|
|
|
2013-04-01 17:18:58 -04:00
|
|
|
ftController *mFtController;
|
|
|
|
ftExtraList *mFtExtra;
|
2008-07-02 09:19:59 -04:00
|
|
|
|
2013-04-01 17:18:58 -04:00
|
|
|
ftDataMultiplex *mFtDataplex;
|
|
|
|
p3turtle *mTurtleRouter ;
|
2008-08-03 08:45:53 -04:00
|
|
|
|
|
|
|
|
2013-04-01 17:18:58 -04:00
|
|
|
ftFileSearch *mFtSearch;
|
2008-07-02 09:19:59 -04:00
|
|
|
|
2013-04-01 17:18:58 -04:00
|
|
|
ftDwlQueue *mFtDwlQueue;
|
2009-07-26 11:00:29 -04:00
|
|
|
|
2013-04-01 17:18:58 -04:00
|
|
|
RsMutex srvMutex;
|
|
|
|
std::string mConfigPath;
|
|
|
|
std::string mDownloadPath;
|
|
|
|
std::string mPartialsPath;
|
2008-07-02 09:19:59 -04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|