summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--opentracker.c2
-rw-r--r--ot_fullscrape.c1
-rw-r--r--ot_http.c1
-rw-r--r--ot_iovec.c2
-rw-r--r--ot_livesync.c15
-rw-r--r--ot_mutex.c15
-rw-r--r--ot_stats.c2
-rw-r--r--ot_sync.c1
-rw-r--r--proxy.c15
-rw-r--r--trackerlogic.c3
10 files changed, 30 insertions, 27 deletions
diff --git a/opentracker.c b/opentracker.c
index e24beb2..89bfd3e 100644
--- a/opentracker.c
+++ b/opentracker.c
@@ -5,7 +5,6 @@
5 $Id$ */ 5 $Id$ */
6 6
7/* System */ 7/* System */
8#include <arpa/inet.h>
9#include <ctype.h> 8#include <ctype.h>
10#include <errno.h> 9#include <errno.h>
11#include <pthread.h> 10#include <pthread.h>
@@ -21,7 +20,6 @@
21#endif 20#endif
22 21
23/* Libowfat */ 22/* Libowfat */
24#include "byte.h"
25#include "io.h" 23#include "io.h"
26#include "iob.h" 24#include "iob.h"
27#include "ip6.h" 25#include "ip6.h"
diff --git a/ot_fullscrape.c b/ot_fullscrape.c
index ec7f2df..3e36e8e 100644
--- a/ot_fullscrape.c
+++ b/ot_fullscrape.c
@@ -10,7 +10,6 @@
10#include <pthread.h> 10#include <pthread.h>
11#include <stdio.h> 11#include <stdio.h>
12#include <string.h> 12#include <string.h>
13#include <sys/param.h>
14#ifdef WANT_COMPRESSION_GZIP 13#ifdef WANT_COMPRESSION_GZIP
15#include <zlib.h> 14#include <zlib.h>
16#endif 15#endif
diff --git a/ot_http.c b/ot_http.c
index e4486fc..45dacdc 100644
--- a/ot_http.c
+++ b/ot_http.c
@@ -15,7 +15,6 @@
15 15
16/* Libowfat */ 16/* Libowfat */
17#include "array.h" 17#include "array.h"
18#include "byte.h"
19#include "case.h" 18#include "case.h"
20#include "iob.h" 19#include "iob.h"
21#include "ip6.h" 20#include "ip6.h"
diff --git a/ot_iovec.c b/ot_iovec.c
index e2cdd4b..b8ea657 100644
--- a/ot_iovec.c
+++ b/ot_iovec.c
@@ -5,9 +5,7 @@
5 5
6/* System */ 6/* System */
7#include <stdlib.h> 7#include <stdlib.h>
8#include <sys/types.h>
9#include <sys/uio.h> 8#include <sys/uio.h>
10#include <unistd.h>
11 9
12/* Libowfat */ 10/* Libowfat */
13 11
diff --git a/ot_livesync.c b/ot_livesync.c
index efba4d7..b876ef8 100644
--- a/ot_livesync.c
+++ b/ot_livesync.c
@@ -4,15 +4,14 @@
4 $id$ */ 4 $id$ */
5 5
6/* System */ 6/* System */
7#include <arpa/inet.h>
7#include <pthread.h> 8#include <pthread.h>
8#include <stdlib.h> 9#include <stdlib.h>
9#include <string.h> 10#include <string.h>
10#include <sys/types.h> 11#include <sys/types.h>
11#include <sys/uio.h>
12#include <unistd.h> 12#include <unistd.h>
13 13
14/* Libowfat */ 14/* Libowfat */
15#include "byte.h"
16#include "ip6.h" 15#include "ip6.h"
17#include "ndelay.h" 16#include "ndelay.h"
18#include "socket.h" 17#include "socket.h"
@@ -58,6 +57,8 @@ static sync_buffer g_v4_buf;
58 57
59static pthread_t thread_id; 58static pthread_t thread_id;
60void livesync_init(void) { 59void livesync_init(void) {
60 uint32_t packet_type6 = htonl(OT_SYNC_PEER6);
61 uint32_t packet_type4 = htonl(OT_SYNC_PEER4);
61 62
62 if (g_socket_in == -1) 63 if (g_socket_in == -1)
63 exerr("No socket address for live sync specified."); 64 exerr("No socket address for live sync specified.");
@@ -66,8 +67,8 @@ void livesync_init(void) {
66 memcpy(g_v6_buf.data, &g_tracker_id, sizeof(g_tracker_id)); 67 memcpy(g_v6_buf.data, &g_tracker_id, sizeof(g_tracker_id));
67 memcpy(g_v4_buf.data, &g_tracker_id, sizeof(g_tracker_id)); 68 memcpy(g_v4_buf.data, &g_tracker_id, sizeof(g_tracker_id));
68 69
69 uint32_pack_big((char *)g_v6_buf.data + sizeof(g_tracker_id), OT_SYNC_PEER6); 70 memcpy(g_v6_buf.data + sizeof(g_tracker_id), &packet_type6, sizeof(packet_type6));
70 uint32_pack_big((char *)g_v4_buf.data + sizeof(g_tracker_id), OT_SYNC_PEER4); 71 memcpy(g_v4_buf.data + sizeof(g_tracker_id), &packet_type4, sizeof(packet_type4));
71 72
72 g_v6_buf.fill = sizeof(g_tracker_id) + sizeof(uint32_t); 73 g_v6_buf.fill = sizeof(g_tracker_id) + sizeof(uint32_t);
73 g_v4_buf.fill = sizeof(g_tracker_id) + sizeof(uint32_t); 74 g_v4_buf.fill = sizeof(g_tracker_id) + sizeof(uint32_t);
@@ -216,6 +217,8 @@ static void *livesync_worker(void *args) {
216 memcpy(in_ip, V4mappedprefix, sizeof(V4mappedprefix)); 217 memcpy(in_ip, V4mappedprefix, sizeof(V4mappedprefix));
217 218
218 while (1) { 219 while (1) {
220 uint32_t packet_type;
221
219 ws.request_size = socket_recv4(g_socket_in, (char *)ws.inbuf, LIVESYNC_INCOMING_BUFFSIZE, 12 + (char *)in_ip, &in_port); 222 ws.request_size = socket_recv4(g_socket_in, (char *)ws.inbuf, LIVESYNC_INCOMING_BUFFSIZE, 12 + (char *)in_ip, &in_port);
220 223
221 /* Expect at least tracker id and packet type */ 224 /* Expect at least tracker id and packet type */
@@ -228,7 +231,9 @@ static void *livesync_worker(void *args) {
228 continue; 231 continue;
229 } 232 }
230 233
231 switch (uint32_read_big(sizeof(g_tracker_id) + (char *)ws.inbuf)) { 234 memcpy(&packet_type, ws.inbuf + sizeof(g_tracker_id), sizeof(packet_type));
235
236 switch (ntohl(packet_type)) {
232 case OT_SYNC_PEER6: 237 case OT_SYNC_PEER6:
233 livesync_handle_peersync(&ws, OT_PEER_SIZE6); 238 livesync_handle_peersync(&ws, OT_PEER_SIZE6);
234 break; 239 break;
diff --git a/ot_mutex.c b/ot_mutex.c
index 300da3a..9aa476d 100644
--- a/ot_mutex.c
+++ b/ot_mutex.c
@@ -4,16 +4,15 @@
4 $id$ */ 4 $id$ */
5 5
6/* System */ 6/* System */
7#include <arpa/inet.h>
7#include <pthread.h> 8#include <pthread.h>
8#include <stdio.h> 9#include <stdio.h>
9#include <stdlib.h> 10#include <stdlib.h>
10#include <string.h> 11#include <string.h>
11#include <sys/mman.h>
12#include <sys/uio.h> 12#include <sys/uio.h>
13 13
14/* Libowfat */ 14/* Libowfat */
15#include "io.h" 15#include "io.h"
16#include "uint32.h"
17 16
18/* Opentracker */ 17/* Opentracker */
19#include "ot_iovec.h" 18#include "ot_iovec.h"
@@ -37,7 +36,15 @@ ot_vector *mutex_bucket_lock(int bucket) {
37 return all_torrents + bucket; 36 return all_torrents + bucket;
38} 37}
39 38
40ot_vector *mutex_bucket_lock_by_hash(ot_hash const hash) { return mutex_bucket_lock(uint32_read_big((const char *)hash) >> OT_BUCKET_COUNT_SHIFT); } 39/* Torrents are spread over buckets by the first four bytes of their info_hash,
40 which may sit at any alignment, hence the memcpy */
41static int bucket_from_hash(ot_hash const hash) {
42 uint32_t bucket;
43 memcpy(&bucket, hash, sizeof(bucket));
44 return ntohl(bucket) >> OT_BUCKET_COUNT_SHIFT;
45}
46
47ot_vector *mutex_bucket_lock_by_hash(ot_hash const hash) { return mutex_bucket_lock(bucket_from_hash(hash)); }
41 48
42void mutex_bucket_unlock(int bucket, int delta_torrentcount) { 49void mutex_bucket_unlock(int bucket, int delta_torrentcount) {
43 pthread_mutex_unlock(bucket_mutex + bucket); 50 pthread_mutex_unlock(bucket_mutex + bucket);
@@ -45,7 +52,7 @@ void mutex_bucket_unlock(int bucket, int delta_torrentcount) {
45} 52}
46 53
47void mutex_bucket_unlock_by_hash(ot_hash const hash, int delta_torrentcount) { 54void mutex_bucket_unlock_by_hash(ot_hash const hash, int delta_torrentcount) {
48 mutex_bucket_unlock(uint32_read_big((char *)hash) >> OT_BUCKET_COUNT_SHIFT, delta_torrentcount); 55 mutex_bucket_unlock(bucket_from_hash(hash), delta_torrentcount);
49} 56}
50 57
51size_t mutex_get_torrent_count(void) { return g_torrent_count; } 58size_t mutex_get_torrent_count(void) { return g_torrent_count; }
diff --git a/ot_stats.c b/ot_stats.c
index 15eef75..afc972a 100644
--- a/ot_stats.c
+++ b/ot_stats.c
@@ -4,13 +4,11 @@
4 $id$ */ 4 $id$ */
5 5
6/* System */ 6/* System */
7#include <arpa/inet.h>
8#include <inttypes.h> 7#include <inttypes.h>
9#include <pthread.h> 8#include <pthread.h>
10#include <stdio.h> 9#include <stdio.h>
11#include <stdlib.h> 10#include <stdlib.h>
12#include <string.h> 11#include <string.h>
13#include <sys/mman.h>
14#include <sys/types.h> 12#include <sys/types.h>
15#include <sys/uio.h> 13#include <sys/uio.h>
16#include <unistd.h> 14#include <unistd.h>
diff --git a/ot_sync.c b/ot_sync.c
index 2241bf3..d3d30fa 100644
--- a/ot_sync.c
+++ b/ot_sync.c
@@ -7,7 +7,6 @@
7#include <pthread.h> 7#include <pthread.h>
8#include <stdio.h> 8#include <stdio.h>
9#include <string.h> 9#include <string.h>
10#include <sys/mman.h>
11#include <sys/types.h> 10#include <sys/types.h>
12#include <sys/uio.h> 11#include <sys/uio.h>
13 12
diff --git a/proxy.c b/proxy.c
index 5a7698b..cec985e 100644
--- a/proxy.c
+++ b/proxy.c
@@ -8,8 +8,6 @@
8#include <ctype.h> 8#include <ctype.h>
9#include <errno.h> 9#include <errno.h>
10#include <pthread.h> 10#include <pthread.h>
11#include <pwd.h>
12#include <signal.h>
13#include <stdint.h> 11#include <stdint.h>
14#include <stdio.h> 12#include <stdio.h>
15#include <stdlib.h> 13#include <stdlib.h>
@@ -472,13 +470,15 @@ static void handle_write(int64 peersocket) {
472} 470}
473 471
474static void server_mainloop() { 472static void server_mainloop() {
475 int64 sock; 473 int64 sock;
474 uint32_t packet_type;
476 475
477 /* inlined livesync_init() */ 476 /* inlined livesync_init() */
478 memset(g_peerbuffer_start, 0, sizeof(g_peerbuffer_start)); 477 memset(g_peerbuffer_start, 0, sizeof(g_peerbuffer_start));
479 g_peerbuffer_pos = g_peerbuffer_start; 478 g_peerbuffer_pos = g_peerbuffer_start;
480 memcpy(g_peerbuffer_pos, &g_tracker_id, sizeof(g_tracker_id)); 479 memcpy(g_peerbuffer_pos, &g_tracker_id, sizeof(g_tracker_id));
481 uint32_pack_big((char *)g_peerbuffer_pos + sizeof(g_tracker_id), OT_SYNC_PEER); 480 packet_type = htonl(OT_SYNC_PEER);
481 memcpy(g_peerbuffer_pos + sizeof(g_tracker_id), &packet_type, sizeof(packet_type));
482 g_peerbuffer_pos += sizeof(g_tracker_id) + sizeof(uint32_t); 482 g_peerbuffer_pos += sizeof(g_tracker_id) + sizeof(uint32_t);
483 g_next_packet_time = time(NULL) + LIVESYNC_MAXDELAY; 483 g_next_packet_time = time(NULL) + LIVESYNC_MAXDELAY;
484 484
@@ -870,6 +870,7 @@ static void *livesync_worker(void *args) {
870 while (1) { 870 while (1) {
871 ot_ip6 in_ip; 871 ot_ip6 in_ip;
872 uint16_t in_port; 872 uint16_t in_port;
873 uint32_t packet_type;
873 size_t datalen = socket_recv4(g_socket_in, (char *)g_inbuffer, LIVESYNC_INCOMING_BUFFSIZE, 12 + (char *)in_ip, &in_port); 874 size_t datalen = socket_recv4(g_socket_in, (char *)g_inbuffer, LIVESYNC_INCOMING_BUFFSIZE, 12 + (char *)in_ip, &in_port);
874 875
875 /* Expect at least tracker id and packet type */ 876 /* Expect at least tracker id and packet type */
@@ -879,7 +880,9 @@ static void *livesync_worker(void *args) {
879 /* drop packet coming from ourselves */ 880 /* drop packet coming from ourselves */
880 continue; 881 continue;
881 } 882 }
882 switch (uint32_read_big((char *)g_inbuffer + sizeof(g_tracker_id))) { 883 memcpy(&packet_type, g_inbuffer + sizeof(g_tracker_id), sizeof(packet_type));
884
885 switch (ntohl(packet_type)) {
883 case OT_SYNC_PEER4: 886 case OT_SYNC_PEER4:
884 livesync_handle_peersync(datalen, OT_PEER_SIZE4); 887 livesync_handle_peersync(datalen, OT_PEER_SIZE4);
885 break; 888 break;
@@ -887,7 +890,7 @@ static void *livesync_worker(void *args) {
887 livesync_handle_peersync(datalen, OT_PEER_SIZE6); 890 livesync_handle_peersync(datalen, OT_PEER_SIZE6);
888 break; 891 break;
889 default: 892 default:
890 // fprintf( stderr, "Received an unknown live sync packet type %u.\n", uint32_read_big( sizeof( g_tracker_id ) + (char*)g_inbuffer ) ); 893 // fprintf( stderr, "Received an unknown live sync packet type %u.\n", ntohl( packet_type ) );
891 break; 894 break;
892 } 895 }
893 } 896 }
diff --git a/trackerlogic.c b/trackerlogic.c
index a76064e..59e9643 100644
--- a/trackerlogic.c
+++ b/trackerlogic.c
@@ -5,15 +5,12 @@
5 5
6/* System */ 6/* System */
7#include <arpa/inet.h> 7#include <arpa/inet.h>
8#include <errno.h>
9#include <stdint.h> 8#include <stdint.h>
10#include <stdio.h> 9#include <stdio.h>
11#include <stdlib.h> 10#include <stdlib.h>
12#include <string.h> 11#include <string.h>
13#include <unistd.h>
14 12
15/* Libowfat */ 13/* Libowfat */
16#include "array.h"
17#include "io.h" 14#include "io.h"
18#include "iob.h" 15#include "iob.h"
19#include "ip6.h" 16#include "ip6.h"