From e70d422da5b14e0a437e5dc24ac94d5a0bd1aba5 Mon Sep 17 00:00:00 2001 From: pxgamer Date: Thu, 18 Oct 2018 23:05:08 +0100 Subject: [PATCH 1/7] Add peers array to the configuration sample --- include/config-sample.inc.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/config-sample.inc.php b/include/config-sample.inc.php index b0b467c..7b29dc1 100755 --- a/include/config-sample.inc.php +++ b/include/config-sample.inc.php @@ -54,6 +54,9 @@ $_config['transaction_propagation_peers'] = 5; // How many new peers to check from each peer $_config['max_test_peers'] = 5; +// The initial peers to sync from in sanity +$_config['initial_peer_list'] = []; + /* |-------------------------------------------------------------------------- | Mempool Configuration From 30c76cab5c169b78c9064514e9c655164a996cdc Mon Sep 17 00:00:00 2001 From: pxgamer Date: Fri, 19 Oct 2018 09:30:11 +0100 Subject: [PATCH 2/7] Add Arionum exception class --- include/Exception.php | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 include/Exception.php diff --git a/include/Exception.php b/include/Exception.php new file mode 100644 index 0000000..e724369 --- /dev/null +++ b/include/Exception.php @@ -0,0 +1,11 @@ + Date: Fri, 19 Oct 2018 09:49:53 +0100 Subject: [PATCH 3/7] Add initial peers from the peer file --- include/config-sample.inc.php | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/include/config-sample.inc.php b/include/config-sample.inc.php index 7b29dc1..63f13d4 100755 --- a/include/config-sample.inc.php +++ b/include/config-sample.inc.php @@ -55,7 +55,35 @@ $_config['transaction_propagation_peers'] = 5; $_config['max_test_peers'] = 5; // The initial peers to sync from in sanity -$_config['initial_peer_list'] = []; +$_config['initial_peer_list'] = [ + 'http://peer1.arionum.com', + 'http://peer2.arionum.com', + 'http://peer3.arionum.com', + 'http://peer4.arionum.com', + 'http://peer5.arionum.com', + 'http://peer6.arionum.com', + 'http://peer7.arionum.com', + 'http://peer8.arionum.com', + 'http://peer9.arionum.com', + 'http://peer10.arionum.com', + 'http://peer11.arionum.com', + 'http://peer12.arionum.com', + 'http://peer13.arionum.com', + 'http://peer14.arionum.com', + 'http://peer15.arionum.com', + 'http://peer16.arionum.com', + 'http://peer17.arionum.com', + 'http://peer18.arionum.com', + 'http://peer19.arionum.com', + 'http://peer20.arionum.com', + 'http://peer21.arionum.com', + 'http://peer22.arionum.com', + 'http://peer23.arionum.com', + 'http://peer24.arionum.com', + 'http://peer25.arionum.com', + 'http://peer26.arionum.com', + 'http://peer27.arionum.com', +]; /* |-------------------------------------------------------------------------- @@ -72,7 +100,7 @@ $_config['max_mempool_rebroadcast'] = 5000; // The number of blocks between rebroadcasting transactions $_config['sanity_rebroadcast_height'] = 30; -// Block accepting transfers from addresses blacklisted by the Arionum devs +// Block accepting transfers from addresses blacklisted by the Arionum devs $_config['use_official_blacklist'] = true; /* From 4c79b7f460c2225413ca67023ed3bd4f365892f3 Mon Sep 17 00:00:00 2001 From: pxgamer Date: Fri, 19 Oct 2018 09:57:29 +0100 Subject: [PATCH 4/7] Add InitialPeers class for manging initial peers --- include/InitialPeers.php | 81 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 include/InitialPeers.php diff --git a/include/InitialPeers.php b/include/InitialPeers.php new file mode 100644 index 0000000..9f71707 --- /dev/null +++ b/include/InitialPeers.php @@ -0,0 +1,81 @@ +peerList = $peerList; + } + + /** + * Retrieve a peer from the initial peer list. + * @return string + * @throws Exception + */ + public function get(): string + { + if (!$this->peerList || count($this->peerList) < self::MINIMUM_PEERS_REQUIRED) { + $this->retrieveFromPreloadList(); + } + + return $this->selectPeer(); + } + + /** + * Retrieve all available initial peers. + * @return array + * @throws Exception + */ + public function getAll(): array + { + if (!$this->peerList || count($this->peerList) < self::MINIMUM_PEERS_REQUIRED) { + $this->retrieveFromPreloadList(); + } + + return $this->peerList; + } + + /** + * @return string + */ + private function selectPeer(): string + { + return $this->peerList[array_rand($this->peerList)]; + } + + /** + * Retrieve a peer from + * + * @return void + * @throws Exception + */ + private function retrieveFromPreloadList(): void + { + $peerList = file(self::PRELOAD_LIST, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + + if (!$peerList || count($peerList) < self::MINIMUM_PEERS_REQUIRED) { + throw new Exception(self::PRELOAD_ERROR); + } + + $this->peerList = $peerList; + } +} From 5bbbca15a97462b271493019d9ffd75e82035637 Mon Sep 17 00:00:00 2001 From: pxgamer Date: Fri, 19 Oct 2018 10:01:07 +0100 Subject: [PATCH 5/7] Update the sanity process to use InitialPeers --- sanity.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/sanity.php b/sanity.php index 736e0cc..72d362d 100755 --- a/sanity.php +++ b/sanity.php @@ -60,8 +60,8 @@ if ($arg != "microsanity") { sleep(3); } - require_once("include/init.inc.php"); +require_once __DIR__.'/include/InitialPeers.php'; if ($argv[1]=="dev") { error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE); @@ -267,16 +267,20 @@ $peered = []; // if we have no peers, get the seed list from the official site if ($total_peers == 0 && $_config['testnet'] == false) { $i = 0; - echo "No peers found. Attempting to get peers from arionum.com\n"; - $f = file("https://www.arionum.com/peers.txt"); - shuffle($f); - // we can't connect to arionum.com - if (count($f) < 2) { - @unlink("tmp/sanity-lock"); - die("Could not connect to arionum.com! Will try later!\n"); + echo 'No peers found. Attempting to get peers from the initial list.'.PHP_EOL; + + $initialPeers = new \Arionum\InitialPeers($_config['initial_peer_list'] ?? []); + + try { + $peers = $initialPeers->getAll(); + } catch (\Arionum\Exception $e) { + @unlink('tmp/sanity-lock'); + die($e->getMessage().PHP_EOL); } - foreach ($f as $peer) { - //peer with all until max_peers, this will ask them to send a peering request to our peer.php where we add their peer to the db. + + foreach ($peers as $peer) { + // Peer with all until max_peers + // This will ask them to send a peering request to our peer.php where we add their peer to the db. $peer = trim(san_host($peer)); $bad_peers = ["127.", "localhost", "10.", "192.168.","172.16.","172.17.","172.18.","172.19.","172.20.","172.21.","172.22.","172.23.","172.24.","172.25.","172.26.","172.27.","172.28.","172.29.","172.30.","172.31."]; From ca9e95e7af246698ce6b9cb4563a31183b4b8b82 Mon Sep 17 00:00:00 2001 From: pxgamer Date: Sat, 20 Oct 2018 18:04:33 +0100 Subject: [PATCH 6/7] Move loading of new files to the init file --- include/init.inc.php | 2 ++ sanity.php | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/init.inc.php b/include/init.inc.php index a0171eb..b833864 100755 --- a/include/init.inc.php +++ b/include/init.inc.php @@ -13,10 +13,12 @@ if (php_sapi_name() !== 'cli' && substr_count($_SERVER['PHP_SELF'], "/") > 1) { die("This application should only be run in the main directory /"); } +require_once __DIR__.'/Exception.php'; require_once("include/config.inc.php"); require_once("include/db.inc.php"); require_once("include/functions.inc.php"); require_once __DIR__.'/Blacklist.php'; +require_once __DIR__.'/InitialPeers.php'; require_once("include/block.inc.php"); require_once("include/account.inc.php"); require_once("include/transaction.inc.php"); diff --git a/sanity.php b/sanity.php index 72d362d..542344d 100755 --- a/sanity.php +++ b/sanity.php @@ -60,8 +60,7 @@ if ($arg != "microsanity") { sleep(3); } -require_once("include/init.inc.php"); -require_once __DIR__.'/include/InitialPeers.php'; +require_once __DIR__.'/include/init.inc.php'; if ($argv[1]=="dev") { error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE); From 98dba661b1bc4b7744eecf52d558279fa0b6c5aa Mon Sep 17 00:00:00 2001 From: pxgamer Date: Sat, 20 Oct 2018 18:15:14 +0100 Subject: [PATCH 7/7] Change namespace to Arionum\Node --- include/Exception.php | 2 +- include/InitialPeers.php | 2 +- sanity.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/Exception.php b/include/Exception.php index e724369..68b9b8e 100644 --- a/include/Exception.php +++ b/include/Exception.php @@ -1,6 +1,6 @@ getAll(); - } catch (\Arionum\Exception $e) { + } catch (\Arionum\Node\Exception $e) { @unlink('tmp/sanity-lock'); die($e->getMessage().PHP_EOL); }