summaryrefslogtreecommitdiff
path: root/proxy.c
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2026-10-24 00:15:34 +0200
committerDirk Engling <erdgeist@erdgeist.org>2026-10-24 00:15:34 +0200
commit6d97e999f1e7b4476faf749abbb5e925d09208c6 (patch)
treef22c04816949de04fc6b971c0a50f98f1cefd1ba /proxy.c
parent4ece9d359fd6668bfbc9c4260463f5b5913ae8fc (diff)
Replace endianess helpers and remove unused system and libowfat included
* Replace libowfat big endian packers with htonl/ntohl * Turn bucket derivation in ot_mutex.c into its own helper * remove unused includes
Diffstat (limited to 'proxy.c')
-rw-r--r--proxy.c15
1 files changed, 9 insertions, 6 deletions
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 }