1
0
mirror of https://github.com/asamy/ctorrent synced 2025-10-05 23:52:41 +02:00

tracker: correctness

This commit is contained in:
A. Samy
2015-11-28 03:58:05 +00:00
parent e02b7b4969
commit 057743b6ce
3 changed files with 10 additions and 7 deletions

View File

@@ -456,10 +456,8 @@ bool TorrentFileManager::registerFiles(const std::string &baseDir, const Torrent
if (inf.path != filePath) {
std::string path = baseDir + filePath;
if (!validatePath(baseDir, path)) {
std::clog << "Error validating dir: " << path << std::endl;
if (!validatePath(baseDir, path))
return false;
}
if (!nodeExists(path))
MKDIR(path);

View File

@@ -27,7 +27,7 @@
bool Tracker::query(const TrackerQuery &req)
{
bool ret = false;
if (m_prot == "http")
if (m_type == TrackerHTTP)
ret = httpRequest(req);
else
ret = udpRequest(req);

View File

@@ -45,14 +45,19 @@ struct TrackerQuery {
class Torrent;
class Tracker
{
enum TrackerType {
TrackerHTTP,
TrackerUDP,
};
public:
Tracker(Torrent *torrent, const std::string &host, const std::string &port, const std::string &proto, uint16_t tport)
: m_torrent(torrent),
m_tport(tport),
m_host(host),
m_port(port),
m_prot(proto)
m_port(port)
{
m_type = proto == "http" ? TrackerHTTP : TrackerUDP;
}
std::string host() const { return m_host; }
@@ -71,10 +76,10 @@ private:
Torrent *m_torrent;
TimePoint m_timeToNextRequest;
TrackerType m_type;
uint16_t m_tport;
std::string m_host;
std::string m_port;
std::string m_prot;
friend class Torrent;
};