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"
|
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;
|
|
|
|
|
|
|
|
class NotifyBase; /* needed by FiStore */
|
|
|
|
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;
|
|
|
|
|
2008-08-17 11:23:11 -04:00
|
|
|
class ftServer: public RsFiles, public ftDataSend, public RsThread
|
2008-07-02 09:19:59 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/***************************************************************/
|
|
|
|
/******************** Setup ************************************/
|
|
|
|
/***************************************************************/
|
|
|
|
|
2010-01-13 15:56:55 -05:00
|
|
|
ftServer(p3ConnectMgr *connMgr);
|
2008-07-02 09:19:59 -04:00
|
|
|
|
|
|
|
/* Assign important variables */
|
|
|
|
void setConfigDirectory(std::string path);
|
|
|
|
|
2008-08-17 11:23:11 -04:00
|
|
|
void setP3Interface(P3Interface *pqi);
|
2008-07-02 09:19:59 -04:00
|
|
|
|
|
|
|
/* add Config Items (Extra, Controller) */
|
|
|
|
void addConfigComponents(p3ConfigMgr *mgr);
|
|
|
|
|
2008-08-03 08:45:53 -04:00
|
|
|
CacheStrapper *getCacheStrapper();
|
2008-07-02 09:19:59 -04:00
|
|
|
CacheTransfer *getCacheTransfer();
|
2008-10-29 16:58:23 -04:00
|
|
|
std::string OwnId();
|
2008-07-02 09:19:59 -04:00
|
|
|
|
2008-08-03 08:45:53 -04:00
|
|
|
/* Final Setup (once everything is assigned) */
|
2008-08-09 13:03:24 -04:00
|
|
|
//void SetupFtServer();
|
|
|
|
void SetupFtServer(NotifyBase *cb);
|
2009-05-26 17:42:45 -04:00
|
|
|
void connectToTurtleRouter(p3turtle *p) ;
|
2008-08-09 13:03:24 -04:00
|
|
|
|
2008-08-03 08:45:53 -04:00
|
|
|
void StartupThreads();
|
2010-05-29 11:14:25 -04:00
|
|
|
void StopThreads();
|
2008-08-03 08:45:53 -04:00
|
|
|
|
2008-08-17 11:23:11 -04:00
|
|
|
/* own thread */
|
|
|
|
virtual void run();
|
|
|
|
|
2010-02-07 13:10:12 -05:00
|
|
|
// Checks that the given hash is well formed. Used to chase
|
|
|
|
// string bugs.
|
|
|
|
static bool checkHash(const std::string& hash,std::string& error_string) ;
|
|
|
|
|
2008-07-02 09:19:59 -04:00
|
|
|
/***************************************************************/
|
|
|
|
/*************** Control Interface *****************************/
|
|
|
|
/************** (Implements RsFiles) ***************************/
|
|
|
|
/***************************************************************/
|
|
|
|
|
2009-05-26 17:42:45 -04:00
|
|
|
// member access
|
|
|
|
|
|
|
|
ftDataMultiplex *getMultiplexer() const { return mFtDataplex ; }
|
|
|
|
ftController *getController() const { return mFtController ; }
|
|
|
|
|
2008-08-03 08:45:53 -04:00
|
|
|
/***
|
|
|
|
* Control of Downloads
|
|
|
|
***/
|
2010-10-05 16:39:14 -04:00
|
|
|
virtual bool alreadyHaveFile(const std::string& hash, FileInfo &info);
|
2010-07-21 19:14:10 -04:00
|
|
|
virtual bool FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, uint32_t flags, const std::list<std::string>& srcIds);
|
|
|
|
virtual bool FileCancel(const std::string& hash);
|
|
|
|
virtual bool FileControl(const std::string& hash, uint32_t flags);
|
2008-07-02 12:58:13 -04:00
|
|
|
virtual bool FileClearCompleted();
|
2009-12-08 17:29:52 -05:00
|
|
|
virtual bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy s) ;
|
2010-03-21 17:07:12 -04:00
|
|
|
virtual void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy) ;
|
|
|
|
virtual FileChunksInfo::ChunkStrategy defaultChunkStrategy() ;
|
2010-05-21 16:49:48 -04:00
|
|
|
virtual uint32_t freeDiskSpaceLimit() const ;
|
|
|
|
virtual void setFreeDiskSpaceLimit(uint32_t size_in_mb) ;
|
2010-03-21 17:07:12 -04:00
|
|
|
|
2008-07-02 09:19:59 -04:00
|
|
|
|
2009-07-26 11:00:29 -04:00
|
|
|
/***
|
|
|
|
* Control of Downloads Priority.
|
|
|
|
***/
|
2010-03-06 18:29:47 -05:00
|
|
|
virtual uint32_t getQueueSize() ;
|
|
|
|
virtual void setQueueSize(uint32_t s) ;
|
|
|
|
virtual bool changeQueuePosition(const std::string hash, QueueMove queue_mv);
|
2010-01-26 18:25:00 -05:00
|
|
|
virtual bool changeDownloadSpeed(const std::string hash, int speed);
|
|
|
|
virtual bool getDownloadSpeed(const std::string hash, int & speed);
|
2009-07-26 11:00:29 -04:00
|
|
|
virtual bool clearDownload(const std::string hash);
|
2010-03-06 18:29:47 -05:00
|
|
|
//virtual void getDwlDetails(std::list<DwlDetails> & details);
|
2009-07-26 11:00:29 -04:00
|
|
|
|
2008-08-03 08:45:53 -04:00
|
|
|
/***
|
2009-07-12 09:22:31 -04:00
|
|
|
* Download/Upload Details
|
2008-08-03 08:45:53 -04:00
|
|
|
***/
|
2008-07-02 09:19:59 -04:00
|
|
|
virtual bool FileDownloads(std::list<std::string> &hashs);
|
|
|
|
virtual bool FileUploads(std::list<std::string> &hashs);
|
2010-10-27 16:01:31 -04:00
|
|
|
virtual bool FileDetails(const std::string &hash, uint32_t hintflags, FileInfo &info);
|
2010-01-11 11:00:42 -05:00
|
|
|
virtual bool FileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info) ;
|
|
|
|
virtual bool FileUploadChunksDetails(const std::string& hash,const std::string& peer_id,CompressedChunkMap& map) ;
|
|
|
|
|
2008-07-02 09:19:59 -04:00
|
|
|
|
2008-08-03 08:45:53 -04:00
|
|
|
/***
|
|
|
|
* Extra List Access
|
|
|
|
***/
|
2009-07-12 09:22:31 -04:00
|
|
|
virtual bool ExtraFileAdd(std::string fname, std::string hash, uint64_t size,
|
2008-08-03 08:45:53 -04:00
|
|
|
uint32_t period, uint32_t flags);
|
2008-07-23 18:01:59 -04:00
|
|
|
virtual bool ExtraFileRemove(std::string hash, uint32_t flags);
|
2009-07-12 09:22:31 -04:00
|
|
|
virtual bool ExtraFileHash(std::string localpath,
|
2008-08-03 08:45:53 -04:00
|
|
|
uint32_t period, uint32_t flags);
|
2008-07-02 09:19:59 -04:00
|
|
|
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info);
|
2008-11-27 16:23:46 -05:00
|
|
|
virtual bool ExtraFileMove(std::string fname, std::string hash, uint64_t size,
|
|
|
|
std::string destpath);
|
2008-07-02 09:19:59 -04:00
|
|
|
|
2008-08-03 08:45:53 -04:00
|
|
|
|
|
|
|
/***
|
|
|
|
* Directory Listing / Search Interface
|
|
|
|
***/
|
2008-07-02 09:19:59 -04:00
|
|
|
virtual int RequestDirDetails(std::string uid, std::string path, DirDetails &details);
|
|
|
|
virtual int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags);
|
2011-04-03 15:59:12 -04:00
|
|
|
virtual uint32_t getType(void *ref,uint32_t flags) ;
|
2008-07-02 09:19:59 -04:00
|
|
|
|
2009-08-25 16:49:50 -04:00
|
|
|
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags);
|
|
|
|
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,uint32_t flags);
|
2008-07-02 09:19:59 -04:00
|
|
|
|
2008-08-03 08:45:53 -04:00
|
|
|
/***
|
2009-07-12 09:22:31 -04:00
|
|
|
* Utility Functions
|
2008-08-03 08:45:53 -04:00
|
|
|
***/
|
2008-07-02 09:19:59 -04:00
|
|
|
virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath);
|
|
|
|
virtual void ForceDirectoryCheck();
|
|
|
|
virtual bool InDirectoryCheck();
|
2010-10-31 15:29:26 -04:00
|
|
|
virtual bool CopyFile(const std::string& source, const std::string& dest);
|
2008-07-02 09:19:59 -04:00
|
|
|
|
2008-08-03 08:45:53 -04:00
|
|
|
/***
|
2009-07-12 09:22:31 -04:00
|
|
|
* Directory Handling
|
2008-08-03 08:45:53 -04:00
|
|
|
***/
|
2008-07-02 09:19:59 -04:00
|
|
|
virtual void setDownloadDirectory(std::string path);
|
|
|
|
virtual void setPartialsDirectory(std::string path);
|
2008-07-02 12:58:13 -04:00
|
|
|
virtual std::string getDownloadDirectory();
|
|
|
|
virtual std::string getPartialsDirectory();
|
2008-07-02 09:19:59 -04:00
|
|
|
|
2009-08-03 15:43:52 -04:00
|
|
|
virtual bool getSharedDirectories(std::list<SharedDirInfo> &dirs);
|
|
|
|
virtual bool setSharedDirectories(std::list<SharedDirInfo> &dirs);
|
2010-09-17 15:21:14 -04:00
|
|
|
virtual bool addSharedDirectory(const SharedDirInfo& dir);
|
2009-08-03 15:43:52 -04:00
|
|
|
virtual bool updateShareFlags(const SharedDirInfo& dir); // updates the flags. The directory should already exist !
|
2008-07-02 12:58:13 -04:00
|
|
|
virtual bool removeSharedDirectory(std::string dir);
|
|
|
|
|
2009-07-12 09:22:31 -04:00
|
|
|
virtual bool getShareDownloadDirectory();
|
2011-03-08 15:05:36 -05:00
|
|
|
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
|
|
|
|
2008-07-02 09:19:59 -04:00
|
|
|
/***************************************************************/
|
|
|
|
/*************** Control Interface *****************************/
|
|
|
|
/***************************************************************/
|
|
|
|
|
2008-07-23 18:01:59 -04:00
|
|
|
/***************************************************************/
|
|
|
|
/*************** Data Transfer Interface ***********************/
|
|
|
|
/***************************************************************/
|
2008-08-03 08:45:53 -04:00
|
|
|
public:
|
2010-01-11 11:00:42 -05:00
|
|
|
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);
|
2010-07-25 15:04:31 -04:00
|
|
|
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) ;
|
2010-07-21 19:14:10 -04:00
|
|
|
virtual bool sendCRC32MapRequest(const std::string&, const std::string&) ;
|
|
|
|
virtual bool sendCRC32Map(const std::string&, const std::string&, const CRC32Map&) ;
|
|
|
|
|
2010-01-11 11:00:42 -05:00
|
|
|
|
2008-08-03 08:45:53 -04:00
|
|
|
|
|
|
|
/*************** Internal Transfer Fns *************************/
|
|
|
|
virtual int tick();
|
2008-07-23 18:01:59 -04:00
|
|
|
|
2008-11-15 15:00:29 -05:00
|
|
|
/* Configuration */
|
|
|
|
bool addConfiguration(p3ConfigMgr *cfgmgr);
|
|
|
|
bool ResumeTransfers();
|
|
|
|
|
2008-08-03 08:45:53 -04:00
|
|
|
private:
|
|
|
|
bool handleInputQueues();
|
|
|
|
bool handleCacheData();
|
|
|
|
bool handleFileData();
|
2008-07-23 18:01:59 -04:00
|
|
|
|
2008-07-02 09:19:59 -04:00
|
|
|
/******************* p3 Config Overload ************************/
|
|
|
|
protected:
|
|
|
|
/* Key Functions to be overloaded for Full Configuration */
|
|
|
|
virtual RsSerialiser *setupSerialiser();
|
2010-12-18 14:35:07 -05:00
|
|
|
virtual bool saveList(bool &cleanup, std::list<RsItem *>&);
|
|
|
|
virtual bool loadList(std::list<RsItem *>& load);
|
2008-07-02 09:19:59 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool loadConfigMap(std::map<std::string, std::string> &configMap);
|
|
|
|
/******************* p3 Config Overload ************************/
|
|
|
|
|
|
|
|
/*************************** p3 Config Overload ********************/
|
2008-08-03 08:45:53 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
/**** INTERNAL FUNCTIONS ***/
|
2008-08-16 11:02:24 -04:00
|
|
|
//virtual int reScanDirs();
|
|
|
|
//virtual int check_dBUpdate();
|
2008-08-03 08:45:53 -04:00
|
|
|
|
2008-07-02 09:19:59 -04:00
|
|
|
private:
|
|
|
|
|
2009-07-12 09:22:31 -04:00
|
|
|
/* no need for Mutex protection -
|
2008-07-02 09:19:59 -04:00
|
|
|
* as each component is protected independently.
|
|
|
|
*/
|
|
|
|
|
2008-08-03 08:45:53 -04:00
|
|
|
P3Interface *mP3iface; /* XXX THIS NEEDS PROTECTION */
|
|
|
|
p3ConnectMgr *mConnMgr;
|
|
|
|
|
2008-08-09 13:03:24 -04:00
|
|
|
ftCacheStrapper *mCacheStrapper;
|
|
|
|
ftFiStore *mFiStore;
|
|
|
|
ftFiMonitor *mFiMon;
|
2008-08-03 08:45:53 -04:00
|
|
|
|
2008-07-02 09:19:59 -04:00
|
|
|
ftController *mFtController;
|
|
|
|
ftExtraList *mFtExtra;
|
|
|
|
|
2008-08-03 08:45:53 -04:00
|
|
|
ftDataMultiplex *mFtDataplex;
|
2009-05-26 17:42:45 -04:00
|
|
|
p3turtle *mTurtleRouter ;
|
2008-08-03 08:45:53 -04:00
|
|
|
|
|
|
|
|
|
|
|
ftFileSearch *mFtSearch;
|
2008-07-02 09:19:59 -04:00
|
|
|
|
2009-07-26 11:00:29 -04:00
|
|
|
ftDwlQueue *mFtDwlQueue;
|
|
|
|
|
2008-07-02 09:19:59 -04:00
|
|
|
RsMutex srvMutex;
|
|
|
|
std::string mConfigPath;
|
|
|
|
std::string mDownloadPath;
|
|
|
|
std::string mPartialsPath;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|