He-Pin commented on code in PR #371:
URL: https://github.com/apache/incubator-pekko/pull/371#discussion_r1221557558


##########
actor/src/main/scala/org/apache/pekko/io/dns/internal/AsyncDnsResolver.scala:
##########
@@ -85,11 +86,25 @@ private[io] final class AsyncDnsResolver(
     settings.SearchDomains,
     settings.NDots)
 
-  private var requestId: Short = 0
+  private var (idIndex, idIncrement) = {
+    val secureRandom = new SecureRandom()
+    (secureRandom.nextLong(), secureRandom.nextLong())
+  }
+
+  private var idCount = 1
 
+  // DNS id's need to be random, see 
https://datatracker.ietf.org/doc/html/rfc5452#section-4.3.
+  // Uses enhanced double hashing technique from
+  // https://en.wikipedia.org/wiki/Double_hashing#Enhanced_double_hashing
   private def nextId(): Short = {
-    requestId = (requestId + 1).toShort
-    requestId
+    val result = (0xFFFFFFFF & idIndex).asInstanceOf[Short]
+    idIndex -= idIncrement
+    // Incorporate the counter into the increment to create a
+    // tetrahedral number additional term.
+    idIncrement -= {
+      idCount += 1; idCount - 1
+    }
+    result

Review Comment:
   I was using https://github.com/apache/incubator-pekko/pull/288



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to