Ignore:
Timestamp:
Mar 10, 2011, 12:35:23 PM (11 years ago)
Author:
jordan
Message:

(trunk libT) Add an enumeration for the peer id length. Use that enum for the peer_id fields in tr_session and tr_torrent.

This also avoids an extra malloc/free per-torrent and per-session, but mostly this tweak is for the extra readability of the PEER_ID_LEN=20 enum.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/test-peer-id.c

    r8233 r12121  
    3636    int i;
    3737    int test = 0;
     38    uint8_t peer_id[PEER_ID_LEN+1];
    3839
    3940    for( i = 0; i < 100000; ++i )
    4041    {
    41         int       j;
    42         int       val = 0;
    43         uint8_t * pch = tr_peerIdNew( );
     42        int j;
     43        int val = 0;
    4444
    45         check( strlen( (char*)pch ) == 20 );
    46         check( !memcmp( pch, PEERID_PREFIX, 8 ) );
     45        tr_peerIdInit( peer_id );
    4746
    48         for( j = 8; j < 20; ++j )
     47        check( strlen( (char*)peer_id ) == PEER_ID_LEN );
     48        check( !memcmp( peer_id, PEERID_PREFIX, 8 ) );
     49
     50        for( j = 8; j < PEER_ID_LEN; ++j )
    4951        {
    50             char tmp[2] = { pch[j], '\0' };
     52            char tmp[2] = { peer_id[j], '\0' };
    5153            val += strtoul( tmp, NULL, 36 );
    5254        }
    5355
    5456        check( ( val % 36 ) == 0 );
    55 
    56         tr_free( pch );
    5757    }
    5858
Note: See TracChangeset for help on using the changeset viewer.