summaryrefslogtreecommitdiff
path: root/trackerlogic.c
diff options
context:
space:
mode:
Diffstat (limited to 'trackerlogic.c')
-rw-r--r--trackerlogic.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/trackerlogic.c b/trackerlogic.c
index 6274c41..ab1f419 100644
--- a/trackerlogic.c
+++ b/trackerlogic.c
@@ -54,7 +54,7 @@ ot_byte *scratch_space = 0;
54#define TESTSET( i ) (scratch_space[index]) 54#define TESTSET( i ) (scratch_space[index])
55#define RANDOM random() 55#define RANDOM random()
56 56
57ot_torrent add_peer_to_torrent( ot_hash hash, ot_peer peer ) { 57ot_torrent add_peer_to_torrent( ot_hash *hash, ot_peer peer ) {
58 ot_torrent torrent; 58 ot_torrent torrent;
59 ot_peer peer_dest; 59 ot_peer peer_dest;
60 int exactmatch; 60 int exactmatch;
@@ -66,7 +66,7 @@ ot_torrent add_peer_to_torrent( ot_hash hash, ot_peer peer ) {
66 66
67 // Create a new torrent entry, then 67 // Create a new torrent entry, then
68 MEMMOVE( &torrent->hash, hash, sizeof( ot_hash ) ); 68 MEMMOVE( &torrent->hash, hash, sizeof( ot_hash ) );
69 torrent->peer_list = map_file( to_hex( hash ) ); 69 torrent->peer_list = map_file( to_hex( *hash ) );
70 torrent->peer_count = 0; 70 torrent->peer_count = 0;
71 torrent->seed_count = 0; 71 torrent->seed_count = 0;
72 } 72 }
@@ -106,8 +106,9 @@ inline int TESTVALIDPEER( ot_peer p ) { return p->death > NOW; }
106// * it is not guaranteed to see all peers, so no assumptions on active seeders/peers may be done 106// * it is not guaranteed to see all peers, so no assumptions on active seeders/peers may be done
107// * since compact format cannot handle v6 addresses, it must be enabled by OT_COMPACT_ONLY 107// * since compact format cannot handle v6 addresses, it must be enabled by OT_COMPACT_ONLY
108// 108//
109void return_peers_for_torrent( ot_torrent torrent, unsigned long amount, char *reply ) { 109size_t return_peers_for_torrent( ot_torrent torrent, unsigned long amount, char *reply ) {
110 register ot_peer peer_base = torrent->peer_list; 110 register ot_peer peer_base = torrent->peer_list;
111 char *r = reply;
111 unsigned long peer_count = torrent->peer_count; 112 unsigned long peer_count = torrent->peer_count;
112 unsigned long selected_count = 0, invalid_count = 0; 113 unsigned long selected_count = 0, invalid_count = 0;
113 unsigned long index = 0; 114 unsigned long index = 0;
@@ -132,9 +133,9 @@ void return_peers_for_torrent( ot_torrent torrent, unsigned long amount, char *r
132 index = 0; 133 index = 0;
133 134
134#ifndef OT_COMPACT_ONLY 135#ifndef OT_COMPACT_ONLY
135 reply += FORMAT_FIXED_STRING( reply, "d5:peersl" ); 136 r += FORMAT_FIXED_STRING( r, "d5:peersl" );
136#else 137#else
137 reply += FORMAT_FORMAT_STRING( reply, "d5:peers%li:",6*selected_count ); 138 r += FORMAT_FORMAT_STRING( r, "d5:peers%li:",6*selected_count );
138#endif 139#endif
139 140
140 while( selected_count-- ) { 141 while( selected_count-- ) {
@@ -142,11 +143,11 @@ void return_peers_for_torrent( ot_torrent torrent, unsigned long amount, char *r
142 while( !TESTSELECTED( index ) ) ++index; 143 while( !TESTSELECTED( index ) ) ++index;
143 peer = peer_base + index; 144 peer = peer_base + index;
144#ifdef OT_COMPACT_ONLY 145#ifdef OT_COMPACT_ONLY
145 MEMMOVE( reply, &peer->ip, 4 ); 146 MEMMOVE( r, &peer->ip, 4 );
146 MEMMOVE( reply+4, &peer->port, 2 ); 147 MEMMOVE( r+4, &peer->port, 2 );
147 reply += 6; 148 r += 6;
148#else 149#else
149 reply += FORMAT_FORMAT_STRING( reply, "d2:ip%d:%s7:peer id20:%20c4:porti%ie", 150 r += FORMAT_FORMAT_STRING( r, "d2:ip%d:%s7:peer id20:%20c4:porti%ie",
150 peer->flags & PEER_IP_LENGTH_MASK, 151 peer->flags & PEER_IP_LENGTH_MASK,
151 peer->ip, 152 peer->ip,
152 peer->id, 153 peer->id,
@@ -154,10 +155,11 @@ void return_peers_for_torrent( ot_torrent torrent, unsigned long amount, char *r
154#endif 155#endif
155 } 156 }
156#ifndef OT_COMPACT_ONLY 157#ifndef OT_COMPACT_ONLY
157 reply += FORMAT_FIXED_STRING( reply, "ee" ); 158 r += FORMAT_FIXED_STRING( r, "ee" );
158#else 159#else
159 reply += FORMAT_FIXED_STRING( reply, "e" ); 160 r += FORMAT_FIXED_STRING( r, "e" );
160#endif 161#endif
162 return r - reply;
161} 163}
162 164
163// Compacts a torrents peer list 165// Compacts a torrents peer list