Browse Source

implement tracker, peers JSON API

yggdrasil-0.4.7
ghost 1 year ago
parent
commit
606a6f1cac
  1. 3
      .gitignore
  2. 7
      README.md
  3. 9
      src/config/app.php.example
  4. 33
      src/crontab/crawler.php
  5. 12
      src/public/search.php

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

7
README.md

@ -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

9
src/config/app.php.example

@ -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);

33
src/crontab/crawler.php

@ -129,9 +129,39 @@ 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()) {
if ($handle = fopen(__DIR__ . '/../public/api/peers.json', 'w+')) {
fwrite($handle, json_encode($connectedPeers));
fclose($handle);
}
} else {
exit;
}
// Update trackers
if (API_PEERS) {
if ($handle = fopen(__DIR__ . '/../public/api/trackers.json', 'w+')) {
fwrite($handle, json_encode(API_PEERS));
fclose($handle);
}
} else {
exit;
}
// @TODO merge peers data from remote trackers
// Collect connected peers
foreach ($connectedPeers as $connectedPeerAddress => $connectedPeerInfo) { foreach ($connectedPeers as $connectedPeerAddress => $connectedPeerInfo) {
try { try {
@ -410,7 +440,6 @@ if ($connectedPeers = Yggverse\Yggdrasilctl\Yggdrasil::getPeers()) {
break; break;
} }
} }
}
// Debug output // Debug output
$debug['time']['total'] = microtime(true) - $debug['time']['total']; $debug['time']['total'] = microtime(true) - $debug['time']['total'];

12
src/public/search.php

@ -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…
Cancel
Save