From 6d97e999f1e7b4476faf749abbb5e925d09208c6 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sat, 24 Oct 2026 00:15:34 +0200 Subject: 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 --- ot_mutex.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'ot_mutex.c') 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 @@ $id$ */ /* System */ +#include #include #include #include #include -#include #include /* Libowfat */ #include "io.h" -#include "uint32.h" /* Opentracker */ #include "ot_iovec.h" @@ -37,7 +36,15 @@ ot_vector *mutex_bucket_lock(int bucket) { return all_torrents + bucket; } -ot_vector *mutex_bucket_lock_by_hash(ot_hash const hash) { return mutex_bucket_lock(uint32_read_big((const char *)hash) >> OT_BUCKET_COUNT_SHIFT); } +/* Torrents are spread over buckets by the first four bytes of their info_hash, + which may sit at any alignment, hence the memcpy */ +static int bucket_from_hash(ot_hash const hash) { + uint32_t bucket; + memcpy(&bucket, hash, sizeof(bucket)); + return ntohl(bucket) >> OT_BUCKET_COUNT_SHIFT; +} + +ot_vector *mutex_bucket_lock_by_hash(ot_hash const hash) { return mutex_bucket_lock(bucket_from_hash(hash)); } void mutex_bucket_unlock(int bucket, int delta_torrentcount) { pthread_mutex_unlock(bucket_mutex + bucket); @@ -45,7 +52,7 @@ void mutex_bucket_unlock(int bucket, int delta_torrentcount) { } void mutex_bucket_unlock_by_hash(ot_hash const hash, int delta_torrentcount) { - mutex_bucket_unlock(uint32_read_big((char *)hash) >> OT_BUCKET_COUNT_SHIFT, delta_torrentcount); + mutex_bucket_unlock(bucket_from_hash(hash), delta_torrentcount); } size_t mutex_get_torrent_count(void) { return g_torrent_count; } -- cgit v1.3