diff options
Diffstat (limited to 'src/ot_livesync.h')
| -rw-r--r-- | src/ot_livesync.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/ot_livesync.h b/src/ot_livesync.h new file mode 100644 index 0000000..cf3c64c --- /dev/null +++ b/src/ot_livesync.h | |||
| @@ -0,0 +1,80 @@ | |||
| 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 group 224.0.23.5, on the | ||
| 11 | port livesync.cluster.listen names, 9696 by default | ||
| 12 | |||
| 13 | Each tracker should join the multicast group and send its live sync packets | ||
| 14 | to that group, using a ttl of 1 | ||
| 15 | |||
| 16 | Format of all sync packets is straight forward, packet type determines | ||
| 17 | which kind of packet this is: | ||
| 18 | |||
| 19 | 0x0000 0x04 id of tracker instance | ||
| 20 | 0x0004 0x04 packet type | ||
| 21 | |||
| 22 | ######## | ||
| 23 | ######## PEER SYNC PROTOCOL ######## | ||
| 24 | ######## | ||
| 25 | |||
| 26 | Each tracker instance accumulates announce requests until its buffer is | ||
| 27 | full or a timeout is reached. Then it broadcasts its live sync packer: | ||
| 28 | |||
| 29 | packet type SYNC_LIVE4 | ||
| 30 | [ 0x0008 0x14 info_hash | ||
| 31 | 0x001c 0x04 peer's ipv4 address | ||
| 32 | 0x0020 0x02 peer's port | ||
| 33 | 0x0024 0x02 peer flags v1 ( SEEDING = 0x80, COMPLETE = 0x40, STOPPED = 0x20 ) | ||
| 34 | ]* | ||
| 35 | |||
| 36 | packet type SYNC_LIVE6 | ||
| 37 | [ 0x0008 0x14 info_hash | ||
| 38 | 0x001c 0x10 peer's ipv6 address | ||
| 39 | 0x002c 0x02 peer's port | ||
| 40 | 0x002e 0x02 peer flags v1 ( SEEDING = 0x80, COMPLETE = 0x40, STOPPED = 0x20 ) | ||
| 41 | ]* | ||
| 42 | */ | ||
| 43 | |||
| 44 | #ifdef WANT_SYNC_LIVE | ||
| 45 | |||
| 46 | #define LIVESYNC_PORT 9696 | ||
| 47 | |||
| 48 | void livesync_init(void); | ||
| 49 | void livesync_deinit(void); | ||
| 50 | |||
| 51 | /* The group to join and to send to, (defaults to 224.0.23.5). | ||
| 52 | Returns -1 if group is not a v4 multicast address. */ | ||
| 53 | int livesync_set_group(const ot_ip6 group); | ||
| 54 | |||
| 55 | /* Join multicast group for listening and create sending socket */ | ||
| 56 | void livesync_bind_mcast(ot_ip6 ip, uint16_t port); | ||
| 57 | |||
| 58 | /* Inform live sync about whats going on. */ | ||
| 59 | void livesync_tell(struct ot_workstruct *ws); | ||
| 60 | |||
| 61 | /* Tickle the live sync module from time to time, so no events get | ||
| 62 | stuck when there's not enough traffic to fill udp packets fast | ||
| 63 | enough */ | ||
| 64 | void livesync_ticker(void); | ||
| 65 | |||
| 66 | /* Handle an incoming live sync packet */ | ||
| 67 | void handle_livesync(const int64_t sock); | ||
| 68 | |||
| 69 | #else | ||
| 70 | |||
| 71 | /* If no syncing is required, save calling code from #ifdef | ||
| 72 | constructions */ | ||
| 73 | #define livesync_deinit() | ||
| 74 | #define livesync_init() | ||
| 75 | #define livesync_ticker() | ||
| 76 | #define handle_livesync(a) | ||
| 77 | |||
| 78 | #endif | ||
| 79 | |||
| 80 | #endif | ||
