<?
// BEP 39 - Updating Torrents Via Feed URL
$dict['info']['update-url'] = sprintf('%/update.php', $CONFIG['base_url']);
$dict['info']['originator'] = $certificate_DER_encoded


This matches the spec, without alternative key in encoded (optional) field (BEP 35) since we are adding the keys after openssl_sign. Now we continue to update.php to push torrent to client if torrent is depreciated/updated.

update.php

<?
// BEP 39 - Updating Torrents Via Feed URL
if (array_key_exists('info_hash', $_GET)) {
   $res = $db->query_params('SELECT b.data FROM torrents_blob b LEFT JOIN torrents t ON t.torrent_id = b.torrent_id WHERE t.info_hash = :info_hash LIMIT 1', array(
       'info_hash' => trim($_GET['info_hash'])
   ));
   if ($row = $res->fetch()) {
       http_response_code(200);
       die($row['data']);
   }
}


Now we accept GET request from uTorrent (confirmed implemented, read spec)
/update.php?info_hash=1835d21d3df92f90ccf23457b73be7b591b91fe0

Next, download.php

<?
// BEP 39 - Updating Torrents Via Feed URL
$pKey = file_get_contents('private.key');
$pKey = openssl_pkey_get_private($pKey, 'somepass');
openssl_sign(Bencode::encode($parse['info']), $signature, $pKey);
$buffer  = file_get_contents('certificate.pem');
$convert = convertToDer($buffer);
if ($convert->status === 'success') {
   $parse['info']['update-url'] = sprintf('%s/update.php', $CONFIG['base_url']);
   $parse['info']['originator'] = $convert->result;
}
Last edited by STorrents2020 on 2022-07-16 06:51:57