1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-27 10:07:40 +00:00

(trunk libT) don't allow duplicate torrents to be added via magnet links

This commit is contained in:
Charles Kerr 2009-11-24 17:31:20 +00:00
parent 3610c5ea62
commit c102f199c3
2 changed files with 15 additions and 7 deletions

View file

@ -1872,7 +1872,7 @@ fillOutputBuffer( tr_peermsgs * msgs, time_t now )
tr_bencInitDict( &tmp, 3 ); tr_bencInitDict( &tmp, 3 );
tr_bencDictAddInt( &tmp, "msg_type", METADATA_MSG_TYPE_DATA ); tr_bencDictAddInt( &tmp, "msg_type", METADATA_MSG_TYPE_DATA );
tr_bencDictAddInt( &tmp, "piece", piece ); tr_bencDictAddInt( &tmp, "piece", piece );
tr_bencDictAddInt( &tmp, "total_size", dataLen ); tr_bencDictAddInt( &tmp, "total_size", msgs->torrent->infoDictLength );
payload = tr_bencToStr( &tmp, TR_FMT_BENC, &payloadLen ); payload = tr_bencToStr( &tmp, TR_FMT_BENC, &payloadLen );
tr_bencFree( &tmp ); tr_bencFree( &tmp );

View file

@ -767,23 +767,31 @@ tr_torrent *
tr_torrentNew( const tr_ctor * ctor, tr_torrentNew( const tr_ctor * ctor,
int * setmeError ) int * setmeError )
{ {
int err;
tr_info tmpInfo; tr_info tmpInfo;
tr_torrent * tor = NULL; tr_torrent * tor = NULL;
const tr_magnet_info * magnetInfo; const tr_magnet_info * magnetInfo;
tr_session * session = tr_ctorGetSession( ctor );
assert( ctor != NULL ); assert( ctor != NULL );
assert( tr_isSession( tr_ctorGetSession( ctor ) ) ); assert( tr_isSession( session ) );
if( !tr_ctorGetMagnet( ctor, &magnetInfo ) ) if( !tr_ctorGetMagnet( ctor, &magnetInfo ) )
{ {
tor = tr_new0( tr_torrent, 1 ); if( tr_torrentFindFromHash( session, magnetInfo->hash ) != NULL )
tr_metainfoSetFromMagnet( &tor->info, magnetInfo ); {
torrentInit( tor, ctor ); if( setmeError )
*setmeError = TR_PARSE_DUPLICATE;
}
else
{
tor = tr_new0( tr_torrent, 1 );
tr_metainfoSetFromMagnet( &tor->info, magnetInfo );
torrentInit( tor, ctor );
}
} }
else else
{ {
err = tr_torrentParse( ctor, &tmpInfo ); const int err = tr_torrentParse( ctor, &tmpInfo );
if( !err ) if( !err )
{ {
tor = tr_new0( tr_torrent, 1 ); tor = tr_new0( tr_torrent, 1 );