summaryrefslogtreecommitdiffstats
path: root/www/insert.php
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2023-02-12 02:08:26 +0100
committerAnton Luka Šijanec <anton@sijanec.eu>2023-02-12 02:08:26 +0100
commitfba85826441851d772152dfd6c82beffb2a54303 (patch)
tree0da04899e95028c1945bb9b2087199a0b3058129 /www/insert.php
parentfix missing piece layers errors (diff)
downloadtravnik-fba85826441851d772152dfd6c82beffb2a54303.tar
travnik-fba85826441851d772152dfd6c82beffb2a54303.tar.gz
travnik-fba85826441851d772152dfd6c82beffb2a54303.tar.bz2
travnik-fba85826441851d772152dfd6c82beffb2a54303.tar.lz
travnik-fba85826441851d772152dfd6c82beffb2a54303.tar.xz
travnik-fba85826441851d772152dfd6c82beffb2a54303.tar.zst
travnik-fba85826441851d772152dfd6c82beffb2a54303.zip
Diffstat (limited to '')
-rwxr-xr-xwww/insert.php27
1 files changed, 19 insertions, 8 deletions
diff --git a/www/insert.php b/www/insert.php
index 28c9c28..f6da24b 100755
--- a/www/insert.php
+++ b/www/insert.php
@@ -11,7 +11,7 @@ $t = TorrentFile::load($argv[4]);
$c = new PDO($argv[1], $argv[2], $argv[3]);
$c->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try {
- $s = $c->prepare("SELECT COUNT(1) FROM torrenti WHERE zgoščena_vrednost=:z");
+ $s = $c->prepare("SELECT COUNT(1) FROM torrenti WHERE sha1=:z");
$s->bindParam(":z", $zgoščena_vrednost);
$zgoščena_vrednost = $t->getInfoHashV1(true);
$s->execute();
@@ -22,8 +22,7 @@ if ($s->fetchColumn()) {
}
try {
$c->exec("CREATE TABLE IF NOT EXISTS torrenti (
- zgoščena_vrednost BINARY(20) NOT NULL PRIMARY KEY,
- " /* . "id INT UNSIGNED AUTO_INCREMENT UNIQUE NOT NULL COMMENT 'samo za lažje ročno navigiranje po podatkovni zbirki, pravi ključ je zgoščena vrednost', " */ . "
+ sha1 BINARY(20) NOT NULL PRIMARY KEY,
pridobljeno TIMESTAMP NOT NULL,
velikost_metainfo INT UNSIGNED NOT NULL COMMENT 'sem se štejejo tudi informacije, ki jih doda travnik, recimo created by, datum izdelave, vir in odjemalec. to ni le velikost info slovarja, vendar je striktno večja, saj je velikost celotne torrent datoteke.',
velikost_koščka INT UNSIGNED NOT NULL,
@@ -31,18 +30,20 @@ try {
ime VARBINARY(4096),
ip BINARY(16) NOT NULL,
vrata SMALLINT UNSIGNED NOT NULL,
- odjemalec VARCHAR(4096)
+ odjemalec VARCHAR(4096),
+ tip ENUM('v1', 'v2, 'hybrid') NOT NULL,
+ sha256 BINARY(32) NOT NULL
)");
$c->exec('CREATE TABLE IF NOT EXISTS datoteke (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
torrent BINARY(20) NOT NULL,
- FOREIGN KEY (torrent) REFERENCES torrenti (zgoščena_vrednost),
+ FOREIGN KEY (torrent) REFERENCES torrenti (sha1),
pot VARBINARY(4096) NOT NULL,
velikost BIGINT NOT NULL
)');
$c->beginTransaction(); // glej php.net/manual/en/pdo.begintransaction.php
$s = $c->prepare("INSERT INTO torrenti (
- zgoščena_vrednost,
+ sha1,
pridobljeno,
velikost_metainfo,
velikost_koščka,
@@ -50,7 +51,9 @@ try {
ime,
ip,
vrata,
- odjemalec
+ odjemalec,
+ tip,
+ sha256
) VALUES (
:z,
:pridobljeno,
@@ -60,7 +63,9 @@ try {
:ime,
INET6_ATON(:ip),
:vrata,
- :odjemalec
+ :odjemalec,
+ :tip,
+ :sha256
)");
$s->bindParam(":z", $zgoščena_vrednost);
$s->bindParam(":pridobljeno", $pridobljeno);
@@ -71,6 +76,8 @@ try {
$s->bindParam(":ip", $ip);
$s->bindParam(":vrata", $vrata);
$s->bindParam(":odjemalec", $odjemalec);
+ $s->bindParam(":tip", $tip);
+ $s->bindParam(":sha256", $sha256);
$pridobljeno = date("Y-m-d H:i:s", $t->getCreationDate());
$velikost_metainfo = filesize($argv[4]);
$velikost_koščka = $t->getPieceLength();
@@ -88,6 +95,10 @@ try {
$vrata = intval(explode("/", $t->getRootData()["source"]["ip"])[1]);
if (isset($t->getRootData()["source"]["v"]))
$odjemalec = $t->getRootData()["source"]["v"];
+ if (strlen($odjemalec) > 4096)
+ echo "$argv[4] odjemalec $odjemalec daljši od 4096";
+ $tip = $t->getProtocol();
+ $sha256 = $t->getInfoHashV2();
$s->execute();
try {
foreach ($t->getFileList() as $datoteka) {