1
0
mirror of https://github.com/danog/dns.git synced 2024-11-26 20:14:51 +01:00

Add explanation comments

This commit is contained in:
Niklas Keller 2017-06-27 18:35:57 +02:00
parent 8dca65bcd4
commit 1a1427ce10
2 changed files with 6 additions and 3 deletions

View File

@ -337,10 +337,13 @@ final class BasicResolver implements Resolver {
}
private function getSocket($uri): Promise {
// We use a new socket for each UDP request, as that increases the entropy and mitigates response forgery.
if (\substr($uri, 0, 3) === "udp") {
return UdpSocket::connect($uri);
}
// Over TCP we might reuse sockets if the server allows to keep them open. Sequence IDs in TCP are already
// better than a random port. Additionally, a TCP connection is more expensive.
if (isset($this->sockets[$uri])) {
return new Success($this->sockets[$uri]);
}

View File

@ -26,7 +26,7 @@ abstract class Socket {
/** @var ResourceOutputStream */
private $output;
/** @var array */
/** @var array Contains already sent queries with no response yet. For UDP this is exactly zero or one item. */
private $pending = [];
/** @var MessageFactory */
@ -35,13 +35,13 @@ abstract class Socket {
/** @var callable */
private $onResolve;
/** @var int */
/** @var int Used for determining whether the socket can be garbage collected, because it's inactive. */
private $lastActivity;
/** @var bool */
private $receiving = false;
/** @var array */
/** @var array Queued requests if the number of concurrent requests is too large. */
private $queue = [];
/**