Drop ot_{byte,word,dword} and use uint{8,16,32}_t, also simplify includes

dynamic-accesslists
erdgeist 17 years ago
parent 9bc0d99c62
commit 848a06a706

@ -10,13 +10,21 @@ typedef enum {
EVENT_CONNECT, /* UDP only */ EVENT_CONNECT, /* UDP only */
EVENT_ANNOUNCE, EVENT_ANNOUNCE,
EVENT_SCRAPE, EVENT_SCRAPE,
EVENT_FULLSCRAPE_REQUEST,
EVENT_FULLSCRAPE_REQUEST_GZIP,
EVENT_FULLSCRAPE, /* TCP only */ EVENT_FULLSCRAPE, /* TCP only */
EVENT_SYNC_IN_REQUEST,
EVENT_SYNC_IN,
EVENT_SYNC_OUT_REQUEST,
EVENT_SYNC_OUT,
EVENT_FAILED_400, EVENT_FAILED_400,
EVENT_FAILED_404, EVENT_FAILED_404,
EVENT_FAILED_505 EVENT_FAILED_505
} ot_status_event; } 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 ); 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 #endif

@ -4,8 +4,6 @@
#ifndef __OT_SYNC_H__ #ifndef __OT_SYNC_H__
#define __OT_SYNC_H__ #define __OT_SYNC_H__
#include "trackerlogic.h"
#ifdef WANT_TRACKER_SYNC #ifdef WANT_TRACKER_SYNC
enum { SYNC_IN, SYNC_OUT }; enum { SYNC_IN, SYNC_OUT };
@ -13,7 +11,7 @@ void sync_init( );
void sync_deinit( ); void sync_deinit( );
void sync_deliver( int64 socket ); 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
#endif #endif

@ -23,10 +23,10 @@ void handle_udp4( int64 serversocket ) {
ot_torrent *torrent; ot_torrent *torrent;
ot_hash *hash = NULL; ot_hash *hash = NULL;
char remoteip[4]; char remoteip[4];
ot_dword *inpacket = (ot_dword*)static_inbuf; uint32_t *inpacket = (uint32_t*)static_inbuf;
ot_dword *outpacket = (ot_dword*)static_outbuf; uint32_t *outpacket = (uint32_t*)static_outbuf;
ot_dword numwant, left, event; uint32_t numwant, left, event;
ot_word port, remoteport; uint16_t port, remoteport;
size_t r, r_out; size_t r, r_out;
r = socket_recv4( serversocket, static_inbuf, sizeof( static_inbuf ), remoteip, &remoteport); 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]; left = inpacket[64/4] | inpacket[68/4];
event = ntohl( inpacket[80/4] ); event = ntohl( inpacket[80/4] );
port = *(ot_word*)( static_inbuf + 96 ); port = *(uint16_t*)( static_inbuf + 96 );
hash = (ot_hash*)( static_inbuf + 16 ); hash = (ot_hash*)( static_inbuf + 16 );
OT_SETIP( &peer, remoteip ); OT_SETIP( &peer, remoteip );

@ -16,7 +16,7 @@
void *binary_search( const void * const key, const void * base, const size_t member_count, const size_t member_size, 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 compare_size, int *exactmatch ) {
size_t mc = member_count; 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; *exactmatch = 1;
while( mc ) { while( mc ) {
@ -27,7 +27,7 @@ void *binary_search( const void * const key, const void * base, const size_t mem
--mc; --mc;
} }
mc >>= 1; mc >>= 1;
lookat = ((ot_byte*)base) + member_size * (mc >> 1); lookat = ((uint8_t*)base) + member_size * (mc >> 1);
} }
*exactmatch = 0; *exactmatch = 0;
return (void*)lookat; 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. 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 ) { 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( *exactmatch ) return match;
if( vector->size + 1 >= vector->space ) { if( vector->size + 1 >= vector->space ) {
size_t new_space = vector->space ? OT_VECTOR_GROW_RATIO * vector->space : OT_VECTOR_MIN_MEMBERS; 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; if( !new_data ) return NULL;
/* Adjust pointer if it moved by realloc */ /* 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->data = new_data;
vector->space = new_space; 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++; vector->size++;
return match; return match;
} }

@ -15,6 +15,7 @@
/* Libowfat */ /* Libowfat */
#include "scan.h" #include "scan.h"
#include "byte.h" #include "byte.h"
#include "io.h"
/* Opentracker */ /* Opentracker */
#include "trackerlogic.h" #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 ) 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 ); 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 { else {
*(ot_dword*)(r+0) = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM ); *(uint32_t*)(r+0) = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM );
*(ot_dword*)(r+4) = htonl( peer_list->peer_count ); *(uint32_t*)(r+4) = htonl( peer_list->peer_count );
*(ot_dword*)(r+8) = htonl( peer_list->seed_count ); *(uint32_t*)(r+8) = htonl( peer_list->seed_count );
r += 12; r += 12;
} }
@ -216,7 +217,7 @@ size_t return_udp_scrape_for_torrent( ot_hash *hash, char *reply ) {
if( !exactmatch ) { if( !exactmatch ) {
memset( reply, 0, 12); memset( reply, 0, 12);
} else { } else {
ot_dword *r = (ot_dword*) reply; uint32_t *r = (uint32_t*) reply;
if( clean_single_torrent( torrent ) ) { if( clean_single_torrent( torrent ) ) {
vector_remove_torrent( torrents_list, 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 ); 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 */ /* Create fake packet to satisfy parser on the other end */
((ot_dword*)reply)[2] = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM ); ((uint32_t*)reply)[2] = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM );
((ot_dword*)reply)[3] = ((ot_dword*)reply)[4] = 0; ((uint32_t*)reply)[3] = ((uint32_t*)reply)[4] = 0;
return (size_t)20; return (size_t)20;
} }
@ -299,9 +300,9 @@ exit_loop:
} }
/* else { Handle UDP reply */ /* else { Handle UDP reply */
((ot_dword*)reply)[2] = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM ); ((uint32_t*)reply)[2] = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM );
((ot_dword*)reply)[3] = peer_list->peer_count - peer_list->seed_count; ((uint32_t*)reply)[3] = peer_list->peer_count - peer_list->seed_count;
((ot_dword*)reply)[4] = peer_list->seed_count; ((uint32_t*)reply)[4] = peer_list->seed_count;
mutex_bucket_unlock_by_hash( hash ); mutex_bucket_unlock_by_hash( hash );
return (size_t)20; return (size_t)20;
@ -322,6 +323,7 @@ int trackerlogic_init( const char * const serverdir ) {
#ifdef WANT_TRACKER_SYNC #ifdef WANT_TRACKER_SYNC
sync_init( ); sync_init( );
#endif #endif
stats_init( );
return 0; return 0;
} }
@ -343,6 +345,7 @@ void trackerlogic_deinit( void ) {
} }
/* Deinitialise background worker threads */ /* Deinitialise background worker threads */
stats_deinit( );
#ifdef WANT_TRACKER_SYNC #ifdef WANT_TRACKER_SYNC
sync_deinit( ); sync_deinit( );
#endif #endif

@ -9,14 +9,7 @@
#include <time.h> #include <time.h>
#include <stdint.h> #include <stdint.h>
/* Should be called BYTE, WORD, DWORD - but some OSs already have that and there's no #iftypedef */ typedef uint8_t ot_hash[20];
/* 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 time_t ot_time; typedef time_t ot_time;
/* Some tracker behaviour tunable */ /* Some tracker behaviour tunable */
@ -46,20 +39,19 @@ typedef time_t ot_time;
#define OT_POOLS_TIMEOUT (60*5) #define OT_POOLS_TIMEOUT (60*5)
/* From opentracker.c */ /* From opentracker.c */
extern time_t ot_start_time;
extern time_t g_now; extern time_t g_now;
#define NOW (g_now/OT_POOLS_TIMEOUT) #define NOW (g_now/OT_POOLS_TIMEOUT)
typedef struct { typedef struct {
ot_byte data[8]; uint8_t data[8];
} ot_peer; } ot_peer;
static const ot_byte PEER_FLAG_SEEDING = 0x80; static const uint8_t PEER_FLAG_SEEDING = 0x80;
static const ot_byte PEER_FLAG_COMPLETED = 0x40; static const uint8_t PEER_FLAG_COMPLETED = 0x40;
static const ot_byte PEER_FLAG_STOPPED = 0x20; static const uint8_t PEER_FLAG_STOPPED = 0x20;
#define OT_SETIP( peer, ip ) memmove((peer),(ip),4); #define OT_SETIP( peer, ip ) memmove((peer),(ip),4);
#define OT_SETPORT( peer, port ) memmove(((ot_byte*)peer)+4,(port),2); #define OT_SETPORT( peer, port ) memmove(((uint8_t*)peer)+4,(port),2);
#define OT_FLAG(peer) (((ot_byte*)(peer))[6]) #define OT_FLAG(peer) (((uint8_t*)(peer))[6])
#define OT_PEER_COMPARE_SIZE ((size_t)6) #define OT_PEER_COMPARE_SIZE ((size_t)6)
#define OT_HASH_COMPARE_SIZE (sizeof(ot_hash)) #define OT_HASH_COMPARE_SIZE (sizeof(ot_hash))

Loading…
Cancel
Save