Browse Source

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
master
Dirk Engling 12 years ago
parent
commit
fa6c870315
10 changed files with 77 additions and 64 deletions
  1. +3
    -3
      opentracker.c
  2. +2
    -2
      ot_accesslist.c
  3. +2
    -2
      ot_clean.c
  4. +4
    -4
      ot_fullscrape.c
  5. +7
    -7
      ot_http.c
  6. +7
    -6
      ot_livesync.c
  7. +7
    -7
      ot_udp.c
  8. +2
    -5
      ot_vector.c
  9. +30
    -24
      trackerlogic.c
  10. +13
    -4
      trackerlogic.h

+ 3
- 3
opentracker.c View File

@@ -2,7 +2,7 @@
It is considered beerware. Prost. Skol. Cheers or whatever.
Some of the stuff below is stolen from Fefes example libowfat httpd.

$Id: opentracker.c,v 1.202 2008/11/28 22:21:09 erdgeist Exp $ */
$Id: opentracker.c,v 1.203 2008/12/06 18:45:59 erdgeist Exp $ */

/* System */
#include <stdlib.h>
@@ -165,7 +165,7 @@ static void handle_accept( const int64 serversocket ) {
io_wantread( i );

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));

@@ -429,4 +429,4 @@ while( scanon ) {
return 0;
}

const char *g_version_opentracker_c = "$Source: /home/cvsroot/opentracker/opentracker.c,v $: $Revision: 1.202 $\n";
const char *g_version_opentracker_c = "$Source: /home/cvsroot/opentracker/opentracker.c,v $: $Revision: 1.203 $\n";

+ 2
- 2
ot_accesslist.c View File

@@ -105,7 +105,7 @@ static unsigned int g_adminip_count = 0;
int accesslist_blessip( char *ip, ot_permissions permissions ) {
if( g_adminip_count >= OT_ADMINIP_MAX )
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;
#ifdef _DEBUG
uint8_t *_ip = (uint8_t*)ip;
@@ -126,4 +126,4 @@ int accesslist_isblessed( char *ip, ot_permissions permissions ) {
return 0;
}

const char *g_version_accesslist_c = "$Source: /home/cvsroot/opentracker/ot_accesslist.c,v $: $Revision: 1.10 $\n";
const char *g_version_accesslist_c = "$Source: /home/cvsroot/opentracker/ot_accesslist.c,v $: $Revision: 1.11 $\n";

+ 2
- 2
ot_clean.c View File

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

return peers - insert_point;
@@ -129,4 +129,4 @@ void clean_deinit( void ) {
pthread_cancel( thread_id );
}

const char *g_version_clean_c = "$Source: /home/cvsroot/opentracker/ot_clean.c,v $: $Revision: 1.13 $\n";
const char *g_version_clean_c = "$Source: /home/cvsroot/opentracker/ot_clean.c,v $: $Revision: 1.14 $\n";

+ 4
- 4
ot_fullscrape.c View File

@@ -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 ) {
int bucket;
int bucket,i;
char *r, *re;
#ifdef WANT_COMPRESSION_GZIP
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 */
*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 */
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 );
break;
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->peer_count-peer_list->seed_count) );
break;
@@ -229,4 +229,4 @@ static void fullscrape_make( int *iovec_entries, struct iovec **iovector, ot_tas
}
#endif

const char *g_version_fullscrape_c = "$Source: /home/cvsroot/opentracker/ot_fullscrape.c,v $: $Revision: 1.24 $\n";
const char *g_version_fullscrape_c = "$Source: /home/cvsroot/opentracker/ot_fullscrape.c,v $: $Revision: 1.25 $\n";

+ 7
- 7
ot_http.c View File

@@ -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_SETPORT( &peer, &port );
OT_FLAG( &peer ) = 0;
OT_PEERFLAG( &peer ) = 0;
numwant = 50;
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" ) ) {
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( !tmp ) OT_FLAG( &peer ) |= PEER_FLAG_SEEDING;
if( !tmp ) OT_PEERFLAG( &peer ) |= PEER_FLAG_SEEDING;
} else
scan_urlencoded_skipvalue( &c );
break;
@@ -438,10 +438,10 @@ static ssize_t http_handle_announce( const int64 client_socket, char *data ) {
case -1:
HTTPERROR_400_PARAM;
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;
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 */
break;
}
@@ -481,7 +481,7 @@ static ssize_t http_handle_announce( const int64 client_socket, char *data ) {
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" );

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 );
else {
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
if( recv_length >= sizeof( debug_request ) )
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;
#endif

@@ -563,4 +563,4 @@ ssize_t http_handle_request( const int64 client_socket, char *data, size_t recv_
return reply_size;
}

const char *g_version_http_c = "$Source: /home/cvsroot/opentracker/ot_http.c,v $: $Revision: 1.22 $\n";
const char *g_version_http_c = "$Source: /home/cvsroot/opentracker/ot_http.c,v $: $Revision: 1.23 $\n";

+ 7
- 6
ot_livesync.c View File

@@ -94,10 +94,11 @@ static void livesync_issuepacket( ) {

/* Inform live sync about whats going on. */
void livesync_tell( ot_hash * const info_hash, const ot_peer * const peer ) {
memmove( livesync_outbuffer_pos , info_hash, sizeof(ot_hash));
memmove( livesync_outbuffer_pos + sizeof(ot_hash), peer, sizeof(ot_peer));

livesync_outbuffer_pos += sizeof(ot_hash) + sizeof(ot_peer);
int i;
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));
if( livesync_outbuffer_pos >= livesync_outbuffer_highwater )
livesync_issuepacket();
}
@@ -146,7 +147,7 @@ static void * livesync_worker( void * args ) {
ot_peer *peer = (ot_peer*)(livesync_inbuffer + off + sizeof(ot_hash));
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);
else
add_peer_to_torrent( hash, peer WANT_SYNC_PARAM(1));
@@ -161,4 +162,4 @@ static void * livesync_worker( void * args ) {
}

#endif
const char *g_version_livesync_c = "$Source: /home/cvsroot/opentracker/ot_livesync.c,v $: $Revision: 1.7 $\n";
const char *g_version_livesync_c = "$Source: /home/cvsroot/opentracker/ot_livesync.c,v $: $Revision: 1.8 $\n";

+ 7
- 7
ot_udp.c View File

@@ -27,7 +27,7 @@ static void udp_make_connectionid( uint32_t * connid, const char * remoteip ) {
(void)remoteip;

/* 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 ) {
@@ -94,21 +94,21 @@ void handle_udp4( int64 serversocket ) {

OT_SETIP( &peer, remoteip );
OT_SETPORT( &peer, &port );
OT_FLAG( &peer ) = 0;
OT_PEERFLAG( &peer ) = 0;

switch( event ) {
case 1: OT_FLAG( &peer ) |= PEER_FLAG_COMPLETED; break;
case 3: OT_FLAG( &peer ) |= PEER_FLAG_STOPPED; break;
case 1: OT_PEERFLAG( &peer ) |= PEER_FLAG_COMPLETED; break;
case 3: OT_PEERFLAG( &peer ) |= PEER_FLAG_STOPPED; break;
default: break;
}

if( !left )
OT_FLAG( &peer ) |= PEER_FLAG_SEEDING;
OT_PEERFLAG( &peer ) |= PEER_FLAG_SEEDING;

outpacket[0] = htonl( 1 ); /* announce action */
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 );
else {
torrent = add_peer_to_torrent( hash, &peer WANT_SYNC_PARAM( 0 ) );
@@ -138,4 +138,4 @@ void handle_udp4( int64 serversocket ) {
}
}

const char *g_version_udp_c = "$Source: /home/cvsroot/opentracker/ot_udp.c,v $: $Revision: 1.17 $\n";
const char *g_version_udp_c = "$Source: /home/cvsroot/opentracker/ot_udp.c,v $: $Revision: 1.18 $\n";

+ 2
- 5
ot_vector.c View File

@@ -16,9 +16,6 @@
#include "uint32.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 ) {
int32_t cmp = READ32(peer1,0) - READ32(peer2,0);
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 );
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 ) );

vector->size--;
@@ -302,4 +299,4 @@ void vector_fixup_peers( ot_vector * vector ) {
vector->data = realloc( vector->data, vector->space * sizeof( ot_peer ) );
}

const char *g_version_vector_c = "$Source: /home/cvsroot/opentracker/ot_vector.c,v $: $Revision: 1.10 $\n";
const char *g_version_vector_c = "$Source: /home/cvsroot/opentracker/ot_vector.c,v $: $Revision: 1.11 $\n";

+ 30
- 24
trackerlogic.c View File

@@ -62,8 +62,8 @@ ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer WANT_SYNC_PARAM(

if( !exactmatch ) {
/* 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) ) ) ) {
vector_remove_torrent( torrents_list, torrent );
mutex_bucket_unlock_by_hash( hash );
@@ -86,8 +86,8 @@ ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer WANT_SYNC_PARAM(
OT_PEERTIME( peer ) = 0;

/* 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 )
OT_FLAG( peer ) ^= PEER_FLAG_COMPLETED;
if( ( OT_PEERFLAG( peer ) & ( PEER_FLAG_COMPLETED | PEER_FLAG_SEEDING ) ) == PEER_FLAG_COMPLETED )
OT_PEERFLAG( peer ) ^= PEER_FLAG_COMPLETED;

/* If we hadn't had a match create peer there */
if( !exactmatch ) {
@@ -96,13 +96,13 @@ ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer WANT_SYNC_PARAM(
if( !from_sync )
livesync_tell( hash, peer );
else
OT_FLAG( peer ) |= PEER_FLAG_FROM_SYNC;
OT_PEERFLAG( peer ) |= PEER_FLAG_FROM_SYNC;
#endif

torrent->peer_list->peer_count++;
if( OT_FLAG(peer) & PEER_FLAG_COMPLETED )
if( OT_PEERFLAG(peer) & PEER_FLAG_COMPLETED )
torrent->peer_list->down_count++;
if( OT_FLAG(peer) & PEER_FLAG_SEEDING )
if( OT_PEERFLAG(peer) & PEER_FLAG_SEEDING )
torrent->peer_list->seed_count++;

} else {
@@ -114,7 +114,7 @@ ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer WANT_SYNC_PARAM(
int 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;
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
@@ -123,19 +123,19 @@ ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer WANT_SYNC_PARAM(
fresh "completed" reports */
if( !from_sync ) {
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 );
}
#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--;
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++;
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++;
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;
}

*(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 ) {
ot_peer * peers = (ot_peer*)bucket_list[bucket].data;
size_t peer_count = bucket_list[bucket].size;
while( peer_count-- )
memmove( r+=6, peers++, 6 );
while( peer_count-- ) {
WRITE32(r+=4,0,READ32(peers,0));
WRITE16(r+=2,0,READ16(peers++,4));
}
}

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;

while( amount-- ) {
ot_peer * peer;

/* This is the aliased, non shifted range, next value may fall into */
unsigned int diff = ( ( ( amount + 1 ) * 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_index = ( bucket_index + 1 ) % num_buckets;
}
memmove( r, ((ot_peer*)bucket_list[bucket_index].data) + bucket_offset, 6 );
r += 6;
peer = ((ot_peer*)bucket_list[bucket_index].data) + bucket_offset;
WRITE32(r+=4,0,READ32(peer,0));
WRITE16(r+=2,0,READ16(peer,4));
}
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 ) ) {
vector_remove_torrent( torrents_list, torrent );
} else {
memmove( r, "20:", 3 ); memmove( r+3, hash, 20 );
r += sprintf( r+23, "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 ) + 23;
int j;
*r++='2';*r++='0';*r++=':';
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 );
@@ -310,7 +316,7 @@ size_t remove_peer_from_torrent( ot_hash *hash, ot_peer *peer, char *reply, PROT

#ifdef WANT_SYNC_LIVE
if( proto != FLAG_MCA ) {
OT_FLAG( peer ) |= PEER_FLAG_STOPPED;
OT_PEERFLAG( peer ) |= PEER_FLAG_STOPPED;
livesync_tell( hash, peer );
}
#endif
@@ -394,4 +400,4 @@ void trackerlogic_deinit( void ) {
mutex_deinit( );
}

const char *g_version_trackerlogic_c = "$Source: /home/cvsroot/opentracker/trackerlogic.c,v $: $Revision: 1.113 $\n";
const char *g_version_trackerlogic_c = "$Source: /home/cvsroot/opentracker/trackerlogic.c,v $: $Revision: 1.114 $\n";

+ 13
- 4
trackerlogic.h View File

@@ -11,6 +11,15 @@
#include <time.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 time_t ot_time;

@@ -55,10 +64,10 @@ static const uint8_t PEER_FLAG_STOPPED = 0x20;
static const uint8_t PEER_FLAG_FROM_SYNC = 0x10;
static const uint8_t PEER_FLAG_LEECHING = 0x00;

#define OT_SETIP( peer, ip ) memmove((peer),(ip),4);
#define OT_SETPORT( peer, port ) memmove(((uint8_t*)peer)+4,(port),2);
#define OT_FLAG(peer) (((uint8_t*)(peer))[6])
#define OT_PEERTIME(peer) (((uint8_t*)(peer))[7])
#define OT_SETIP(peer,ip) WRITE32((peer),0,READ32((ip),0))
#define OT_SETPORT(peer,port) WRITE16((peer),4,READ16((port),0))
#define OT_PEERFLAG(peer) (((uint8_t*)(peer))[6])
#define OT_PEERTIME(peer) (((uint8_t*)(peer))[7])

#define OT_PEER_COMPARE_SIZE ((size_t)6)
#define OT_HASH_COMPARE_SIZE (sizeof(ot_hash))


Loading…
Cancel
Save