diff options
| -rw-r--r-- | opentracker.c | 34 | ||||
| -rw-r--r-- | trackerlogic.c | 6 | ||||
| -rw-r--r-- | trackerlogic.h | 12 |
3 files changed, 17 insertions, 35 deletions
diff --git a/opentracker.c b/opentracker.c index ccb9603..013441a 100644 --- a/opentracker.c +++ b/opentracker.c | |||
| @@ -76,6 +76,9 @@ static size_t ot_sockets_count = 0; | |||
| 76 | 76 | ||
| 77 | #ifdef _DEBUG_HTTPERROR | 77 | #ifdef _DEBUG_HTTPERROR |
| 78 | static char debug_request[8192]; | 78 | static char debug_request[8192]; |
| 79 | #define _DEBUG_HTTPERROR_PARAM( param ) , param | ||
| 80 | #else | ||
| 81 | #define _DEBUG_HTTPERROR_PARAM( param ) | ||
| 79 | #endif | 82 | #endif |
| 80 | 83 | ||
| 81 | typedef enum { | 84 | typedef enum { |
| @@ -99,12 +102,7 @@ static int ot_ip_compare( const void *a, const void *b ) { return memcmp( a,b,4 | |||
| 99 | int main( int argc, char **argv ); | 102 | int main( int argc, char **argv ); |
| 100 | 103 | ||
| 101 | static void httperror( const int64 s, const char *title, const char *message ); | 104 | static void httperror( const int64 s, const char *title, const char *message ); |
| 102 | 105 | static void httpresponse( const int64 s, char *data _DEBUG_HTTPERROR_PARAM(size_t l ) ); | |
| 103 | #ifdef _DEBUG_HTTPERROR | ||
| 104 | static void httpresponse( const int64 s, char *data, size_t l ); | ||
| 105 | #else | ||
| 106 | static void httpresponse( const int64 s, char *data ); | ||
| 107 | #endif | ||
| 108 | 106 | ||
| 109 | static void sendmmapdata( const int64 s, char *buffer, const size_t size ); | 107 | static void sendmmapdata( const int64 s, char *buffer, const size_t size ); |
| 110 | static void senddata( const int64 s, char *buffer, const size_t size ); | 108 | static void senddata( const int64 s, char *buffer, const size_t size ); |
| @@ -226,11 +224,7 @@ static void senddata( const int64 s, char *buffer, size_t size ) { | |||
| 226 | } | 224 | } |
| 227 | } | 225 | } |
| 228 | 226 | ||
| 229 | #ifdef _DEBUG_HTTPERROR | 227 | static void httpresponse( const int64 s, char *data _DEBUG_HTTPERROR_PARAM( size_t l ) ) { |
| 230 | static void httpresponse( const int64 s, char *data, size_t l ) { | ||
| 231 | #else | ||
| 232 | static void httpresponse( const int64 s, char *data ) { | ||
| 233 | #endif | ||
| 234 | struct http_data* h = io_getcookie( s ); | 228 | struct http_data* h = io_getcookie( s ); |
| 235 | char *c, *reply; | 229 | char *c, *reply; |
| 236 | ot_peer peer; | 230 | ot_peer peer; |
| @@ -675,13 +669,8 @@ static void handle_read( const int64 clientsocket ) { | |||
| 675 | 669 | ||
| 676 | /* If we get the whole request in one packet, handle it without copying */ | 670 | /* If we get the whole request in one packet, handle it without copying */ |
| 677 | if( !array_start( &h->request ) ) { | 671 | if( !array_start( &h->request ) ) { |
| 678 | if( memchr( static_inbuf, '\n', l ) ) { | 672 | if( memchr( static_inbuf, '\n', l ) ) |
| 679 | return httpresponse( clientsocket, static_inbuf | 673 | return httpresponse( clientsocket, static_inbuf _DEBUG_HTTPERROR_PARAM( l ) ); |
| 680 | #ifdef _DEBUG_HTTPERROR | ||
| 681 | , l | ||
| 682 | #endif | ||
| 683 | ); | ||
| 684 | } | ||
| 685 | h->flag |= STRUCT_HTTP_FLAG_ARRAY_USED; | 674 | h->flag |= STRUCT_HTTP_FLAG_ARRAY_USED; |
| 686 | return array_catb( &h->request, static_inbuf, l ); | 675 | return array_catb( &h->request, static_inbuf, l ); |
| 687 | } | 676 | } |
| @@ -695,13 +684,8 @@ static void handle_read( const int64 clientsocket ) { | |||
| 695 | if( ( array_bytes( &h->request ) > 8192 ) && NOTBLESSED( h ) ) | 684 | if( ( array_bytes( &h->request ) > 8192 ) && NOTBLESSED( h ) ) |
| 696 | return httperror( clientsocket, "500 request too long", "You sent too much headers"); | 685 | return httperror( clientsocket, "500 request too long", "You sent too much headers"); |
| 697 | 686 | ||
| 698 | if( memchr( array_start( &h->request ), '\n', array_bytes( &h->request ) ) ) { | 687 | if( memchr( array_start( &h->request ), '\n', array_bytes( &h->request ) ) ) |
| 699 | return httpresponse( clientsocket, array_start( &h->request ) | 688 | return httpresponse( clientsocket, array_start( &h->request ) _DEBUG_HTTPERROR_PARAM( array_bytes( &h->request ) ) ); |
| 700 | #ifdef _DEBUG_HTTPERROR | ||
| 701 | , array_bytes( &h->request ) | ||
| 702 | #endif | ||
| 703 | ); | ||
| 704 | } | ||
| 705 | } | 689 | } |
| 706 | 690 | ||
| 707 | static void handle_write( const int64 clientsocket ) { | 691 | static void handle_write( const int64 clientsocket ) { |
diff --git a/trackerlogic.c b/trackerlogic.c index fd34d28..134c504 100644 --- a/trackerlogic.c +++ b/trackerlogic.c | |||
| @@ -145,11 +145,7 @@ static void vector_remove_torrent( ot_vector *vector, ot_torrent *match ) { | |||
| 145 | } | 145 | } |
| 146 | } | 146 | } |
| 147 | 147 | ||
| 148 | #ifdef WANT_TRACKER_SYNC | 148 | ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer WANT_TRACKER_SYNC_PARAM( int from_changeset ) ) { |
| 149 | ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer, int from_changeset ) { | ||
| 150 | #else | ||
| 151 | ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer ) { | ||
| 152 | #endif | ||
| 153 | int exactmatch; | 149 | int exactmatch; |
| 154 | ot_torrent *torrent; | 150 | ot_torrent *torrent; |
| 155 | ot_peer *peer_dest; | 151 | ot_peer *peer_dest; |
diff --git a/trackerlogic.h b/trackerlogic.h index 9cbffc1..7cf75b2 100644 --- a/trackerlogic.h +++ b/trackerlogic.h | |||
| @@ -98,16 +98,18 @@ typedef struct { | |||
| 98 | Exported functions | 98 | Exported functions |
| 99 | */ | 99 | */ |
| 100 | 100 | ||
| 101 | #ifdef WANT_TRACKER_SYNC | ||
| 102 | #define WANT_TRACKER_SYNC_PARAM( param ) , param | ||
| 103 | #else | ||
| 104 | #define WANT_TRACKER_SYNC_PARAM( param ) | ||
| 105 | #endif | ||
| 106 | |||
| 101 | int init_logic( const char * const serverdir ); | 107 | int init_logic( const char * const serverdir ); |
| 102 | void deinit_logic( void ); | 108 | void deinit_logic( void ); |
| 103 | 109 | ||
| 104 | enum { STATS_MRTG, STATS_TOP5, STATS_DMEM, STATS_TCP, STATS_UDP, STATS_SLASH24S, STATS_SLASH24S_OLD, SYNC_IN, SYNC_OUT, STATS_FULLSCRAPE }; | 110 | enum { STATS_MRTG, STATS_TOP5, STATS_DMEM, STATS_TCP, STATS_UDP, STATS_SLASH24S, STATS_SLASH24S_OLD, SYNC_IN, SYNC_OUT, STATS_FULLSCRAPE }; |
| 105 | 111 | ||
| 106 | #ifdef WANT_TRACKER_SYNC | 112 | ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer WANT_TRACKER_SYNC_PARAM( int from_changeset ) ); |
| 107 | ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer, int from_changeset ); | ||
| 108 | #else | ||
| 109 | ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer ); | ||
| 110 | #endif | ||
| 111 | size_t remove_peer_from_torrent( ot_hash *hash, ot_peer *peer, char *reply, int is_tcp ); | 113 | size_t remove_peer_from_torrent( ot_hash *hash, ot_peer *peer, char *reply, int is_tcp ); |
| 112 | size_t return_peers_for_torrent( ot_torrent *torrent, size_t amount, char *reply, int is_tcp ); | 114 | size_t return_peers_for_torrent( ot_torrent *torrent, size_t amount, char *reply, int is_tcp ); |
| 113 | size_t return_fullscrape_for_tracker( char **reply ); | 115 | size_t return_fullscrape_for_tracker( char **reply ); |
