summaryrefslogtreecommitdiff
path: root/trackerlogic.h
diff options
context:
space:
mode:
Diffstat (limited to 'trackerlogic.h')
-rw-r--r--trackerlogic.h48
1 files changed, 20 insertions, 28 deletions
diff --git a/trackerlogic.h b/trackerlogic.h
index 5b03012..fd80f92 100644
--- a/trackerlogic.h
+++ b/trackerlogic.h
@@ -1,8 +1,8 @@
1/* This software was written by Dirk Engling <erdgeist@erdgeist.org> 1/* This software was written by Dirk Engling <erdgeist@erdgeist.org>
2 It is considered beerware. Prost. Skol. Cheers or whatever. */ 2 It is considered beerware. Prost. Skol. Cheers or whatever. */
3 3
4#ifndef __TRACKERLOGIC_H__ 4#ifndef __OT_TRACKERLOGIC_H__
5#define __TRACKERLOGIC_H__ 5#define __OT_TRACKERLOGIC_H__
6 6
7#include <sys/types.h> 7#include <sys/types.h>
8#include <sys/time.h> 8#include <sys/time.h>
@@ -20,16 +20,6 @@ typedef ot_byte ot_hash[20];
20typedef ot_dword ot_ip; 20typedef ot_dword ot_ip;
21typedef time_t ot_time; 21typedef time_t ot_time;
22 22
23#define OT_VECTOR_MIN_MEMBERS 4
24#define OT_VECTOR_GROW_RATIO 8
25#define OT_VECTOR_SHRINK_THRESH 6
26#define OT_VECTOR_SHRINK_RATIO 4
27typedef struct {
28 void *data;
29 size_t size;
30 size_t space;
31} ot_vector;
32
33/* Some tracker behaviour tunable */ 23/* Some tracker behaviour tunable */
34#define OT_CLIENT_TIMEOUT 30 24#define OT_CLIENT_TIMEOUT 30
35#define OT_CLIENT_TIMEOUT_CHECKINTERVAL 10 25#define OT_CLIENT_TIMEOUT_CHECKINTERVAL 10
@@ -42,6 +32,10 @@ typedef struct {
42 32
43#define OT_CLIENT_REQUEST_INTERVAL_RANDOM ( OT_CLIENT_REQUEST_INTERVAL - OT_CLIENT_REQUEST_VARIATION/2 + (int)( random( ) % OT_CLIENT_REQUEST_VARIATION ) ) 33#define OT_CLIENT_REQUEST_INTERVAL_RANDOM ( OT_CLIENT_REQUEST_INTERVAL - OT_CLIENT_REQUEST_VARIATION/2 + (int)( random( ) % OT_CLIENT_REQUEST_VARIATION ) )
44 34
35/* We maintain a list of 1024 pointers to sorted list of ot_torrent structs
36 Sort key is, of course, its hash */
37#define OT_BUCKET_COUNT 1024
38
45/* Number of tracker admin ip addresses allowed */ 39/* Number of tracker admin ip addresses allowed */
46#define OT_ADMINIP_MAX 64 40#define OT_ADMINIP_MAX 64
47#define OT_MAX_THREADS 16 41#define OT_MAX_THREADS 16
@@ -70,7 +64,16 @@ static const ot_byte PEER_FLAG_STOPPED = 0x20;
70#define OT_PEER_COMPARE_SIZE ((size_t)6) 64#define OT_PEER_COMPARE_SIZE ((size_t)6)
71#define OT_HASH_COMPARE_SIZE (sizeof(ot_hash)) 65#define OT_HASH_COMPARE_SIZE (sizeof(ot_hash))
72 66
67struct ot_peerlist;
68typedef struct ot_peerlist ot_peerlist;
73typedef struct { 69typedef struct {
70 ot_hash hash;
71 ot_peerlist *peer_list;
72} ot_torrent;
73
74#include "ot_vector.h"
75
76struct ot_peerlist {
74 ot_time base; 77 ot_time base;
75 size_t seed_count; 78 size_t seed_count;
76 size_t peer_count; 79 size_t peer_count;
@@ -80,12 +83,7 @@ typedef struct {
80#ifdef WANT_TRACKER_SYNC 83#ifdef WANT_TRACKER_SYNC
81 ot_vector changeset; 84 ot_vector changeset;
82#endif 85#endif
83} ot_peerlist; 86};
84
85typedef struct {
86 ot_hash hash;
87 ot_peerlist *peer_list;
88} ot_torrent;
89 87
90/* 88/*
91 Exported functions 89 Exported functions
@@ -100,27 +98,21 @@ typedef struct {
100int trackerlogic_init( const char * const serverdir ); 98int trackerlogic_init( const char * const serverdir );
101void trackerlogic_deinit( void ); 99void trackerlogic_deinit( void );
102 100
103enum { STATS_CONNS, STATS_PEERS, STATS_TOP5, STATS_DMEM, STATS_TCP, STATS_UDP, STATS_SLASH24S, SYNC_IN, SYNC_OUT, STATS_FULLSCRAPE };
104
105ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer WANT_TRACKER_SYNC_PARAM( int from_changeset ) ); 101ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer WANT_TRACKER_SYNC_PARAM( int from_changeset ) );
106size_t remove_peer_from_torrent( ot_hash *hash, ot_peer *peer, char *reply, int is_tcp ); 102size_t remove_peer_from_torrent( ot_hash *hash, ot_peer *peer, char *reply, int is_tcp );
107size_t return_peers_for_torrent( ot_hash *hash, size_t amount, char *reply, int is_tcp ); 103size_t return_peers_for_torrent( ot_hash *hash, size_t amount, char *reply, int is_tcp );
108size_t return_fullscrape_for_tracker( char **reply ); 104size_t return_fullscrape_for_tracker( char **reply );
109size_t return_tcp_scrape_for_torrent( ot_hash *hash, int amount, char *reply ); 105size_t return_tcp_scrape_for_torrent( ot_hash *hash, int amount, char *reply );
110size_t return_udp_scrape_for_torrent( ot_hash *hash, char *reply ); 106size_t return_udp_scrape_for_torrent( ot_hash *hash, char *reply );
111size_t return_stats_for_tracker( char *reply, int mode );
112size_t return_stats_for_slash24s( char *reply, size_t amount, ot_dword thresh );
113size_t return_memstat_for_tracker( char **reply );
114void clean_all_torrents( void ); 107void clean_all_torrents( void );
115 108
116#ifdef WANT_TRACKER_SYNC
117size_t return_changeset_for_tracker( char **reply );
118int add_changeset_to_tracker( ot_byte *data, size_t len );
119#endif
120
121#if defined ( WANT_BLACKLISTING ) || defined ( WANT_CLOSED_TRACKER ) 109#if defined ( WANT_BLACKLISTING ) || defined ( WANT_CLOSED_TRACKER )
122int accesslist_addentry( ot_hash *hash ); 110int accesslist_addentry( ot_hash *hash );
123void accesslist_reset( void ); 111void accesslist_reset( void );
124#endif 112#endif
125 113
114/* Helper, before it moves to its own object */
115void fix_mmapallocation( void *buf, size_t old_alloc, size_t new_alloc );
116void free_peerlist( ot_peerlist *peer_list );
117
126#endif 118#endif