From 4afeaeb4b6ab6c56e582436b17f367e216f16de1 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sun, 25 Oct 2026 02:43:09 +0200 Subject: Use the new ot_socket abstraction for socket creation, read and write --- ot_livesync.c | 42 ++++++++++-------------------------------- 1 file changed, 10 insertions(+), 32 deletions(-) (limited to 'ot_livesync.c') diff --git a/ot_livesync.c b/ot_livesync.c index 8b2dee6..5a63f3c 100644 --- a/ot_livesync.c +++ b/ot_livesync.c @@ -5,19 +5,16 @@ /* System */ #include -#include #include #include #include #include #include -/* Libowfat */ -#include "socket.h" - /* Opentracker */ #include "ot_accesslist.h" #include "ot_ip.h" +#include "ot_socket.h" #include "ot_livesync.h" #include "ot_mutex.h" #include "ot_stats.h" @@ -25,7 +22,7 @@ #ifdef WANT_SYNC_LIVE -char groupip_1[4] = {224, 0, 23, 5}; +ot_ip6 groupip_1 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 224, 0, 23, 5}; #define LIVESYNC_INCOMING_BUFFSIZE (256 * 256) @@ -39,11 +36,11 @@ enum { OT_SYNC_PEER4, OT_SYNC_PEER6 }; /* Forward declaration */ static void *livesync_worker(void *args); -/* For outgoing packets */ -static int64_t g_socket_in = -1; - /* For incoming packets */ -static int64_t g_socket_out = -1; +static int g_socket_in = -1; + +/* For outgoing packets */ +static int g_socket_out = -1; static pthread_mutex_t g_outbuf_mutex = PTHREAD_MUTEX_INITIALIZER; typedef struct { @@ -89,34 +86,17 @@ void livesync_deinit(void) { } void livesync_bind_mcast(ot_ip6 ip, uint16_t port) { - char tmpip[4] = {0, 0, 0, 0}; - char *v4ip; - if (!ip_is_v4mapped(ip)) exerr("v6 mcast support not yet available."); - v4ip = ip + 12; if (g_socket_in != -1) exerr("Error: Livesync listen ip specified twice."); - if ((g_socket_in = socket_udp4()) < 0) - exerr("Error: Cant create live sync incoming socket."); - - fcntl(g_socket_in, F_SETFL, fcntl(g_socket_in, F_GETFL, 0) & ~O_NONBLOCK); - - if (socket_bind4_reuse(g_socket_in, tmpip, port) == -1) + if ((g_socket_in = socket_mcast_join(groupip_1, ip, port)) == -1) exerr("Error: Cant bind live sync incoming socket."); - if (socket_mcjoin4(g_socket_in, groupip_1, v4ip)) - exerr("Error: Cant make live sync incoming socket join mcast group."); - - if ((g_socket_out = socket_udp4()) < 0) - exerr("Error: Cant create live sync outgoing socket."); - if (socket_bind4_reuse(g_socket_out, v4ip, port) == -1) + if ((g_socket_out = socket_mcast_bind(ip, port, 0)) == -1) exerr("Error: Cant bind live sync outgoing socket."); - - socket_mcttl4(g_socket_out, 1); - socket_mcloop4(g_socket_out, 0); } /* Caller MUST hold g_outbuf_mutex. Returns with g_outbuf_mutex unlocked */ @@ -132,7 +112,7 @@ static void livesync_issue_peersync(sync_buffer *buf) { has modified the protected element */ pthread_mutex_unlock(&g_outbuf_mutex); - socket_send4(g_socket_out, mycopy, fill, groupip_1, LIVESYNC_PORT); + socket_mcast_send(g_socket_out, mycopy, fill, groupip_1, LIVESYNC_PORT); } static void livesync_handle_peersync(struct ot_workstruct *ws, size_t peer_size) { @@ -215,12 +195,10 @@ static void *livesync_worker(void *args) { ws.inbuf = ws.request = malloc(LIVESYNC_INCOMING_BUFFSIZE); ws.outbuf = ws.reply = 0; - memcpy(in_ip, ip_v4mapped_prefix, sizeof(ip_v4mapped_prefix)); - while (1) { uint32_t packet_type; - ws.request_size = socket_recv4(g_socket_in, (char *)ws.inbuf, LIVESYNC_INCOMING_BUFFSIZE, 12 + (char *)in_ip, &in_port); + ws.request_size = socket_recv(g_socket_in, ws.inbuf, LIVESYNC_INCOMING_BUFFSIZE, in_ip, &in_port); /* Expect at least tracker id and packet type */ if (ws.request_size <= (ssize_t)(sizeof(g_tracker_id) + sizeof(uint32_t))) -- cgit v1.3