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. 11
      src/config/app.php.example
  4. 35
      src/crontab/crawler.php
  5. 12
      src/public/search.php

3
.gitignore vendored

@ -6,5 +6,8 @@ @@ -6,5 +6,8 @@
/src/config/app.php
/src/public/api/peers.json
/src/public/api/trackers.json
.ftpignore
composer.lock

7
README.md

@ -54,7 +54,12 @@ git checkout -b my-pr-branch-name @@ -54,7 +54,12 @@ git checkout -b my-pr-branch-name
#### Roadmap
* [ ] Federated tracking API
API
* [x] trackers
* [x] peers
Crawler
* [ ] federated model
#### Donate to contributors

11
src/config/app.php.example

@ -72,12 +72,13 @@ define('WEBSITE_PEER_REMOTE_PAGINATION_LIMIT', 20); @@ -72,12 +72,13 @@ define('WEBSITE_PEER_REMOTE_PAGINATION_LIMIT', 20);
define('WEBSITE_PEER_PORT_CHECK_TIMEOUT', 60 * 5);
// Trackers
define('TRACKER_PUBLIC_PEERS', (object)
[
'tls://94.140.114.241:4708',
// API
define('API_PEERS', (object)
[
'tls://94.140.114.241:4708' => WEBSITE_URL,
// ...
]);
]
);
// Crawler
define('CRAWL_STOP_DISK_QUOTA_MB_LEFT', 128);

35
src/crontab/crawler.php

@ -129,10 +129,40 @@ try { @@ -129,10 +129,40 @@ try {
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()) {
foreach ($connectedPeers as $connectedPeerAddress => $connectedPeerInfo) {
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) {
try {
@ -409,7 +439,6 @@ if ($connectedPeers = Yggverse\Yggdrasilctl\Yggdrasil::getPeers()) { @@ -409,7 +439,6 @@ if ($connectedPeers = Yggverse\Yggdrasilctl\Yggdrasil::getPeers()) {
break;
}
}
}
// Debug output

12
src/public/search.php

@ -235,10 +235,10 @@ $results = $sphinx->searchPeers($requestQuery, @@ -235,10 +235,10 @@ $results = $sphinx->searchPeers($requestQuery,
<?php } ?>
</td>
<td colspan="5" class="text-right">
<?php if (TRACKER_PUBLIC_PEERS) { ?>
<?php if (API_PEERS) { ?>
<div class="margin-top-8"><?php echo _('trackers') ?></div>
<?php foreach (TRACKER_PUBLIC_PEERS as $address) { ?>
<div><?php echo $address ?></div>
<?php foreach (API_PEERS as $tracker => $website) { ?>
<div><?php echo $tracker ?></div>
<?php } ?>
<?php } ?>
</td>
@ -249,10 +249,10 @@ $results = $sphinx->searchPeers($requestQuery, @@ -249,10 +249,10 @@ $results = $sphinx->searchPeers($requestQuery,
<tr>
<td class="text-center">
<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>
<?php foreach (TRACKER_PUBLIC_PEERS as $address) { ?>
<div class="margin-y-8"><?php echo $address ?></div>
<?php foreach (API_PEERS as $tracker => $website) { ?>
<div class="margin-y-8"><?php echo $tracker ?></div>
<?php } ?>
<?php } ?>
</td>

Loading…
Cancel
Save