FileTransfer.h

00001 #ifndef FILE_TRANSFER_H
00002 #define FILE_TRANSFER_H
00003 
00004 #include "../aMule-2.2.4/src/MD4Hash.h"
00005 
00006 #define MAXSIZE         1024
00007 
00014 class CFileTransfer{
00015 
00016 public:
00023         CFileTransfer(int iSockFd, const std::string& sSharedDir, const std::string& sDownloadDir, int iSearchID=-1);
00024 
00028         virtual ~CFileTransfer();
00029 
00034         static int ConnectPeer(uint32_t iRemoteIP, uint16_t iRemotePort);
00035         int GetSockFd(){return m_iSockFd;}
00036         std::string GetFileName(){return m_sFileName.c_str();}
00037         int GetFileSize(){return m_iFileSize;}
00038 
00039         int GetSearchID(){return m_iSearchID;}
00040         std::string GetSharedDir(){return m_sSharedDir;}
00041         std::string GetDownloadDir(){return m_sDownloadDir;}
00042         void Cleanup();
00043         void CloseSocket();
00044 
00048         void SetFileHash(const CMD4Hash& fHash){ m_fileHash = fHash;}
00049         CMD4Hash GetFileHash(){return m_fileHash;}
00050         void SetSocketPair(int iFd){m_iSocketPairFd = iFd;}
00051 
00055         int GetSocketPair(){return m_iSocketPairFd;}
00056 
00060         void NotifyComplete(bool bSuccess);
00061 
00067         int HandShake(bool bPassive, bool bPush=false, const std::string& sFileName=std::string(), int iFileSize=0);
00068         int HandShake(bool bPassive, bool bPush, int iSockFd);
00069         uint8_t GetFileType(){return m_8FileType;}
00070         void SetFilePath(const std::string& sPath){m_sFilePath = sPath;}
00071         bool IsCompleted(){return m_bCompleted;}
00072         const std::string GetExtraData(){return m_sExtraData;}
00073 
00077         int StartFileTransfer();
00078 
00079 private:
00080         int SendPacket(int iSockFD, const char* szPayload, int iSize); /*code is unused at this time*/
00081         
00085         int ParseHandShakePacket(const char* szBuffer, int iReceived, bool& bPull);
00086 
00090         int WaitForHandShakePacket(bool& bPull, bool bWaitForAck=false);
00091 
00095         int WaitForHandShakePacketAck();
00096 
00100         int SendHandShakePacket(bool bPush);
00101         int StartFileTransferThread();
00102         static void* FileTransferThread(void* arg);
00103 
00107         void ReceiveFile();
00108 
00112         void SendFile();
00113 
00114 private:
00115         int m_iSockFd;
00116         std::string m_sFileName;
00117         std::string m_sFilePath;
00118         int m_iFileSize;
00119         pthread_t m_pTID;
00120         int m_iSearchID;
00121         std::string m_sSharedDir;
00122         std::string m_sDownloadDir;
00123         CMD4Hash m_fileHash;
00124         int m_iSocketPairFd;
00125         uint8_t m_8FileType;
00126         std::string m_sExtraData;
00127         bool m_bCompleted;
00128         bool m_bPassive;
00129         bool m_bPush;
00130 
00131 };
00132 
00133 
00134 #endif //FILE_TRANSFER_H

Generated on Thu Sep 16 11:51:44 2010 for Communication Component by  doxygen 1.4.7