From d05820a99209a305d60e9ad9e049143065650565 Mon Sep 17 00:00:00 2001 From: Naim A Date: Fri, 22 Mar 2013 13:54:50 +0200 Subject: [PATCH] Modified HTTP Server; Added notice incase a user tries to use tracker as a HTTP tracker. --- src/http/webapp.cpp | 10 ++++++++++ src/http/webapp.hpp | 1 + src/main.cpp | 1 + src/udpTracker.cpp | 4 ++-- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/http/webapp.cpp b/src/http/webapp.cpp index d388cb7..4f2f870 100644 --- a/src/http/webapp.cpp +++ b/src/http/webapp.cpp @@ -137,8 +137,13 @@ namespace UDPT { list path; this->instance->addApp(&path, &WebApp::handleRoot); + path.push_back("api"); this->instance->addApp(&path, &WebApp::handleAPI); // "/api" + + path.pop_back(); + path.push_back("announce"); + this->instance->addApp(&path, &WebApp::handleAnnounce); } void WebApp::handleRoot (HTTPServer *srv, HTTPServer::Request *req, HTTPServer::Response *resp) @@ -220,6 +225,11 @@ namespace UDPT resp->write("{\"error\":\"failed to add torrent to DB\"}"); } + void WebApp::handleAnnounce (HTTPServer *srv, HTTPServer::Request *req, HTTPServer::Response *resp) + { + resp->write("d14:failure reason42:this is a UDP tracker, not a HTTP tracker.e"); + } + void WebApp::handleAPI(HTTPServer *srv, HTTPServer::Request *req, HTTPServer::Response *resp) { if (req->getAddress()->sin_family != AF_INET) diff --git a/src/http/webapp.hpp b/src/http/webapp.hpp index 11f89bb..6a8011f 100644 --- a/src/http/webapp.hpp +++ b/src/http/webapp.hpp @@ -49,6 +49,7 @@ namespace UDPT std::map > ip_whitelist; static void handleRoot (HTTPServer*,HTTPServer::Request*, HTTPServer::Response*); + static void handleAnnounce (HTTPServer*,HTTPServer::Request*, HTTPServer::Response*); static void handleAPI (HTTPServer*,HTTPServer::Request*, HTTPServer::Response*); static bool isAllowedIP (WebApp *, string, uint32_t); diff --git a/src/main.cpp b/src/main.cpp index eef927a..32e83f0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,6 +24,7 @@ #include "settings.hpp" #include "http/httpserver.hpp" #include "http/webapp.hpp" +#include // atoi using namespace std; using namespace UDPT; diff --git a/src/udpTracker.cpp b/src/udpTracker.cpp index 555fb51..d9e0a34 100644 --- a/src/udpTracker.cpp +++ b/src/udpTracker.cpp @@ -455,7 +455,7 @@ static int _isIANA_IP (uint32_t ip) } } - cout << ":: " << (void*)m_hton32(remote->sin_addr.s_addr) << ": " << m_hton16(remote->sin_port) << " ACTION=" << action << endl; +// cout << ":: " << (void*)m_hton32(remote->sin_addr.s_addr) << ": " << m_hton16(remote->sin_port) << " ACTION=" << action << endl; if (action == 0 && r >= 16) return UDPTracker::handleConnection (usi, remote, data); @@ -465,7 +465,7 @@ static int _isIANA_IP (uint32_t ip) return UDPTracker::handleScrape (usi, remote, data, r); else { - cout << "E: action=" << action << ", r=" << r << endl; +// cout << "E: action=" << action << ", r=" << r << endl; UDPTracker::sendError (usi, remote, cR->transaction_id, "Tracker couldn't understand Client's request."); return -1; }