$cfg["total_upload"] = $cfg["total_upload"] + GetSpeedValue($sf->up_speed); continue; } // status-image $hd = getStatusImage($sf); // --------------------------------------------------------------------- //XFER: update1: add upload/download stats to the xfer array if ($cfg['enable_xfer'] == 1 && $cfg['xfer_realtime'] == 1) { @Xfer::update1($transfer, $transferowner, $settingsAry['client'], $settingsAry['hash'], $sf->uptotal, $sf->downtotal); } // --------------------------------------------------------------------- // injects new if (!file_exists($cfg["transfer_file_path"] . $transfer . ".stat")) { $transferRunning = 2; $sf->running = "2"; $sf->size = getTransferSize($transfer); injectTransfer($transfer); } // totals-preparation // if downtotal + uptotal + progress > 0 if ($settings[2] + $settings[3] + $settings[5] > 0) { $ch = ClientHandler::getInstance($settingsAry['client']); $transferTotals = $ch->getTransferTotalOP($transfer, $settingsAry['hash'], $sf->uptotal, $sf->downtotal); } // --------------------------------------------------------------------- // preprocess stat-file and get some vars $estTime = " "; $statusStr = " "; $show_run = true; switch ($transferRunning) { case 2:
/** * injects a transfer * * @param $transfer * @return boolean */ function injectTransfer($transfer) { global $cfg; $sf = new StatFile($transfer); $sf->running = "2"; // file is new $sf->size = getTransferSize($transfer); if ($sf->write()) { // set transfers-cache cacheTransfersSet(); return true; } else { AuditAction($cfg["constants"]["error"], "stat-file cannot be written when injecting : " . $transfer); return false; } }
/** * recalc sharekill * * @return boolean */ function _recalcSharekill() { global $cfg; $this->logMessage("recalc sharekill for " . $this->transfer . "\n", true); if ($this->sharekill == 0) { // nice, we seed forever $this->sharekill_param = 0; $this->logMessage("seed forever\n", true); // return return true; } elseif ($this->sharekill > 0) { // recalc sharekill /* get size */ // try stat-file first $sf = new StatFile($this->transfer, $this->owner); $transferSize = empty($sf->size) ? 0 : floatval($sf->size); // try to reget if stat was empty if ($transferSize <= 0) { $transferSize = floatval(getTransferSize($this->transfer)); } // if still no size just pass thru the param if ($transferSize <= 0) { // message $msg = "data-size = '" . $transferSize . "' when recalcing share-kill for " . $this->transfer . ", setting sharekill-param to " . $this->sharekill_param; array_push($this->messages, $msg); // debug-log if ($cfg['debuglevel'] > 0) { AuditAction($cfg["constants"]["debug"], $msg); } // log $this->logMessage($msg . "\n", true); // set sharekill param $this->sharekill_param = $this->sharekill; // return return true; } /* get vars */ // get totals $totalAry = $this->getTransferTotal($this->transfer); $upTotal = floatval($totalAry["uptotal"]); $downTotal = floatval($totalAry["downtotal"]); // check totals if ($upTotal < 0 || $downTotal < 0) { // message $msg = "problems getting totals (upTotal: " . $upTotal . "; downTotal: " . $downTotal . ") when recalcing share-kill for " . $this->transfer . ", setting sharekill-param to " . $this->sharekill_param; array_push($this->messages, $msg); // debug-log if ($cfg['debuglevel'] > 0) { AuditAction($cfg["constants"]["debug"], $msg); } // log $this->logMessage($msg . "\n", true); // set sharekill param $this->sharekill_param = $this->sharekill; // return return true; } // wanted $upWanted = $this->sharekill / 100 * $transferSize; // check wanted if ($upWanted <= 0) { // message $msg = "problems calculating wanted upload (upWanted: " . $upWanted . ") when recalcing share-kill for " . $this->transfer . ", setting sharekill-param to " . $this->sharekill_param; array_push($this->messages, $msg); // debug-log if ($cfg['debuglevel'] > 0) { AuditAction($cfg["constants"]["debug"], $msg); } // log $this->logMessage($msg . "\n", true); // set sharekill param $this->sharekill_param = $this->sharekill; // return return true; } // share percentage $sharePercentage = $upTotal / $transferSize * 100; // check percentage if ($sharePercentage < 0 || $sharePercentage >= 2147483647) { // message $msg = "problems calculating share percentage (sharePercentage: " . $sharePercentage . ") when recalcing share-kill for " . $this->transfer . ", setting sharekill-param to " . $this->sharekill_param; array_push($this->messages, $msg); // debug-log if ($cfg['debuglevel'] > 0) { AuditAction($cfg["constants"]["debug"], $msg); } // log $this->logMessage($msg . "\n", true); // set sharekill param $this->sharekill_param = $this->sharekill; // return return true; } /* check */ if ($upTotal >= $upWanted && $downTotal >= $transferSize) { // just pass thru param if runtime is true if ($this->runtime == "True") { $this->sharekill_param = $this->sharekill; $this->logMessage("setting sharekill-param to " . $this->sharekill_param . "\n", true); // return return true; } // we already have seeded at least wanted percentage. skip start of client // set state $this->state = CLIENTHANDLER_STATE_NULL; // message $msg = "skip " . $this->transfer . " due to share-ratio (has: " . @number_format($sharePercentage, 2) . "; set:" . $this->sharekill . "; upTotal: " . $upTotal . "; upWanted: " . $upWanted . ")"; array_push($this->messages, $msg); // debug-log if ($cfg['debuglevel'] > 0) { AuditAction($cfg["constants"]["debug"], $msg); } // log $this->logMessage($msg . "\n", true); // write Skipped to stat $sf = new StatFile($this->transfer, $this->owner); $sf->time_left = 'Skipped'; $sf->write(); // return return false; } else { // not done seeding wanted percentage $this->sharekill_param = intval(ceil($this->sharekill - $sharePercentage)); // sanity-check. if ($this->sharekill_param < 1) { $this->sharekill_param = 1; } $this->logMessage("recalcing sharekill. wanted: " . $this->sharekill . "; done: " . $sharePercentage . "\n", true); $this->logMessage("setting sharekill-param to " . $this->sharekill_param . "\n", true); // return return true; } } else { $this->sharekill_param = $this->sharekill; $this->logMessage("setting sharekill-param to " . $this->sharekill_param . "\n", true); // return return true; } // return return true; }
/** * @return full size */ function getTransferSize($transfer) { require_once 'inc/functions/functions.core.transfer.php'; return getTransferSize($transfer); }
/** * injects a torrent * * @param $url * @return boolean */ function inject($url) { global $cfg; // set vars from the url $this->setVarsFromUrl($url); // write meta-file $resultSuccess = false; if ($handle = @fopen($this->transferFilePath, "w")) { $resultSuccess = @fwrite($handle, $this->url) !== false; @fclose($handle); } if ($resultSuccess) { // Make an entry for the owner AuditAction($cfg["constants"]["file_upload"], basename($this->transferFilePath)); // inject stat $sf = new StatFile($this->transfer); $sf->running = "2"; // file is new $sf->size = getTransferSize($this->transfer); if (!$sf->write()) { $this->state = CLIENTHANDLER_STATE_ERROR; $msg = "wget-inject-error when writing stat-file for transfer : " . $this->transfer; array_push($this->messages, $msg); AuditAction($cfg["constants"]["error"], $msg); $this->logMessage($msg . "\n", true); $resultSuccess = false; } } else { $this->state = CLIENTHANDLER_STATE_ERROR; $msg = "wget-metafile cannot be written : " . $this->transferFilePath; array_push($this->messages, $msg); AuditAction($cfg["constants"]["error"], $msg); $this->logMessage($msg . "\n", true); } // set transfers-cache cacheTransfersSet(); // return return $resultSuccess; }