diff options
Diffstat (limited to 'src/ot_livesync.h')
| -rw-r--r-- | src/ot_livesync.h | 75 |
1 files changed, 75 insertions, 0 deletions
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 @@ | |||
| 1 | /* This software was written by Dirk Engling <erdgeist@erdgeist.org> | ||
| 2 | It is considered beerware. Prost. Skol. Cheers or whatever. */ | ||
| 3 | |||
| 4 | #ifndef OT_LIVESYNC_H__ | ||
| 5 | #define OT_LIVESYNC_H__ | ||
| 6 | |||
| 7 | #include "trackerlogic.h" | ||
| 8 | |||
| 9 | /* | ||
| 10 | Syncing is done as udp packets in the multicast domain 224.0.42.5 port 9696 | ||
| 11 | |||
| 12 | Each tracker should join the multicast group and send its live sync packets | ||
| 13 | to that group, using a ttl of 1 | ||
| 14 | |||
| 15 | Format of all sync packets is straight forward, packet type determines | ||
| 16 | which kind of packet this is: | ||
| 17 | |||
| 18 | 0x0000 0x04 id of tracker instance | ||
| 19 | 0x0004 0x04 packet type | ||
| 20 | |||
| 21 | ######## | ||
| 22 | ######## PEER SYNC PROTOCOL ######## | ||
| 23 | ######## | ||
| 24 | |||
| 25 | Each tracker instance accumulates announce requests until its buffer is | ||
| 26 | full or a timeout is reached. Then it broadcasts its live sync packer: | ||
| 27 | |||
| 28 | packet type SYNC_LIVE4 | ||
| 29 | [ 0x0008 0x14 info_hash | ||
| 30 | 0x001c 0x04 peer's ipv4 address | ||
| 31 | 0x0020 0x02 peer's port | ||
| 32 | 0x0024 0x02 peer flags v1 ( SEEDING = 0x80, COMPLETE = 0x40, STOPPED = 0x20 ) | ||
| 33 | ]* | ||
| 34 | |||
| 35 | packet type SYNC_LIVE6 | ||
| 36 | [ 0x0008 0x14 info_hash | ||
| 37 | 0x001c 0x10 peer's ipv6 address | ||
| 38 | 0x002c 0x02 peer's port | ||
| 39 | 0x002e 0x02 peer flags v1 ( SEEDING = 0x80, COMPLETE = 0x40, STOPPED = 0x20 ) | ||
| 40 | ]* | ||
| 41 | */ | ||
| 42 | |||
| 43 | #ifdef WANT_SYNC_LIVE | ||
| 44 | |||
| 45 | #define LIVESYNC_PORT 9696 | ||
| 46 | |||
| 47 | void livesync_init(void); | ||
| 48 | void livesync_deinit(void); | ||
| 49 | |||
| 50 | /* Join multicast group for listening and create sending socket */ | ||
| 51 | void livesync_bind_mcast(ot_ip6 ip, uint16_t port); | ||
| 52 | |||
| 53 | /* Inform live sync about whats going on. */ | ||
| 54 | void livesync_tell(struct ot_workstruct *ws); | ||
| 55 | |||
| 56 | /* Tickle the live sync module from time to time, so no events get | ||
| 57 | stuck when there's not enough traffic to fill udp packets fast | ||
| 58 | enough */ | ||
| 59 | void livesync_ticker(void); | ||
| 60 | |||
| 61 | /* Handle an incoming live sync packet */ | ||
| 62 | void handle_livesync(const int64_t sock); | ||
| 63 | |||
| 64 | #else | ||
| 65 | |||
| 66 | /* If no syncing is required, save calling code from #ifdef | ||
| 67 | constructions */ | ||
| 68 | #define livesync_deinit() | ||
| 69 | #define livesync_init() | ||
| 70 | #define livesync_ticker() | ||
| 71 | #define handle_livesync(a) | ||
| 72 | |||
| 73 | #endif | ||
| 74 | |||
| 75 | #endif | ||
