Sergey A. Proforov | 1 Apr 2009 14:00

create_torrent multifile

Hello, I have some problems with creating torrent.
I want to create torrent and start seeding it immediately.

1) If I create torrent with one file, it is all right. If I create
multifile torrent, and try to open it, "invalid torrent file"
exception is thrown, while parsing torrent. uTorrent also can't open it.
All files are placed in same directory.

        m_root = tpath( *m_files.begin() ).branch_path();
        file_storage fs;
        for( files_coll::iterator i = m_files.begin(); i != m_files.end(); ++i )
        {
                add_files( fs, *i );
        }

        int piece_size = 16*1024; //16 KB

        create_torrent t( fs, piece_size );
        set_piece_hashes( t, m_root, &CDlgCreateTorrent::PieceCallBack );
        ...
        std::ofstream fout( m_szFileName ,std::ios_base::binary );
        fout.unsetf(std::ios_base::skipws);
        bencode(std::ostream_iterator<char>(fout), t.generate() );

2) Is it possible to select files from different directories, and make multifile
torrent?

3) Is it possible to skip hash checking when adding a torrent, and
set paths to files that will be seeding?

(Continue reading)

arvid | 1 Apr 2009 19:40
Picon
Picon
Favicon

Re: create_torrent multifile

Quoting "Sergey A. Proforov" <snatch <at> agava.com>:

> Hello, I have some problems with creating torrent.
> I want to create torrent and start seeding it immediately.
> 
> 1) If I create torrent with one file, it is all right. If I create
> multifile torrent, and try to open it, "invalid torrent file"
> exception is thrown, while parsing torrent. uTorrent also can't open it.
> All files are placed in same directory.
> 
>         m_root = tpath( *m_files.begin() ).branch_path();
>         file_storage fs;
>         for( files_coll::iterator i = m_files.begin(); i != m_files.end();
> ++i )
>         {
>                 add_files( fs, *i );

If you build this in debug mode you should get an assert. All files needs to
have a common root directory. This directory will be the name of the torrent,
and when added in a torrent client, it will be saved with the same file
structure.

>         }
> 
>         int piece_size = 16*1024; //16 KB
> 
>         create_torrent t( fs, piece_size );
>         set_piece_hashes( t, m_root, &CDlgCreateTorrent::PieceCallBack );
>         ...
>         std::ofstream fout( m_szFileName ,std::ios_base::binary );
(Continue reading)

Shidong Chen | 3 Apr 2009 00:52

Re: Any way to create 20 byte sha1-hash sum from piece hashes and how the last piece is downloaded?

Hello Arvid,

In order to "read once, hash twice", it seems I need to read the data of
file into memory by myself and call hash function. Currently, the
create_torrent only read data directly from file. It doesn't take data in
memory. Given the data has already been read into memory, how could I hash
it?

Thanks
Shidong
------------------------------------------------------------------------------
arvid | 4 Apr 2009 10:51
Picon
Picon
Favicon

Re: Any way to create 20 byte sha1-hash sum from piece hashes and how the last piece is downloaded?

Quoting Shidong Chen <shidong.chen <at> iminvision.com>:

> Hello Arvid,
> 
> In order to "read once, hash twice", it seems I need to read the data of
> file into memory by myself and call hash function. Currently, the
> create_torrent only read data directly from file. It doesn't take data in
> memory.

Not sure what you mean. The only way to give create_torrent the file hashes is
through memory:

http://www.rasterbar.com/products/libtorrent/make_torrent.html#set-hash

--

-- 
Arvid Norberg

------------------------------------------------------------------------------
Shidong Chen | 5 Apr 2009 07:47

Re: Any way to create 20 byte sha1-hash sum from piece hashes and how the last piece is downloaded?

>
>
> Not sure what you mean. The only way to give create_torrent the file hashes
> is
> through memory:
>
Besides the generating the piece hashes, I need to generate a sha1 hash sum
for the whole file. I'll hash the file twice. According to your advice that
99% of time is spent on reading file, I'm trying to find a way I can read
the file into memory by my app and then pass the data in memory to
create_torrent to get it hashed twice. The question is how I could hash the
data already in memory, not in file.
------------------------------------------------------------------------------
arvid | 5 Apr 2009 20:36
Picon
Picon
Favicon

Re: Any way to create 20 byte sha1-hash sum from piece hashes and how the last piece is downloaded?

Quoting Shidong Chen <shidong.chen <at> iminvision.com>:
> >
> >
> > Not sure what you mean. The only way to give create_torrent the file
> hashes
> > is
> > through memory:
> >
> Besides the generating the piece hashes, I need to generate a sha1 hash sum
> for the whole file. I'll hash the file twice. According to your advice that
> 99% of time is spent on reading file, I'm trying to find a way I can read
> the file into memory by my app and then pass the data in memory to
> create_torrent to get it hashed twice. The question is how I could hash the
> data already in memory, not in file.

You create two hasher objects, one for the entire file and one used for each
piece.

for each piece:
  read piece from disk
  update() the file hashes with buffer
  reset the piece hasher
  update() the piece hasher with the buffer
  set the piece hash on the create_torrent object with the piece hasher digest

digest the the file hasher object and you have the file sha-1.

--

-- 
Arvid Norberg

(Continue reading)

Shidong Chen | 9 Apr 2009 18:29

Re: Any way to create 20 byte sha1-hash sum from piece hashes and how the last piece is downloaded?

>
>
> You create two hasher objects, one for the entire file and one used for
> each
> piece.
>
> for each piece:
>  read piece from disk
>  update() the file hashes with buffer
>  reset the piece hasher
>  update() the piece hasher with the buffer
>  set the piece hash on the create_torrent object with the piece hasher
> digest
>
> digest the the file hasher object and you have the file sha-1.
>

After I feed one piece to hasher, I happened to call final() twice. The
returned hash values differ. It seems I can only call final() once before
reset() it. Is this correct?
------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
chris erway | 10 Apr 2009 03:06
Favicon

Re: Any way to create 20 byte sha1-hash sum from piece hashes and how the last piece is downloaded?

On Apr 9, 2009, at 12:29 PM, Shidong Chen wrote:

> After I feed one piece to hasher, I happened to call final() twice.  
> The
> returned hash values differ. It seems I can only call final() once  
> before
> reset() it. Is this correct?

yes -- best to just look at the source.  below is the ENTIRE hasher  
class from libtorrent/hasher.hpp (with asserts removed).  calling  
SHA1_Final() erases the SHA1 context: see http://www.openssl.org/docs/crypto/sha.html 
  for more details.

     class hasher
     {
     public:
         hasher() { SHA1_Init(&m_context); }
         hasher(const char* data, int len)
         {
             SHA1_Init(&m_context);
             SHA1_Update(&m_context, reinterpret_cast<unsigned char  
const*>(data), len);
         }
         void update(const char* data, int len)
         {
             SHA1_Update(&m_context, reinterpret_cast<unsigned char  
const*>(data), len);
         }
         sha1_hash final()
         {
(Continue reading)

Sergey A. Proforov | 10 Apr 2009 09:42

Set torrent status

Hi, Arvid.
In our application we want to add the ability to import torrents from uTorrent.
Also, we want to import torrent counters (such as upload, download,
active_time and etc.). We tried to specify the counters in the
fastresume data when adding a torrent, but it does not help.
Can you add the ability to set the initial torrent status?
--

-- 
Best regards,
 Sergey                          mailto:snatch <at> agava.com

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
Adam Fisk | 11 Apr 2009 04:35
Favicon

stopping seeding

Many LittleShoot users have been requesting the ability to stop
seeding.  While I don't want them to stop seeding, what's the best way
to do it?  I'm currently just calling set_upload_rate_limit(0) on the
session.  Is there a better way?

Thanks.

-Adam

--

-- 
Adam Fisk
http://www.littleshoot.org

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com

Gmane