Login
Username: Password:
Remember me

[Sign Up] / [Recover Password]

Theme / Language

Popular
New Torrents
new name
Size: 18.40 MB
Most active
new name
S: 74 L: 3
New Posters
V2 LibTorrent
Controls ·  Search New posts · Mark unread

You are in: Forum / Forum / General / General Chat

2022-01-14 16:32:47
For those interested in torrenting this is a place to share information about the new v2 implementation.

This can be links, wikis, videos, code snippets anything and is here to help keep update for connecting to clients in PHP.

Few Links
libtorrent  https://blog.libtorrent.org/2020/09/bittorrent-v2/
BEP52 http://bittorrent.org/beps/bep_0052.html

The first things that stuck out to me are:
The hash is now SHA-256 this still needs to be 20 bytes long (bytes not characters at moment the sha1 is 40bytes but we use hexbin to 20 this should be the same using a limit on a custom hex_bin function like on bitstorm - after having a quick look at this we don't send the hash back to the client ist just to identify in our dB that id to the id of the client  it's connecting to that should be just a case of changing table column length and change for sh256

A integer with any leading zeros (except 0 itself). e.g. “i0004e” are not allowed - this bit had me puzzled at first until i read my notes on bencoding, this will be extremely uncommon  if at all bencode is string length say eg 5 followed by the string eg hello so that would be i5ehello so the torrent string should never start with 0

In the future all old torrents will be obsolete, but for now we can do hybrid torrents so saving the new hash and data is a good idea to start on now

The structure of the torrent file array is different filetree, but also how pieces & paths work this needs live test

Here is a few test v2 torrents https://github.com/arvidn/libtorrent/tree/RC_2_0/test/test_torrents

If anyone has anything to add or has any progress please can you post here and ill update the post as we go. Progress might be slow but if everyone shares there work and knowledge we can keep up to date  👍

At moment qbit crashes for me so cant make a v2 torrent with my own announce but i have tried decoding one of the test ones from above, when i try upload to TT i get a few things come back null from the parser function, if someone knows how to set qbit to create v2 torrent that would be a big help i think i can grab the data but until qbit 4.4 works for me i cant test that much

here is link to test - first two dumps are v2 & last one is v1 so far it looks like its just the parse function (upload & import) and announce will need changing
https://torrenttrader.uk/atest

code used for testing page ive attached my bencode class, im using not sure if its working as it should for v2 but ive been using it for v1 for some time
        echo '<br><br>v2 torrent<br><br>';
       
       $torrent_dir = UPLOADDIR."/torrents/2.torrent";

       $test = Bencode::load($torrent_dir);
       var_dump($test);

       echo '<br><br>another v2 torrent<br><br>';

       $torrent_dir = UPLOADDIR."/torrents/16.torrent";

       $test = Bencode::load($torrent_dir);
       var_dump($test);
       
       echo '<br><br>original v1 torrent<br><br>';

       $torrent_dir = UPLOADDIR."/torrents/1.torrent";

       $test = Bencode::load($torrent_dir);
       var_dump($test);
Bencode.zip
File missing
Last edited by M-jay warn on 2022-01-14 17:55:11
2022-01-14 18:22:46
here is a small v2 torrent using your announce. I didnt upload anything, its just a torrent
Wind's.mp3.zip
File missing

TTv3 Micro Edition
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
Last edited by MicroMonkey on 2022-01-14 18:23:40
2022-01-14 18:33:15
what about this https://github.com/arokettu/bencode

documentation is poor

i can't decode file with this lib

another lib is https://github.com/bhutanio/bencode

i am not sure if decoding file is possible
follow the thread for updates
checkout my project: https://bvlist.com/showthread.php?t=12349
Last edited by JohnHasher on 2022-01-14 18:44:53
2022-01-14 18:35:23
add <pre> tag to make the array readable
follow the thread for updates
checkout my project: https://bvlist.com/showthread.php?t=12349
2022-01-14 20:28:54
added pre tags  👍  the path would need changing for v3 eg
$torrent_dir = "uploads/2.torrent";


thanks for torrent micromonkey still getting errors uploading but it looks like it just the parse function returning null on some of the data could you add something like TTv3 in a v2 torrent so i can check file/folder/path reading

Quote:
Uncaught Exception: 2022-01-14 20:16:26 - SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'size' cannot be null in file /global/torrent1/app/libraries/DB.php on line 39

Call Stack

[0] File: /global/torrent1/app/libraries/DB.php Line: 39
Function: PDOStatement->execute
Call parameters
Param[0]: Passed value: array (
 0 => 'Wind\'s.mp3.torrent',
 1 => '1',
 2 => 'Wind\'s.mp3',
 3 => 0,
 4 => 'test v2',
 5 => NULL,
 6 => NULL,
 7 => 18,
 8 => NULL,
 9 => '2022-01-14 20:16:26',
 10 => 'c22e5f3b13ce8e230a6c3b0775fb83c9a524f91d',
 11 => NULL,
 12 => 1,
 13 => 'Wind\'s.mp3.torrent',
 14 => 'https://torrenttrader.uk/announce.php',
 15 => 'no',
 16 => 'no',
 17 => 0,
 18 => 'no',
 19 => '2022-01-14 20:16:26',
 20 => 0,
 21 => NULL,
 22 => NULL,
 23 => 'b:0;',
)
Last edited by M-jay warn on 2022-01-14 20:29:25
2022-01-14 21:25:41
not a lot of details of php torrents online and its had me scratching my head a few times so if it helps any one

the only thing the client does is connect to the announce.php to get a return of peer_ids, ports & ips.
thats all - all the other data like files, announcelist is not used for the client - in TT we have users, torrents, agentchecks etc but thats got nothing to do with the torrent or client.

The hash is just a id to recognise that connecting client to the site so as long as it is always same shouldn't matter how its encoded instead of sha256 it could be md5 because when you md5 a sha256 hash you will always get same result - this is just to give idea how it works use sha256

For the client the torrent file itself shares all the information about files, announces etc and in TT we dont write a file - we just copy that file to our server, we dont encode or decode - just straight copy. We add passkey on download but thats fine the code does that already

The torrent & client side is pretty straight forward its the interaction with TT this is where the parse function comes in we need to be able to read the file array to save the details in the database - nothing to do with the torrent itself, just the database im thinking return a big array for v1 & v2

2022-01-15 05:01:05
instead of var_dump use print_r too
follow the thread for updates
checkout my project: https://bvlist.com/showthread.php?t=12349
2022-01-15 05:14:29


Array
(
   [file tree] => Array
       (
           [Dont.Look.Up.2021.1080p.WEBRip.x264.AAC5.1-[YTS.MX].mp4] => Array
               (
                   [] => Array
                       (
                           [length] => 2833229849
                           [pieces root] => �r<{��5����hy�x�0�JchO<#��0L�
                       )

               )

           [Dont.Look.Up.2021.1080p.WEBRip.x264.AAC5.1-[YTS.MX].srt] => Array
               (
                   [] => Array
                       (
                           [length] => 175761
                           [pieces root] => i:kh=J���5G�
���n�5l/��8��
                       )

               )

           [Subs] => Array
               (
                   [Arabic.ara.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 216419
                                   [pieces root] => �@f��E�(���j���L��[%e#�U/
                               )

                       )

                   [Brazilian Portuguese.por.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 140190
                                   [pieces root] => ӳ(N�N�"�w=���^�E|O���9��{�u.�
                               )

                       )

                   [Chinese Simplified.chi.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 151080
                                   [pieces root] => :9+�g�#�r���
���*a�)�5ۺ�
                               )

                       )

                   [Chinese Traditional.chi.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 146874
                                   [pieces root] => kX�����0h��l.)�x��lʠ�Oe�.��
                               )

                       )

                   [Croatian.hrv.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 138433
                                   [pieces root] => �hbn�0*�eɅ�ͨ0 Array
                       (
                           [] => Array
                               (
                                   [length] => 140204
                                   [pieces root] => �a�����6�X� "�w�Z�R�z��f��
                               )

                       )

                   [Danish.dan.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 135763
                                   [pieces root] => I��1:�'��ۏ�ƈ�& ڊ��<ݝ���2�
                               )

                       )

                   [Dutch.dut.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 129308
                                   [pieces root] => ȹ���A�� 4�&��(y!2l�t��#݀
                               )

                       )

                   [English [SDH].eng.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 175761
                                   [pieces root] => i:kh=J���5G�
���n�5l/��8��
                               )

                       )

                   [European Spanish.spa.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 147261
                                   [pieces root] => �$j(��H�����)��+�x� fzr��ܯ
                               )

                       )

                   [Finnish.fin.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 128347
                                   [pieces root] => ]a�K�O�u+@��\��h���H{��q<��Yd,
                               )

                       )

                   [French.fre.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 140480
                                   [pieces root] => �&9>Y{�'� �P��.f�kKU!��`�B
                               )

                       )

                   [German.ger.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 141457
                                   [pieces root] => �Ȫ���:�B��l/��,��X�Oc�1��
                               )

                       )

                   [Greek.gre.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 195696
                                   [pieces root] => p�����S�^R��=�I�e��'4bΒ��3�
                               )

                       )

                   [Hebrew.heb.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 190228
                                   [pieces root] => ���}etUlv��6�CT�D�Կ��������
                               )

                       )

                   [Hungarian.hun.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 145866
                                   [pieces root] => �67K�z�Q�2�&�o�����+8��g
                               )

                       )

                   [Indonesian.ind.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 141899
                                   [pieces root] => m��ُ��R��]^1�䑤׀�?-.0n�]�\[�
                               )

                       )

                   [Italian.ita.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 142224
                                   [pieces root] => ��Y��r|�"�4��\5$ �-�+�3 �
                               )

                       )

                   [Japanese.jpn.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 147454
                                   [pieces root] => ��]"b���[�V��tW�t���i!�Jw@
                               )

                       )

                   [Korean.kor.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 156316
                                   [pieces root] => m���ٝ>�Λ�i�Kf�"�!�7T6���b
                               )

                       )

                   [Malay.may.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 140277
                                   [pieces root] => ��U ���U����x���f�8a%�[�!�N
                               )

                       )

                   [Norwegian Bokmal.nob.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 132641
                                   [pieces root] => �{�;z�@�.��=���P�?e��
;�����
                               )

                       )

                   [Polish.pol.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 141924
                                   [pieces root] => 4 L\Y��Q�\�1t���B��u���j�IȢ
                               )

                       )

                   [Portuguese.por.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 142554
                                   [pieces root] => �7;�6ڧ�cgdW�&�t5�z*�ո���^�
                               )

                       )

                   [Romanian.rum.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 155807
                                   [pieces root] => �\Z��bpj�Sy��.j��ޛ�%I�=Bl�{
                               )

                       )

                   [Russian.rus.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 190832
                                   [pieces root] => �/D~�p�Ĭ���]|�I�/�����“���
                               )

                       )

                   [Spanish.spa.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 145674
                                   [pieces root] => ��3!��u�00�/���f�JVjm5#�c$i
                               )

                       )

                   [Swedish.swe.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 131559
                                   [pieces root] => �
�!t)+Ɯ�_� @oA����\�^��p
                               )

                       )

                   [Thai.tha.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 267122
                                   [pieces root] => ����-L��5�s���|Y�m���f����G
                               )

                       )

                   [Turkish.tur.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 146612
                                   [pieces root] => X�Ӟ�¶�8r���A^��Ĩ������e��_��s
                               )

                       )

                   [Ukrainian.ukr.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 186665
                                   [pieces root] => �odv���b���PfN׌n��! wi�DY��N�O
                               )

                       )

                   [Vietnamese.vie.srt] => Array
                       (
                           [] => Array
                               (
                                   [length] => 176855
                                   [pieces root] => �#pc�MM�u82���{"���=Mׄ-���yV
                               )

                       )

               )

       )

   [meta version] => 2
   [name] => Dont Look Up (2021) [1080p] [WEBRip] [5.1] [YTS.MX]
   [piece length] => 1048576
)


return by using arokettu/bencode
follow the thread for updates
checkout my project: https://bvlist.com/showthread.php?t=12349
2022-01-15 05:15:33
array keys contain file tree, this is great
follow the thread for updates
checkout my project: https://bvlist.com/showthread.php?t=12349
2022-01-15 06:48:56
ive manged to get a qbit - official source didn't work at all lol

ive uploaded a v2 torrent fine just need to check the files are inserted correctly just the files and announce-list could do with a big multi external v2 to thoroughly test not sure the big sites will use v2 torrents.

this is whats returned from parse.  These items are missing announcelist(not external needs tests), files(not sure why current issue), comments (not used any way)
Quote:
array(6) {
["announce"]=> string(27) "http://example.com/announce"
["hash"]=> string(40) "c14199bbec64d0e9e439aa3b6b7639e666b86eca"
["creation date"]=> string(31) "Sat, 15 Jan 2022 07:44:49 +0100"
["name"]=> string(7) "test64K"
["length"]=> int(65536)
["ttfilecount"]=> int(1)
}


heres the inserted row
INSERT INTO `torrents` (`id`, `info_hash`, `name`, `filename`, `save_as`, `descr`, `image1`, `image2`, `category`, `size`, `added`, `type`, `numfiles`, `comments`, `views`, `hits`, `times_completed`, `leechers`, `seeders`, `last_action`, `visible`, `banned`, `owner`, `anon`, `numratings`, `ratingsum`, `nfo`, `announce`, `external`, `torrentlang`, `freeleech`, `tube`, `tmdb`, `uplreq`, `sticky`, `vip`, `announcelist`, `filelist`) VALUES
(2, 'c14199bbec64d0e9e439aa3b6b7639e666b86eca', 'test64K', '2.torrent', '2.torrent', 'test', NULL, NULL, 45, 65536, '2022-01-15 06:36:43', 'single', 1, 0, 0, 0, 0, 0, 0, '2022-01-15 06:36:43', 'yes', 'no', 1, 'no', 0, 0, 'no', 0x687474703a2f2f6578616d706c652e636f6d2f616e6e6f756e6365, 'yes', 0, '0', NULL, NULL, 'no', 'no', '', 'b:0;', 'b:0;');
Last edited by M-jay warn on 2022-01-15 06:54:10
2022-01-15 07:08:26
v1 and v2 decoder file structure output is different thats why

on v1 file list are decoded like

[info] => Array
       (
           [files] => Array
               (
                   [0] => Array
                       (
                           [length] => 1535753602
                           [path] => Array
                               (
                                   [0] => products
                                   [1] => PPRO
                                   [2] => AdobePremierePro15AllTrial.zip
                               )

                       )

                   [1] => Array
                       (
                           [length] => 799
                           [path] => Array
                               (
                                   [0] => Instructions!.txt
                               )

                       )


on v2 torrent, its decoded like

   [info] => Array
       (
           [file tree] => Array
               (
                   [Dont.Look.Up.2021.1080p.WEBRip.x264.AAC5.1-[YTS.MX].mp4] => Array
                       (
                           [] => Array
                               (
                                   [length] => 2833229849
                                   [pieces root] => �r<{��5����hy�x�0�JchO<#��0L�
                               )

                       )


on v2 its a perfect file tree.
follow the thread for updates
checkout my project: https://bvlist.com/showthread.php?t=12349
2022-01-15 07:09:32
i think either we need to force uploaders to use the v2 or continue on using v1

in my opinion v2 is better
follow the thread for updates
checkout my project: https://bvlist.com/showthread.php?t=12349
2022-01-15 07:17:09
if you want to edit the torrent check this lib https://github.com/arokettu/torrent-file

since you guys are using private tracker, need to work on inserting passkey...
follow the thread for updates
checkout my project: https://bvlist.com/showthread.php?t=12349
Last edited by JohnHasher on 2022-01-15 07:22:02
2022-01-15 08:54:07
Passkey is added on internal on download so that's fine we use sprintf to replace announce.php in  parsed string with announce?passkey=

Maybe we could use array_key_exsist on file tree if tree is there means v2 mark torrent as v2

If that file tree not there must be v1 file continue with original code

Or if table column can be null try save as both file and file tree

If file tree key exist we would have to mark the torrent with a column type eg 1 or 2 so we can identify in are code because printing out the files would be different
2022-01-15 09:13:49
Looking at hashes as well need to replace binhex from announce need to return the sha256 and sha1 hashes from the client so there same length maybe so there 32, remember we only us hash to identify the torrent in our code its also used in scraping but we get the hash and trackers directly from the file not the database

this seems to be working switching between both, the sha256 hash is to big for table its 64 but this could be useful you can tell difference in future by hash length

update fully working using $info["file tree"][$torrentInfo['name']]

        // Target File
       $torrent_dir = UPLOADDIR."/torrents/2.torrent";
       // Lets Get Contents
       $parse = file_get_contents($torrent_dir);
       
       // If Parse Lets Read It
       if (!isset($parse)) {
           Redirect::autolink(URLROOT, Lang::T("Error Getting Torrent file"));
       } else {
           // Decode File Array
           $array = Bencode::decode($parse);
           // If Array Lets Read It
           if ($array === false) {
               Redirect::autolink(URLROOT, Lang::T("Unable to decode file."));
           } else {
               if (array_key_exists("info", $array) === false) {
                   Redirect::autolink(URLROOT . "/index", Lang::T("Error opening torrent.<br>"));
               } else {
                   //Get Announce URL
                   $torrentInfo['announce'] = $array["announce"];
                   //Get Announce List Array
                   if (isset($array["announce-list"])) {
                       $torrentInfo["announce-list"] = $array["announce-list"];
                   }
                   // Calculates date from UNIX Epoch
                   $torrentInfo["creation date"] = date('r', $array["creation date"]);
                   //Get torrents comment
                   if (isset($array['comment'])) {
                       $torrentInfo['comment'] = $array['comment'];
                   }
                   // Read info - files
                   $info = $array["info"];
                   // The name of the torrents is different to the file name
                   $torrentInfo['name'] = $info['name'];
                   // Calculate Size/Count
                   $filecount = 0;
                   $torrentsize = 0;
                   // Get file list
                   if (isset($info["files"]) && is_array($info["files"])) {
                       // Calculates SHA1 Hash
                       $torrentInfo['hash'] = hash('sha1', Bencode::encode($info));
                       // Return Marker To identify as v1
                       $torrentInfo['type'] = '1';
                       //Get files here
                       $torrentInfo['files'] = $info["files"];
                       foreach ($info["files"] as $file) {
                           $filecount = ++$filecount;
                           $torrentsize += $file['length'];
                       }
                       $torrentInfo['length'] = $torrentsize;
                       $torrentInfo['ttfilecount'] = $filecount;

                   } elseif (isset($info["file tree"]) && is_array($info["file tree"])) {
                       // Calculates SHA256 Hash
                       $torrentInfo['hash'] = hash('sha256', Bencode::encode($info));
                       // Return Marker To identify as v2
                       $torrentInfo['type'] = '2';
                       //Get files here
                       $torrentInfo['files'] = $info["file tree"][$torrentInfo['name']];
                       foreach ($info["file tree"][$torrentInfo['name']] as $file) {
                           $filecount = ++$filecount;
                           $torrentsize += $file['length'];
                       }
                       $torrentInfo['length'] = $torrentsize;
                       $torrentInfo['ttfilecount'] = $filecount;

                   } else {
                       // Single File Torrent
                       $torrentInfo['name'] = $info['name'];
                       $torrentInfo['length'] = $info['length'];
                       $torrentInfo['ttfilecount'] = 1;
                   }
               
                   echo 'so heres the return parse function<br>';
                   echo '<pre>' , print_r($torrentInfo) , '</pre><br>';

               }
           }
           
       }


new test
https://torrenttrader.uk/atest
Last edited by M-jay warn on 2022-01-15 12:23:48
Users online

No users online

Search



Statistics

    Torrents

  • Tracking: 3
  • Todays torrents: 0
  • Seeders: 0
  • Leechers: 0
  • Peers: 0
  • Downloaded: 89.96 GB
  • Uploaded: 9.86 GB

  • Members

  • We have: 838
  • New today: 0
  • Guest today: 9

  • Online

  • Total online: 6
  • Members: 0
  • Guests online: 6
  • Comments: 3
  • Messages: 1,728