diff options
| author | erdgeist <> | 2006-12-14 02:44:50 +0000 |
|---|---|---|
| committer | erdgeist <> | 2006-12-14 02:44:50 +0000 |
| commit | 688a4edd9e489de26a9b53ea79f513e6461c7533 (patch) | |
| tree | 25cb8c040bf69fbb350a602950528f5f15addd61 /trackerlogic.h | |
| parent | c0f667defe1efd74b98e283aad635eed5092475e (diff) | |
Now actually seems to work for the most parts
Added scraping
Added graceful disconnect
Diffstat (limited to 'trackerlogic.h')
| -rw-r--r-- | trackerlogic.h | 48 |
1 files changed, 21 insertions, 27 deletions
diff --git a/trackerlogic.h b/trackerlogic.h index 3243eb7..44bd744 100644 --- a/trackerlogic.h +++ b/trackerlogic.h | |||
| @@ -32,40 +32,31 @@ typedef time_t ot_time; | |||
| 32 | #define OT_POOLS_TIMEOUT 300 | 32 | #define OT_POOLS_TIMEOUT 300 |
| 33 | #define NOW (time(NULL)/OT_POOLS_TIMEOUT) | 33 | #define NOW (time(NULL)/OT_POOLS_TIMEOUT) |
| 34 | 34 | ||
| 35 | typedef struct ot_vector { | 35 | typedef struct { |
| 36 | void *data; | 36 | void *data; |
| 37 | size_t size; | 37 | size_t size; |
| 38 | size_t space; | 38 | size_t space; |
| 39 | } *ot_vector; | 39 | } ot_vector; |
| 40 | 40 | ||
| 41 | typedef struct ot_peer { | 41 | typedef struct { |
| 42 | ot_ip ip; | 42 | ot_ip ip; |
| 43 | ot_dword port_flags; | 43 | ot_dword port_flags; |
| 44 | } *ot_peer; | 44 | } ot_peer; |
| 45 | static const ot_byte PEER_FLAG_SEEDING = 0x80; | 45 | static const ot_byte PEER_FLAG_SEEDING = 0x80; |
| 46 | static const ot_byte PEER_FLAG_COMPLETED = 0x40; | ||
| 47 | static const ot_byte PEER_FLAG_STOPPED = 0x20; | ||
| 46 | 48 | ||
| 47 | typedef struct ot_peerlist { | 49 | typedef struct { |
| 48 | ot_time base; | 50 | ot_time base; |
| 49 | unsigned long seed_count[ OT_POOLS_COUNT ]; | 51 | unsigned long seed_count[ OT_POOLS_COUNT ]; |
| 50 | struct ot_vector peers[ OT_POOLS_COUNT ]; | 52 | unsigned long downloaded; |
| 51 | } *ot_peerlist; | 53 | ot_vector peers[ OT_POOLS_COUNT ]; |
| 54 | } ot_peerlist; | ||
| 52 | 55 | ||
| 53 | typedef struct ot_torrent { | 56 | typedef struct { |
| 54 | ot_hash hash; | 57 | ot_hash hash; |
| 55 | ot_peerlist peer_list; | 58 | ot_peerlist *peer_list; |
| 56 | } *ot_torrent; | 59 | } ot_torrent; |
| 57 | |||
| 58 | void *map_file( char *file_name, size_t map_size ); | ||
| 59 | void unmap_file( char *file_name, void *map, size_t mapped_size, unsigned long real_size ); | ||
| 60 | |||
| 61 | // This behaves quite like bsearch but allows to find | ||
| 62 | // the insertion point for inserts after unsuccessful searches | ||
| 63 | // in this case exactmatch is 0 on exit | ||
| 64 | // | ||
| 65 | void *binary_search( const void *key, const void *base, | ||
| 66 | const unsigned long member_count, const unsigned long member_size, | ||
| 67 | int (*compar) (const void *, const void *), | ||
| 68 | int *exactmatch ); | ||
| 69 | 60 | ||
| 70 | // | 61 | // |
| 71 | // Exported functions | 62 | // Exported functions |
| @@ -74,7 +65,10 @@ void *binary_search( const void *key, const void *base, | |||
| 74 | int init_logic( char *chdir_directory ); | 65 | int init_logic( char *chdir_directory ); |
| 75 | void deinit_logic( ); | 66 | void deinit_logic( ); |
| 76 | 67 | ||
| 77 | ot_torrent add_peer_to_torrent( ot_hash *hash, ot_peer peer ); | 68 | ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer ); |
| 78 | size_t return_peers_for_torrent( ot_torrent torrent, unsigned long amount, char *reply ); | 69 | size_t return_peers_for_torrent( ot_torrent *torrent, unsigned long amount, char *reply ); |
| 70 | size_t return_scrape_for_torrent( ot_hash *hash, char *reply ); | ||
| 71 | void remove_peer_from_torrent( ot_hash *hash, ot_peer *peer ); | ||
| 72 | void cleanup_torrents( void ); | ||
| 79 | 73 | ||
| 80 | #endif | 74 | #endif |
