Renamed OT_FLAG to OT_PEERFLAG to make code easier to read

Introduced READ16/32 and WRITE16/32 makros to abstract loading/storing from unaligned addresses away on cpu's that can actually load/store everywhere
Removed all unnecessary memmoves, especially where it only moved 6 bytes in inner loop. I replaced them with WRITE16/32(READ16/32()) makros
dynamic-accesslists
erdgeist 16 years ago
parent a4ed31d517
commit 08c7162783

@ -165,7 +165,7 @@ static void handle_accept( const int64 serversocket ) {
io_wantread( i ); io_wantread( i );
memset( h, 0, sizeof( struct http_data ) ); memset( h, 0, sizeof( struct http_data ) );
memmove( h->ip, ip, sizeof( ip ) ); WRITE32(h->ip,0,READ32(ip,0));
stats_issue_event( EVENT_ACCEPT, FLAG_TCP, ntohl(*(uint32_t*)ip)); stats_issue_event( EVENT_ACCEPT, FLAG_TCP, ntohl(*(uint32_t*)ip));

@ -105,7 +105,7 @@ static unsigned int g_adminip_count = 0;
int accesslist_blessip( char *ip, ot_permissions permissions ) { int accesslist_blessip( char *ip, ot_permissions permissions ) {
if( g_adminip_count >= OT_ADMINIP_MAX ) if( g_adminip_count >= OT_ADMINIP_MAX )
return -1; return -1;
memmove( g_adminip_addresses + g_adminip_count, ip, 4 ); WRITE32(g_adminip_addresses + g_adminip_count,0,READ32(ip,0));
g_adminip_permissions[ g_adminip_count++ ] = permissions; g_adminip_permissions[ g_adminip_count++ ] = permissions;
#ifdef _DEBUG #ifdef _DEBUG
uint8_t *_ip = (uint8_t*)ip; uint8_t *_ip = (uint8_t*)ip;

@ -35,7 +35,7 @@ static ssize_t clean_single_bucket( ot_peer *peers, size_t peer_count, time_t ti
OT_PEERTIME( peers ) = timediff; OT_PEERTIME( peers ) = timediff;
*(uint64_t*)(insert_point++) = *(uint64_t*)(peers++); *(uint64_t*)(insert_point++) = *(uint64_t*)(peers++);
} else } else
if( OT_FLAG( peers++ ) & PEER_FLAG_SEEDING ) if( OT_PEERFLAG( peers++ ) & PEER_FLAG_SEEDING )
(*removed_seeders)++; (*removed_seeders)++;
return peers - insert_point; return peers - insert_point;

@ -113,7 +113,7 @@ static int fullscrape_increase( int *iovec_entries, struct iovec **iovector,
} }
static void fullscrape_make( int *iovec_entries, struct iovec **iovector, ot_tasktype mode ) { static void fullscrape_make( int *iovec_entries, struct iovec **iovector, ot_tasktype mode ) {
int bucket; int bucket,i;
char *r, *re; char *r, *re;
#ifdef WANT_COMPRESSION_GZIP #ifdef WANT_COMPRESSION_GZIP
char compress_buffer[OT_SCRAPE_MAXENTRYLEN]; char compress_buffer[OT_SCRAPE_MAXENTRYLEN];
@ -163,7 +163,7 @@ static void fullscrape_make( int *iovec_entries, struct iovec **iovector, ot_tas
/* push hash as bencoded string */ /* push hash as bencoded string */
*r++='2'; *r++='0'; *r++=':'; *r++='2'; *r++='0'; *r++=':';
memmove( r, hash, 20 ); r+=20; for(i=0;i<20;i+=4) WRITE32(r+=4,0,READ32(hash,i));
/* push rest of the scrape string */ /* push rest of the scrape string */
r += sprintf( r, "d8:completei%zde10:downloadedi%zde10:incompletei%zdee", peer_list->seed_count, peer_list->down_count, peer_list->peer_count-peer_list->seed_count ); r += sprintf( r, "d8:completei%zde10:downloadedi%zde10:incompletei%zdee", peer_list->seed_count, peer_list->down_count, peer_list->peer_count-peer_list->seed_count );
@ -174,7 +174,7 @@ static void fullscrape_make( int *iovec_entries, struct iovec **iovector, ot_tas
r += sprintf( r, ":%zd:%zd\n", peer_list->seed_count, peer_list->peer_count-peer_list->seed_count ); r += sprintf( r, ":%zd:%zd\n", peer_list->seed_count, peer_list->peer_count-peer_list->seed_count );
break; break;
case TASK_FULLSCRAPE_TPB_BINARY: case TASK_FULLSCRAPE_TPB_BINARY:
memmove( r, hash, 20 ); r+=20; for(i=0;i<20;i+=4) WRITE32(r+=4,0,READ32(hash,i));
*(uint32_t*)r++ = htonl( (uint32_t)peer_list->seed_count ); *(uint32_t*)r++ = htonl( (uint32_t)peer_list->seed_count );
*(uint32_t*)r++ = htonl( (uint32_t)( peer_list->peer_count-peer_list->seed_count) ); *(uint32_t*)r++ = htonl( (uint32_t)( peer_list->peer_count-peer_list->seed_count) );
break; break;

@ -399,7 +399,7 @@ static ssize_t http_handle_announce( const int64 client_socket, char *data ) {
OT_SETIP( &peer, ((struct http_data*)io_getcookie( client_socket ) )->ip ); OT_SETIP( &peer, ((struct http_data*)io_getcookie( client_socket ) )->ip );
OT_SETPORT( &peer, &port ); OT_SETPORT( &peer, &port );
OT_FLAG( &peer ) = 0; OT_PEERFLAG( &peer ) = 0;
numwant = 50; numwant = 50;
scanon = 1; scanon = 1;
@ -427,7 +427,7 @@ static ssize_t http_handle_announce( const int64 client_socket, char *data ) {
} else if( !byte_diff( data, 4, "left" ) ) { } else if( !byte_diff( data, 4, "left" ) ) {
if( ( len = scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ) ) <= 0 ) HTTPERROR_400_PARAM; if( ( len = scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ) ) <= 0 ) HTTPERROR_400_PARAM;
if( scan_fixed_int( data, len, &tmp ) ) tmp = 0; if( scan_fixed_int( data, len, &tmp ) ) tmp = 0;
if( !tmp ) OT_FLAG( &peer ) |= PEER_FLAG_SEEDING; if( !tmp ) OT_PEERFLAG( &peer ) |= PEER_FLAG_SEEDING;
} else } else
scan_urlencoded_skipvalue( &c ); scan_urlencoded_skipvalue( &c );
break; break;
@ -438,10 +438,10 @@ static ssize_t http_handle_announce( const int64 client_socket, char *data ) {
case -1: case -1:
HTTPERROR_400_PARAM; HTTPERROR_400_PARAM;
case 7: case 7:
if( !byte_diff( data, 7, "stopped" ) ) OT_FLAG( &peer ) |= PEER_FLAG_STOPPED; if( !byte_diff( data, 7, "stopped" ) ) OT_PEERFLAG( &peer ) |= PEER_FLAG_STOPPED;
break; break;
case 9: case 9:
if( !byte_diff( data, 9, "completed" ) ) OT_FLAG( &peer ) |= PEER_FLAG_COMPLETED; if( !byte_diff( data, 9, "completed" ) ) OT_PEERFLAG( &peer ) |= PEER_FLAG_COMPLETED;
default: /* Fall through intended */ default: /* Fall through intended */
break; break;
} }
@ -481,7 +481,7 @@ static ssize_t http_handle_announce( const int64 client_socket, char *data ) {
if( !hash ) if( !hash )
return sprintf( static_outbuf + SUCCESS_HTTP_HEADER_LENGTH, "d14:failure reason80:Your client forgot to send your torrent's info_hash. Please upgrade your client.e" ); return sprintf( static_outbuf + SUCCESS_HTTP_HEADER_LENGTH, "d14:failure reason80:Your client forgot to send your torrent's info_hash. Please upgrade your client.e" );
if( OT_FLAG( &peer ) & PEER_FLAG_STOPPED ) if( OT_PEERFLAG( &peer ) & PEER_FLAG_STOPPED )
len = remove_peer_from_torrent( hash, &peer, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, FLAG_TCP ); len = remove_peer_from_torrent( hash, &peer, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, FLAG_TCP );
else { else {
torrent = add_peer_to_torrent( hash, &peer WANT_SYNC_PARAM( 0 ) ); torrent = add_peer_to_torrent( hash, &peer WANT_SYNC_PARAM( 0 ) );
@ -498,7 +498,7 @@ ssize_t http_handle_request( const int64 client_socket, char *data, size_t recv_
#ifdef _DEBUG_HTTPERROR #ifdef _DEBUG_HTTPERROR
if( recv_length >= sizeof( debug_request ) ) if( recv_length >= sizeof( debug_request ) )
recv_length = sizeof( debug_request) - 1; recv_length = sizeof( debug_request) - 1;
memcpy( debug_request, recv_header, recv_length ); memmove( debug_request, recv_header, recv_length );
debug_request[ recv_length ] = 0; debug_request[ recv_length ] = 0;
#endif #endif

@ -94,10 +94,11 @@ static void livesync_issuepacket( ) {
/* Inform live sync about whats going on. */ /* Inform live sync about whats going on. */
void livesync_tell( ot_hash * const info_hash, const ot_peer * const peer ) { void livesync_tell( ot_hash * const info_hash, const ot_peer * const peer ) {
memmove( livesync_outbuffer_pos , info_hash, sizeof(ot_hash)); int i;
memmove( livesync_outbuffer_pos + sizeof(ot_hash), peer, sizeof(ot_peer)); for(i=0;i<20;i+=4) WRITE32(livesync_outbuffer_pos+=4,0,READ32(info_hash,i));
WRITE32(livesync_outbuffer_pos+=4,0,READ32(peer,0));
WRITE32(livesync_outbuffer_pos+=4,0,READ32(peer,4));
livesync_outbuffer_pos += sizeof(ot_hash) + sizeof(ot_peer);
if( livesync_outbuffer_pos >= livesync_outbuffer_highwater ) if( livesync_outbuffer_pos >= livesync_outbuffer_highwater )
livesync_issuepacket(); livesync_issuepacket();
} }
@ -146,7 +147,7 @@ static void * livesync_worker( void * args ) {
ot_peer *peer = (ot_peer*)(livesync_inbuffer + off + sizeof(ot_hash)); ot_peer *peer = (ot_peer*)(livesync_inbuffer + off + sizeof(ot_hash));
ot_hash *hash = (ot_hash*)(livesync_inbuffer + off); ot_hash *hash = (ot_hash*)(livesync_inbuffer + off);
if( OT_FLAG(peer) & PEER_FLAG_STOPPED ) if( OT_PEERFLAG(peer) & PEER_FLAG_STOPPED )
remove_peer_from_torrent(hash, peer, NULL, FLAG_MCA); remove_peer_from_torrent(hash, peer, NULL, FLAG_MCA);
else else
add_peer_to_torrent( hash, peer WANT_SYNC_PARAM(1)); add_peer_to_torrent( hash, peer WANT_SYNC_PARAM(1));

@ -27,7 +27,7 @@ static void udp_make_connectionid( uint32_t * connid, const char * remoteip ) {
(void)remoteip; (void)remoteip;
/* Use a static secret for now */ /* Use a static secret for now */
memcpy( connid, g_static_connid, 8 ); memmove( connid, g_static_connid, 8 );
} }
static int udp_test_connectionid( const uint32_t * const connid, const char * remoteip ) { static int udp_test_connectionid( const uint32_t * const connid, const char * remoteip ) {
@ -94,21 +94,21 @@ void handle_udp4( int64 serversocket ) {
OT_SETIP( &peer, remoteip ); OT_SETIP( &peer, remoteip );
OT_SETPORT( &peer, &port ); OT_SETPORT( &peer, &port );
OT_FLAG( &peer ) = 0; OT_PEERFLAG( &peer ) = 0;
switch( event ) { switch( event ) {
case 1: OT_FLAG( &peer ) |= PEER_FLAG_COMPLETED; break; case 1: OT_PEERFLAG( &peer ) |= PEER_FLAG_COMPLETED; break;
case 3: OT_FLAG( &peer ) |= PEER_FLAG_STOPPED; break; case 3: OT_PEERFLAG( &peer ) |= PEER_FLAG_STOPPED; break;
default: break; default: break;
} }
if( !left ) if( !left )
OT_FLAG( &peer ) |= PEER_FLAG_SEEDING; OT_PEERFLAG( &peer ) |= PEER_FLAG_SEEDING;
outpacket[0] = htonl( 1 ); /* announce action */ outpacket[0] = htonl( 1 ); /* announce action */
outpacket[1] = inpacket[12/4]; outpacket[1] = inpacket[12/4];
if( OT_FLAG( &peer ) & PEER_FLAG_STOPPED ) /* Peer is gone. */ if( OT_PEERFLAG( &peer ) & PEER_FLAG_STOPPED ) /* Peer is gone. */
r = remove_peer_from_torrent( hash, &peer, static_outbuf, FLAG_UDP ); r = remove_peer_from_torrent( hash, &peer, static_outbuf, FLAG_UDP );
else { else {
torrent = add_peer_to_torrent( hash, &peer WANT_SYNC_PARAM( 0 ) ); torrent = add_peer_to_torrent( hash, &peer WANT_SYNC_PARAM( 0 ) );

@ -16,9 +16,6 @@
#include "uint32.h" #include "uint32.h"
#include "uint16.h" #include "uint16.h"
#define READ16(addr,offs) ((int16_t)uint16_read((offs)+(uint8_t*)(addr)))
#define READ32(addr,offs) ((int32_t)uint32_read((offs)+(uint8_t*)(addr)))
static int vector_compare_peer(const void *peer1, const void *peer2 ) { static int vector_compare_peer(const void *peer1, const void *peer2 ) {
int32_t cmp = READ32(peer1,0) - READ32(peer2,0); int32_t cmp = READ32(peer1,0) - READ32(peer2,0);
if (cmp == 0) cmp = READ16(peer1,4) - READ16(peer2,4); if (cmp == 0) cmp = READ16(peer1,4) - READ16(peer2,4);
@ -166,7 +163,7 @@ int vector_remove_peer( ot_vector *vector, ot_peer *peer ) {
match = binary_search_peer( peer, vector->data, vector->size, &exactmatch ); match = binary_search_peer( peer, vector->data, vector->size, &exactmatch );
if( !exactmatch ) return 0; if( !exactmatch ) return 0;
exactmatch = ( OT_FLAG( match ) & PEER_FLAG_SEEDING ) ? 2 : 1; exactmatch = ( OT_PEERFLAG( match ) & PEER_FLAG_SEEDING ) ? 2 : 1;
memmove( match, match + 1, sizeof(ot_peer) * ( end - match - 1 ) ); memmove( match, match + 1, sizeof(ot_peer) * ( end - match - 1 ) );
vector->size--; vector->size--;

@ -62,7 +62,7 @@ ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer WANT_SYNC_PARAM(
if( !exactmatch ) { if( !exactmatch ) {
/* Create a new torrent entry, then */ /* Create a new torrent entry, then */
memmove( &torrent->hash, hash, sizeof( ot_hash ) ); int i; for(i=0;i<20;i+=4) WRITE32(&torrent->hash,i,READ32(hash,i));
if( !( torrent->peer_list = malloc( sizeof (ot_peerlist) ) ) ) { if( !( torrent->peer_list = malloc( sizeof (ot_peerlist) ) ) ) {
vector_remove_torrent( torrents_list, torrent ); vector_remove_torrent( torrents_list, torrent );
@ -86,8 +86,8 @@ ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer WANT_SYNC_PARAM(
OT_PEERTIME( peer ) = 0; OT_PEERTIME( peer ) = 0;
/* Sanitize flags: Whoever claims to have completed download, must be a seeder */ /* Sanitize flags: Whoever claims to have completed download, must be a seeder */
if( ( OT_FLAG( peer ) & ( PEER_FLAG_COMPLETED | PEER_FLAG_SEEDING ) ) == PEER_FLAG_COMPLETED ) if( ( OT_PEERFLAG( peer ) & ( PEER_FLAG_COMPLETED | PEER_FLAG_SEEDING ) ) == PEER_FLAG_COMPLETED )
OT_FLAG( peer ) ^= PEER_FLAG_COMPLETED; OT_PEERFLAG( peer ) ^= PEER_FLAG_COMPLETED;
/* If we hadn't had a match create peer there */ /* If we hadn't had a match create peer there */
if( !exactmatch ) { if( !exactmatch ) {
@ -96,13 +96,13 @@ ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer WANT_SYNC_PARAM(
if( !from_sync ) if( !from_sync )
livesync_tell( hash, peer ); livesync_tell( hash, peer );
else else
OT_FLAG( peer ) |= PEER_FLAG_FROM_SYNC; OT_PEERFLAG( peer ) |= PEER_FLAG_FROM_SYNC;
#endif #endif
torrent->peer_list->peer_count++; torrent->peer_list->peer_count++;
if( OT_FLAG(peer) & PEER_FLAG_COMPLETED ) if( OT_PEERFLAG(peer) & PEER_FLAG_COMPLETED )
torrent->peer_list->down_count++; torrent->peer_list->down_count++;
if( OT_FLAG(peer) & PEER_FLAG_SEEDING ) if( OT_PEERFLAG(peer) & PEER_FLAG_SEEDING )
torrent->peer_list->seed_count++; torrent->peer_list->seed_count++;
} else { } else {
@ -114,7 +114,7 @@ ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer WANT_SYNC_PARAM(
int i; int i;
for( i=0;i<20;++i)printf("%02X",(*hash)[i]); for( i=0;i<20;++i)printf("%02X",(*hash)[i]);
if( g_this_peerid_data ) g_this_peerid_data[g_this_peerid_len] = 0; if( g_this_peerid_data ) g_this_peerid_data[g_this_peerid_len] = 0;
printf( " %d.%d.%d.%d:%d\t%d %02X %s\n", _ip[0], _ip[1], _ip[2], _ip[3], OT_PEERTIME( peer_dest ), *(uint16_t*)( ((char*)peer_dest)+4 ), OT_FLAG(peer_dest), g_this_peerid_data ? g_this_peerid_data : "-" ); printf( " %d.%d.%d.%d:%d\t%d %02X %s\n", _ip[0], _ip[1], _ip[2], _ip[3], OT_PEERTIME( peer_dest ), *(uint16_t*)( ((char*)peer_dest)+4 ), OT_PEERFLAG(peer_dest), g_this_peerid_data ? g_this_peerid_data : "-" );
} }
#endif #endif
@ -123,19 +123,19 @@ ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer WANT_SYNC_PARAM(
fresh "completed" reports */ fresh "completed" reports */
if( !from_sync ) { if( !from_sync ) {
if( OT_PEERTIME( peer_dest ) > OT_CLIENT_SYNC_RENEW_BOUNDARY || if( OT_PEERTIME( peer_dest ) > OT_CLIENT_SYNC_RENEW_BOUNDARY ||
( !(OT_FLAG(peer_dest) & PEER_FLAG_COMPLETED ) && (OT_FLAG(peer) & PEER_FLAG_COMPLETED ) ) ) ( !(OT_PEERFLAG(peer_dest) & PEER_FLAG_COMPLETED ) && (OT_PEERFLAG(peer) & PEER_FLAG_COMPLETED ) ) )
livesync_tell( hash, peer ); livesync_tell( hash, peer );
} }
#endif #endif
if( (OT_FLAG(peer_dest) & PEER_FLAG_SEEDING ) && !(OT_FLAG(peer) & PEER_FLAG_SEEDING ) ) if( (OT_PEERFLAG(peer_dest) & PEER_FLAG_SEEDING ) && !(OT_PEERFLAG(peer) & PEER_FLAG_SEEDING ) )
torrent->peer_list->seed_count--; torrent->peer_list->seed_count--;
if( !(OT_FLAG(peer_dest) & PEER_FLAG_SEEDING ) && (OT_FLAG(peer) & PEER_FLAG_SEEDING ) ) if( !(OT_PEERFLAG(peer_dest) & PEER_FLAG_SEEDING ) && (OT_PEERFLAG(peer) & PEER_FLAG_SEEDING ) )
torrent->peer_list->seed_count++; torrent->peer_list->seed_count++;
if( !(OT_FLAG(peer_dest) & PEER_FLAG_COMPLETED ) && (OT_FLAG(peer) & PEER_FLAG_COMPLETED ) ) if( !(OT_PEERFLAG(peer_dest) & PEER_FLAG_COMPLETED ) && (OT_PEERFLAG(peer) & PEER_FLAG_COMPLETED ) )
torrent->peer_list->down_count++; torrent->peer_list->down_count++;
if( OT_FLAG(peer_dest) & PEER_FLAG_COMPLETED ) if( OT_PEERFLAG(peer_dest) & PEER_FLAG_COMPLETED )
OT_FLAG( peer ) |= PEER_FLAG_COMPLETED; OT_PEERFLAG( peer ) |= PEER_FLAG_COMPLETED;
} }
*(uint64_t*)(peer_dest) = *(uint64_t*)(peer); *(uint64_t*)(peer_dest) = *(uint64_t*)(peer);
@ -163,8 +163,10 @@ static size_t return_peers_all( ot_peerlist *peer_list, char *reply ) {
for( bucket = 0; bucket<num_buckets; ++bucket ) { for( bucket = 0; bucket<num_buckets; ++bucket ) {
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-- ) {
memmove( r+=6, peers++, 6 ); WRITE32(r+=4,0,READ32(peers,0));
WRITE16(r+=2,0,READ16(peers++,4));
}
} }
return r - reply; return r - reply;
@ -194,6 +196,8 @@ static size_t return_peers_selection( ot_peerlist *peer_list, size_t amount, cha
bucket_offset = random() % peer_list->peer_count; bucket_offset = random() % peer_list->peer_count;
while( amount-- ) { while( amount-- ) {
ot_peer * peer;
/* This is the aliased, non shifted range, next value may fall into */ /* This is the aliased, non shifted range, next value may fall into */
unsigned int diff = ( ( ( amount + 1 ) * shifted_step ) >> shift ) - unsigned int diff = ( ( ( amount + 1 ) * shifted_step ) >> shift ) -
( ( amount * shifted_step ) >> shift ); ( ( amount * shifted_step ) >> shift );
@ -203,9 +207,9 @@ static size_t return_peers_selection( ot_peerlist *peer_list, size_t amount, cha
bucket_offset -= bucket_list[bucket_index].size; bucket_offset -= bucket_list[bucket_index].size;
bucket_index = ( bucket_index + 1 ) % num_buckets; bucket_index = ( bucket_index + 1 ) % num_buckets;
} }
peer = ((ot_peer*)bucket_list[bucket_index].data) + bucket_offset;
memmove( r, ((ot_peer*)bucket_list[bucket_index].data) + bucket_offset, 6 ); WRITE32(r+=4,0,READ32(peer,0));
r += 6; WRITE16(r+=2,0,READ16(peer,4));
} }
return r - reply; return r - reply;
} }
@ -288,9 +292,11 @@ size_t return_tcp_scrape_for_torrent( ot_hash *hash_list, int amount, char *repl
if( clean_single_torrent( torrent ) ) { if( clean_single_torrent( torrent ) ) {
vector_remove_torrent( torrents_list, torrent ); vector_remove_torrent( torrents_list, torrent );
} else { } else {
memmove( r, "20:", 3 ); memmove( r+3, hash, 20 ); int j;
r += sprintf( r+23, "d8:completei%zde10:downloadedi%zde10:incompletei%zdee", *r++='2';*r++='0';*r++=':';
torrent->peer_list->seed_count, torrent->peer_list->down_count, torrent->peer_list->peer_count-torrent->peer_list->seed_count ) + 23; for(j=0;j<20;j+=4) WRITE32(r+=4,0,READ32(hash,i));
r += sprintf( r, "d8:completei%zde10:downloadedi%zde10:incompletei%zdee",
torrent->peer_list->seed_count, torrent->peer_list->down_count, torrent->peer_list->peer_count-torrent->peer_list->seed_count );
} }
} }
mutex_bucket_unlock_by_hash( hash ); mutex_bucket_unlock_by_hash( hash );
@ -310,7 +316,7 @@ size_t remove_peer_from_torrent( ot_hash *hash, ot_peer *peer, char *reply, PROT
#ifdef WANT_SYNC_LIVE #ifdef WANT_SYNC_LIVE
if( proto != FLAG_MCA ) { if( proto != FLAG_MCA ) {
OT_FLAG( peer ) |= PEER_FLAG_STOPPED; OT_PEERFLAG( peer ) |= PEER_FLAG_STOPPED;
livesync_tell( hash, peer ); livesync_tell( hash, peer );
} }
#endif #endif

@ -11,6 +11,15 @@
#include <time.h> #include <time.h>
#include <stdint.h> #include <stdint.h>
/* Libowfat */
#include <uint16.h>
#include <uint32.h>
#define READ16(addr,offs) ((int16_t)uint16_read((offs)+(uint8_t*)(addr)))
#define READ32(addr,offs) ((int32_t)uint32_read((offs)+(uint8_t*)(addr)))
#define WRITE16(addr,offs,val) uint16_pack((offs)+(uint8_t*)(addr),(val))
#define WRITE32(addr,offs,val) uint32_pack((offs)+(uint8_t*)(addr),(val))
typedef uint8_t ot_hash[20]; typedef uint8_t ot_hash[20];
typedef time_t ot_time; typedef time_t ot_time;
@ -55,9 +64,9 @@ static const uint8_t PEER_FLAG_STOPPED = 0x20;
static const uint8_t PEER_FLAG_FROM_SYNC = 0x10; static const uint8_t PEER_FLAG_FROM_SYNC = 0x10;
static const uint8_t PEER_FLAG_LEECHING = 0x00; static const uint8_t PEER_FLAG_LEECHING = 0x00;
#define OT_SETIP( peer, ip ) memmove((peer),(ip),4); #define OT_SETIP(peer,ip) WRITE32((peer),0,READ32((ip),0))
#define OT_SETPORT( peer, port ) memmove(((uint8_t*)peer)+4,(port),2); #define OT_SETPORT(peer,port) WRITE16((peer),4,READ16((port),0))
#define OT_FLAG(peer) (((uint8_t*)(peer))[6]) #define OT_PEERFLAG(peer) (((uint8_t*)(peer))[6])
#define OT_PEERTIME(peer) (((uint8_t*)(peer))[7]) #define OT_PEERTIME(peer) (((uint8_t*)(peer))[7])
#define OT_PEER_COMPARE_SIZE ((size_t)6) #define OT_PEER_COMPARE_SIZE ((size_t)6)

Loading…
Cancel
Save