function antiConcurrency(ISblamPost $p) { return; // slows down server under heavy load :( $ip = $p->getAuthorIP(); if (!apc_add('ip.lock:' . $ip, 1, 2) && apc_fetch('ip-ban:' . $ip) < time()) { $wait = 500000 + 100000 * (mt_rand() % 10); usleep($wait); $this->waittime += $wait; d("*Throttled*"); } }
function testPost(ISblamPost $p) { if (!$this->checksum) { return; } $res = $this->db->query(sprintf("/*maxtime5*/SELECT count,ip FROM dupes WHERE checksum = UNHEX('%s') LIMIT 1", $this->checksum)); if ($res) { $res = $res->fetchAll(); } else { return NULL; } if (count($res)) { $res = $res[0]; $allowed = 2; // double-posting? if (false !== strpos($p->getPath(), 'editpost')) { $allowed++; } $score = ($res['count'] - $allowed) / 15; $cert = self::CERTAINITY_LOW; if ($res['count'] > 35) { $score += 2; $cert = self::CERTAINITY_HIGH; } elseif ($res['count'] > 20) { $score += 0.8; $cert = self::CERTAINITY_HIGH; } elseif ($res['count'] > 10) { $score += 0.4; $cert = self::CERTAINITY_HIGH; } elseif ($res['count'] > 5) { $score += 0.2; $cert = self::CERTAINITY_NORMAL; } $ip = long2ip($res['ip']); if ($ip != $p->getAuthorIP()) { $score = ($score + 0.3) * 1.2; } // different IP? botnet! if ($this->length > 250) { $score = ($score + 0.1) * 1.5; } // less likely to accidentally dupe if ($score > 0.1) { $score = min($score, 2) + min($score / 5, 4); return array($score, $cert, "Duplicate (x" . round($res['count']) . " = " . round($score, 1) . ")"); } } }