#ifndef __TORRENT_H #define __TORRENT_H //To use POSIX TIMER library #define __USE_POSIX199309 1 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef _WIN32 #define DIR_SEPARATOR '\\' #else #define DIR_SEPARATOR '/' #endif class FileItem { public: std::string Path; long long int Size; long long int Offset; std::string FormattedSize; FileItem(); void set_FormattedSize(); }; class Tracker; class Torrent { public: eventpp::EventDispatcher &)> PeerListUpdated; long long int torrentFileSize; std::string Name; int IsPrivate; std::vector Files; std::string FileDirectory(); std::string DownloadDirectory; std::vector Trackers; std::string Comment; std::string CreatedBy; time_t CreationDate; std::string Encoding; int BlockSize; int PieceSize; long long int TotalSize(); std::string FormattedPieceSize(); std::string FormattedTotalSize(); int PieceCount(); std::vector> PieceHashes; std::vector IsPieceVerified; std::vector> IsBlockAcquired; std::string VerifiedPiecesString(); int VerifiedPieceCount(); double VerifiedRatio(); bool IsCompleted(); bool IsStarted(); long long int Uploaded; long long int Downloaded(); long long int Left(); char Infohash[20]; std::string HexStringInfoHash(); //Not Implemented... std::string UrlSafeStringInfoHash(); //Locking... Torrent(); Torrent(std::string name, std::string location, std::vector files, std::vector trackers, int pieceSize, char* pieceHashes, int blockSize, int isPrivate); void UpdateTrackers(TrackerEvent ev, std::string id, int port); void ResetTrackerLastRequest(); bNode* TorrentToBEncodingObject(Torrent torrent); bDictionary* TorrentInfoToBEncodingObject(Torrent torrent); Torrent* BEncodingObjectToTorrent(bNode* bencoding, std::string name, std::string downloadPath); //Encoding and creationdate left to implement... void Verify(int piece); int GetPieceSize(int piece); int GetBlockCount(int piece); std::vector GetHash(int piece); std::string ReadPiece(int piece); std::string Read(long long int start, int length); Torrent* LoadFromFile(std::string filePath, std::string downloadPath); }; #endif