summaryrefslogtreecommitdiff
path: root/ot_livesync.c
diff options
context:
space:
mode:
authorerdgeist <>2008-11-28 22:21:10 +0000
committererdgeist <>2008-11-28 22:21:10 +0000
commit334c6e4bbb97a4c0656e1b07c3e6a565f68eae2b (patch)
treef84ad28c39b32d0906e32e8ba5e461ecdaed7799 /ot_livesync.c
parentff6c0339c13a6b42149ba91da14dbb824307cea7 (diff)
The BIG refactoring [tm]. Too many changes to count them. If it doesn't suite you, revert to last version.
Diffstat (limited to 'ot_livesync.c')
-rw-r--r--ot_livesync.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/ot_livesync.c b/ot_livesync.c
index 3e27c9a..f6e4e51 100644
--- a/ot_livesync.c
+++ b/ot_livesync.c
@@ -50,7 +50,7 @@ void livesync_init( ) {
50 livesync_outbuffer_pos = livesync_outbuffer_start; 50 livesync_outbuffer_pos = livesync_outbuffer_start;
51 memmove( livesync_outbuffer_pos, &g_tracker_id, sizeof( g_tracker_id ) ); 51 memmove( livesync_outbuffer_pos, &g_tracker_id, sizeof( g_tracker_id ) );
52 livesync_outbuffer_pos += sizeof( g_tracker_id ); 52 livesync_outbuffer_pos += sizeof( g_tracker_id );
53 livesync_lastpacket_time = g_now; 53 livesync_lastpacket_time = g_now_seconds;
54 54
55 pthread_create( &thread_id, NULL, livesync_worker, NULL ); 55 pthread_create( &thread_id, NULL, livesync_worker, NULL );
56} 56}
@@ -88,14 +88,13 @@ static void livesync_issuepacket( ) {
88 socket_send4(g_livesync_socket_out, (char*)livesync_outbuffer_start, livesync_outbuffer_pos - livesync_outbuffer_start, 88 socket_send4(g_livesync_socket_out, (char*)livesync_outbuffer_start, livesync_outbuffer_pos - livesync_outbuffer_start,
89 groupip_1, LIVESYNC_PORT); 89 groupip_1, LIVESYNC_PORT);
90 livesync_outbuffer_pos = livesync_outbuffer_start + sizeof( g_tracker_id ); 90 livesync_outbuffer_pos = livesync_outbuffer_start + sizeof( g_tracker_id );
91 livesync_lastpacket_time = g_now; 91 livesync_lastpacket_time = g_now_seconds;
92} 92}
93 93
94/* Inform live sync about whats going on. */ 94/* Inform live sync about whats going on. */
95void livesync_tell( ot_hash * const info_hash, const ot_peer * const peer, const uint8_t peerflag ) { 95void livesync_tell( ot_hash * const info_hash, const ot_peer * const peer ) {
96 memmove( livesync_outbuffer_pos , info_hash, sizeof(ot_hash)); 96 memmove( livesync_outbuffer_pos , info_hash, sizeof(ot_hash));
97 memmove( livesync_outbuffer_pos + sizeof(ot_hash), peer, sizeof(ot_peer)); 97 memmove( livesync_outbuffer_pos + sizeof(ot_hash), peer, sizeof(ot_peer));
98 OT_FLAG( livesync_outbuffer_pos + sizeof(ot_hash) ) |= peerflag;
99 98
100 livesync_outbuffer_pos += sizeof(ot_hash) + sizeof(ot_peer); 99 livesync_outbuffer_pos += sizeof(ot_hash) + sizeof(ot_peer);
101 if( livesync_outbuffer_pos >= livesync_outbuffer_highwater ) 100 if( livesync_outbuffer_pos >= livesync_outbuffer_highwater )
@@ -106,7 +105,7 @@ void livesync_tell( ot_hash * const info_hash, const ot_peer * const peer, const
106 stuck when there's not enough traffic to fill udp packets fast 105 stuck when there's not enough traffic to fill udp packets fast
107 enough */ 106 enough */
108void livesync_ticker( ) { 107void livesync_ticker( ) {
109 if( ( g_now - livesync_lastpacket_time > LIVESYNC_MAXDELAY) && 108 if( ( g_now_seconds - livesync_lastpacket_time > LIVESYNC_MAXDELAY) &&
110 ( livesync_outbuffer_pos > livesync_outbuffer_start + sizeof( g_tracker_id ) ) ) 109 ( livesync_outbuffer_pos > livesync_outbuffer_start + sizeof( g_tracker_id ) ) )
111 livesync_issuepacket(); 110 livesync_issuepacket();
112} 111}
@@ -126,22 +125,22 @@ static void * livesync_worker( void * args ) {
126 continue; 125 continue;
127 126
128 if( datalen < (ssize_t)(sizeof( g_tracker_id ) + sizeof( ot_hash ) + sizeof( ot_peer ) ) ) { 127 if( datalen < (ssize_t)(sizeof( g_tracker_id ) + sizeof( ot_hash ) + sizeof( ot_peer ) ) ) {
129 // TODO: log invalid sync packet 128 /* TODO: log invalid sync packet */
130 continue; 129 continue;
131 } 130 }
132 131
133 if( !accesslist_isblessed((char*)in_ip, OT_PERMISSION_MAY_LIVESYNC)) { 132 if( !accesslist_isblessed((char*)in_ip, OT_PERMISSION_MAY_LIVESYNC)) {
134 // TODO: log invalid sync packet 133 /* TODO: log invalid sync packet */
135 continue; 134 continue;
136 } 135 }
137 136
138 if( !memcmp( livesync_inbuffer, &g_tracker_id, sizeof( g_tracker_id ) ) ) { 137 if( !memcmp( livesync_inbuffer, &g_tracker_id, sizeof( g_tracker_id ) ) ) {
139 // TODO: log packet coming from ourselves 138 /* TODO: log packet coming from ourselves */
140 continue; 139 continue;
141 } 140 }
142 141
143 // Now basic sanity checks have been done on the live sync packet 142 /* Now basic sanity checks have been done on the live sync packet
144 // We might add more testing and logging. 143 We might add more testing and logging. */
145 while( off + (ssize_t)sizeof( ot_hash ) + (ssize_t)sizeof( ot_peer ) <= datalen ) { 144 while( off + (ssize_t)sizeof( ot_hash ) + (ssize_t)sizeof( ot_peer ) <= datalen ) {
146 ot_peer *peer = (ot_peer*)(livesync_inbuffer + off + sizeof(ot_hash)); 145 ot_peer *peer = (ot_peer*)(livesync_inbuffer + off + sizeof(ot_hash));
147 ot_hash *hash = (ot_hash*)(livesync_inbuffer + off); 146 ot_hash *hash = (ot_hash*)(livesync_inbuffer + off);