From ad541c67761b8aa6da1566802c347cac4018d0c2 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Mon, 2 Nov 2026 20:50:24 +0100 Subject: Move the build sources into src/ --- src/ot_livesync.h | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/ot_livesync.h (limited to 'src/ot_livesync.h') diff --git a/src/ot_livesync.h b/src/ot_livesync.h new file mode 100644 index 0000000..4bd3af0 --- /dev/null +++ b/src/ot_livesync.h @@ -0,0 +1,75 @@ +/* This software was written by Dirk Engling + It is considered beerware. Prost. Skol. Cheers or whatever. */ + +#ifndef OT_LIVESYNC_H__ +#define OT_LIVESYNC_H__ + +#include "trackerlogic.h" + +/* + Syncing is done as udp packets in the multicast domain 224.0.42.5 port 9696 + + Each tracker should join the multicast group and send its live sync packets + to that group, using a ttl of 1 + + Format of all sync packets is straight forward, packet type determines + which kind of packet this is: + + 0x0000 0x04 id of tracker instance + 0x0004 0x04 packet type + + ######## + ######## PEER SYNC PROTOCOL ######## + ######## + + Each tracker instance accumulates announce requests until its buffer is + full or a timeout is reached. Then it broadcasts its live sync packer: + + packet type SYNC_LIVE4 + [ 0x0008 0x14 info_hash + 0x001c 0x04 peer's ipv4 address + 0x0020 0x02 peer's port + 0x0024 0x02 peer flags v1 ( SEEDING = 0x80, COMPLETE = 0x40, STOPPED = 0x20 ) + ]* + + packet type SYNC_LIVE6 + [ 0x0008 0x14 info_hash + 0x001c 0x10 peer's ipv6 address + 0x002c 0x02 peer's port + 0x002e 0x02 peer flags v1 ( SEEDING = 0x80, COMPLETE = 0x40, STOPPED = 0x20 ) + ]* +*/ + +#ifdef WANT_SYNC_LIVE + +#define LIVESYNC_PORT 9696 + +void livesync_init(void); +void livesync_deinit(void); + +/* Join multicast group for listening and create sending socket */ +void livesync_bind_mcast(ot_ip6 ip, uint16_t port); + +/* Inform live sync about whats going on. */ +void livesync_tell(struct ot_workstruct *ws); + +/* Tickle the live sync module from time to time, so no events get + stuck when there's not enough traffic to fill udp packets fast + enough */ +void livesync_ticker(void); + +/* Handle an incoming live sync packet */ +void handle_livesync(const int64_t sock); + +#else + +/* If no syncing is required, save calling code from #ifdef + constructions */ +#define livesync_deinit() +#define livesync_init() +#define livesync_ticker() +#define handle_livesync(a) + +#endif + +#endif -- cgit v1.3