Skip to content

Commit

Permalink
Add explanation comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Jun 27, 2017
1 parent 8dca65b commit 1a1427c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/BasicResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,13 @@ private function normalizeName(string $name, int $type) {
}

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]);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Internal/Socket.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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 = [];

/**
Expand Down

0 comments on commit 1a1427c

Please sign in to comment.