diff options
Diffstat (limited to 'proxy.c')
| -rw-r--r-- | proxy.c | 36 |
1 files changed, 18 insertions, 18 deletions
| @@ -19,13 +19,13 @@ | |||
| 19 | /* Libowfat */ | 19 | /* Libowfat */ |
| 20 | #include "io.h" | 20 | #include "io.h" |
| 21 | #include "iob.h" | 21 | #include "iob.h" |
| 22 | #include "ip6.h" | ||
| 23 | #include "socket.h" | 22 | #include "socket.h" |
| 24 | 23 | ||
| 25 | /* Opentracker */ | 24 | /* Opentracker */ |
| 25 | #include "ot_ip.h" | ||
| 26 | #include "ot_mutex.h" | 26 | #include "ot_mutex.h" |
| 27 | #include "ot_scan.h" | ||
| 28 | #include "ot_random.h" | 27 | #include "ot_random.h" |
| 28 | #include "ot_scan.h" | ||
| 29 | #include "ot_stats.h" | 29 | #include "ot_stats.h" |
| 30 | #include "ot_vector.h" | 30 | #include "ot_vector.h" |
| 31 | #include "trackerlogic.h" | 31 | #include "trackerlogic.h" |
| @@ -63,11 +63,11 @@ enum { OT_SYNC_PEER4, OT_SYNC_PEER6 }; | |||
| 63 | enum { FLAG_SERVERSOCKET = 1 }; | 63 | enum { FLAG_SERVERSOCKET = 1 }; |
| 64 | 64 | ||
| 65 | /* For incoming packets */ | 65 | /* For incoming packets */ |
| 66 | static int64 g_socket_in = -1; | 66 | static int64_t g_socket_in = -1; |
| 67 | static uint8_t g_inbuffer[LIVESYNC_INCOMING_BUFFSIZE]; | 67 | static uint8_t g_inbuffer[LIVESYNC_INCOMING_BUFFSIZE]; |
| 68 | 68 | ||
| 69 | /* For outgoing packets */ | 69 | /* For outgoing packets */ |
| 70 | static int64 g_socket_out = -1; | 70 | static int64_t g_socket_out = -1; |
| 71 | static uint8_t g_peerbuffer_start[LIVESYNC_OUTGOING_BUFFSIZE_PEERS]; | 71 | static uint8_t g_peerbuffer_start[LIVESYNC_OUTGOING_BUFFSIZE_PEERS]; |
| 72 | static uint8_t *g_peerbuffer_pos; | 72 | static uint8_t *g_peerbuffer_pos; |
| 73 | static uint8_t *g_peerbuffer_highwater = g_peerbuffer_start + LIVESYNC_OUTGOING_BUFFSIZE_PEERS - LIVESYNC_OUTGOING_WATERMARK_PEERS; | 73 | static uint8_t *g_peerbuffer_highwater = g_peerbuffer_start + LIVESYNC_OUTGOING_BUFFSIZE_PEERS - LIVESYNC_OUTGOING_WATERMARK_PEERS; |
| @@ -92,7 +92,7 @@ void livesync_bind_mcast(ot_ip6 ip, uint16_t port) { | |||
| 92 | char tmpip[4] = {0, 0, 0, 0}; | 92 | char tmpip[4] = {0, 0, 0, 0}; |
| 93 | char *v4ip; | 93 | char *v4ip; |
| 94 | 94 | ||
| 95 | if (!ip6_isv4mapped(ip)) | 95 | if (!ip_is_v4mapped(ip)) |
| 96 | exerr("v6 mcast support not yet available."); | 96 | exerr("v6 mcast support not yet available."); |
| 97 | v4ip = ip + 12; | 97 | v4ip = ip + 12; |
| 98 | 98 | ||
| @@ -249,7 +249,7 @@ typedef struct { | |||
| 249 | uint8_t indata[8192 * 16]; /* Any data not processed yet */ | 249 | uint8_t indata[8192 * 16]; /* Any data not processed yet */ |
| 250 | size_t indata_length; /* Length of unprocessed data */ | 250 | size_t indata_length; /* Length of unprocessed data */ |
| 251 | uint32_t tracker_id; /* How the other end greeted */ | 251 | uint32_t tracker_id; /* How the other end greeted */ |
| 252 | int64 fd; /* A file handle, if connected, <= 0 is disconnected (0 initially, -1 else) */ | 252 | int64_t fd; /* A file handle, if connected, <= 0 is disconnected (0 initially, -1 else) */ |
| 253 | io_batch outdata; /* The iobatch containing our sync data */ | 253 | io_batch outdata; /* The iobatch containing our sync data */ |
| 254 | 254 | ||
| 255 | size_t packet_tcount; /* Number of unprocessed torrents in packet we currently receive */ | 255 | size_t packet_tcount; /* Number of unprocessed torrents in packet we currently receive */ |
| @@ -283,7 +283,7 @@ static void handle_reconnects(void) { | |||
| 283 | size_t i; | 283 | size_t i; |
| 284 | for (i = 0; i < g_connection_count; ++i) | 284 | for (i = 0; i < g_connection_count; ++i) |
| 285 | if (PROXYPEER_NEEDSCONNECT(g_connections[i].state)) { | 285 | if (PROXYPEER_NEEDSCONNECT(g_connections[i].state)) { |
| 286 | int64 newfd = socket_tcp6(); | 286 | int64_t newfd = socket_tcp6(); |
| 287 | fprintf(stderr, "(Re)connecting to peer..."); | 287 | fprintf(stderr, "(Re)connecting to peer..."); |
| 288 | if (newfd < 0) | 288 | if (newfd < 0) |
| 289 | continue; /* No socket for you */ | 289 | continue; /* No socket for you */ |
| @@ -308,10 +308,10 @@ static void handle_reconnects(void) { | |||
| 308 | } | 308 | } |
| 309 | 309 | ||
| 310 | /* Handle incoming connection requests, check against whitelist */ | 310 | /* Handle incoming connection requests, check against whitelist */ |
| 311 | static void handle_accept(int64 serversocket) { | 311 | static void handle_accept(int64_t serversocket) { |
| 312 | int64 newfd; | 312 | int64_t newfd; |
| 313 | ot_ip6 ip; | 313 | ot_ip6 ip; |
| 314 | uint16 port; | 314 | uint16 port; |
| 315 | 315 | ||
| 316 | while ((newfd = socket_accept6(serversocket, ip, &port, NULL)) != -1) { | 316 | while ((newfd = socket_accept6(serversocket, ip, &port, NULL)) != -1) { |
| 317 | 317 | ||
| @@ -351,9 +351,9 @@ static void handle_accept(int64 serversocket) { | |||
| 351 | } | 351 | } |
| 352 | 352 | ||
| 353 | /* New sync data on the stream */ | 353 | /* New sync data on the stream */ |
| 354 | static void handle_read(int64 peersocket) { | 354 | static void handle_read(int64_t peersocket) { |
| 355 | int i; | 355 | int i; |
| 356 | int64 datalen; | 356 | int64_t datalen; |
| 357 | uint32_t tracker_id; | 357 | uint32_t tracker_id; |
| 358 | proxy_peer *peer = io_getcookie(peersocket); | 358 | proxy_peer *peer = io_getcookie(peersocket); |
| 359 | 359 | ||
| @@ -420,7 +420,7 @@ static void handle_read(int64 peersocket) { | |||
| 420 | } | 420 | } |
| 421 | 421 | ||
| 422 | /* Can write new sync data to the stream */ | 422 | /* Can write new sync data to the stream */ |
| 423 | static void handle_write(int64 peersocket) { | 423 | static void handle_write(int64_t peersocket) { |
| 424 | proxy_peer *peer = io_getcookie(peersocket); | 424 | proxy_peer *peer = io_getcookie(peersocket); |
| 425 | 425 | ||
| 426 | if (!peer) { | 426 | if (!peer) { |
| @@ -472,7 +472,7 @@ static void handle_write(int64 peersocket) { | |||
| 472 | } | 472 | } |
| 473 | 473 | ||
| 474 | static void server_mainloop() { | 474 | static void server_mainloop() { |
| 475 | int64 sock; | 475 | int64_t sock; |
| 476 | uint32_t packet_type; | 476 | uint32_t packet_type; |
| 477 | 477 | ||
| 478 | /* inlined livesync_init() */ | 478 | /* inlined livesync_init() */ |
| @@ -515,7 +515,7 @@ static void panic(const char *routine) { | |||
| 515 | } | 515 | } |
| 516 | 516 | ||
| 517 | static int64_t ot_try_bind(ot_ip6 ip, uint16_t port) { | 517 | static int64_t ot_try_bind(ot_ip6 ip, uint16_t port) { |
| 518 | int64 sock = socket_tcp6(); | 518 | int64_t sock = socket_tcp6(); |
| 519 | 519 | ||
| 520 | if (socket_bind6_reuse(sock, ip, port, 0) == -1) | 520 | if (socket_bind6_reuse(sock, ip, port, 0) == -1) |
| 521 | panic("socket_bind6_reuse"); | 521 | panic("socket_bind6_reuse"); |
| @@ -539,14 +539,14 @@ static int scan_ip6_port(const char *src, ot_ip6 ip, uint16_t *port) { | |||
| 539 | ++s; | 539 | ++s; |
| 540 | if (*s == '[') | 540 | if (*s == '[') |
| 541 | ++s, ++bracket; /* for v6 style notation */ | 541 | ++s, ++bracket; /* for v6 style notation */ |
| 542 | if (!(off = scan_ip6(s, ip))) | 542 | if (!(off = ip_scan(s, ip))) |
| 543 | return 0; | 543 | return 0; |
| 544 | s += off; | 544 | s += off; |
| 545 | if (*s == 0 || isspace(*s)) | 545 | if (*s == 0 || isspace(*s)) |
| 546 | return s - src; | 546 | return s - src; |
| 547 | if (*s == ']' && bracket) | 547 | if (*s == ']' && bracket) |
| 548 | ++s; | 548 | ++s; |
| 549 | if (!ip6_isv4mapped(ip)) { | 549 | if (!ip_is_v4mapped(ip)) { |
| 550 | if ((bracket && *(s) != ':') || (*(s) != '.')) | 550 | if ((bracket && *(s) != ':') || (*(s) != '.')) |
| 551 | return 0; | 551 | return 0; |
| 552 | s++; | 552 | s++; |
