Browse Source

draft nex protocol support

main
yggverse 4 weeks ago
parent
commit
71e3c270c4
  1. 5
      README.md
  2. 1
      composer.json
  3. 136
      src/Entity/Tab/Page.php

5
README.md

@ -2,6 +2,11 @@ @@ -2,6 +2,11 @@
At this moment project under development!
## Protocols
* [x] Gemini
* [ ] Nex
## Features
* [x] Custom DNS resolver with memory cache (useful for alt networks like [Yggdrasil](https://github.com/yggdrasil-network/yggdrasil-go))

1
composer.json

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
"type": "project",
"require": {
"yggverse/gemini": "dev-main",
"yggverse/nex": "dev-main",
"yggverse/net": "dev-main"
},
"license": "MIT",

136
src/Entity/Tab/Page.php

@ -560,6 +560,14 @@ class Page @@ -560,6 +560,14 @@ class Page
break;
case str_starts_with($url, 'nex://'):
$this->_openNex(
$url
);
break;
case str_starts_with($url, 'yoda://'):
$this->_openYoda(
@ -797,6 +805,134 @@ class Page @@ -797,6 +805,134 @@ class Page
}
}
private function _openNex(
string $url,
bool $history = true
): void
{
// Init progressbar
if ($this->config->progressbar->visible)
{
$this->setProgress(0);
}
// Init base URL
$origin = new \Yggverse\Net\Address(
$url
);
// Track response time
$start = microtime(true);
// Init custom resolver
$host = null;
if ($this->config->resolver->enabled)
{
$address = new \Yggverse\Net\Address(
$url
);
$name = $address->getHost();
if (!$host = $this->dns->get($name))
{
$resolve = new \Yggverse\Net\Resolve(
$this->config->resolver->request->record,
$this->config->resolver->request->host,
$this->config->resolver->request->timeout,
$this->config->resolver->result->shuffle
);
$resolved = $resolve->address(
$address
);
if ($resolved)
{
$host = $resolved->getHost();
$this->dns->set(
$name,
$host
);
}
}
}
$request = new \Yggverse\Nex\Client\Request(
$url,
$host
);
$raw = $request->getResponse();
$end = microtime(true);
$this->content->set_markup(
$raw // @TODO
);
$this->setTitle(
$origin->getHost()
);
$this->status->set_markup(
str_replace( // Custom macros mask from config.json
[
'{TIME_C}',
'{REQUEST_BASE}',
'{REQUEST_BASE_URL}',
'{RESPONSE_CODE}',
'{RESPONSE_META}',
'{RESPONSE_LENGTH}',
'{RESPONSE_SECONDS}'
],
[
date(
'c'
),
$origin->getHost(),
sprintf(
'<a href="%s">%s</a>',
$origin->get(
true, // scheme
true, // user
true, // pass
true, // host
true, // port
false, // path
false, // query
false // fragment
),
$origin->getHost()
),
'-', // @TODO
'-',
number_format(
mb_strlen(
$raw
)
),
round(
$end - $start, 2
)
],
$this->config->footer->status->open->complete
)
);
// Update history database
if ($history && $this->config->history->database->enabled)
{
$this->app->history->add(
$url,
$title,
$this->config->history->database->mode->renew
);
}
}
private function _openYoda(
string $url
): void

Loading…
Cancel
Save