diff options
| author | erdgeist <> | 2010-08-15 01:59:09 +0000 |
|---|---|---|
| committer | erdgeist <> | 2010-08-15 01:59:09 +0000 |
| commit | 3e30fa32aa1369d2580e9dad593561d007adc0b8 (patch) | |
| tree | 151e9cce66cdc11be7241ab23f2b64d6d7ebe81f | |
| parent | 4fe2f355950d0bc810e665a68ded157531c6a367 (diff) | |
Fixed sync loss bug
| -rw-r--r-- | proxy.c | 19 |
1 files changed, 7 insertions, 12 deletions
| @@ -603,17 +603,16 @@ static void * streamsync_worker( void * args ) { | |||
| 603 | /* Address torrents members */ | 603 | /* Address torrents members */ |
| 604 | ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[tor_offset] ).peer_list; | 604 | ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[tor_offset] ).peer_list; |
| 605 | switch( peer_list->peer_count ) { | 605 | switch( peer_list->peer_count ) { |
| 606 | case 2: count_two++; break; | 606 | case 2: count_two++; break; |
| 607 | case 1: count_one++; break; | 607 | case 1: count_one++; break; |
| 608 | case 0: break; | 608 | case 0: break; |
| 609 | default: | 609 | default: count_def++; |
| 610 | count_peers += peer_list->peer_count; | 610 | count_peers += peer_list->peer_count; |
| 611 | count_def += 1 + ( peer_list->peer_count >> 8 ); | ||
| 612 | } | 611 | } |
| 613 | } | 612 | } |
| 614 | 613 | ||
| 615 | /* Maximal memory requirement: max 3 blocks, max torrents * 20 + max peers * 7 */ | 614 | /* Maximal memory requirement: max 3 blocks, max torrents * 20 + max peers * 7 */ |
| 616 | mem = 3 * ( 4 + 1 + 1 + 2 ) + ( count_one + count_two ) * 19 + count_def * ( 19 + 6 ) + | 615 | mem = 3 * ( 4 + 1 + 1 + 2 ) + ( count_one + count_two ) * 19 + count_def * ( 19 + 8 ) + |
| 617 | ( count_one + 2 * count_two + count_peers ) * 7; | 616 | ( count_one + 2 * count_two + count_peers ) * 7; |
| 618 | 617 | ||
| 619 | fprintf( stderr, "Mem: %zd\n", mem ); | 618 | fprintf( stderr, "Mem: %zd\n", mem ); |
| @@ -781,7 +780,6 @@ static void process_indata( proxy_peer * peer ) { | |||
| 781 | printf( "type: %hhu, prefix: %02X, torrentcount: %zd\n", peer->packet_type, peer->packet_tprefix, peer->packet_tcount ); | 780 | printf( "type: %hhu, prefix: %02X, torrentcount: %zd\n", peer->packet_type, peer->packet_tprefix, peer->packet_tcount ); |
| 782 | } | 781 | } |
| 783 | 782 | ||
| 784 | next_torrent: | ||
| 785 | /* Ensure size for a minimal torrent block */ | 783 | /* Ensure size for a minimal torrent block */ |
| 786 | if( data + sizeof(ot_hash) + OT_IP_SIZE + 3 > dataend ) break; | 784 | if( data + sizeof(ot_hash) + OT_IP_SIZE + 3 > dataend ) break; |
| 787 | 785 | ||
| @@ -800,14 +798,11 @@ next_torrent: | |||
| 800 | /* Ensure enough data being read to hold all peers */ | 798 | /* Ensure enough data being read to hold all peers */ |
| 801 | if( data + (OT_IP_SIZE + 3) * peers > dataend ) break; | 799 | if( data + (OT_IP_SIZE + 3) * peers > dataend ) break; |
| 802 | 800 | ||
| 803 | printf( "peers: %zd\n", peers ); | ||
| 804 | |||
| 805 | while( peers-- ) { | 801 | while( peers-- ) { |
| 806 | livesync_proxytell( peer->packet_tprefix, hash, data ); | 802 | livesync_proxytell( peer->packet_tprefix, hash, data ); |
| 807 | data += OT_IP_SIZE + 3; | 803 | data += OT_IP_SIZE + 3; |
| 808 | } | 804 | } |
| 809 | if( --peer->packet_tcount ) | 805 | --peer->packet_tcount; |
| 810 | goto next_torrent; | ||
| 811 | } | 806 | } |
| 812 | 807 | ||
| 813 | consumed = data - peer->indata; | 808 | consumed = data - peer->indata; |
