diff options
author | erdgeist <> | 2008-10-03 21:33:53 +0000 |
---|---|---|
committer | erdgeist <> | 2008-10-03 21:33:53 +0000 |
commit | 00c8a89efe6757ee0cbe43f776f4f7985d988291 (patch) | |
tree | f5f41c12da30dc4127033ae34633e4926183a59b /ot_livesync.h | |
parent | cee13cbebb6cb47b0f4c09106e19e07d0c851d04 (diff) |
Live syncing between multiple tracker instances via udp multicast.
Diffstat (limited to 'ot_livesync.h')
-rw-r--r-- | ot_livesync.h | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/ot_livesync.h b/ot_livesync.h new file mode 100644 index 0000000..4dc6b60 --- /dev/null +++ b/ot_livesync.h | |||
@@ -0,0 +1,85 @@ | |||
1 | /* This software was written by Dirk Engling <erdgeist@erdgeist.org> | ||
2 | It is considered beerware. Prost. Skol. Cheers or whatever. | ||
3 | |||
4 | $id$ */ | ||
5 | |||
6 | #ifndef __OT_LIVESYNC_H__ | ||
7 | #define __OT_LIVESYNC_H__ | ||
8 | |||
9 | #include "io.h" | ||
10 | #include "trackerlogic.h" | ||
11 | |||
12 | /* | ||
13 | Syncing is done as udp packets in the multicast domain 224.23.42.N port 9696 | ||
14 | |||
15 | Each tracker should join the multicast group and send its live sync packets | ||
16 | to that group, using a ttl of 1 | ||
17 | |||
18 | Format of a live sync packet is straight forward and depends on N: | ||
19 | |||
20 | For N == 1: (simple tracker2tracker sync) | ||
21 | 0x0000 0x04 id of tracker instance | ||
22 | [ 0x0004 0x14 info_hash | ||
23 | 0x0018 0x04 peer's ipv4 address | ||
24 | 0x001c 0x02 peer's port | ||
25 | 0x0020 0x02 peer flags v1 ( SEEDING = 0x80, COMPLETE = 0x40, STOPPED = 0x20 ) | ||
26 | ]* | ||
27 | |||
28 | For N == 2: (aggregator syncs) | ||
29 | 0x0000 0x04 id of tracker instance | ||
30 | [ 0x0004 0x14 info_hash | ||
31 | 0x0018 0x01 number of peers | ||
32 | [ 0x0019 0x04 peer's ipv4 address | ||
33 | 0x001a 0x02 peer's port | ||
34 | 0x0021 0x02 peer flags v1 ( SEEDING = 0x80, COMPLETE = 0x40, STOPPED = 0x20 ) | ||
35 | ]+ | ||
36 | ]* | ||
37 | |||
38 | |||
39 | */ | ||
40 | |||
41 | #ifdef WANT_SYNC_LIVE | ||
42 | |||
43 | #define LIVESYNC_PORT 9696 | ||
44 | #define LIVESYNC_MCASTDOMAIN_1 224,23,42,1 | ||
45 | #define LIVESYNC_MCASTDOMAIN_2 224,23,42,2 | ||
46 | extern char groupip_1[4]; | ||
47 | extern char groupip_2[4]; | ||
48 | |||
49 | extern int64 g_livesync_socket; | ||
50 | |||
51 | #define LIVESYNC_BUFFINSIZE (256*256) | ||
52 | #define LIVESYNC_BUFFSIZE 1504 | ||
53 | #define LIVESYNC_BUFFWATER (sizeof(ot_peer)+sizeof(ot_hash)) | ||
54 | |||
55 | #define LIVESYNC_MAXDELAY 15 | ||
56 | |||
57 | void livesync_init(); | ||
58 | void livesync_deinit(); | ||
59 | |||
60 | /* Join multicast group for listening and create sending socket */ | ||
61 | void livesync_bind_mcast( char *ip, uint16_t port ); | ||
62 | |||
63 | /* Inform live sync about whats going on. */ | ||
64 | void livesync_tell( ot_hash * const info_hash, const ot_peer * const peer, const uint8_t peerflag ); | ||
65 | |||
66 | /* Tickle the live sync module from time to time, so no events get | ||
67 | stuck when there's not enough traffic to fill udp packets fast | ||
68 | enough */ | ||
69 | void livesync_ticker( ); | ||
70 | |||
71 | /* Handle an incoming live sync packet */ | ||
72 | void handle_livesync( const int64 serversocket ); | ||
73 | |||
74 | #else | ||
75 | |||
76 | /* If no syncing is required, save calling code from #ifdef | ||
77 | constructions */ | ||
78 | |||
79 | #define livesync_init() | ||
80 | #define livesync_ticker() | ||
81 | #define handle_livesync(a) | ||
82 | |||
83 | #endif | ||
84 | |||
85 | #endif | ||