/**
 * setFilePriority
 *
 * @param $transfer
 */
function dispatcher_setFilePriority($transfer)
{
    global $cfg;
    if ($cfg["enable_file_priority"]) {
        setFilePriority($transfer);
    }
}
 /**
  * starts a client
  *
  * @param $transfer name of the transfer
  * @param $interactive (boolean) : is this a interactive startup with dialog ?
  * @param $enqueue (boolean) : enqueue ?
  */
 function start($transfer, $interactive = false, $enqueue = false)
 {
     global $cfg;
     // set vars
     $this->_setVarsForTransfer($transfer);
     // log
     $this->logMessage($this->client . "-start : " . $transfer . "\n", true);
     // do tornado special-pre-start-checks
     // check to see if the path to the python script is valid
     if (!is_file($this->tornadoBin)) {
         $this->state = CLIENTHANDLER_STATE_ERROR;
         $msg = "path for tftornado.py is not valid";
         AuditAction($cfg["constants"]["error"], $msg);
         $this->logMessage($msg . "\n", true);
         array_push($this->messages, $msg);
         array_push($this->messages, "tornadoBin : " . $this->tornadoBin);
         // write error to stat
         $sf = new StatFile($this->transfer, $this->owner);
         $sf->time_left = 'Error';
         $sf->write();
         // return
         return false;
     }
     // init starting of client
     $this->_init($interactive, $enqueue, true, $cfg['enable_sharekill'] == 1);
     // only continue if init succeeded (skip start / error)
     if ($this->state != CLIENTHANDLER_STATE_READY) {
         if ($this->state == CLIENTHANDLER_STATE_ERROR) {
             $msg = "Error after init (" . $transfer . "," . $interactive . "," . $enqueue . ",true," . $cfg['enable_sharekill'] . ")";
             array_push($this->messages, $msg);
             $this->logMessage($msg . "\n", true);
         }
         // return
         return false;
     }
     // file-prio
     if ($cfg["enable_file_priority"]) {
         setFilePriority($transfer);
     }
     // pythonCmd
     $pyCmd = $cfg["pythonCmd"] . " -OO";
     // build the command-string
     $skipHashCheck = "";
     if (!empty($this->skip_hash_check) && getTorrentDataSize($transfer) > 0) {
         $skipHashCheck = " --check_hashes 0";
     }
     $filePrio = "";
     if (@file_exists($this->transferFilePath . ".prio")) {
         $priolist = explode(',', @file_get_contents($this->transferFilePath . ".prio"));
         $priolist = implode(',', array_slice($priolist, 1, $priolist[0]));
         $filePrio = " --priority " . tfb_shellencode($priolist);
     }
     // build the command-string
     // note : order of args must not change for ps-parsing-code in
     // RunningTransferTornado
     $this->command = "";
     //	       Proxy Hack
     //	       $this->command .= 'export http_proxy=127.0.0.1:8118; HTTP_PROXY=$http_proxy;';
     $this->command .= "cd " . tfb_shellencode($this->savepath) . ";";
     $this->command .= " HOME=" . tfb_shellencode($cfg["path"]);
     $this->command .= "; export HOME;";
     $this->command .= $this->umask;
     $this->command .= " nohup ";
     $this->command .= $this->nice;
     $this->command .= $pyCmd . " " . tfb_shellencode($this->tornadoBin);
     $this->command .= " " . tfb_shellencode($this->runtime);
     $this->command .= " " . tfb_shellencode($this->sharekill_param);
     $this->command .= " " . tfb_shellencode($this->owner);
     $this->command .= " " . tfb_shellencode($this->transferFilePath);
     $this->command .= " --responsefile " . tfb_shellencode($this->transferFilePath);
     $this->command .= " --display_interval 1";
     $this->command .= " --max_download_rate " . tfb_shellencode($this->drate);
     $this->command .= " --max_upload_rate " . tfb_shellencode($this->rate);
     $this->command .= " --max_uploads " . tfb_shellencode($this->maxuploads);
     $this->command .= " --minport " . tfb_shellencode($this->port);
     $this->command .= " --maxport " . tfb_shellencode($this->maxport);
     $this->command .= " --rerequest_interval " . tfb_shellencode($this->rerequest);
     $this->command .= " --super_seeder " . tfb_shellencode($this->superseeder);
     $this->command .= " --max_connections " . tfb_shellencode($this->maxcons);
     $this->command .= $skipHashCheck;
     $this->command .= $filePrio;
     if (strlen($cfg["btclient_tornado_options"]) > 0) {
         $this->command .= " " . $cfg["btclient_tornado_options"];
     }
     $this->command .= " 1>> " . tfb_shellencode($this->transferFilePath . ".log");
     $this->command .= " 2>> " . tfb_shellencode($this->transferFilePath . ".log");
     $this->command .= " &";
     // start the client
     $this->_start();
 }