Skip to content

Commit

Permalink
Add api call icon
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirobit committed Dec 13, 2020
1 parent 0f72f30 commit 9c82fe1
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 60 deletions.
56 changes: 28 additions & 28 deletions src/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,45 @@
namespace App;

function createMainContent(){
$peersInfo = getPeerData();
$peerCount = count($peersInfo["peers"]);
$banListInfo = createBanListContent();

$content = [];
$content['bannedPeers'] = $banListInfo['totalBans'];
$content['last24h'] = $banListInfo['lastCount'];
$content['node'] = new Node();
if(Config::PEERS_GEO){
$content['map'] = createMapJs($peerCount, $peersInfo['countryList']);
}
$content['geo'] = Config::PEERS_GEO;
$content['nPeers'] = $peersInfo["newPeersCount"];
$content['chartData'] = getTopClients($peersInfo["peers"]);

// Current peers traffic
$content['cTrafficIn'] = round($peersInfo["cTrafficIn"]/1000, 2);
$content['cTrafficOut'] = round($peersInfo["cTrafficOut"]/1000, 2);

return $content;
$peersData = getPeerData();
$peerCount = count($peersData["peers"]);
$banListInfo = createBanListContent();

$content = [];
$content['bannedPeers'] = $banListInfo['totalBans'];
$content['last24h'] = $banListInfo['lastCount'];
$content['node'] = new Node();
$content['geo'] = Config::PEERS_GEO;
if(isset($peersData['countryList'])) $content['map'] = createMapJs($peerCount, $peersData['countryList']);
if(isset($peersData['api'])) $content['api'] = $peersData['api'];
$content['nPeers'] = $peersData["newPeersCount"];
$content['chartData'] = getTopClients($peersData["peers"]);

// Current peers traffic
$content['cTrafficIn'] = round($peersData["cTrafficIn"]/1000, 2);
$content['cTrafficOut'] = round($peersData["cTrafficOut"]/1000, 2);

return $content;
}

function createPeerContent(){
global $bitcoind;

$peersInfo = getPeerData();
$peersData = getPeerData();
$netinfo = $bitcoind->getnettotals();
$content = getMostPop($peersInfo["peers"]);
$content['peers'] = $peersInfo["peers"];
$content['tPeers'] = count($peersInfo["peers"]);
$content['nPeers'] = $peersInfo["newPeersCount"];
$content = getMostPop($peersData["peers"]);
$content['peers'] = $peersData["peers"];
$content['tPeers'] = count($peersData["peers"]);
$content['nPeers'] = $peersData["newPeersCount"];
//$content['segWitP'] = round($content['segWitC']/($content['tPeers'] > 0 ? $content['tPeers'] : 1),2)*100;
$content['cTraffic'] = round($peersInfo["cTraffic"]/1000,2);
$content['cTrafficIn'] = round($peersInfo["cTrafficIn"]/1000, 2);
$content['cTrafficOut'] = round($peersInfo["cTrafficOut"]/1000, 2);
$content['cTraffic'] = round($peersData["cTraffic"]/1000,2);
$content['cTrafficIn'] = round($peersData["cTrafficIn"]/1000, 2);
$content['cTrafficOut'] = round($peersData["cTrafficOut"]/1000, 2);
$content['tTraffic'] = round(($netinfo["totalbytesrecv"] + $netinfo["totalbytessent"])/1000000000,2);
$content['tTrafficOutP'] = round(($netinfo["totalbytessent"]/($netinfo["totalbytesrecv"] + $netinfo["totalbytessent"])),2)*100;
$content['cTrafficP'] = round($content['cTraffic']/($content['tTraffic'] > 0 ? $content['tTraffic'] : 1),2)*100;
$content['geo'] = Config::PEERS_GEO;
if(isset($peersData['api'])) $content['api'] = $peersData['api'];

return $content;
}
Expand Down
42 changes: 21 additions & 21 deletions src/Utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,16 +479,16 @@ function getPeerData(bool $geo = CONFIG::PEERS_GEO){
}

function createPeersGeo($peerinfo){
$peersInfo['countryList'] = [];
$peersInfo["peers"] = [];
$peerData['countryList'] = [];
$peerData["peers"] = [];
// Current traffic
$peersInfo["cTraffic"] = 0;
$peersInfo["cTrafficIn"] = 0;
$peersInfo["cTrafficOut"] = 0;
$peersInfo["newPeersCount"] = 0;
$peerData["cTraffic"] = 0;
$peerData["cTrafficIn"] = 0;
$peerData["cTrafficOut"] = 0;
$peerData["newPeersCount"] = 0;
// Not used yet
$peersInfo["hosterCount"] = 0;
$peersInfo["privateCount"] = 0;
$peerData["hosterCount"] = 0;
$peerData["privateCount"] = 0;

$noGeoData = false;

Expand Down Expand Up @@ -559,15 +559,15 @@ function createPeersGeo($peerinfo){
// Adds the new peer to the save list
$arrayPeers[$peerObj->id] = array($peerObj->ip, $countryCode, $country, $isp, $hosted, 1);
// Only counted for peers older than 5 minutes
$peersInfo["newPeersCount"]++;
$peerData["newPeersCount"]++;
}elseif($peerObj->age > 5){
// If IP-Api.com call failed we set all data to Unknown and don't store the data
$countryCode = "UN";
$country = "Unknown";
$isp = "Unknown";
$hosted = false;
// Only counted for peers older than 5 minutes
$peersInfo["newPeersCount"]++;
$peerData["newPeersCount"]++;
}else{
// If peer is younger than 5 minutes
$countryCode = "NX";
Expand All @@ -590,11 +590,11 @@ function createPeersGeo($peerinfo){
}

// Counts the countries
if(isset($peersInfo['countryList'][$country])){
$peersInfo['countryList'][$country]['count']++;
if(isset($peerData['countryList'][$country])){
$peerData['countryList'][$country]['count']++;
}else{
$peersInfo['countryList'][$country]['code'] = $countryCode;
$peersInfo['countryList'][$country]['count'] = 1;
$peerData['countryList'][$country]['code'] = $countryCode;
$peerData['countryList'][$country]['count'] = 1;
}

// Adds country data to peer object
Expand All @@ -603,17 +603,17 @@ function createPeersGeo($peerinfo){
$peerObj->isp = $isp;
$peerObj->hosted = $hosted;
if($hosted){
$peersInfo["hosterCount"]++;
$peerData["hosterCount"]++;
}else{
$peersInfo["privateCount"]++;
$peerData["privateCount"]++;
}
// Adds traffic of each peer to total traffic (in MB)
$peersInfo["cTraffic"] += $peerObj->traffic;
$peersInfo["cTrafficIn"] += $peerObj->trafficIn;
$peersInfo["cTrafficOut"] += $peerObj->trafficOut;
$peerData["cTraffic"] += $peerObj->traffic;
$peerData["cTrafficIn"] += $peerObj->trafficIn;
$peerData["cTrafficOut"] += $peerObj->trafficOut;

// Adds peer to peer array
$peersInfo["peers"][] = $peerObj;
$peerData["peers"][] = $peerObj;

}

Expand All @@ -630,7 +630,7 @@ function createPeersGeo($peerinfo){
file_put_contents('data/geodatapeers.inc', $newSerializePeers);
}

return $peersInfo;
return $peerData;
}

function getIpData($ips){
Expand Down
9 changes: 4 additions & 5 deletions views/main.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,10 @@
<h2>Global Peer Distribution</h2>
<ul class="nav navbar-right panel_toolbox">

<li><a class="close-link"><i class="fa fa-close"></i></a>
</li><li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
<li><a><i class="fa fa-question-circle-o" data-toggle="tooltip" data-html="true" data-placement="left" title="BNM will only check the country/isp for peers that are older than 2 minutes."></i></a>
</li>
</li>
<li><a class="close-link"><i class="fa fa-close"></i></a></li>
<li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a></li>
<li><a><i class="fa fa-question-circle-o" data-toggle="tooltip" data-html="true" data-placement="left" title="BNM will only check the country/isp for peers that are older than 5 minutes."></i></a></li>
<?php if(isset($content['api'])) { ?><li><a><i class="fa fa-refresh" data-toggle="tooltip" data-html="true" data-placement="left" title="<?= $content["api"]["callc"] ?> call(s) to API with <?= $content["api"]["ipc"] ?> new ip(s)."></i></a></li><?php }?>

</ul>
<div class="clearfix"></div>
Expand Down
11 changes: 5 additions & 6 deletions views/peers.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@
<div class="x_title">
<h2>Peers <small>Connected</small></h2>
<ul class="nav navbar-right panel_toolbox">
<li><a class="close-link"><i class="fa fa-close"></i></a>
<li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
<li><a><i class="fa fa-question-circle-o" data-toggle="tooltip" data-html="true" data-placement="left" title="
Click the 'Rules' button below to run rules."></i></a>
</li>
<li><a class="close-link"><i class="fa fa-close"></i></a></li>
<li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a></li>
<li><a><i class="fa fa-question-circle-o" data-toggle="tooltip" data-html="true" data-placement="left" title="Click the 'Rules' button below to run rules."></i></a></li>
<?php if(isset($content['api'])) { ?><li><a><i class="fa fa-refresh" data-toggle="tooltip" data-html="true" data-placement="left" title="<?= $content["api"]["callc"] ?> call(s) to API with <?= $content["api"]["ipc"] ?> new ip(s)."></i></a></li><?php }?>
</ul>
<div class="clearfix"></div>
</div>
Expand Down Expand Up @@ -99,7 +98,7 @@
<td style="padding-right:0px;"> <?= $peer->ping ?></td>
<?php if($content['geo']){ ?> <td style="padding-right:0px;"><?php if($peer->hosted){ ?><i class="fa fa-cloud" title="Hosted"></i><?php } else{ ?><span style="padding-left:18px;"></span><?php } ?> <span title="<?= $peer->isp ?>"><?= substr($peer->isp,0,22) ?></span></td> <?php } ?>
<td style="padding-right:0px;"> <?= $peer->age ?></td>
<td style="padding-right:0px;"><?php if($peer->monitoring){ ?><i class="fa fa-binoculars" title="Monitoring"></i><?php } else{ ?><span style="padding-left:18px;"></span><?php } ?> <span title="<?= $peer->client ?>"><?= substr($peer->client,0,13) ?></span></td>
<td style="padding-right:0px;"><?php if($peer->monitoring){ ?><i class="fa fa-binoculars" title="Monitoring"></i><?php } else{ ?><span style="padding-left:18px;"></span><?php } ?> <span title="<?= $peer->client ?>"><?= substr($peer->client,0,14) ?></span></td>
<td style="padding-right:0px;"> <?= $peer->traffic ?></td>
<td style="padding-right:0px;">
<div class="btn-group pull-left" style="padding:5px 0 3px 0px; margin-bottom:0px">
Expand Down

0 comments on commit 9c82fe1

Please sign in to comment.