mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-05 10:49:37 +02:00
Begin WebSocket support for Broadcast and Player control
This commit is contained in:
parent
2b128b122d
commit
6adf8307c4
516 changed files with 64260 additions and 18 deletions
66
modules/React/Dns/Query/CachedExecutor.php
Normal file
66
modules/React/Dns/Query/CachedExecutor.php
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
namespace React\Dns\Query;
|
||||
|
||||
use React\Dns\Model\Message;
|
||||
use React\Dns\Model\Record;
|
||||
|
||||
class CachedExecutor implements ExecutorInterface
|
||||
{
|
||||
private $executor;
|
||||
private $cache;
|
||||
|
||||
public function __construct(ExecutorInterface $executor, RecordCache $cache)
|
||||
{
|
||||
$this->executor = $executor;
|
||||
$this->cache = $cache;
|
||||
}
|
||||
|
||||
public function query($nameserver, Query $query)
|
||||
{
|
||||
$executor = $this->executor;
|
||||
$cache = $this->cache;
|
||||
|
||||
return $this->cache
|
||||
->lookup($query)
|
||||
->then(
|
||||
function ($cachedRecords) use ($query) {
|
||||
return $this->buildResponse($query, $cachedRecords);
|
||||
},
|
||||
function () use ($executor, $cache, $nameserver, $query) {
|
||||
return $executor
|
||||
->query($nameserver, $query)
|
||||
->then(function ($response) use ($cache, $query) {
|
||||
$cache->storeResponseMessage($query->currentTime, $response);
|
||||
return $response;
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function buildResponse(Query $query, array $cachedRecords)
|
||||
{
|
||||
$response = new Message();
|
||||
|
||||
$response->header->set('id', $this->generateId());
|
||||
$response->header->set('qr', 1);
|
||||
$response->header->set('opcode', Message::OPCODE_QUERY);
|
||||
$response->header->set('rd', 1);
|
||||
$response->header->set('rcode', Message::RCODE_OK);
|
||||
|
||||
$response->questions[] = new Record($query->name, $query->type, $query->class);
|
||||
|
||||
foreach ($cachedRecords as $record) {
|
||||
$response->answers[] = $record;
|
||||
}
|
||||
|
||||
$response->prepare();
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
protected function generateId()
|
||||
{
|
||||
return mt_rand(0, 0xffff);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue