Skip to content

Commit

Permalink
Fix problem with non-8333 working nodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Corallo committed Dec 18, 2011
1 parent a18fc3c commit d29dfa9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bitcoin-scan.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
if (!empty($nodes)) {
start_db_transaction();
if ($port == 8333)
add_node_to_dns($arr[0], $origNode->getVersion());
add_node_to_dns($arr[0], $port, $origNode->getVersion());

foreach ($nodes as &$node) {
if ($node["services1"] == 1 && $node["services2"] == 0 && $node["timestamp"] >= time() - $CONFIG['MIN_LAST_SEEN'])
Expand Down
22 changes: 11 additions & 11 deletions global.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,24 @@ function commit_db_transaction() {
}
function add_node_to_dns($ip, $version) {
function add_node_to_dns($ip, $port, $version) {
global $db, $CONFIG;
if (empty($db))
connect_to_db();
if (!empty($ip) && ip2long($ip) != 0 && is_numeric($version) && $version > 0) {
if (!empty($ip) && ip2long($ip) != 0 && !empty($port) && is_numeric($port) && $port != 0 && is_numeric($version) && $version > 0) {
$db->query("INSERT INTO `".$CONFIG['MYSQL_BITCOIN_TABLE']."` "
."(`ipv4`, `accepts_incoming`, `last_check`, `version`, `first_up`) VALUES "
."('" . ip2long($ip) . "' , b'1', NOW(), '" . $version . "', NOW());");
."(`ipv4`, `port`, `accepts_incoming`, `last_check`, `version`, `first_up`) VALUES "
."('" . ip2long($ip) . "', '" . $port . "', b'1', NOW(), '" . $version . "', NOW());");
$db->query("UPDATE `".$CONFIG['MYSQL_BITCOIN_TABLE']."` SET "
."`accepts_incoming` = b'1', "
."`last_check` = NOW(), "
."`version` = '" . $version . "', "
."`first_up` = IF(`first_up` IS NULL, NOW(), `first_up`) "
."WHERE `ipv4` = '" . ip2long($ip) . "' AND `port` = '8333';");
."WHERE `ipv4` = '" . ip2long($ip) . "' AND `port` = '" . $port . "';");
}
if (!empty($ip) && ip2long($ip) != 0 && $version >= $CONFIG['MIN_VERSION'])
if (!empty($ip) && ip2long($ip) != 0 && $version >= $CONFIG['MIN_VERSION'] && $port == 8333)
$db->query("INSERT INTO `".$CONFIG['MYSQL_PDNS_DB']."`.`".$CONFIG['MYSQL_PDNS_RECORDS_TABLE']."` "
."(`domain_id`, `name`, `type`, `content`, `ttl`, `prio`, `change_date`) VALUES "
."('" . $CONFIG['PDNS_DOMAIN_ID'] . "', '" . $CONFIG['DOMAIN_NAME'] . "', 'A', '" . $ip . "', '" . $CONFIG['PDNS_RECORD_TTL'] . "', '0', '" . date("Ymd") . "00');");
Expand Down Expand Up @@ -177,22 +177,22 @@ function commit_db_transaction() {
$transaction_open = false;
}

function add_node_to_dns($ip, $version) {
function add_node_to_dns($ip, $port, $version) {
global $db, $CONFIG;
if (empty($db))
connect_to_db();

if (!empty($ip) && ip2long($ip) != 0 && is_numeric($version) && $version > 0) {
if (!empty($ip) && ip2long($ip) != 0 && !empty($port) && is_numeric($port) && $port != 0 && is_numeric($version) && $version > 0) {
@$db->exec("INSERT INTO nodes "
."(ipv4, accepts_incoming, last_check, version, last_seen, first_up) VALUES "
."(" . ip2long($ip) . " , 1, ".time().", " . $version . ",".time().", ".time().");");
."(ipv4, port, accepts_incoming, last_check, version, last_seen, first_up) VALUES "
."(" . ip2long($ip) . ", " . $port . ", 1, ".time().", " . $version . ",".time().", ".time().");");
$db->exec("UPDATE nodes SET "
."accepts_incoming = 1, "
."last_check = ".time().", "
."version = " . $version . ", "
."last_seen = ".time().", "
."first_up = CASE WHEN first_up > 0 THEN first_up ELSE ".time()." END "
."WHERE ipv4 = " . ip2long($ip) . " AND port = 8333;");
."WHERE ipv4 = " . ip2long($ip) . " AND port = " . $port . ";");
}
}

Expand Down

0 comments on commit d29dfa9

Please sign in to comment.