#include <FileTransfer.h>
Public Member Functions | |
CFileTransfer (int iSockFd, const std::string &sSharedDir, const std::string &sDownloadDir, int iSearchID=-1) | |
virtual | ~CFileTransfer () |
int | GetSockFd () |
std::string | GetFileName () |
int | GetFileSize () |
int | GetSearchID () |
std::string | GetSharedDir () |
std::string | GetDownloadDir () |
void | Cleanup () |
void | CloseSocket () |
void | SetFileHash (const CMD4Hash &fHash) |
CMD4Hash | GetFileHash () |
void | SetSocketPair (int iFd) |
int | GetSocketPair () |
void | NotifyComplete (bool bSuccess) |
int | HandShake (bool bPassive, bool bPush=false, const std::string &sFileName=std::string(), int iFileSize=0) |
int | HandShake (bool bPassive, bool bPush, int iSockFd) |
uint8_t | GetFileType () |
void | SetFilePath (const std::string &sPath) |
bool | IsCompleted () |
const std::string | GetExtraData () |
int | StartFileTransfer () |
Static Public Member Functions | |
static int | ConnectPeer (uint32_t iRemoteIP, uint16_t iRemotePort) |
Private Member Functions | |
int | SendPacket (int iSockFD, const char *szPayload, int iSize) |
int | ParseHandShakePacket (const char *szBuffer, int iReceived, bool &bPull) |
int | WaitForHandShakePacket (bool &bPull, bool bWaitForAck=false) |
int | WaitForHandShakePacketAck () |
int | SendHandShakePacket (bool bPush) |
int | StartFileTransferThread () |
void | ReceiveFile () |
void | SendFile () |
Static Private Member Functions | |
static void * | FileTransferThread (void *arg) |
Private Attributes | |
int | m_iSockFd |
std::string | m_sFileName |
std::string | m_sFilePath |
int | m_iFileSize |
pthread_t | m_pTID |
int | m_iSearchID |
std::string | m_sSharedDir |
std::string | m_sDownloadDir |
CMD4Hash | m_fileHash |
int | m_iSocketPairFd |
uint8_t | m_8FileType |
std::string | m_sExtraData |
bool | m_bCompleted |
bool | m_bPassive |
bool | m_bPush |
CFileTransfer::CFileTransfer | ( | int | iSockFd, | |
const std::string & | sSharedDir, | |||
const std::string & | sDownloadDir, | |||
int | iSearchID = -1 | |||
) |
Constructor. It takes the socket as its argument. Because, before creating an object, initiator node needs to call static function ConnectPeer function. If that is successful, it returns the socket fd, which is used in this argument. SharedDir is used to download certificate files which have been searched from p2p KAD network. Download directory is used to download Gossip Messages.
CFileTransfer::~CFileTransfer | ( | ) | [virtual] |
Destructor of the class.
int CFileTransfer::ConnectPeer | ( | uint32_t | iRemoteIP, | |
uint16_t | iRemotePort | |||
) | [static] |
A static function to connect peer using iRemoteIP and iRemotePort. If the connectionis successful, then the socket fd is returned, else -1 is returned.
int CFileTransfer::GetSocketPair | ( | ) | [inline] |
A socket pair is used to communicate between sender/receiver threads and the main thread.
int CFileTransfer::HandShake | ( | bool | bPassive, | |
bool | bPush = false , |
|||
const std::string & | sFileName = std::string() , |
|||
int | iFileSize = 0 | |||
) |
File tranfer is used both gossiping (push based) and certificate download using kademlia (pull based). So, to make the sender and receiver dynamic, this function is used instead of static sender or receiver. HandShake funtion sends EventMessage to the peer. After handshaking, sender and receiver becomes fixed.
void CFileTransfer::NotifyComplete | ( | bool | bSuccess | ) |
Sends an EventMessage to the network thread after file tranfer is done.
int CFileTransfer::ParseHandShakePacket | ( | const char * | szBuffer, | |
int | iReceived, | |||
bool & | bPull | |||
) | [private] |
Parses the Handshake EventMessage to figure out who is sender, who is receiver of a particular file.
void CFileTransfer::ReceiveFile | ( | ) | [private] |
Receives a file.
void CFileTransfer::SendFile | ( | ) | [private] |
Sends a file.
int CFileTransfer::SendHandShakePacket | ( | bool | bPush | ) | [private] |
Sends the handshake packet.
void CFileTransfer::SetFileHash | ( | const CMD4Hash & | fHash | ) | [inline] |
File Hash is stored so that later the corresponding object can be retrived.
int CFileTransfer::StartFileTransfer | ( | ) |
Starts the file tranfer thread.
int CFileTransfer::WaitForHandShakePacket | ( | bool & | bPull, | |
bool | bWaitForAck = false | |||
) | [private] |
Waits for handshake packet in the poll.
int CFileTransfer::WaitForHandShakePacketAck | ( | ) | [private] |
Waits for handshake packet Acknowledgement in the poll.