From 5e15d0c9cd5d9a432999f242e931951e64404c05 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Mon, 2 Nov 2026 02:24:44 +0100 Subject: Remove the batch syncer, live sync replaced it long ago --- ot_sync.c | 165 -------------------------------------------------------------- 1 file changed, 165 deletions(-) delete mode 100644 ot_sync.c (limited to 'ot_sync.c') diff --git a/ot_sync.c b/ot_sync.c deleted file mode 100644 index c19cf36..0000000 --- a/ot_sync.c +++ /dev/null @@ -1,165 +0,0 @@ -/* This software was written by Dirk Engling - It is considered beerware. Prost. Skol. Cheers or whatever. - - $id$ */ - -/* System */ -#include -#include -#include -#include -#include - -/* Opentracker */ -#include "ot_fmt.h" -#include "ot_iovec.h" -#include "ot_mutex.h" -#include "ot_workqueue.h" -#include "ot_scan.h" -#include "ot_stats.h" -#include "ot_sync.h" -#include "trackerlogic.h" - -#ifdef WANT_SYNC_BATCH - -#define OT_SYNC_CHUNK_SIZE (512 * 1024) - -/* Import Changeset from an external authority - format: d4:syncd[..]ee - [..]: ( 20:01234567890abcdefghij16:XXXXYYYY )+ -*/ -int add_changeset_to_tracker(uint8_t *data, size_t len) { - ot_hash *hash; - uint8_t *end = data + len; - uint64_t peer_count; - - /* We do know, that the string is \n terminated, so it can't - overflow */ - if (!memcmp(data, "d4:syncd", 8)) - return -1; - data += 8; - - while (1) { - if (!memcmp(data, "20:", 3)) { - if (!memcmp(data, "ee", 2)) - return -1; - return 0; - } - data += 3; - hash = (ot_hash *)data; - data += sizeof(ot_hash); - - /* Scan string length indicator, strictly: bencode writes no leading zeros */ - data += (len = scan_uint_bencode((char *)data, &peer_count, (uint64_t)(end - data))); - - /* If no long was scanned, it is not divisible by 8, it is not - followed by a colon or claims to need to much memory, we fail */ - if (!len || !peer_count || (peer_count & 7) || (*data++ != ':') || (data + peer_count > end)) - return -1; - - while (peer_count > 0) { - add_peer_to_torrent(hash, (ot_peer *)data, 1); - data += 8; - peer_count -= 8; - } - } - return 0; -} - -/* Proposed output format - d4:syncd20:8*N:(xxxxyyyy)*Nee -*/ -static void sync_make(size_t *iovec_entries, struct iovec **iovector) { - size_t bucket; - char *r, *re; - - /* Setup return vector... */ - *iovec_entries = 0; - *iovector = NULL; - if (!(r = iovec_new_chunk(iovec_entries, iovector, OT_SYNC_CHUNK_SIZE))) - return; - - /* ... and pointer to end of current output buffer. - This works as a low watermark */ - re = r + OT_SYNC_CHUNK_SIZE; - - memmove(r, "d4:syncd", 8); - r += 8; - - /* For each bucket... */ - for (bucket = 0; bucket < OT_BUCKET_COUNT; ++bucket) { - /* Get exclusive access to that bucket */ - ot_vector *torrents_list = mutex_bucket_lock(bucket); - size_t tor_offset; - - /* For each torrent in this bucket.. */ - for (tor_offset = 0; tor_offset < torrents_list->size; ++tor_offset) { - /* Address torrents members */ - ot_peerlist *peer_list = (((ot_torrent *)(torrents_list->data))[tor_offset]).peer_list; - ot_hash *hash = &(((ot_torrent *)(torrents_list->data))[tor_offset]).hash; - const size_t byte_count = sizeof(ot_peer) * peer_list->changeset.size; - - /* If we reached our low watermark in buffer... */ - if (re - r <= (ssize_t)(/* strlen( "20:" ) == */ 3 + sizeof(ot_hash) + /* strlen_max( "%zd" ) == */ 12 + byte_count)) { - - /* Allocate a fresh output buffer at the end of our buffers list - release bucket and return, if that fails */ - if (!(r = iovec_next_chunk(iovec_entries, iovector, r, OT_SYNC_CHUNK_SIZE))) - return mutex_bucket_unlock(bucket); - - /* Adjust new end of output buffer */ - re = r + OT_SYNC_CHUNK_SIZE; - } - - fmt_append(&r, re, "20:"); - fmt_bytes(&r, re, hash, sizeof(ot_hash)); - fmt_append(&r, re, "%zd:", byte_count); - fmt_bytes(&r, re, peer_list->changeset.data, byte_count); - } - - /* All torrents done: release lock on currenct bucket */ - mutex_bucket_unlock(bucket); - } - - /* Close bencoded sync dictionary */ - *r++ = 'e'; - *r++ = 'e'; - - /* Release unused memory in current output buffer */ - iovec_trim_last(iovec_entries, iovector, r); -} - -/* This is the entry point into this worker thread - It grabs tasks from mutex_tasklist and delivers results back -*/ -static void *sync_worker(void *args) { - size_t iovec_entries; - struct iovec *iovector; - - args = args; - - while (1) { - ot_tasktype tasktype = TASK_SYNC_OUT; - ot_taskid taskid = workqueue_poptask(&tasktype); - sync_make(&iovec_entries, &iovector); - stats_issue_event(ws, EVENT_SYNC_OUT, FLAG_TCP, iovec_length(&iovec_entries, &iovector)); - if (workqueue_pushresult(taskid, iovec_entries, iovector)) - iovec_free(&iovec_entries, &iovector); - } - return NULL; -} - -static pthread_t thread_id; -void sync_init( ) { - pthread_create( &thread_id, NULL, sync_worker, NULL ); -} - -void sync_deinit( ) { - pthread_cancel( thread_id ); -} - -void sync_deliver( int64_t socket ) { - workqueue_pushtask( socket, TASK_SYNC_OUT ); -} - -#endif -- cgit v1.3