Modified HTTP Server;

Added notice incase a user tries to use tracker as a HTTP tracker.
This commit is contained in:
Naim A 2013-03-22 13:54:50 +02:00
parent 1aa7eceb2f
commit d05820a992
4 changed files with 14 additions and 2 deletions

View file

@ -137,8 +137,13 @@ namespace UDPT
{ {
list<string> path; list<string> path;
this->instance->addApp(&path, &WebApp::handleRoot); this->instance->addApp(&path, &WebApp::handleRoot);
path.push_back("api"); path.push_back("api");
this->instance->addApp(&path, &WebApp::handleAPI); // "/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) 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\"}"); 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) void WebApp::handleAPI(HTTPServer *srv, HTTPServer::Request *req, HTTPServer::Response *resp)
{ {
if (req->getAddress()->sin_family != AF_INET) if (req->getAddress()->sin_family != AF_INET)

View file

@ -49,6 +49,7 @@ namespace UDPT
std::map<std::string, list<uint32_t> > ip_whitelist; std::map<std::string, list<uint32_t> > ip_whitelist;
static void handleRoot (HTTPServer*,HTTPServer::Request*, HTTPServer::Response*); 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 void handleAPI (HTTPServer*,HTTPServer::Request*, HTTPServer::Response*);
static bool isAllowedIP (WebApp *, string, uint32_t); static bool isAllowedIP (WebApp *, string, uint32_t);

View file

@ -24,6 +24,7 @@
#include "settings.hpp" #include "settings.hpp"
#include "http/httpserver.hpp" #include "http/httpserver.hpp"
#include "http/webapp.hpp" #include "http/webapp.hpp"
#include <cstdlib> // atoi
using namespace std; using namespace std;
using namespace UDPT; using namespace UDPT;

View file

@ -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) if (action == 0 && r >= 16)
return UDPTracker::handleConnection (usi, remote, data); return UDPTracker::handleConnection (usi, remote, data);
@ -465,7 +465,7 @@ static int _isIANA_IP (uint32_t ip)
return UDPTracker::handleScrape (usi, remote, data, r); return UDPTracker::handleScrape (usi, remote, data, r);
else 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."); UDPTracker::sendError (usi, remote, cR->transaction_id, "Tracker couldn't understand Client's request.");
return -1; return -1;
} }