Ignore:
Timestamp:
Apr 17, 2011, 5:22:50 AM (11 years ago)
Author:
jordan
Message:

(trunk libT) more heap pruning: use composition rather than aggregation for the tr_crypto object owned by tr_peerIo.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/crypto.c

    r12223 r12365  
    7878static const uint8_t dh_G[] = { 2 };
    7979
    80 /** @brief Holds state information for encrypted peer communications */
    81 struct tr_crypto
    82 {
    83     RC4_KEY         dec_key;
    84     RC4_KEY         enc_key;
    85     uint8_t         torrentHash[SHA_DIGEST_LENGTH];
    86     bool            isIncoming;
    87     bool            torrentHashIsSet;
    88     bool            mySecretIsSet;
    89     uint8_t         myPublicKey[KEY_LEN];
    90     uint8_t         mySecret[KEY_LEN];
    91     DH *            dh;
    92 };
    93 
    9480/**
    9581***
     
    144130}
    145131
    146 tr_crypto *
    147 tr_cryptoNew( const uint8_t * torrentHash,
    148               int             isIncoming )
    149 {
    150     tr_crypto * crypto;
    151 
    152     crypto = tr_new0( tr_crypto, 1 );
    153     crypto->isIncoming = isIncoming ? 1 : 0;
     132void
     133tr_cryptoConstruct( tr_crypto * crypto, const uint8_t * torrentHash, bool isIncoming )
     134{
     135    memset( crypto, 0, sizeof ( tr_crypto ) );
     136
     137    crypto->dh = NULL;
     138    crypto->isIncoming = isIncoming;
    154139    tr_cryptoSetTorrentHash( crypto, torrentHash );
    155     crypto->dh = NULL;
    156 
    157     return crypto;
    158 }
    159 
    160 void
    161 tr_cryptoFree( tr_crypto * crypto )
     140}
     141
     142void
     143tr_cryptoDestruct( tr_crypto * crypto )
    162144{
    163145    if( crypto->dh != NULL )
    164146        DH_free( crypto->dh );
    165     tr_free( crypto );
    166147}
    167148
Note: See TracChangeset for help on using the changeset viewer.