From 848a06a706b1661666f1923817ee99e9710a52d4 Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Mon, 3 Dec 2007 01:07:41 +0000 Subject: Drop ot_{byte,word,dword} and use uint{8,16,32}_t, also simplify includes --- ot_stats.h | 10 +++++++++- ot_sync.h | 4 +--- ot_udp.c | 10 +++++----- ot_vector.c | 12 ++++++------ trackerlogic.c | 21 ++++++++++++--------- trackerlogic.h | 22 +++++++--------------- 6 files changed, 40 insertions(+), 39 deletions(-) diff --git a/ot_stats.h b/ot_stats.h index 1e603ad..b3ac1dc 100644 --- a/ot_stats.h +++ b/ot_stats.h @@ -10,13 +10,21 @@ typedef enum { EVENT_CONNECT, /* UDP only */ EVENT_ANNOUNCE, EVENT_SCRAPE, + EVENT_FULLSCRAPE_REQUEST, + EVENT_FULLSCRAPE_REQUEST_GZIP, EVENT_FULLSCRAPE, /* TCP only */ + EVENT_SYNC_IN_REQUEST, + EVENT_SYNC_IN, + EVENT_SYNC_OUT_REQUEST, + EVENT_SYNC_OUT, EVENT_FAILED_400, EVENT_FAILED_404, EVENT_FAILED_505 } ot_status_event; +void stats_issue_event( ot_status_event event, int is_tcp, size_t event_data ); size_t return_stats_for_tracker( char *reply, int mode, int format ); -void stats_issue_event( ot_status_event event, int is_tcp, size_t event_data ); +void stats_init( ); +void stats_deinit( ); #endif diff --git a/ot_sync.h b/ot_sync.h index 87fb1f1..af7db8f 100644 --- a/ot_sync.h +++ b/ot_sync.h @@ -4,8 +4,6 @@ #ifndef __OT_SYNC_H__ #define __OT_SYNC_H__ -#include "trackerlogic.h" - #ifdef WANT_TRACKER_SYNC enum { SYNC_IN, SYNC_OUT }; @@ -13,7 +11,7 @@ void sync_init( ); void sync_deinit( ); void sync_deliver( int64 socket ); -int add_changeset_to_tracker( ot_byte *data, size_t len ); +int add_changeset_to_tracker( uint8_t *data, size_t len ); #endif #endif diff --git a/ot_udp.c b/ot_udp.c index af4bdc9..56b5f44 100644 --- a/ot_udp.c +++ b/ot_udp.c @@ -23,10 +23,10 @@ void handle_udp4( int64 serversocket ) { ot_torrent *torrent; ot_hash *hash = NULL; char remoteip[4]; - ot_dword *inpacket = (ot_dword*)static_inbuf; - ot_dword *outpacket = (ot_dword*)static_outbuf; - ot_dword numwant, left, event; - ot_word port, remoteport; + uint32_t *inpacket = (uint32_t*)static_inbuf; + uint32_t *outpacket = (uint32_t*)static_outbuf; + uint32_t numwant, left, event; + uint16_t port, remoteport; size_t r, r_out; r = socket_recv4( serversocket, static_inbuf, sizeof( static_inbuf ), remoteip, &remoteport); @@ -59,7 +59,7 @@ void handle_udp4( int64 serversocket ) { left = inpacket[64/4] | inpacket[68/4]; event = ntohl( inpacket[80/4] ); - port = *(ot_word*)( static_inbuf + 96 ); + port = *(uint16_t*)( static_inbuf + 96 ); hash = (ot_hash*)( static_inbuf + 16 ); OT_SETIP( &peer, remoteip ); diff --git a/ot_vector.c b/ot_vector.c index aa71279..1cfa4df 100644 --- a/ot_vector.c +++ b/ot_vector.c @@ -16,7 +16,7 @@ void *binary_search( const void * const key, const void * base, const size_t member_count, const size_t member_size, size_t compare_size, int *exactmatch ) { size_t mc = member_count; - ot_byte *lookat = ((ot_byte*)base) + member_size * (member_count >> 1); + uint8_t *lookat = ((uint8_t*)base) + member_size * (member_count >> 1); *exactmatch = 1; while( mc ) { @@ -27,7 +27,7 @@ void *binary_search( const void * const key, const void * base, const size_t mem --mc; } mc >>= 1; - lookat = ((ot_byte*)base) + member_size * (mc >> 1); + lookat = ((uint8_t*)base) + member_size * (mc >> 1); } *exactmatch = 0; return (void*)lookat; @@ -41,22 +41,22 @@ void *binary_search( const void * const key, const void * base, const size_t mem took place. If resizing the vector failed, NULL is returned, else the pointer to the object in vector. */ void *vector_find_or_insert( ot_vector *vector, void *key, size_t member_size, size_t compare_size, int *exactmatch ) { - ot_byte *match = binary_search( key, vector->data, vector->size, member_size, compare_size, exactmatch ); + uint8_t *match = binary_search( key, vector->data, vector->size, member_size, compare_size, exactmatch ); if( *exactmatch ) return match; if( vector->size + 1 >= vector->space ) { size_t new_space = vector->space ? OT_VECTOR_GROW_RATIO * vector->space : OT_VECTOR_MIN_MEMBERS; - ot_byte *new_data = realloc( vector->data, new_space * member_size ); + uint8_t *new_data = realloc( vector->data, new_space * member_size ); if( !new_data ) return NULL; /* Adjust pointer if it moved by realloc */ - match = new_data + (match - (ot_byte*)vector->data); + match = new_data + (match - (uint8_t*)vector->data); vector->data = new_data; vector->space = new_space; } - memmove( match + member_size, match, ((ot_byte*)vector->data) + member_size * vector->size - match ); + memmove( match + member_size, match, ((uint8_t*)vector->data) + member_size * vector->size - match ); vector->size++; return match; } diff --git a/trackerlogic.c b/trackerlogic.c index 756ed0f..47548fa 100644 --- a/trackerlogic.c +++ b/trackerlogic.c @@ -15,6 +15,7 @@ /* Libowfat */ #include "scan.h" #include "byte.h" +#include "io.h" /* Opentracker */ #include "trackerlogic.h" @@ -163,9 +164,9 @@ size_t return_peers_for_torrent( ot_hash *hash, size_t amount, char *reply, int if( is_tcp ) r += sprintf( r, "d8:completei%zde10:incompletei%zde8:intervali%ie5:peers%zd:", peer_list->seed_count, peer_list->peer_count-peer_list->seed_count, OT_CLIENT_REQUEST_INTERVAL_RANDOM, 6*amount ); else { - *(ot_dword*)(r+0) = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM ); - *(ot_dword*)(r+4) = htonl( peer_list->peer_count ); - *(ot_dword*)(r+8) = htonl( peer_list->seed_count ); + *(uint32_t*)(r+0) = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM ); + *(uint32_t*)(r+4) = htonl( peer_list->peer_count ); + *(uint32_t*)(r+8) = htonl( peer_list->seed_count ); r += 12; } @@ -216,7 +217,7 @@ size_t return_udp_scrape_for_torrent( ot_hash *hash, char *reply ) { if( !exactmatch ) { memset( reply, 0, 12); } else { - ot_dword *r = (ot_dword*) reply; + uint32_t *r = (uint32_t*) reply; if( clean_single_torrent( torrent ) ) { vector_remove_torrent( torrents_list, torrent ); @@ -273,8 +274,8 @@ size_t remove_peer_from_torrent( ot_hash *hash, ot_peer *peer, char *reply, int return sprintf( reply, "d8:completei0e10:incompletei0e8:intervali%ie5:peers0:e", OT_CLIENT_REQUEST_INTERVAL_RANDOM ); /* Create fake packet to satisfy parser on the other end */ - ((ot_dword*)reply)[2] = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM ); - ((ot_dword*)reply)[3] = ((ot_dword*)reply)[4] = 0; + ((uint32_t*)reply)[2] = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM ); + ((uint32_t*)reply)[3] = ((uint32_t*)reply)[4] = 0; return (size_t)20; } @@ -299,9 +300,9 @@ exit_loop: } /* else { Handle UDP reply */ - ((ot_dword*)reply)[2] = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM ); - ((ot_dword*)reply)[3] = peer_list->peer_count - peer_list->seed_count; - ((ot_dword*)reply)[4] = peer_list->seed_count; + ((uint32_t*)reply)[2] = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM ); + ((uint32_t*)reply)[3] = peer_list->peer_count - peer_list->seed_count; + ((uint32_t*)reply)[4] = peer_list->seed_count; mutex_bucket_unlock_by_hash( hash ); return (size_t)20; @@ -322,6 +323,7 @@ int trackerlogic_init( const char * const serverdir ) { #ifdef WANT_TRACKER_SYNC sync_init( ); #endif + stats_init( ); return 0; } @@ -343,6 +345,7 @@ void trackerlogic_deinit( void ) { } /* Deinitialise background worker threads */ + stats_deinit( ); #ifdef WANT_TRACKER_SYNC sync_deinit( ); #endif diff --git a/trackerlogic.h b/trackerlogic.h index 1eff6df..eefc038 100644 --- a/trackerlogic.h +++ b/trackerlogic.h @@ -9,14 +9,7 @@ #include #include -/* Should be called BYTE, WORD, DWORD - but some OSs already have that and there's no #iftypedef */ -/* They mark memory used as data instead of integer or human readable string - - they should be cast before used as integer/text */ -typedef uint8_t ot_byte; -typedef uint16_t ot_word; -typedef uint32_t ot_dword; - -typedef ot_byte ot_hash[20]; +typedef uint8_t ot_hash[20]; typedef time_t ot_time; /* Some tracker behaviour tunable */ @@ -46,20 +39,19 @@ typedef time_t ot_time; #define OT_POOLS_TIMEOUT (60*5) /* From opentracker.c */ -extern time_t ot_start_time; extern time_t g_now; #define NOW (g_now/OT_POOLS_TIMEOUT) typedef struct { - ot_byte data[8]; + uint8_t data[8]; } ot_peer; -static const ot_byte PEER_FLAG_SEEDING = 0x80; -static const ot_byte PEER_FLAG_COMPLETED = 0x40; -static const ot_byte PEER_FLAG_STOPPED = 0x20; +static const uint8_t PEER_FLAG_SEEDING = 0x80; +static const uint8_t PEER_FLAG_COMPLETED = 0x40; +static const uint8_t PEER_FLAG_STOPPED = 0x20; #define OT_SETIP( peer, ip ) memmove((peer),(ip),4); -#define OT_SETPORT( peer, port ) memmove(((ot_byte*)peer)+4,(port),2); -#define OT_FLAG(peer) (((ot_byte*)(peer))[6]) +#define OT_SETPORT( peer, port ) memmove(((uint8_t*)peer)+4,(port),2); +#define OT_FLAG(peer) (((uint8_t*)(peer))[6]) #define OT_PEER_COMPARE_SIZE ((size_t)6) #define OT_HASH_COMPARE_SIZE (sizeof(ot_hash)) -- cgit v1.2.3