update according to Bob's comments.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@651 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
ewensun 2008-07-29 15:16:31 +00:00
parent 79727897dd
commit 3bcb97ff4c

View file

@ -37,7 +37,13 @@
#include <map> #include <map>
#include <list> #include <list>
#include "ft/ftfilecreator.h" #include <ftFileCreator.h>
const int PQIPEER_INIT = 0x0000;
const int PQIPEER_NOT_ONLINE = 0x0001;
const int PQIPEER_DOWNLOADING = 0x0002;
const int PQIPEER_IDLE = 0x0004;
const int PQIPEER_SUSPEND = 0x0010;
class Request class Request
{ {
@ -47,54 +53,63 @@ class Request
class peerInfo class peerInfo
{ {
std::string peerId; std:string peerId;
uint16_t state; uint32_t state;
uint32_t desiredRate; uint32_t desiredRate;
Request lastRequest; Request lastRequest;
uint32_t actualRate; uint32_t actualRate;
//current file data request
uint64_t req_loc;
uint32_t req_size;
time_t lastTS;
}; };
class ftTransferModule class ftTransferModule
{ {
public: public:
ftTransferModule(std::string hash, uint64_t size); ftTransferModule(ftFileCreator *fc,ftClientModule *cm);
~ftTransferModule(); ~ftTransferModule();
//interface to download controller //interface to download controller
bool setFileSources(std::list<peerInfo> availableSrcs); bool setFileSources(std::list<std::string> peerIds);
bool requestFile(std::list<std::string> onlineSrcs, uint32_t dataRate); bool setPeerState(std::string peerId,uint32_t state,uint32_t maxRate); //state = ONLINE/OFFLINE
bool changePeerState(std::string peerId, uint16_t newState); uint32_t getDataRate(std::string peerId);
uint32_t getDataRate();
bool setDataRate(uint32_t dataRate);
bool stopTransfer(); bool stopTransfer();
bool resumeTransfer(); bool resumeTransfer();
bool completeFileTransfer(); bool completeFileTransfer();
//interface to client module //interface to client module
bool recvFileData(std::string peerId, uint64_t offset, bool recvFileData(uint64_t offset, uint32_t chunk_size, void *data); //called by ftClientModule when data arrives
uint32_t chunk_size, void *data); void requestData(uint64_t offset, uint32_t chunk_size);
void requestData(std::string hash, uint64_t offset, uint32_t chunk_size);
//interface to file creator //interface to file creator , just wrapper functions that call the ftFileCreator
bool getChunk(uint64_t &offset, uint32_t &chunk_size); bool getChunk(uint64_t &offset, uint32_t &chunk_size);
bool storeData(uint64_t offset, uint32_t chunk_size); bool storeData(uint64_t offset, uint32_t chunk_size, void *data);
void tick(); //internal used functions
void queryInactive();
int tick();
/* add by DrBob for interfaces */ /* add by DrBob for interfaces */
std::string hash() { return mHash; } std::string hash() { return mHash; }
uint64_t size() { return mSize; } uint64_t size() { return mSize; }
public: public:
ftFileCreator* fc; ftFileCreator *mFileCreator;
ftClientModule *mClientModule;
private: private:
std::string mHash; std::string mHash;
uint64_t mSize; uint64_t mSize;
uint32_t dataRate; //data transfer rate for current file std::list<std::string> mFileSources;
uint16_t state; //file transfer state std::map<std::string,peerInfo> mOnlinePeers;
std::list<std::string> onlinePeerList;
std::map<std::string,peerInfo> availablePeerList; uint64_t mOffset;
uint32_t mChunkSize;
bool mFlag; //1:transfer complete, 0: not complete
}; };
#endif //FT_TRANSFER_MODULE_HEADER #endif //FT_TRANSFER_MODULE_HEADER