Skip to content

Commit 5210423

Browse files
committed
ETCM-365: Put the version info into the client ID. Allow override from properties.
1 parent d792c84 commit 5210423

File tree

6 files changed

+62
-5
lines changed

6 files changed

+62
-5
lines changed

src/main/resources/application.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
mantis {
2-
# Identifier used when connecting to other clients
3-
client-id = "mantis"
2+
# Optionally override the client ID sent in Hello messages.
3+
client-id = null
44

55
# Version string (reported by an RPC method)
66
client-version = "mantis/v2.0"

src/main/scala/io/iohk/ethereum/utils/Config.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ object Config {
2323

2424
val testmode: Boolean = config.getBoolean("testmode")
2525

26-
val clientId: String = config.getString("client-id")
26+
val clientId =
27+
ConfigUtils
28+
.getOptionalValue(config, "client-id", _.getString("client-id"))
29+
.getOrElse(VersionInfo.clientId)
2730

2831
val clientVersion: String = config.getString("client-version")
2932

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package io.iohk.ethereum.utils
2+
3+
object VersionInfo {
4+
5+
/** Produce a node name that get sent in `WireProtocol.Hello.clientId` according to Ethereum conventions.
6+
*
7+
* Check out examples on https://etcnodes.org
8+
*
9+
* e.g.
10+
* - mantis/v3.0-cd5ae33/linux-amd64/ubuntu-openjdk64bitservervm-java-11.0.9
11+
* - besu/v20.10.0/linux-x86_64/oracle_openjdk-java-11
12+
* - coregeth/v1.11.8-stable-305b5089/linux-amd64/go1.14.4
13+
*/
14+
val clientId = {
15+
val appName = BuildInfo.name
16+
val appVersion = BuildInfo.version
17+
val appCommit = BuildInfo.gitHeadCommit.map("-" + _.take(7)).getOrElse("")
18+
19+
val osName = norm(prop("os.name"))
20+
val osArch = norm(prop("os.arch"))
21+
22+
val javaVendor = norm(prop("java.vendor"))
23+
val javaVmName = norm(prop("java.vm.name"))
24+
val javaVersion = prop("java.version")
25+
26+
s"$appName/v$appVersion$appCommit/$osName-$osArch/$javaVendor-$javaVmName-java-$javaVersion"
27+
}
28+
29+
private def prop(name: String) =
30+
System.getProperty(name)
31+
32+
private def norm(value: String) =
33+
value.toLowerCase.replaceAll("[^a-z0-9]+", "")
34+
}

src/test/resources/application.conf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
mantis {
22

3-
client-id = "mantis"
4-
53
datadir = "/tmp/mantis-test/"
64

75
secure-random-algo = "NativePRNGNonBlocking"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package io.iohk.ethereum.utils
2+
3+
import org.scalatest.flatspec.AnyFlatSpec
4+
import org.scalatest.matchers.should.Matchers
5+
6+
class ConfigSpec extends AnyFlatSpec with Matchers {
7+
"clientId" should "by default come from VersionInfo" in {
8+
Config.clientId shouldBe VersionInfo.clientId
9+
}
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.iohk.ethereum.utils
2+
3+
import org.scalatest.flatspec.AnyFlatSpec
4+
import org.scalatest.matchers.should.Matchers
5+
6+
class VersionInfoSpec extends AnyFlatSpec with Matchers {
7+
behavior of "clientId"
8+
9+
it should "preserve major and minor Java version" in {
10+
VersionInfo.clientId should fullyMatch regex """.+/v\d.*-[a-z0-9]{7}/.+-.+/.+-.+-java-\d+\.\d+.*"""
11+
}
12+
}

0 commit comments

Comments
 (0)