* Switched to rsFiles interface for all File Information.

* added TMP p3Files class to interface with old system.
 * cleaned up old RsControl + RsIface file information.
 * removed unnecessary functions from RsServer.
 * Tweaked interfaces for ftServer + ftExtraList.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@630 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2008-07-02 16:58:13 +00:00
parent 6d3c5679c5
commit be392405e8
14 changed files with 571 additions and 390 deletions

View File

@ -92,13 +92,13 @@ bool addExtraFile(std::string path, std::string hash,
**/ **/
bool hashExtraFile(std::string path, uint32_t period, uint32_t flags); bool hashExtraFile(std::string path, uint32_t period, uint32_t flags);
bool hashExtraFileDone(std::string path, FileDetails &details); bool hashExtraFileDone(std::string path, FileInfo &info);
/*** /***
* Search Function - used by File Transfer * Search Function - used by File Transfer
* *
**/ **/
bool searchExtraFiles(std::string hash, FileDetails &details); bool searchExtraFiles(std::string hash, FileInfo &info);
/*** /***
* Configuration - store extra files. * Configuration - store extra files.
@ -114,7 +114,7 @@ virtual bool loadList(std::list<RsItem *> load);
RsMutex extMutex; RsMutex extMutex;
std::map<std::string, std::string> hashedList; /* path -> hash ( not saved ) */ std::map<std::string, std::string> hashedList; /* path -> hash ( not saved ) */
std::map<std::string, FileDetails> files; std::map<std::string, FileInfo> files;
}; };

View File

@ -90,11 +90,11 @@ CacheTransfer *getCacheTransfer();
/************** (Implements RsFiles) ***************************/ /************** (Implements RsFiles) ***************************/
/***************************************************************/ /***************************************************************/
virtual int FileRequest(std::string fname, std::string hash, virtual bool FileRequest(std::string fname, std::string hash,
uint32_t size, std::string dest, uint32_t flags); uint32_t size, std::string dest, uint32_t flags);
virtual int FileCancel(std::string hash); virtual bool FileCancel(std::string hash);
virtual int FileControl(std::string hash, uint32_t flags); virtual bool FileControl(std::string hash, uint32_t flags);
virtual int FileClearCompleted(); virtual bool FileClearCompleted();
/* get Details of File Transfers */ /* get Details of File Transfers */
virtual bool FileDownloads(std::list<std::string> &hashs); virtual bool FileDownloads(std::list<std::string> &hashs);
@ -102,9 +102,9 @@ virtual bool FileUploads(std::list<std::string> &hashs);
virtual bool FileDetails(std::string hash, uint32_t hintflags, FileInfo &info); virtual bool FileDetails(std::string hash, uint32_t hintflags, FileInfo &info);
/* Access ftExtraList - Details */ /* Access ftExtraList - Details */
virtual int ExtraFileAdd(std::string fname, std::string hash, uint32_t size, virtual bool ExtraFileAdd(std::string fname, std::string hash, uint32_t size,
uint32_t period, uint32_t flags); uint32_t period, uint32_t flags);
virtual int ExtraFileRemove(std::string hash, uin32_t flags); virtual bool ExtraFileRemove(std::string hash, uin32_t flags);
virtual bool ExtraFileHash(std::string localpath, uint32_t period, uint32_t flags); virtual bool ExtraFileHash(std::string localpath, uint32_t period, uint32_t flags);
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info); virtual bool ExtraFileStatus(std::string localpath, FileInfo &info);
@ -124,10 +124,14 @@ virtual bool InDirectoryCheck();
/* Directory Handling */ /* Directory Handling */
virtual void setDownloadDirectory(std::string path); virtual void setDownloadDirectory(std::string path);
virtual void setPartialsDirectory(std::string path); virtual void setPartialsDirectory(std::string path);
virtual std::string getDownloadDirectory();
virtual std::string getPartialsDirectory();
virtual bool getSharedDirectories(std::list<std::string> &dirs); virtual bool getSharedDirectories(std::list<std::string> &dirs);
virtual int addSharedDirectory(std::string dir); virtual bool addSharedDirectory(std::string dir);
virtual int removeSharedDirectory(std::string dir); virtual bool removeSharedDirectory(std::string dir);
virtual int reScanDirs(); virtual int reScanDirs();
virtual int check_dBUpdate(); virtual int check_dBUpdate();

View File

@ -33,12 +33,10 @@
#include "rsiface/rstypes.h" #include "rsiface/rstypes.h"
std::ostream &operator<<(std::ostream &out, const MessageInfo &info);
std::ostream &operator<<(std::ostream &out, const ChatInfo &info);
class RsFiles; class RsFiles;
extern RsFiles *rsFiles; extern RsFiles *rsFiles;
class Expression;
const uint32_t RS_FILE_CTRL_PAUSE = 0x0100; const uint32_t RS_FILE_CTRL_PAUSE = 0x0100;
const uint32_t RS_FILE_CTRL_START = 0x0200; const uint32_t RS_FILE_CTRL_START = 0x0200;
@ -81,11 +79,11 @@ virtual bool FileDetails(std::string hash, uint32_t hintflags, FileInfo &info)=
*/ */
virtual int FileRequest(std::string fname, std::string hash, virtual bool FileRequest(std::string fname, std::string hash,
uint32_t size, std::string dest, uint32_t flags) = 0; uint32_t size, std::string dest, uint32_t flags) = 0;
virtual int FileCancel(std::string hash)= 0; virtual bool FileCancel(std::string hash) = 0;
virtual int FileControl(std::string hash, uint32_t flags)= 0; virtual bool FileControl(std::string hash, uint32_t flags) = 0;
virtual int FileClearCompleted()= 0; virtual bool FileClearCompleted() = 0;
/* /*
@ -101,9 +99,9 @@ virtual int FileClearCompleted()= 0;
*/ */
/* Access ftExtraList - Details */ /* Access ftExtraList - Details */
virtual int ExtraFileAdd(std::string fname, std::string hash, uint32_t size, virtual bool ExtraFileAdd(std::string fname, std::string hash, uint32_t size,
uint32_t period, uint32_t flags) = 0; uint32_t period, uint32_t flags) = 0;
virtual int ExtraFileRemove(std::string hash, uin32_t flags)= 0; virtual bool ExtraFileRemove(std::string hash, uint32_t flags) = 0;
virtual bool ExtraFileHash(std::string localpath, virtual bool ExtraFileHash(std::string localpath,
uint32_t period, uint32_t flags) = 0; uint32_t period, uint32_t flags) = 0;
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info) = 0; virtual bool ExtraFileStatus(std::string localpath, FileInfo &info) = 0;
@ -121,13 +119,22 @@ virtual int SearchKeywords(std::list<std::string> keywords, std::list<FileDetail
virtual int SearchBoolExp(Expression * exp, std::list<FileDetail> &results) = 0; virtual int SearchBoolExp(Expression * exp, std::list<FileDetail> &results) = 0;
/* /*
* 5) Utility Functions. * 5) Directory Control / Shared Files Utility Functions.
*/ */
virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath) = 0; virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath) = 0;
virtual void ForceDirectoryCheck() = 0; virtual void ForceDirectoryCheck() = 0;
virtual bool InDirectoryCheck() = 0; virtual bool InDirectoryCheck() = 0;
virtual void setDownloadDirectory(std::string path) = 0;
virtual void setPartialsDirectory(std::string path) = 0;
virtual std::string getDownloadDirectory() = 0;
virtual std::string getPartialsDirectory() = 0;
virtual bool getSharedDirectories(std::list<std::string> &dirs) = 0;
virtual bool addSharedDirectory(std::string dir) = 0;
virtual bool removeSharedDirectory(std::string dir) = 0;
}; };

View File

@ -34,9 +34,7 @@
class NotifyBase; class NotifyBase;
class RsIface; class RsIface;
class RsControl; class RsControl;
//class RsServer;
class RsInit; class RsInit;
class Expression;
/* declare single RsIface for everyone to use! */ /* declare single RsIface for everyone to use! */
@ -88,9 +86,6 @@ public:
virtual void lockData() = 0; virtual void lockData() = 0;
virtual void unlockData() = 0; virtual void unlockData() = 0;
const std::list<FileTransferInfo> &getTransferList()
{ return mTransferList; }
const std::list<FileInfo> &getRecommendList() const std::list<FileInfo> &getRecommendList()
{ return mRecommendList; } { return mRecommendList; }
@ -129,7 +124,6 @@ bool hasChanged(DataFlags set); /* resets it */
void fillLists(); /* create some dummy data to display */ void fillLists(); /* create some dummy data to display */
/* Internals */ /* Internals */
std::list<FileTransferInfo> mTransferList;
std::list<FileInfo> mRecommendList; std::list<FileInfo> mRecommendList;
bool mChanged[NumOfFlags]; bool mChanged[NumOfFlags];
@ -156,34 +150,6 @@ virtual ~RsControl() { return; }
/* Real Startup Fn */ /* Real Startup Fn */
virtual int StartupRetroShare(RsInit *config) = 0; virtual int StartupRetroShare(RsInit *config) = 0;
/****************************************/
/* Directory Actions */
virtual int RequestDirDetails(std::string uid, std::string path, DirDetails &details) = 0;
virtual int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) = 0;
virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath) = 0;
virtual void ForceDirectoryCheck() = 0;
virtual bool InDirectoryCheck() = 0;
/****************************************/
/* Search Actions */
virtual int SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results) = 0;
virtual int SearchBoolExp(Expression *exp, std::list<FileDetail> &results) = 0;
/****************************************/
/* Actions For Upload/Download */
//virtual int FileDelete(std::string uId, std::string fname) = 0;
//virtual int FileMove(std::string uId, std::string src, std::string dest) = 0;
virtual int FileRecommend(std::string fname, std::string hash, int size) = 0;
virtual int FileRequest(std::string fname, std::string hash, uint32_t size, std::string dest) = 0;
virtual int FileCancel(std::string fname, std::string hash, uint32_t size) = 0;
// Transfer control.
virtual int FileClearCompleted() = 0;
virtual int FileSetBandwidthTotals(float outkB, float inkB) = 0;
/****************************************/ /****************************************/
/* Flagging Persons / Channels / Files in or out of a set (CheckLists) */ /* Flagging Persons / Channels / Files in or out of a set (CheckLists) */
@ -201,16 +167,8 @@ virtual int ClearInRecommend() = 0;
virtual bool IsInChat(std::string id) = 0; /* friend : chat msgs */ virtual bool IsInChat(std::string id) = 0; /* friend : chat msgs */
virtual bool IsInMsg(std::string id) = 0; /* friend : msg recpts*/ virtual bool IsInMsg(std::string id) = 0; /* friend : msg recpts*/
/****************************************/
/* RsIface Networking */
//virtual int NetworkDHTActive(bool active) = 0;
//virtual int NetworkUPnPActive(bool active) = 0;
/****************************************/ /****************************************/
/* Config */ /* Config */
virtual int ConfigAddSharedDir( std::string dir ) = 0;
virtual int ConfigRemoveSharedDir( std::string dir ) = 0;
virtual int ConfigSetIncomingDir( std::string dir ) = 0;
virtual int ConfigSetDataRates( int total, int indiv ) = 0; virtual int ConfigSetDataRates( int total, int indiv ) = 0;
virtual int ConfigGetDataRates( float &inKb, float &outKb) = 0; virtual int ConfigGetDataRates( float &inKb, float &outKb) = 0;

View File

@ -105,9 +105,6 @@ class RsConfig
std::string ownId; std::string ownId;
std::string ownName; std::string ownName;
std::list<std::string> sharedDirList;
std::string incomingDir;
std::string localAddr; std::string localAddr;
int localPort; int localPort;
std::string extAddr; std::string extAddr;

View File

@ -13,13 +13,14 @@ RSOBJ = p3peers.o \
p3msgs.o \ p3msgs.o \
p3Blog.o \ p3Blog.o \
p3discovery.o \ p3discovery.o \
p3face-file.o \
p3face-server.o \ p3face-server.o \
p3face-config.o \ p3face-config.o \
p3face-startup.o \ p3face-startup.o \
p3face-msgs.o \ p3face-msgs.o \
rsiface.o rsiface.o \
p3files.o \
# p3face-file.o \
# rstypes.o \ # rstypes.o \
# pqistrings.o \ # pqistrings.o \
# p3face-people.o # p3face-people.o

View File

@ -41,204 +41,6 @@ const int p3facemsgzone = 11453;
/* RsIface Config */ /* RsIface Config */
/* Config */ /* Config */
int RsServer::ConfigAddSharedDir( std::string dir )
{
/* call the server... */
RsIface &iface = getIface();
/* lock Mutexes */
lockRsCore(); /* LOCK */
iface.lockData(); /* LOCK */
server -> addSearchDirectory(dir);
/* unlock Mutexes */
iface.unlockData(); /* UNLOCK */
unlockRsCore(); /* UNLOCK */
/* does its own locking */
UpdateAllConfig();
return 1;
}
int RsServer::ConfigRemoveSharedDir( std::string dir )
{
/* fill the rsiface class */
RsIface &iface = getIface();
/* lock Mutexes */
lockRsCore(); /* LOCK */
iface.lockData(); /* LOCK */
server -> removeSearchDirectory(dir);
/* unlock Mutexes */
iface.unlockData(); /* UNLOCK */
unlockRsCore(); /* UNLOCK */
/* does its own locking */
UpdateAllConfig();
return 1;
}
int RsServer::ConfigSetIncomingDir( std::string dir )
{
/* fill the rsiface class */
RsIface &iface = getIface();
/* lock Mutexes */
lockRsCore(); /* LOCK */
iface.lockData(); /* LOCK */
server -> setSaveDir(dir);
/* unlock Mutexes */
iface.unlockData(); /* UNLOCK */
unlockRsCore(); /* UNLOCK */
/* does its own locking */
UpdateAllConfig();
return 1;
}
#if 0
int RsServer::ConfigSetLocalAddr( std::string ipAddr, int port )
{
/* check if this is all necessary */
struct in_addr inaddr_local;
if (0 == inet_aton(ipAddr.c_str(), &inaddr_local))
{
//bad address - reset.
return 0;
}
/* fill the rsiface class */
RsIface &iface = getIface();
/* lock Mutexes */
lockRsCore(); /* LOCK */
iface.lockData(); /* LOCK */
/* a little rough and ready, should be moved to the server! */
cert *c = sslr -> getOwnCert();
/* always change the address (checked by sslr->checkNetAddress()) */
c -> localaddr.sin_addr = inaddr_local;
c -> localaddr.sin_port = htons((short) port);
sslr -> checkNetAddress();
pqih -> restart_listener();
sslr -> CertsChanged();
/* unlock Mutexes */
iface.unlockData(); /* UNLOCK */
unlockRsCore(); /* UNLOCK */
/* does its own locking */
UpdateAllConfig();
return 1;
}
int RsServer::ConfigSetExtAddr( std::string ipAddr, int port )
{
/* check if this is all necessary */
struct in_addr inaddr;
if (0 == inet_aton(ipAddr.c_str(), &inaddr))
{
//bad address - reset.
return 0;
}
/* fill the rsiface class */
RsIface &iface = getIface();
/* lock Mutexes */
lockRsCore(); /* LOCK */
iface.lockData(); /* LOCK */
/* a little rough and ready, should be moved to the server! */
cert *c = sslr -> getOwnCert();
/* always change the address (checked by sslr->checkNetAddress()) */
c -> serveraddr.sin_addr = inaddr;
c -> serveraddr.sin_port = htons((short) port);
sslr -> checkNetAddress();
sslr -> CertsChanged();
/* unlock Mutexes */
iface.unlockData(); /* UNLOCK */
unlockRsCore(); /* UNLOCK */
/* does its own locking */
UpdateAllConfig();
return 1;
}
int RsServer::ConfigSetLanConfig( bool firewalled, bool forwarded )
{
/* fill the rsiface class */
RsIface &iface = getIface();
/* lock Mutexes */
lockRsCore(); /* LOCK */
iface.lockData(); /* LOCK */
/* a little rough and ready, should be moved to the server! */
cert *c = sslr -> getOwnCert();
c -> Firewalled(firewalled);
c -> Forwarded(forwarded);
sslr -> checkNetAddress();
sslr -> CertsChanged();
/* unlock Mutexes */
iface.unlockData(); /* UNLOCK */
unlockRsCore(); /* UNLOCK */
/* does its own locking */
UpdateAllConfig();
return 1;
}
int RsServer::ConfigSetExtName( std::string addr )
{
/* fill the rsiface class */
RsIface &iface = getIface();
/* lock Mutexes */
lockRsCore(); /* LOCK */
iface.lockData(); /* LOCK */
/* a little rough and ready, should be moved to the server! */
//cert *c = sslr -> getOwnCert();
/* set the Name here */
sslr -> checkNetAddress();
sslr -> CertsChanged();
/* unlock Mutexes */
iface.unlockData(); /* UNLOCK */
unlockRsCore(); /* UNLOCK */
/* does its own locking */
UpdateAllConfig();
return 1;
}
#endif /* 0 */
int RsServer::ConfigSetDataRates( int total, int indiv ) /* in kbrates */ int RsServer::ConfigSetDataRates( int total, int indiv ) /* in kbrates */
{ {
/* fill the rsiface class */ /* fill the rsiface class */
@ -291,7 +93,6 @@ int RsServer::ConfigSetBootPrompt( bool on )
} }
int RsServer::UpdateAllConfig() int RsServer::UpdateAllConfig()
{ {
/* fill the rsiface class */ /* fill the rsiface class */
@ -308,12 +109,6 @@ int RsServer::UpdateAllConfig()
peerConnectState pstate; peerConnectState pstate;
mConnMgr->getOwnNetStatus(pstate); mConnMgr->getOwnNetStatus(pstate);
/* shared dirs */
std::list<std::string> &dirs = server -> getSearchDirectories();
config.sharedDirList = dirs;
config.incomingDir = server->getSaveDir();
/* ports */ /* ports */
config.localAddr = inet_ntoa(pstate.localaddr.sin_addr); config.localAddr = inet_ntoa(pstate.localaddr.sin_addr);
config.localPort = ntohs(pstate.localaddr.sin_port); config.localPort = ntohs(pstate.localaddr.sin_port);

View File

@ -38,14 +38,6 @@ const int p3facemsgzone = 11453;
#include <time.h> #include <time.h>
void RsServer::intCheckFileStatus(FileInfo &file)
{
/* see if its being transfered */
file.avail = file.size / 2;
file.rank = 0;
}
/* Flagging Persons / Channels / Files in or out of a set (CheckLists) */ /* Flagging Persons / Channels / Files in or out of a set (CheckLists) */
int RsServer::ClearInChat() int RsServer::ClearInChat()
{ {

View File

@ -26,6 +26,7 @@
#include "rsserver/p3face.h" #include "rsserver/p3face.h"
#include "rsserver/p3files.h" // TMP FOR HACK!
#include "tcponudp/tou.h" #include "tcponudp/tou.h"
#include <sstream> #include <sstream>
@ -190,7 +191,13 @@ void RsServer::run()
// currently Dummy Functions. // currently Dummy Functions.
//std::cerr << "RsServer::run() UpdateAllTransfers()" << std::endl; //std::cerr << "RsServer::run() UpdateAllTransfers()" << std::endl;
UpdateAllTransfers(); //
// TMP HACK.
p3Files *p3f = (p3Files *) rsFiles;
if (p3f)
{
p3f -> UpdateAllTransfers();
}
//std::cerr << "RsServer::run() "; //std::cerr << "RsServer::run() ";
//std::cerr << "UpdateRemotePeople()"<<std::endl; //std::cerr << "UpdateRemotePeople()"<<std::endl;

View File

@ -70,6 +70,7 @@
#include "rsserver/p3Blog.h" #include "rsserver/p3Blog.h"
#include "rsiface/rsgame.h" #include "rsiface/rsgame.h"
#include "rsserver/p3files.h"
#include "pqi/p3notify.h" // HACK - moved to pqi for compilation order. #include "pqi/p3notify.h" // HACK - moved to pqi for compilation order.
@ -564,6 +565,13 @@ int RsServer::StartupRetroShare(RsInit *config)
server->setFileCallback(ownId, mCacheStrapper, mCacheTransfer, &(getNotify())); server->setFileCallback(ownId, mCacheStrapper, mCacheTransfer, &(getNotify()));
server->setEmergencySaveDir(emergencySaveDir); /* (after setFileCallback()) if saveDir invalid */ server->setEmergencySaveDir(emergencySaveDir); /* (after setFileCallback()) if saveDir invalid */
/*
* *** TMP NEW INTERFACE FOR FILES - until ftServer comes online ***
*/
rsFiles = new p3Files(server, this, mAuthMgr);
mConfigMgr = new p3ConfigMgr(mAuthMgr, config->basedir, "rs-v0.4.cfg", "rs-v0.4.sgn"); mConfigMgr = new p3ConfigMgr(mAuthMgr, config->basedir, "rs-v0.4.cfg", "rs-v0.4.sgn");
mGeneralConfig = new p3GeneralConfig(); mGeneralConfig = new p3GeneralConfig();
@ -781,6 +789,7 @@ int RsServer::StartupRetroShare(RsInit *config)
rsDisc = new p3Discovery(ad); rsDisc = new p3Discovery(ad);
rsRanks = new p3Rank(mRanking); rsRanks = new p3Rank(mRanking);
#ifndef RS_RELEASE #ifndef RS_RELEASE
rsGameLauncher = gameLauncher; rsGameLauncher = gameLauncher;
rsPhoto = new p3Photo(photoService); rsPhoto = new p3Photo(photoService);

View File

@ -55,24 +55,6 @@ int LoadCertificates(RsInit *config);
RsControl *createRsControl(RsIface &iface, NotifyBase &notify); RsControl *createRsControl(RsIface &iface, NotifyBase &notify);
#if 0
class PendingDirectory
{
public:
PendingDirectory(RsCertId in_id, const DirInfo *req_dir, int depth);
void addEntry(PQFileItem *item);
RsCertId id;
int reqDepth;
int reqTime;
DirInfo data;
};
#endif
class RsServer: public RsControl, public RsThread class RsServer: public RsControl, public RsThread
{ {
public: public:
@ -90,7 +72,7 @@ virtual int StartupRetroShare(RsInit *config);
/* Thread Fn: Run the Core */ /* Thread Fn: Run the Core */
virtual void run(); virtual void run();
private: public: // no longer private:!!!
/* locking stuff */ /* locking stuff */
void lockRsCore() void lockRsCore()
{ {
@ -104,6 +86,8 @@ void unlockRsCore()
coreMutex.unlock(); coreMutex.unlock();
} }
private:
/* mutex */ /* mutex */
RsMutex coreMutex; RsMutex coreMutex;
@ -115,48 +99,6 @@ cert *intFindCert(RsCertId id);
RsCertId intGetCertId(cert *c); RsCertId intGetCertId(cert *c);
#endif #endif
/****************************************/
/* p3face-people Operations */
/****************************************/
/****************************************/
/* p3face-file Operations */
public:
/* Directory Actions */
virtual int RequestDirDetails(std::string uid, std::string path,
DirDetails &details);
virtual int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags);
virtual int SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results);
virtual int SearchBoolExp(Expression *exp, std::list<FileDetail> &results);
virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath);
virtual void ForceDirectoryCheck();
virtual bool InDirectoryCheck();
/* Actions For Upload/Download */
// REDO these three TODO XXX .
//virtual int FileBroadcast(std::string uId, std::string src, int size);
//virtual int FileDelete(std::string, std::string);
virtual int FileRecommend(std::string fname, std::string hash, int size);
virtual int FileRequest(std::string fname, std::string hash, uint32_t size, std::string dest);
virtual int FileCancel(std::string fname, std::string hash, uint32_t size);
virtual int FileClearCompleted();
virtual int FileSetBandwidthTotals(float outkB, float inkB);
private:
int UpdateAllTransfers();
/* send requests to people */
int UpdateRemotePeople();
/****************************************/ /****************************************/
/****************************************/ /****************************************/
/* p3face-msg Operations */ /* p3face-msg Operations */
@ -182,49 +124,14 @@ virtual bool IsInMsg(std::string id); /* friend : msg recpts*/
std::list<std::string> mInChatList, mInMsgList; std::list<std::string> mInChatList, mInMsgList;
void intCheckFileStatus(FileInfo &file);
void initRsMI(RsMsgItem *msg, MessageInfo &mi); void initRsMI(RsMsgItem *msg, MessageInfo &mi);
/****************************************/ /****************************************/
/****************************************/ /****************************************/
public:
/****************************************/ /****************************************/
/* RsIface Networking */
//virtual int NetworkDHTActive(bool active);
//virtual int NetworkUPnPActive(bool active);
//virtual int NetworkDHTStatus();
//virtual int NetworkUPnPStatus();
private:
/* internal */
//int InitNetworking(std::string);
//int CheckNetworking();
//int InitDHT(std::string);
//int CheckDHT();
//int InitUPnP();
//int CheckUPnP();
//int UpdateNetworkConfig(RsConfig &config);
//int SetExternalPorts();
public:
/****************************************/ /****************************************/
/* RsIface Config */ public:
/* Config */ /* Config */
virtual int ConfigAddSharedDir( std::string dir );
virtual int ConfigRemoveSharedDir( std::string dir );
virtual int ConfigSetIncomingDir( std::string dir );
//virtual int ConfigSetLocalAddr( std::string ipAddr, int port );
//virtual int ConfigSetExtAddr( std::string ipAddr, int port );
//virtual int ConfigSetExtName( std::string addr );
//virtual int ConfigSetLanConfig( bool fire, bool forw );
virtual int ConfigGetDataRates(float &inKb, float &outKb); virtual int ConfigGetDataRates(float &inKb, float &outKb);
virtual int ConfigSetDataRates( int total, int indiv ); virtual int ConfigSetDataRates( int total, int indiv );

View File

@ -0,0 +1,384 @@
/*
* "$Id: p3face-file.cc,v 1.6 2007-04-15 18:45:23 rmf24 Exp $"
*
* RetroShare C++ Interface.
*
* Copyright 2004-2006 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".
*
*/
#include "rsserver/p3files.h"
#include "rsserver/p3face.h"
#include "server/filedexserver.h"
#include <iostream>
#include <sstream>
RsFiles *rsFiles = NULL;
void p3Files::lockRsCore()
{
mCore->lockRsCore();
}
void p3Files::unlockRsCore()
{
mCore->unlockRsCore();
}
int p3Files::UpdateAllTransfers()
{
/* lock Mutexes */
lockRsCore(); /* LOCK */
std::list<RsFileTransfer *> nTransList = mServer -> getTransfers();
std::list<RsFileTransfer *>::iterator it;
mTransfers.clear();
for(it = nTransList.begin(); it != nTransList.end(); it++)
{
FileInfo ti;
ti.id = (*it)->cPeerId;
ti.source = mAuthMgr->getName(ti.id);
ti.peerIds = (*it) -> allPeerIds.ids;
ti.fname = (*it) -> file.name;
ti.hash = (*it) -> file.hash;
ti.path = (*it) -> file.path;
ti.size = (*it) -> file.filesize;
ti.transfered = (*it) -> transferred;
/* other ones!!! */
ti.tfRate = (*it) -> crate / 1000;
ti.download = (*it) -> in;
ti.downloadStatus = (*it) -> state;
mTransfers[ti.hash] = ti;
delete (*it);
}
unlockRsCore(); /* UNLOCK */
return 1;
}
/* 1) Access to downloading / uploading files. */
bool p3Files::FileDownloads(std::list<std::string> &hashs)
{
RsStackMutex stack(fMutex); /**** LOCKED ****/
std::map<std::string, FileInfo>::iterator it;
for(it = mTransfers.begin(); it != mTransfers.end(); it++)
{
if (it->second.download)
{
hashs.push_back(it->second.hash);
}
}
return true;
}
bool p3Files::FileUploads(std::list<std::string> &hashs)
{
RsStackMutex stack(fMutex); /**** LOCKED ****/
std::map<std::string, FileInfo>::iterator it;
for(it = mTransfers.begin(); it != mTransfers.end(); it++)
{
if (!(it->second.download))
{
hashs.push_back(it->second.hash);
}
}
return true;
}
bool p3Files::FileDetails(std::string hash, uint32_t hintflags, FileInfo &info)
{
RsStackMutex stack(fMutex); /**** LOCKED ****/
/* for the moment this will only show transferred data */
std::map<std::string, FileInfo>::iterator it;
if (mTransfers.end() == (it = mTransfers.find(hash)))
{
return false;
}
info = it->second;
return true;
}
/* 2) Control of Downloads. */
bool p3Files::FileControl(std::string hash, uint32_t flags)
{
/* dummy function for now */
return false;
}
bool p3Files::FileRequest(std::string fname, std::string hash,
uint32_t size, std::string dest, uint32_t flags)
{
lockRsCore(); /* LOCKED */
std::cerr << "p3Files::FileRequest(" << fname << ", ";
std::cerr << hash << ", " << size << ", " << dest << ")" << std::endl;
int ret = mServer -> getFile(fname, hash, size, dest);
unlockRsCore(); /* UNLOCKED */
return ret;
}
bool p3Files::FileCancel(std::string hash)
{
lockRsCore(); /* LOCKED */
mServer -> cancelTransfer("", hash, 0); // other args not actually used!.
unlockRsCore(); /* UNLOCKED */
return 1;
}
bool p3Files::FileClearCompleted()
{
std::cerr << "p3Files::FileClearCompleted()" << std::endl;
/* lock Mutexes */
lockRsCore(); /* LOCK */
mServer -> clear_old_transfers();
unlockRsCore(); /* UNLOCK */
/* update data */
UpdateAllTransfers();
return 1;
}
/* 3) Addition of Extra Files... From File System (Dummy at the moment) */
bool p3Files::ExtraFileAdd(std::string fname, std::string hash, uint32_t size,
uint32_t period, uint32_t flags)
{
return false;
}
bool p3Files::ExtraFileRemove(std::string hash, uint32_t flags)
{
return false;
}
bool p3Files::ExtraFileHash(std::string localpath,
uint32_t period, uint32_t flags)
{
return false;
}
bool p3Files::ExtraFileStatus(std::string localpath, FileInfo &info)
{
return false;
}
/* 4) Search and Listing Interface */
int p3Files::RequestDirDetails(std::string uid, std::string path,
DirDetails &details)
{
lockRsCore(); /* LOCK */
/* call to filedexmServer */
int val = mServer->RequestDirDetails(uid, path, details);
unlockRsCore(); /* UNLOCK */
return val;
}
int p3Files::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
{
lockRsCore(); /* LOCK */
/* call to filedexmServer */
int val = mServer->RequestDirDetails(ref, details, flags);
unlockRsCore(); /* UNLOCK */
return val;
}
int p3Files::SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results)
{
lockRsCore(); /* LOCK */
/* call to filedexmServer */
int val = mServer->SearchKeywords(keywords, results);
unlockRsCore(); /* UNLOCK */
return val;
}
int p3Files::SearchBoolExp(Expression *exp, std::list<FileDetail> &results)
{
lockRsCore(); /* LOCK */
/* call to filedexmServer */
int val = mServer->SearchBoolExp(exp, results);
unlockRsCore(); /* UNLOCK */
return val;
}
/* 5) Utility Functions. */
bool p3Files::ConvertSharedFilePath(std::string path, std::string &fullpath)
{
lockRsCore(); /* LOCK */
/* call to filedexmServer */
bool val = mServer->ConvertSharedFilePath(path, fullpath);
/* done! */
/* unlock Mutexes */
unlockRsCore(); /* UNLOCK */
return val;
}
void p3Files::ForceDirectoryCheck()
{
lockRsCore(); /* LOCK */
/* call to filedexmServer */
mServer->ForceDirectoryCheck();
/* done! */
/* unlock Mutexes */
unlockRsCore(); /* UNLOCK */
}
bool p3Files::InDirectoryCheck()
{
lockRsCore(); /* LOCK */
/* call to filedexmServer */
bool val = mServer->InDirectoryCheck();
/* done! */
/* unlock Mutexes */
unlockRsCore(); /* UNLOCK */
return val;
}
void p3Files::setDownloadDirectory(std::string path)
{
/* lock Mutexes */
lockRsCore(); /* LOCK */
mServer -> setSaveDir(path);
unlockRsCore(); /* UNLOCK */
}
std::string p3Files::getDownloadDirectory()
{
/* lock Mutexes */
lockRsCore(); /* LOCK */
std::string path = mServer -> getSaveDir();
unlockRsCore(); /* UNLOCK */
return path;
}
void p3Files::setPartialsDirectory(std::string path)
{
/* dummy */
return;
}
std::string p3Files::getPartialsDirectory()
{
std::string path;
return path;
}
bool p3Files::getSharedDirectories(std::list<std::string> &dirs)
{
/* lock Mutexes */
lockRsCore(); /* LOCK */
dirs = mServer -> getSearchDirectories();
unlockRsCore(); /* UNLOCK */
return true;
}
bool p3Files::addSharedDirectory(std::string dir)
{
/* lock Mutexes */
lockRsCore(); /* LOCK */
mServer -> addSearchDirectory(dir);
unlockRsCore(); /* UNLOCK */
return true;
}
bool p3Files::removeSharedDirectory(std::string dir)
{
lockRsCore(); /* LOCK */
mServer -> removeSearchDirectory(dir);
unlockRsCore(); /* UNLOCK */
return true;
}

View File

@ -0,0 +1,118 @@
#ifndef P3_FILES_TMP_INTERFACE_H
#define P3_FILES_TMP_INTERFACE_H
/*
* libretroshare/src/rsserver: p3files.h
*
* RetroShare C++ Interface.
*
* 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".
*
*/
#include <map>
#include <list>
#include <iostream>
#include <string>
#include "rsiface/rsfiles.h"
#include "util/rsthreads.h"
class filedexserver;
class RsServer;
class p3AuthMgr;
class p3Files: public RsFiles
{
public:
p3Files(filedexserver *s, RsServer *c, p3AuthMgr *a)
:mServer(s), mCore(c), mAuthMgr(a) { return; }
virtual ~p3Files() { return; }
/****************************************/
/* 1) Access to downloading / uploading files. */
virtual bool FileDownloads(std::list<std::string> &hashs);
virtual bool FileUploads(std::list<std::string> &hashs);
virtual bool FileDetails(std::string hash, uint32_t hintflags, FileInfo &info);
/* 2) Control of Downloads. */
virtual bool FileRequest(std::string fname, std::string hash,
uint32_t size, std::string dest, uint32_t flags);
virtual bool FileCancel(std::string hash);
virtual bool FileControl(std::string hash, uint32_t flags);
virtual bool FileClearCompleted();
/* 3) Addition of Extra Files... From File System */
virtual bool ExtraFileAdd(std::string fname, std::string hash, uint32_t size,
uint32_t period, uint32_t flags);
virtual bool ExtraFileRemove(std::string hash, uint32_t flags);
virtual bool ExtraFileHash(std::string localpath,
uint32_t period, uint32_t flags);
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info);
/* 4) Search and Listing Interface */
virtual int RequestDirDetails(std::string uid, std::string path, DirDetails &details);
virtual int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags);
virtual int SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results);
virtual int SearchBoolExp(Expression * exp, std::list<FileDetail> &results);
/* 5) Utility Functions. */
virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath);
virtual void ForceDirectoryCheck();
virtual bool InDirectoryCheck();
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<std::string> &dirs);
virtual bool addSharedDirectory(std::string dir);
virtual bool removeSharedDirectory(std::string dir);
/* Update functions! */
int UpdateAllTransfers();
private:
void lockRsCore();
void unlockRsCore();
filedexserver *mServer;
RsServer *mCore;
p3AuthMgr *mAuthMgr;
RsMutex fMutex;
std::map<std::string, FileInfo> mTransfers;
};
#endif

View File

@ -58,6 +58,8 @@ class FileIndexMonitor;
class ftFileRequest; class ftFileRequest;
class ftFileData; class ftFileData;
class Expression;
#define MAX_RESULTS 100 // nice balance between results and traffic. #define MAX_RESULTS 100 // nice balance between results and traffic.
class filedexserver: public p3Config class filedexserver: public p3Config