diff options
Diffstat (limited to 'proxy.c')
| -rw-r--r-- | proxy.c | 20 |
1 files changed, 11 insertions, 9 deletions
| @@ -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> |
| @@ -18,7 +16,6 @@ | |||
| 18 | #include <unistd.h> | 16 | #include <unistd.h> |
| 19 | 17 | ||
| 20 | /* Libowfat */ | 18 | /* Libowfat */ |
| 21 | #include "byte.h" | ||
| 22 | #include "io.h" | 19 | #include "io.h" |
| 23 | #include "iob.h" | 20 | #include "iob.h" |
| 24 | #include "ip6.h" | 21 | #include "ip6.h" |
| @@ -142,8 +139,8 @@ size_t add_peer_to_torrent_proxy(ot_hash hash, ot_peer *peer, size_t peer_size) | |||
| 142 | return -1; | 139 | return -1; |
| 143 | } | 140 | } |
| 144 | 141 | ||
| 145 | byte_zero(torrent->peer_list6, sizeof(ot_peerlist)); | 142 | memset(torrent->peer_list6, 0, sizeof(ot_peerlist)); |
| 146 | byte_zero(torrent->peer_list4, sizeof(ot_peerlist)); | 143 | memset(torrent->peer_list4, 0, sizeof(ot_peerlist)); |
| 147 | } | 144 | } |
| 148 | 145 | ||
| 149 | peer_list = peer_size == OT_PEER_SIZE6 ? torrent->peer_list6 : torrent->peer_list4; | 146 | peer_list = peer_size == OT_PEER_SIZE6 ? torrent->peer_list6 : torrent->peer_list4; |
| @@ -473,13 +470,15 @@ static void handle_write(int64 peersocket) { | |||
| 473 | } | 470 | } |
| 474 | 471 | ||
| 475 | static void server_mainloop() { | 472 | static void server_mainloop() { |
| 476 | int64 sock; | 473 | int64 sock; |
| 474 | uint32_t packet_type; | ||
| 477 | 475 | ||
| 478 | /* inlined livesync_init() */ | 476 | /* inlined livesync_init() */ |
| 479 | memset(g_peerbuffer_start, 0, sizeof(g_peerbuffer_start)); | 477 | memset(g_peerbuffer_start, 0, sizeof(g_peerbuffer_start)); |
| 480 | g_peerbuffer_pos = g_peerbuffer_start; | 478 | g_peerbuffer_pos = g_peerbuffer_start; |
| 481 | memcpy(g_peerbuffer_pos, &g_tracker_id, sizeof(g_tracker_id)); | 479 | memcpy(g_peerbuffer_pos, &g_tracker_id, sizeof(g_tracker_id)); |
| 482 | 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)); | ||
| 483 | g_peerbuffer_pos += sizeof(g_tracker_id) + sizeof(uint32_t); | 482 | g_peerbuffer_pos += sizeof(g_tracker_id) + sizeof(uint32_t); |
| 484 | g_next_packet_time = time(NULL) + LIVESYNC_MAXDELAY; | 483 | g_next_packet_time = time(NULL) + LIVESYNC_MAXDELAY; |
| 485 | 484 | ||
| @@ -871,6 +870,7 @@ static void *livesync_worker(void *args) { | |||
| 871 | while (1) { | 870 | while (1) { |
| 872 | ot_ip6 in_ip; | 871 | ot_ip6 in_ip; |
| 873 | uint16_t in_port; | 872 | uint16_t in_port; |
| 873 | uint32_t packet_type; | ||
| 874 | 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); |
| 875 | 875 | ||
| 876 | /* Expect at least tracker id and packet type */ | 876 | /* Expect at least tracker id and packet type */ |
| @@ -880,7 +880,9 @@ static void *livesync_worker(void *args) { | |||
| 880 | /* drop packet coming from ourselves */ | 880 | /* drop packet coming from ourselves */ |
| 881 | continue; | 881 | continue; |
| 882 | } | 882 | } |
| 883 | 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)) { | ||
| 884 | case OT_SYNC_PEER4: | 886 | case OT_SYNC_PEER4: |
| 885 | livesync_handle_peersync(datalen, OT_PEER_SIZE4); | 887 | livesync_handle_peersync(datalen, OT_PEER_SIZE4); |
| 886 | break; | 888 | break; |
| @@ -888,7 +890,7 @@ static void *livesync_worker(void *args) { | |||
| 888 | livesync_handle_peersync(datalen, OT_PEER_SIZE6); | 890 | livesync_handle_peersync(datalen, OT_PEER_SIZE6); |
| 889 | break; | 891 | break; |
| 890 | default: | 892 | default: |
| 891 | // 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 ) ); |
| 892 | break; | 894 | break; |
| 893 | } | 895 | } |
| 894 | } | 896 | } |
