mirror of
https://github.com/YGGverse/YGGstate.git
synced 2025-02-09 13:14:20 +00:00
implement tracker, peers JSON API
This commit is contained in:
parent
f03da2cd3d
commit
606a6f1cac
3
.gitignore
vendored
3
.gitignore
vendored
@ -6,5 +6,8 @@
|
|||||||
|
|
||||||
/src/config/app.php
|
/src/config/app.php
|
||||||
|
|
||||||
|
/src/public/api/peers.json
|
||||||
|
/src/public/api/trackers.json
|
||||||
|
|
||||||
.ftpignore
|
.ftpignore
|
||||||
composer.lock
|
composer.lock
|
||||||
|
@ -54,7 +54,12 @@ git checkout -b my-pr-branch-name
|
|||||||
|
|
||||||
#### Roadmap
|
#### Roadmap
|
||||||
|
|
||||||
* [ ] Federated tracking API
|
API
|
||||||
|
* [x] trackers
|
||||||
|
* [x] peers
|
||||||
|
|
||||||
|
Crawler
|
||||||
|
* [ ] federated model
|
||||||
|
|
||||||
#### Donate to contributors
|
#### Donate to contributors
|
||||||
|
|
||||||
|
@ -72,12 +72,13 @@ define('WEBSITE_PEER_REMOTE_PAGINATION_LIMIT', 20);
|
|||||||
|
|
||||||
define('WEBSITE_PEER_PORT_CHECK_TIMEOUT', 60 * 5);
|
define('WEBSITE_PEER_PORT_CHECK_TIMEOUT', 60 * 5);
|
||||||
|
|
||||||
// Trackers
|
// API
|
||||||
define('TRACKER_PUBLIC_PEERS', (object)
|
define('API_PEERS', (object)
|
||||||
[
|
[
|
||||||
'tls://94.140.114.241:4708',
|
'tls://94.140.114.241:4708' => WEBSITE_URL,
|
||||||
// ...
|
// ...
|
||||||
]);
|
]
|
||||||
|
);
|
||||||
|
|
||||||
// Crawler
|
// Crawler
|
||||||
define('CRAWL_STOP_DISK_QUOTA_MB_LEFT', 128);
|
define('CRAWL_STOP_DISK_QUOTA_MB_LEFT', 128);
|
@ -129,286 +129,315 @@ try {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect connected peers
|
// Delete cache
|
||||||
|
@unlink(__DIR__ . '/../public/api/peers.json');
|
||||||
|
@unlink(__DIR__ . '/../public/api/trackers.json');
|
||||||
|
|
||||||
|
// Update peers
|
||||||
if ($connectedPeers = Yggverse\Yggdrasilctl\Yggdrasil::getPeers()) {
|
if ($connectedPeers = Yggverse\Yggdrasilctl\Yggdrasil::getPeers()) {
|
||||||
|
|
||||||
foreach ($connectedPeers as $connectedPeerAddress => $connectedPeerInfo) {
|
if ($handle = fopen(__DIR__ . '/../public/api/peers.json', 'w+')) {
|
||||||
|
fwrite($handle, json_encode($connectedPeers));
|
||||||
|
fclose($handle);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
} else {
|
||||||
|
|
||||||
$db->beginTransaction();
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
// Init peer
|
// Update trackers
|
||||||
if ($dbPeer = $db->findPeer($connectedPeerAddress)) {
|
if (API_PEERS) {
|
||||||
|
|
||||||
$dbPeerId = $dbPeer->peerId;
|
if ($handle = fopen(__DIR__ . '/../public/api/trackers.json', 'w+')) {
|
||||||
|
fwrite($handle, json_encode(API_PEERS));
|
||||||
|
fclose($handle);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if ($dbPeerId = $db->addPeer($connectedPeerAddress, $connectedPeerInfo->key, time())) {
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
$debug['yggdrasil']['peer']['total']['insert']++;
|
// @TODO merge peers data from remote trackers
|
||||||
}
|
|
||||||
|
// Collect connected peers
|
||||||
|
foreach ($connectedPeers as $connectedPeerAddress => $connectedPeerInfo) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
$db->beginTransaction();
|
||||||
|
|
||||||
|
// Init peer
|
||||||
|
if ($dbPeer = $db->findPeer($connectedPeerAddress)) {
|
||||||
|
|
||||||
|
$dbPeerId = $dbPeer->peerId;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if ($dbPeerId = $db->addPeer($connectedPeerAddress, $connectedPeerInfo->key, time())) {
|
||||||
|
|
||||||
|
$debug['yggdrasil']['peer']['total']['insert']++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Init peer session
|
// Init peer session
|
||||||
if ($dbLastPeerSession = $db->findLastPeerSessionByPeerId($dbPeerId)) {
|
if ($dbLastPeerSession = $db->findLastPeerSessionByPeerId($dbPeerId)) {
|
||||||
|
|
||||||
$dbPeerSessionId = $dbLastPeerSession->peerSessionId;
|
$dbPeerSessionId = $dbLastPeerSession->peerSessionId;
|
||||||
|
|
||||||
// If remote session uptime < than stored, register new one
|
// If remote session uptime < than stored, register new one
|
||||||
if ($connectedPeerInfo->uptime < $dbLastPeerSession->uptime) {
|
if ($connectedPeerInfo->uptime < $dbLastPeerSession->uptime) {
|
||||||
|
|
||||||
if ($dbPeerSessionId = $db->addPeerSession($dbPeerId,
|
|
||||||
round($connectedPeerInfo->uptime),
|
|
||||||
$connectedPeerInfo->bytes_sent,
|
|
||||||
$connectedPeerInfo->bytes_recvd,
|
|
||||||
time())) {
|
|
||||||
|
|
||||||
$debug['yggdrasil']['peer']['session']['total']['insert']++;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
$debug['yggdrasil']['peer']['session']['total']['update'] +=
|
|
||||||
$db->updatePeerSession($dbLastPeerSession->peerSessionId,
|
|
||||||
round($connectedPeerInfo->uptime),
|
|
||||||
$connectedPeerInfo->bytes_sent,
|
|
||||||
$connectedPeerInfo->bytes_recvd,
|
|
||||||
time());
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if ($dbPeerSessionId = $db->addPeerSession($dbPeerId,
|
if ($dbPeerSessionId = $db->addPeerSession($dbPeerId,
|
||||||
round($connectedPeerInfo->uptime),
|
round($connectedPeerInfo->uptime),
|
||||||
$connectedPeerInfo->bytes_sent,
|
$connectedPeerInfo->bytes_sent,
|
||||||
$connectedPeerInfo->bytes_recvd,
|
$connectedPeerInfo->bytes_recvd,
|
||||||
time())) {
|
time())) {
|
||||||
|
|
||||||
$debug['yggdrasil']['peer']['session']['total']['insert']++;
|
$debug['yggdrasil']['peer']['session']['total']['insert']++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Init peer coordinate
|
|
||||||
if ($dbPeerCoordinate = $db->findLastPeerCoordinateByPeerId($dbPeerId)) {
|
|
||||||
|
|
||||||
$dbPeerCoordinateId = $dbPeerCoordinate->peerCoordinateId;
|
|
||||||
|
|
||||||
// Peer have changed it port, init new coordinate
|
|
||||||
if ($dbPeerCoordinate->port != $connectedPeerInfo->port) {
|
|
||||||
|
|
||||||
if ($dbPeerCoordinateId = $db->addPeerCoordinate($dbPeerId, $connectedPeerInfo->port, time())) {
|
|
||||||
|
|
||||||
$debug['yggdrasil']['peer']['coordinate']['total']['insert']++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
$debug['yggdrasil']['peer']['session']['total']['update'] +=
|
||||||
|
$db->updatePeerSession($dbLastPeerSession->peerSessionId,
|
||||||
|
round($connectedPeerInfo->uptime),
|
||||||
|
$connectedPeerInfo->bytes_sent,
|
||||||
|
$connectedPeerInfo->bytes_recvd,
|
||||||
|
time());
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if ($dbPeerSessionId = $db->addPeerSession($dbPeerId,
|
||||||
|
round($connectedPeerInfo->uptime),
|
||||||
|
$connectedPeerInfo->bytes_sent,
|
||||||
|
$connectedPeerInfo->bytes_recvd,
|
||||||
|
time())) {
|
||||||
|
|
||||||
|
$debug['yggdrasil']['peer']['session']['total']['insert']++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init peer coordinate
|
||||||
|
if ($dbPeerCoordinate = $db->findLastPeerCoordinateByPeerId($dbPeerId)) {
|
||||||
|
|
||||||
|
$dbPeerCoordinateId = $dbPeerCoordinate->peerCoordinateId;
|
||||||
|
|
||||||
|
// Peer have changed it port, init new coordinate
|
||||||
|
if ($dbPeerCoordinate->port != $connectedPeerInfo->port) {
|
||||||
|
|
||||||
if ($dbPeerCoordinateId = $db->addPeerCoordinate($dbPeerId, $connectedPeerInfo->port, time())) {
|
if ($dbPeerCoordinateId = $db->addPeerCoordinate($dbPeerId, $connectedPeerInfo->port, time())) {
|
||||||
|
|
||||||
$debug['yggdrasil']['peer']['coordinate']['total']['insert']++;
|
$debug['yggdrasil']['peer']['coordinate']['total']['insert']++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init peer coordinate route
|
} else {
|
||||||
$dbCoords = [];
|
|
||||||
foreach ($db->findPeerCoordinateRouteByCoordinateId($dbPeerCoordinateId) as $dbPeerCoordinateRoute) {
|
if ($dbPeerCoordinateId = $db->addPeerCoordinate($dbPeerId, $connectedPeerInfo->port, time())) {
|
||||||
$dbCoords[$dbPeerCoordinateRoute->level] = $dbPeerCoordinateRoute->port;
|
|
||||||
|
$debug['yggdrasil']['peer']['coordinate']['total']['insert']++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init peer coordinate route
|
||||||
|
$dbCoords = [];
|
||||||
|
foreach ($db->findPeerCoordinateRouteByCoordinateId($dbPeerCoordinateId) as $dbPeerCoordinateRoute) {
|
||||||
|
$dbCoords[$dbPeerCoordinateRoute->level] = $dbPeerCoordinateRoute->port;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compare remote / local route, create new on changed
|
||||||
|
if ($dbCoords !== $connectedPeerInfo->coords) {
|
||||||
|
|
||||||
|
if ($dbPeerCoordinateId = $db->addPeerCoordinate($dbPeerId, $connectedPeerInfo->port, time())) {
|
||||||
|
|
||||||
|
$debug['yggdrasil']['peer']['coordinate']['total']['insert']++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compare remote / local route, create new on changed
|
foreach ($connectedPeerInfo->coords as $level => $port) {
|
||||||
if ($dbCoords !== $connectedPeerInfo->coords) {
|
|
||||||
|
|
||||||
if ($dbPeerCoordinateId = $db->addPeerCoordinate($dbPeerId, $connectedPeerInfo->port, time())) {
|
if ($db->addPeerCoordinateRoute($dbPeerCoordinateId, $level, $port)) {
|
||||||
|
|
||||||
$debug['yggdrasil']['peer']['coordinate']['total']['insert']++;
|
$debug['yggdrasil']['peer']['coordinate']['route']['total']['insert']++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($connectedPeerInfo->coords as $level => $port) {
|
// Init peer remote
|
||||||
|
if ($connectedPeerRemoteUrl = Yggverse\Parser\Url::parse($connectedPeerInfo->remote)) {
|
||||||
|
|
||||||
if ($db->addPeerCoordinateRoute($dbPeerCoordinateId, $level, $port)) {
|
// Init peer scheme
|
||||||
|
if ($dbPeerRemoteScheme = $db->findPeerRemoteScheme($connectedPeerRemoteUrl->host->scheme)) {
|
||||||
|
|
||||||
$debug['yggdrasil']['peer']['coordinate']['route']['total']['insert']++;
|
$dbPeerRemoteSchemeId = $dbPeerRemoteScheme->peerRemoteSchemeId;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if ($dbPeerRemoteSchemeId = $db->addPeerRemoteScheme($connectedPeerRemoteUrl->host->scheme, time())) {
|
||||||
|
|
||||||
|
$debug['yggdrasil']['peer']['remote']['scheme']['total']['insert']++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init peer host
|
||||||
|
if ($dbPeerRemoteHost = $db->findPeerRemoteHost($connectedPeerRemoteUrl->host->name)) {
|
||||||
|
|
||||||
|
$dbPeerRemoteHostId = $dbPeerRemoteHost->peerRemoteHostId;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if ($dbPeerRemoteHostId = $db->addPeerRemoteHost($connectedPeerRemoteUrl->host->name, time())) {
|
||||||
|
|
||||||
|
$debug['yggdrasil']['peer']['remote']['host']['total']['insert']++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init peer port
|
||||||
|
if ($dbPeerRemotePort = $db->findPeerRemotePort($connectedPeerRemoteUrl->host->port)) {
|
||||||
|
|
||||||
|
$dbPeerRemotePortId = $dbPeerRemotePort->peerRemotePortId;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if ($dbPeerRemotePortId = $db->addPeerRemotePort($connectedPeerRemoteUrl->host->port, time())) {
|
||||||
|
|
||||||
|
$debug['yggdrasil']['peer']['remote']['port']['total']['insert']++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init geo data
|
||||||
|
|
||||||
|
/// Country
|
||||||
|
$countryIsoCode = $geoIp2Country->country($connectedPeerRemoteUrl->host->name)->country->isoCode;
|
||||||
|
$countryName = $geoIp2Country->country($connectedPeerRemoteUrl->host->name)->country->name;
|
||||||
|
|
||||||
|
$dbGeoCountryId = null;
|
||||||
|
|
||||||
|
if (!empty($countryIsoCode) && !empty($countryName)) {
|
||||||
|
|
||||||
|
if ($dbGeoCountry = $db->findGeoCountryByIsoCode($countryIsoCode)) {
|
||||||
|
|
||||||
|
$dbGeoCountryId = $dbGeoCountry->geoCountryId;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if ($dbGeoCountryId = $db->addGeoCountry($countryIsoCode, $countryName)) {
|
||||||
|
|
||||||
|
$debug['yggdrasil']['geo']['country']['total']['insert']++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// City
|
||||||
|
$cityName = $geoIp2City->city($connectedPeerRemoteUrl->host->name)->city->name;
|
||||||
|
|
||||||
|
$dbGeoCityId = null;
|
||||||
|
|
||||||
|
if (!empty($cityName)) {
|
||||||
|
|
||||||
|
if ($dbGeoCity = $db->findGeoCityByName($cityName)) {
|
||||||
|
|
||||||
|
$dbGeoCityId = $dbGeoCity->geoCityId;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if ($dbGeoCityId = $db->addGeoCity($cityName)) {
|
||||||
|
|
||||||
|
$debug['yggdrasil']['geo']['city']['total']['insert']++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Coordinate
|
||||||
|
$latitude = $geoIp2City->city($connectedPeerRemoteUrl->host->name)->location->latitude;
|
||||||
|
$longitude = $geoIp2City->city($connectedPeerRemoteUrl->host->name)->location->longitude;
|
||||||
|
|
||||||
|
$dbGeoCoordinateId = null;
|
||||||
|
|
||||||
|
if (!empty($latitude) && !empty($longitude)) {
|
||||||
|
|
||||||
|
if ($dbGeoCoordinate = $db->findGeoCoordinate($geoIp2City->city($connectedPeerRemoteUrl->host->name)->location->latitude,
|
||||||
|
$geoIp2City->city($connectedPeerRemoteUrl->host->name)->location->longitude)) {
|
||||||
|
|
||||||
|
$dbGeoCoordinateId = $dbGeoCoordinate->geoCoordinateId;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if ($dbGeoCoordinateId = $db->addGeoCoordinate($geoIp2City->city($connectedPeerRemoteUrl->host->name)->location->latitude,
|
||||||
|
$geoIp2City->city($connectedPeerRemoteUrl->host->name)->location->longitude)) {
|
||||||
|
|
||||||
|
$debug['yggdrasil']['geo']['coordinate']['total']['insert']++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Geo
|
||||||
|
$dbGeoId = null;
|
||||||
|
|
||||||
|
if ($dbGeo = $db->findGeo($dbGeoCountryId, $dbGeoCityId, $dbGeoCoordinateId)) {
|
||||||
|
|
||||||
|
$dbGeoId = $dbGeo->geoId;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if ($dbGeoId = $db->addGeo($dbGeoCountryId, $dbGeoCityId, $dbGeoCoordinateId)) {
|
||||||
|
|
||||||
|
$debug['yggdrasil']['geo']['total']['insert']++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Init peer remote
|
// Init peer remote
|
||||||
if ($connectedPeerRemoteUrl = Yggverse\Parser\Url::parse($connectedPeerInfo->remote)) {
|
if ($dbPeerRemote = $db->findPeerRemote($dbPeerId,
|
||||||
|
$dbGeoId,
|
||||||
|
$dbPeerRemoteSchemeId,
|
||||||
|
$dbPeerRemoteHostId,
|
||||||
|
$dbPeerRemotePortId)) {
|
||||||
|
|
||||||
// Init peer scheme
|
$dbPeerRemoteId = $dbPeerRemote->peerRemoteId;
|
||||||
if ($dbPeerRemoteScheme = $db->findPeerRemoteScheme($connectedPeerRemoteUrl->host->scheme)) {
|
|
||||||
|
|
||||||
$dbPeerRemoteSchemeId = $dbPeerRemoteScheme->peerRemoteSchemeId;
|
} else {
|
||||||
|
|
||||||
} else {
|
if ($dbPeerRemoteId = $db->addPeerRemote($dbPeerId,
|
||||||
|
|
||||||
if ($dbPeerRemoteSchemeId = $db->addPeerRemoteScheme($connectedPeerRemoteUrl->host->scheme, time())) {
|
|
||||||
|
|
||||||
$debug['yggdrasil']['peer']['remote']['scheme']['total']['insert']++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Init peer host
|
|
||||||
if ($dbPeerRemoteHost = $db->findPeerRemoteHost($connectedPeerRemoteUrl->host->name)) {
|
|
||||||
|
|
||||||
$dbPeerRemoteHostId = $dbPeerRemoteHost->peerRemoteHostId;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if ($dbPeerRemoteHostId = $db->addPeerRemoteHost($connectedPeerRemoteUrl->host->name, time())) {
|
|
||||||
|
|
||||||
$debug['yggdrasil']['peer']['remote']['host']['total']['insert']++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Init peer port
|
|
||||||
if ($dbPeerRemotePort = $db->findPeerRemotePort($connectedPeerRemoteUrl->host->port)) {
|
|
||||||
|
|
||||||
$dbPeerRemotePortId = $dbPeerRemotePort->peerRemotePortId;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if ($dbPeerRemotePortId = $db->addPeerRemotePort($connectedPeerRemoteUrl->host->port, time())) {
|
|
||||||
|
|
||||||
$debug['yggdrasil']['peer']['remote']['port']['total']['insert']++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Init geo data
|
|
||||||
|
|
||||||
/// Country
|
|
||||||
$countryIsoCode = $geoIp2Country->country($connectedPeerRemoteUrl->host->name)->country->isoCode;
|
|
||||||
$countryName = $geoIp2Country->country($connectedPeerRemoteUrl->host->name)->country->name;
|
|
||||||
|
|
||||||
$dbGeoCountryId = null;
|
|
||||||
|
|
||||||
if (!empty($countryIsoCode) && !empty($countryName)) {
|
|
||||||
|
|
||||||
if ($dbGeoCountry = $db->findGeoCountryByIsoCode($countryIsoCode)) {
|
|
||||||
|
|
||||||
$dbGeoCountryId = $dbGeoCountry->geoCountryId;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if ($dbGeoCountryId = $db->addGeoCountry($countryIsoCode, $countryName)) {
|
|
||||||
|
|
||||||
$debug['yggdrasil']['geo']['country']['total']['insert']++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// City
|
|
||||||
$cityName = $geoIp2City->city($connectedPeerRemoteUrl->host->name)->city->name;
|
|
||||||
|
|
||||||
$dbGeoCityId = null;
|
|
||||||
|
|
||||||
if (!empty($cityName)) {
|
|
||||||
|
|
||||||
if ($dbGeoCity = $db->findGeoCityByName($cityName)) {
|
|
||||||
|
|
||||||
$dbGeoCityId = $dbGeoCity->geoCityId;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if ($dbGeoCityId = $db->addGeoCity($cityName)) {
|
|
||||||
|
|
||||||
$debug['yggdrasil']['geo']['city']['total']['insert']++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Coordinate
|
|
||||||
$latitude = $geoIp2City->city($connectedPeerRemoteUrl->host->name)->location->latitude;
|
|
||||||
$longitude = $geoIp2City->city($connectedPeerRemoteUrl->host->name)->location->longitude;
|
|
||||||
|
|
||||||
$dbGeoCoordinateId = null;
|
|
||||||
|
|
||||||
if (!empty($latitude) && !empty($longitude)) {
|
|
||||||
|
|
||||||
if ($dbGeoCoordinate = $db->findGeoCoordinate($geoIp2City->city($connectedPeerRemoteUrl->host->name)->location->latitude,
|
|
||||||
$geoIp2City->city($connectedPeerRemoteUrl->host->name)->location->longitude)) {
|
|
||||||
|
|
||||||
$dbGeoCoordinateId = $dbGeoCoordinate->geoCoordinateId;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if ($dbGeoCoordinateId = $db->addGeoCoordinate($geoIp2City->city($connectedPeerRemoteUrl->host->name)->location->latitude,
|
|
||||||
$geoIp2City->city($connectedPeerRemoteUrl->host->name)->location->longitude)) {
|
|
||||||
|
|
||||||
$debug['yggdrasil']['geo']['coordinate']['total']['insert']++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Geo
|
|
||||||
$dbGeoId = null;
|
|
||||||
|
|
||||||
if ($dbGeo = $db->findGeo($dbGeoCountryId, $dbGeoCityId, $dbGeoCoordinateId)) {
|
|
||||||
|
|
||||||
$dbGeoId = $dbGeo->geoId;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if ($dbGeoId = $db->addGeo($dbGeoCountryId, $dbGeoCityId, $dbGeoCoordinateId)) {
|
|
||||||
|
|
||||||
$debug['yggdrasil']['geo']['total']['insert']++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Init peer remote
|
|
||||||
if ($dbPeerRemote = $db->findPeerRemote($dbPeerId,
|
|
||||||
$dbGeoId,
|
$dbGeoId,
|
||||||
$dbPeerRemoteSchemeId,
|
$dbPeerRemoteSchemeId,
|
||||||
$dbPeerRemoteHostId,
|
$dbPeerRemoteHostId,
|
||||||
$dbPeerRemotePortId)) {
|
$dbPeerRemotePortId,
|
||||||
|
time())) {
|
||||||
|
|
||||||
$dbPeerRemoteId = $dbPeerRemote->peerRemoteId;
|
$debug['yggdrasil']['peer']['remote']['total']['insert']++;
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if ($dbPeerRemoteId = $db->addPeerRemote($dbPeerId,
|
|
||||||
$dbGeoId,
|
|
||||||
$dbPeerRemoteSchemeId,
|
|
||||||
$dbPeerRemoteHostId,
|
|
||||||
$dbPeerRemotePortId,
|
|
||||||
time())) {
|
|
||||||
|
|
||||||
$debug['yggdrasil']['peer']['remote']['total']['insert']++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If something went wrong with URL parse, skip next operations for this peer
|
|
||||||
} else {
|
|
||||||
|
|
||||||
$db->rollBack();
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Init peer connection
|
|
||||||
if (!$db->findPeerConnection($dbPeerSessionId, $dbPeerRemoteId, $dbPeerCoordinateId)) {
|
|
||||||
|
|
||||||
if ($db->addPeerConnection($dbPeerSessionId, $dbPeerRemoteId, $dbPeerCoordinateId, time())) {
|
|
||||||
|
|
||||||
$debug['yggdrasil']['peer']['connection']['total']['insert']++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$debug['yggdrasil']['peer']['total']['online']++;
|
// If something went wrong with URL parse, skip next operations for this peer
|
||||||
|
} else {
|
||||||
$db->commit();
|
|
||||||
|
|
||||||
} catch(Exception $e) {
|
|
||||||
|
|
||||||
$db->rollBack();
|
$db->rollBack();
|
||||||
|
|
||||||
var_dump($e);
|
continue;
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Init peer connection
|
||||||
|
if (!$db->findPeerConnection($dbPeerSessionId, $dbPeerRemoteId, $dbPeerCoordinateId)) {
|
||||||
|
|
||||||
|
if ($db->addPeerConnection($dbPeerSessionId, $dbPeerRemoteId, $dbPeerCoordinateId, time())) {
|
||||||
|
|
||||||
|
$debug['yggdrasil']['peer']['connection']['total']['insert']++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$debug['yggdrasil']['peer']['total']['online']++;
|
||||||
|
|
||||||
|
$db->commit();
|
||||||
|
|
||||||
|
} catch(Exception $e) {
|
||||||
|
|
||||||
|
$db->rollBack();
|
||||||
|
|
||||||
|
var_dump($e);
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,10 +235,10 @@ $results = $sphinx->searchPeers($requestQuery,
|
|||||||
<?php } ?>
|
<?php } ?>
|
||||||
</td>
|
</td>
|
||||||
<td colspan="5" class="text-right">
|
<td colspan="5" class="text-right">
|
||||||
<?php if (TRACKER_PUBLIC_PEERS) { ?>
|
<?php if (API_PEERS) { ?>
|
||||||
<div class="margin-top-8"><?php echo _('trackers') ?></div>
|
<div class="margin-top-8"><?php echo _('trackers') ?></div>
|
||||||
<?php foreach (TRACKER_PUBLIC_PEERS as $address) { ?>
|
<?php foreach (API_PEERS as $tracker => $website) { ?>
|
||||||
<div><?php echo $address ?></div>
|
<div><?php echo $tracker ?></div>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</td>
|
</td>
|
||||||
@ -249,10 +249,10 @@ $results = $sphinx->searchPeers($requestQuery,
|
|||||||
<tr>
|
<tr>
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
<div class="margin-y-8"><?php echo _('not found') ?></div>
|
<div class="margin-y-8"><?php echo _('not found') ?></div>
|
||||||
<?php if (TRACKER_PUBLIC_PEERS) { ?>
|
<?php if (API_PEERS) { ?>
|
||||||
<div class="margin-y-8"><?php echo _('get yourself tracked by connection') ?></div>
|
<div class="margin-y-8"><?php echo _('get yourself tracked by connection') ?></div>
|
||||||
<?php foreach (TRACKER_PUBLIC_PEERS as $address) { ?>
|
<?php foreach (API_PEERS as $tracker => $website) { ?>
|
||||||
<div class="margin-y-8"><?php echo $address ?></div>
|
<div class="margin-y-8"><?php echo $tracker ?></div>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</td>
|
</td>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user