summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <>2010-08-15 16:38:43 +0000
committererdgeist <>2010-08-15 16:38:43 +0000
commit894bd4625f4c2744e64e7f143da1d4336fa74deb (patch)
tree246d8f482bb1f9b0ad8363fb9a118f9115f585b9
parent470a690e0dfe4df04ca836a352871247afcd7c08 (diff)
Stop sending tracker id with every packet
-rw-r--r--proxy.c54
1 files changed, 25 insertions, 29 deletions
diff --git a/proxy.c b/proxy.c
index 3058bb6..82789cb 100644
--- a/proxy.c
+++ b/proxy.c
@@ -620,7 +620,7 @@ static void * streamsync_worker( void * args ) {
620 } 620 }
621 621
622 /* Maximal memory requirement: max 3 blocks, max torrents * 20 + max peers * 7 */ 622 /* Maximal memory requirement: max 3 blocks, max torrents * 20 + max peers * 7 */
623 mem = 3 * ( 4 + 1 + 1 + 2 ) + ( count_one + count_two ) * ( 19 + 1 ) + count_def * ( 19 + 8 ) + 623 mem = 3 * ( 1 + 1 + 2 ) + ( count_one + count_two ) * ( 19 + 1 ) + count_def * ( 19 + 8 ) +
624 ( count_one + 2 * count_two + count_peers ) * 7; 624 ( count_one + 2 * count_two + count_peers ) * 7;
625 625
626 fprintf( stderr, "Mem: %zd\n", mem ); 626 fprintf( stderr, "Mem: %zd\n", mem );
@@ -628,37 +628,34 @@ static void * streamsync_worker( void * args ) {
628 ptr = ptr_a = ptr_b = ptr_c = malloc( mem ); 628 ptr = ptr_a = ptr_b = ptr_c = malloc( mem );
629 if( !ptr ) goto unlock_continue; 629 if( !ptr ) goto unlock_continue;
630 630
631 if( count_one > 8 || !count_def ) { 631 if( count_one > 4 || !count_def ) {
632 mem_a = 4 + 1 + 1 + 2 + count_one * ( 19 + 7 ); 632 mem_a = 1 + 1 + 2 + count_one * ( 19 + 7 );
633 ptr_b += mem_a; ptr_c += mem_a; 633 ptr_b += mem_a; ptr_c += mem_a;
634 memcpy( ptr_a, &g_tracker_id, sizeof(g_tracker_id)); /* Offset 0: the tracker ID */ 634 ptr_a[0] = 1; /* Offset 0: packet type 1 */
635 ptr_a[4] = 1; /* Offset 4: packet type 1 */ 635 ptr_a[1] = (bucket << 8) >> OT_BUCKET_COUNT_BITS; /* Offset 1: the shared prefix */
636 ptr_a[5] = (bucket << 8) >> OT_BUCKET_COUNT_BITS; /* Offset 5: the shared prefix */ 636 ptr_a[2] = count_one >> 8;
637 ptr_a[6] = count_one >> 8; 637 ptr_a[3] = count_one & 255;
638 ptr_a[7] = count_one & 255; 638 ptr_a += 4;
639 ptr_a += 8;
640 } else 639 } else
641 count_def += count_one; 640 count_def += count_one;
642 641
643 if( count_two > 8 || !count_def ) { 642 if( count_two > 4 || !count_def ) {
644 mem_b = 4 + 1 + 1 + 2 + count_two * ( 19 + 14 ); 643 mem_b = 1 + 1 + 2 + count_two * ( 19 + 14 );
645 ptr_c += mem_b; 644 ptr_c += mem_b;
646 memcpy( ptr_b, &g_tracker_id, sizeof(g_tracker_id)); /* Offset 0: the tracker ID */ 645 ptr_b[0] = 2; /* Offset 0: packet type 2 */
647 ptr_b[4] = 2; /* Offset 4: packet type 2 */ 646 ptr_b[1] = (bucket << 8) >> OT_BUCKET_COUNT_BITS; /* Offset 1: the shared prefix */
648 ptr_b[5] = (bucket << 8) >> OT_BUCKET_COUNT_BITS; /* Offset 5: the shared prefix */ 647 ptr_b[2] = count_two >> 8;
649 ptr_b[6] = count_two >> 8; 648 ptr_b[3] = count_two & 255;
650 ptr_b[7] = count_two & 255; 649 ptr_b += 4;
651 ptr_b += 8;
652 } else 650 } else
653 count_def += count_two; 651 count_def += count_two;
654 652
655 if( count_def ) { 653 if( count_def ) {
656 memcpy( ptr_c, &g_tracker_id, sizeof(g_tracker_id)); /* Offset 0: the tracker ID */ 654 ptr_c[0] = 0; /* Offset 0: packet type 0 */
657 ptr_c[4] = 0; /* Offset 4: packet type 0 */ 655 ptr_c[1] = (bucket << 8) >> OT_BUCKET_COUNT_BITS; /* Offset 1: the shared prefix */
658 ptr_c[5] = (bucket << 8) >> OT_BUCKET_COUNT_BITS; /* Offset 5: the shared prefix */ 656 ptr_c[2] = count_def >> 8;
659 ptr_c[6] = count_def >> 8; 657 ptr_c[3] = count_def & 255;
660 ptr_c[7] = count_def & 255; 658 ptr_c += 4;
661 ptr_c += 8;
662 } 659 }
663 660
664 /* For each torrent in this bucket.. */ 661 /* For each torrent in this bucket.. */
@@ -780,12 +777,11 @@ static void process_indata( proxy_peer * peer ) {
780 /* If we're not inside of a packet, make a new one */ 777 /* If we're not inside of a packet, make a new one */
781 if( !peer->packet_tcount ) { 778 if( !peer->packet_tcount ) {
782 /* Ensure the header is complete or postpone processing */ 779 /* Ensure the header is complete or postpone processing */
783 if( data + 8 > dataend ) break; 780 if( data + 4 > dataend ) break;
784 memcpy( &peer->packet_tid, data, sizeof(peer->packet_tid) ); 781 peer->packet_type = data[0];
785 peer->packet_type = data[4]; 782 peer->packet_tprefix = data[1];
786 peer->packet_tprefix = data[5]; 783 peer->packet_tcount = data[2] * 256 + data[3];
787 peer->packet_tcount = data[6] * 256 + data[7]; 784 data += 4;
788 data += 8;
789printf( "type: %hhu, prefix: %02X, torrentcount: %zd\n", peer->packet_type, peer->packet_tprefix, peer->packet_tcount ); 785printf( "type: %hhu, prefix: %02X, torrentcount: %zd\n", peer->packet_type, peer->packet_tprefix, peer->packet_tcount );
790 } 786 }
791 787