GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: bracket resolved IPv6 hostnames in Artery settings · apache/pekko@ebfb43c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • docs/src/main/paradox
    • remoting-artery.md
  • remote/src
    • main/scala/org/apache/pekko/remote/artery
      • ArterySettings.scala
    • test/scala/org/apache/pekko/remote/artery
      • ArterySettingsSpec.scala
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎docs/src/main/paradox/remoting-artery.md‎

Copy file name to clipboardExpand all lines: docs/src/main/paradox/remoting-artery.md
+3Lines changed: 3 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,9 @@ the system might have less latency than at low message rates.
700700
There are lots of configuration properties that are related to remoting in Pekko. We refer to the
701701
@ref:[reference configuration](general/configuration-reference.md#config-pekko-remote-artery) for more information.
702702

703+
IPv6 literals in Artery's canonical and bind hostnames use brackets in remoting addresses. Pekko adds them when
704+
needed, including when `<getHostAddress>` or `<getHostName>` returns an IPv6 literal.
705+
703706
@@@ note
704707

705708
Setting properties like the listening IP and port number programmatically is
Collapse file

‎remote/src/main/scala/org/apache/pekko/remote/artery/ArterySettings.scala‎

Copy file name to clipboardExpand all lines: remote/src/main/scala/org/apache/pekko/remote/artery/ArterySettings.scala
+11-8Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,17 @@ private[pekko] object ArterySettings {
340340
final val Debug = false // unlocks additional very verbose debug logging of compression events (to stdout)
341341
}
342342

343-
def getHostname(key: String, config: Config): String = config.getString(key) match {
344-
case "<getHostAddress>" => InetAddress.getLocalHost.getHostAddress
345-
case "<getHostName>" => InetAddress.getLocalHost.getHostName
346-
case other =>
347-
if (other.startsWith("[") && other.endsWith("]")) other
348-
else if (AsyncDnsResolver.isIpv6Address(other)) {
349-
"[" + other + "]"
350-
} else other
343+
def getHostname(key: String, config: Config): String = getHostname(key, config, InetAddress.getLocalHost)
344+
345+
private[artery] def getHostname(key: String, config: Config, localHost: => InetAddress): String = {
346+
val hostname = config.getString(key) match {
347+
case "<getHostAddress>" => localHost.getHostAddress
348+
case "<getHostName>" => localHost.getHostName
349+
case other => other
350+
}
351+
if (hostname.startsWith("[") && hostname.endsWith("]")) hostname
352+
else if (AsyncDnsResolver.isIpv6Address(hostname)) s"[$hostname]"
353+
else hostname
351354
}
352355

353356
sealed trait Transport {
Collapse file

‎remote/src/test/scala/org/apache/pekko/remote/artery/ArterySettingsSpec.scala‎

Copy file name to clipboardExpand all lines: remote/src/test/scala/org/apache/pekko/remote/artery/ArterySettingsSpec.scala
+50Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717

1818
package org.apache.pekko.remote.artery
1919

20+
import java.net.{ Inet6Address, InetAddress, InetSocketAddress }
2021
import java.nio.charset.StandardCharsets
2122

2223
import org.apache.pekko
24+
import pekko.actor.{ Address, AddressFromURIString }
2325
import pekko.util.ByteString
2426

2527
import org.scalatest.matchers.should.Matchers
@@ -39,6 +41,54 @@ class ArterySettingsSpec extends AnyWordSpec with Matchers {
3941

4042
private def magic(s: String): ByteString = ByteString(s.getBytes(StandardCharsets.UTF_8))
4143

44+
"Artery hostname settings" must {
45+
"render the resolved IPv6 literal with brackets for canonical and bind hostnames" in {
46+
val loopback = InetAddress.getByName("::1")
47+
val expected = s"[${loopback.getHostAddress}]"
48+
val address = Address("pekko", "system", expected, 25520)
49+
val defaults = ConfigFactory.load().getConfig("pekko.remote.artery")
50+
val canonical = ArterySettings.getHostname("hostname", defaults.getConfig("canonical"), loopback)
51+
canonical shouldBe expected
52+
AddressFromURIString(Address("pekko", "system", canonical, 25520).toString) shouldBe address
53+
54+
val bind = ConfigFactory.parseString("""hostname = "<getHostAddress>" """)
55+
val bindHost = ArterySettings.getHostname("hostname", bind, loopback)
56+
bindHost shouldBe expected
57+
new InetSocketAddress(bindHost, 25520).getAddress shouldBe loopback
58+
}
59+
60+
"preserve the numeric scope of a bracketed IPv6 literal" in {
61+
val bytes = Array[Byte](0xFE.toByte, 0x80.toByte, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)
62+
val linkLocal = Inet6Address.getByAddress(null, bytes, 7)
63+
val config = ConfigFactory.parseString("""hostname = "<getHostAddress>" """)
64+
65+
val hostname = ArterySettings.getHostname("hostname", config, linkLocal)
66+
val expected = s"[${linkLocal.getHostAddress}]"
67+
hostname shouldBe expected
68+
AddressFromURIString(Address("pekko", "system", hostname, 25520).toString).host shouldBe Some(expected)
69+
}
70+
71+
"bracket an IPv6 literal returned by <getHostName>" in {
72+
val loopback = InetAddress.getByAddress("::1", Array.fill[Byte](15)(0) :+ 1.toByte)
73+
val config = ConfigFactory.parseString("""hostname = "<getHostName>" """)
74+
75+
ArterySettings.getHostname("hostname", config, loopback) shouldBe "[::1]"
76+
}
77+
78+
"preserve IPv4, DNS names, and explicitly configured brackets" in {
79+
val loopback = InetAddress.getByAddress("local.example", Array[Byte](127, 0, 0, 1))
80+
def hostname(value: String): String =
81+
ArterySettings.getHostname("hostname", ConfigFactory.parseString(s"""hostname = "$value" """), loopback)
82+
83+
hostname("<getHostAddress>") shouldBe "127.0.0.1"
84+
hostname("<getHostName>") shouldBe "local.example"
85+
hostname("::1") shouldBe "[::1]"
86+
hostname("[::1]") shouldBe "[::1]"
87+
hostname("127.0.0.1") shouldBe "127.0.0.1"
88+
hostname("example.com") shouldBe "example.com"
89+
}
90+
}
91+
4292
"ArterySettings.TcpMagicValues" must {
4393

4494
// Held as a Seq rather than a Set: a Set hashes its members, and hashing a ByteString walks

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.