function corePeerPing($peer) { $key = rand(0, 10000); $db = new db(OPENHELLOS); if (!$db->addSingle(array('key' => $key, 'Hash' => $peer->getHash()))) { die(ERR_YACY_DB_SAVE); } $host = 'http://' . $peer->getAddress() . '/yacy/hello.html'; $args = "key={$key}&seed=" . MYHASH . "&count=20"; $hello = explode("\n", file_get_contents("{$host}?{$args}")); $arr = splitArray(array_slice($hello, 0, 4)); updatePeer($peer->getHash(), $arr['myversion'], $arr['uptime'], $arr['mytype']); updateFromSeeds(array_slice($hello, 5)); }
function start($info_hash, $ip, $port, $peer_id, $left, $uploaded, $clientVer) { if ($left == 0) { $status = "seeder"; } else { $status = "leecher"; } if (@isFireWalled($info_hash, $peer_id, $ip, $port)) { $nat = "'Y'"; } else { $nat = "'N'"; } $results = @mysql_query("INSERT INTO x{$info_hash} SET peer_id=\"{$peer_id}\", port=\"{$port}\", ip=\"{$ip}\", lastupdate=UNIX_TIMESTAMP(), bytes=\"{$left}\", status=\"{$status}\", natuser={$nat}, uploaded={$uploaded}, clientversion=\"{$clientVer}\""); // Special case: duplicated peer_id. if (!$results) { $error = mysql_error(); if (stristr($error, "key")) { // Duplicate peer_id! Check IP address $peer = getPeerInfo($peer_id, $info_hash); if ($ip == $peer["ip"]) { // Same IP address. Tolerate this error. updatePeer($peer_id, $info_hash); return "WHERE natuser='******'"; } //showError("Duplicated peer_id or changed IP address. Please restart BitTorrent."); // Different IP address. Assume they were disconnected, and alter the IP address. quickQuery("UPDATE x{$info_hash} SET ip=\"{$ip}\", uploaded={$uploaded}, clientversion=\"{$clientVer}\" WHERE peer_id=\"{$peer_id}\""); return "WHERE natuser='******'"; } error_log("PHPBTTracker: start: " . $error); showError("Tracker/database error. The details are in the error log."); } $GLOBALS["trackerid"] = mysql_insert_id(); if ($GLOBALS["peercaching"]) { $compact = mysql_real_escape_string(pack('Nn', ip2long($ip), $port)); $peerid = mysql_real_escape_string('2:ip' . strlen($ip) . ':' . $ip . '7:peer id20:' . hex2bin($peer_id) . "4:porti{$port}e"); $no_peerid = mysql_real_escape_string('2:ip' . strlen($ip) . ':' . $ip . "4:porti{$port}e"); mysql_query("INSERT INTO y{$info_hash} SET sequence=\"{$GLOBALS["trackerid"]}\", compact=\"{$compact}\", with_peerid=\"{$peerid}\", without_peerid=\"{$no_peerid}\""); // Let's just assume success... :/ } if ($left == 0) { summaryAdd("seeds", 1); return "WHERE status=\"leecher\" AND natuser='******'"; } else { summaryAdd("leechers", 1); return "WHERE natuser='******'"; } }
function start($info_hash, $ip, $port, $peer_id, $left) { if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) { foreach (explode(",", $_SERVER["HTTP_X_FORWARDED_FOR"]) as $address) { $addr = ip2long(trim($address)); if ($addr != -1) { if ($addr >= -1062731776 && $addr <= -1062666241) { // 192.168.x.x } else { if ($addr >= -1442971648 && $addr <= -1442906113) { // 169.254.x.x } else { if ($addr >= 167772160 && $addr <= 184549375) { // 10.x.x.x } else { if ($addr >= 2130706432 && $addr <= 2147483647) { // 127.0.0.1 } else { if ($addr >= -1408237568 && $addr <= -1407188993) { // 172.[16-31].x.x } else { // Finally, we can accept it as a "real" ip address. $ip = mysql_escape_string(trim($address)); break; } } } } } } } } if (isset($_GET["ip"]) && $GLOBALS["ip_override"]) { // compact check: valid IP address: if (ip2long($_GET["ip"]) == -1) { showError("Invalid IP address. Must be standard dotted decimal (hostnames not allowed)"); } $ip = mysql_escape_string($_GET["ip"]); } if ($left == 0) { $status = "seeder"; } else { $status = "leecher"; } if (@isFireWalled($info_hash, $peer_id, $ip, $port)) { $nat = "'Y'"; } else { $nat = "'N'"; } $results = @mysql_query("INSERT INTO x{$info_hash} SET peer_id=\"{$peer_id}\", port=\"{$port}\", ip=\"{$ip}\", lastupdate=UNIX_TIMESTAMP(), bytes=\"{$left}\", status=\"{$status}\", natuser={$nat}"); // Special case: duplicated peer_id. if (!$results) { $error = mysql_error(); if (stristr($error, "key")) { // Duplicate peer_id! Check IP address $peer = getPeerInfo($peer_id, $info_hash); if ($ip == $peer["ip"]) { // Same IP address. Tolerate this error. updatePeer($peer_id, $info_hash); return "WHERE natuser='******'"; } //showError("Duplicated peer_id or changed IP address. Please restart BitTorrent."); // Different IP address. Assume they were disconnected, and alter the IP address. quickQuery("UPDATE x{$info_hash} SET ip=\"{$ip}\" WHERE peer_id=\"{$peer_id}\""); return "WHERE natuser='******'"; } error_log("PHPBTTracker: start: " . $error); showError("Tracker/database error. The details are in the error log."); } $GLOBALS["trackerid"] = mysql_insert_id(); if ($GLOBALS["peercaching"]) { $compact = mysql_escape_string(pack('Nn', ip2long($ip), $port)); $peerid = mysql_escape_string('2:ip' . strlen($ip) . ':' . $ip . '7:peer id20:' . hex2bin($peer_id) . "4:porti{$port}e"); $no_peerid = mysql_escape_string('2:ip' . strlen($ip) . ':' . $ip . "4:porti{$port}e"); mysql_query("INSERT INTO y{$info_hash} SET sequence=\"{$GLOBALS["trackerid"]}\", compact=\"{$compact}\", with_peerid=\"{$peerid}\", without_peerid=\"{$no_peerid}\""); // Let's just assume success... :/ } if ($left == 0) { summaryAdd("seeds", 1); return "WHERE status=\"leecher\" AND natuser='******'"; } else { summaryAdd("leechers", 1); return "WHERE natuser='******'"; } }