mirror of
				git://erdgeist.org/opentracker
				synced 2025-11-04 03:43:23 +08:00 
			
		
		
		
	Order peers by whether they seed. This way clients can chose if they prefer leechers (at the beginning) or leechers (at the end of the list).
This commit is contained in:
		
							parent
							
								
									d729c88d88
								
							
						
					
					
						commit
						bb9650f55e
					
				@ -184,7 +184,8 @@ size_t add_peer_to_torrent_and_return_peers( ot_hash hash, ot_peer *peer, PROTO_
 | 
				
			|||||||
static size_t return_peers_all( ot_peerlist *peer_list, char *reply ) {
 | 
					static size_t return_peers_all( ot_peerlist *peer_list, char *reply ) {
 | 
				
			||||||
  unsigned int bucket, num_buckets = 1;
 | 
					  unsigned int bucket, num_buckets = 1;
 | 
				
			||||||
  ot_vector  * bucket_list = &peer_list->peers;
 | 
					  ot_vector  * bucket_list = &peer_list->peers;
 | 
				
			||||||
  char      * r = reply;
 | 
					  size_t       result = OT_PEER_COMPARE_SIZE * peer_list->peer_count;
 | 
				
			||||||
 | 
					  char       * r_end = reply + result;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if( OT_PEERLIST_HASBUCKETS(peer_list) ) {
 | 
					  if( OT_PEERLIST_HASBUCKETS(peer_list) ) {
 | 
				
			||||||
    num_buckets = bucket_list->size;
 | 
					    num_buckets = bucket_list->size;
 | 
				
			||||||
@ -195,12 +196,16 @@ static size_t return_peers_all( ot_peerlist *peer_list, char *reply ) {
 | 
				
			|||||||
    ot_peer * peers = (ot_peer*)bucket_list[bucket].data;
 | 
					    ot_peer * peers = (ot_peer*)bucket_list[bucket].data;
 | 
				
			||||||
    size_t    peer_count = bucket_list[bucket].size;
 | 
					    size_t    peer_count = bucket_list[bucket].size;
 | 
				
			||||||
    while( peer_count-- ) {
 | 
					    while( peer_count-- ) {
 | 
				
			||||||
      memcpy(r,peers++,OT_PEER_COMPARE_SIZE);
 | 
					      if( OT_PEERFLAG(peers) & PEER_FLAG_SEEDING ) {
 | 
				
			||||||
      r+=OT_PEER_COMPARE_SIZE;
 | 
					        r_end-=OT_PEER_COMPARE_SIZE;
 | 
				
			||||||
 | 
					        memcpy(r_end,peers++,OT_PEER_COMPARE_SIZE);      
 | 
				
			||||||
 | 
					      } else {
 | 
				
			||||||
 | 
					        memcpy(reply,peers++,OT_PEER_COMPARE_SIZE);
 | 
				
			||||||
 | 
					        reply+=OT_PEER_COMPARE_SIZE;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  return r - reply;
 | 
					  return result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static size_t return_peers_selection( ot_peerlist *peer_list, size_t amount, char *reply ) {
 | 
					static size_t return_peers_selection( ot_peerlist *peer_list, size_t amount, char *reply ) {
 | 
				
			||||||
@ -209,7 +214,8 @@ static size_t return_peers_selection( ot_peerlist *peer_list, size_t amount, cha
 | 
				
			|||||||
  unsigned int shifted_pc = peer_list->peer_count;
 | 
					  unsigned int shifted_pc = peer_list->peer_count;
 | 
				
			||||||
  unsigned int shifted_step = 0;
 | 
					  unsigned int shifted_step = 0;
 | 
				
			||||||
  unsigned int shift = 0;
 | 
					  unsigned int shift = 0;
 | 
				
			||||||
  char       * r = reply;
 | 
					  size_t       result = OT_PEER_COMPARE_SIZE * amount;
 | 
				
			||||||
 | 
					  char       * r_end = reply + result;
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  if( OT_PEERLIST_HASBUCKETS(peer_list) ) {
 | 
					  if( OT_PEERLIST_HASBUCKETS(peer_list) ) {
 | 
				
			||||||
    num_buckets = bucket_list->size;
 | 
					    num_buckets = bucket_list->size;
 | 
				
			||||||
@ -239,10 +245,15 @@ static size_t return_peers_selection( ot_peerlist *peer_list, size_t amount, cha
 | 
				
			|||||||
      bucket_index = ( bucket_index + 1 ) % num_buckets;
 | 
					      bucket_index = ( bucket_index + 1 ) % num_buckets;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    peer = ((ot_peer*)bucket_list[bucket_index].data) + bucket_offset;
 | 
					    peer = ((ot_peer*)bucket_list[bucket_index].data) + bucket_offset;
 | 
				
			||||||
    memcpy(r,peer,OT_PEER_COMPARE_SIZE);
 | 
					    if( OT_PEERFLAG(peer) & PEER_FLAG_SEEDING ) {
 | 
				
			||||||
    r+=OT_PEER_COMPARE_SIZE;
 | 
					      r_end-=OT_PEER_COMPARE_SIZE;
 | 
				
			||||||
 | 
					      memcpy(r_end,peer,OT_PEER_COMPARE_SIZE);      
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      memcpy(reply,peer,OT_PEER_COMPARE_SIZE);
 | 
				
			||||||
 | 
					      reply+=OT_PEER_COMPARE_SIZE;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  return r - reply;
 | 
					  }
 | 
				
			||||||
 | 
					  return result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Compiles a list of random peers for a torrent
 | 
					/* Compiles a list of random peers for a torrent
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user