-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ETCM-365: Put the version info into the client ID. Allow override fro…
…m properties.
- Loading branch information
Showing
6 changed files
with
62 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.iohk.ethereum.utils | ||
|
||
object VersionInfo { | ||
|
||
/** Produce a node name that get sent in `WireProtocol.Hello.clientId` according to Ethereum conventions. | ||
* | ||
* Check out examples on https://etcnodes.org | ||
* | ||
* e.g. | ||
* - mantis/v3.0-cd5ae33/linux-amd64/ubuntu-openjdk64bitservervm-java-11.0.9 | ||
* - besu/v20.10.0/linux-x86_64/oracle_openjdk-java-11 | ||
* - coregeth/v1.11.8-stable-305b5089/linux-amd64/go1.14.4 | ||
*/ | ||
val clientId = { | ||
val appName = BuildInfo.name | ||
val appVersion = BuildInfo.version | ||
val appCommit = BuildInfo.gitHeadCommit.map("-" + _.take(7)).getOrElse("") | ||
|
||
val osName = norm(prop("os.name")) | ||
val osArch = norm(prop("os.arch")) | ||
|
||
val javaVendor = norm(prop("java.vendor")) | ||
val javaVmName = norm(prop("java.vm.name")) | ||
val javaVersion = prop("java.version") | ||
|
||
s"$appName/v$appVersion$appCommit/$osName-$osArch/$javaVendor-$javaVmName-java-$javaVersion" | ||
} | ||
|
||
private def prop(name: String) = | ||
System.getProperty(name) | ||
|
||
private def norm(value: String) = | ||
value.toLowerCase.replaceAll("[^a-z0-9]+", "") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
mantis { | ||
|
||
client-id = "mantis" | ||
|
||
datadir = "/tmp/mantis-test/" | ||
|
||
secure-random-algo = "NativePRNGNonBlocking" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.iohk.ethereum.utils | ||
|
||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class ConfigSpec extends AnyFlatSpec with Matchers { | ||
"clientId" should "by default come from VersionInfo" in { | ||
Config.clientId shouldBe VersionInfo.clientId | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/test/scala/io/iohk/ethereum/utils/VersionInfoSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.iohk.ethereum.utils | ||
|
||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class VersionInfoSpec extends AnyFlatSpec with Matchers { | ||
behavior of "clientId" | ||
|
||
it should "preserve major and minor Java version" in { | ||
VersionInfo.clientId should fullyMatch regex """.+/v\d.*-[a-z0-9]{7}/.+-.+/.+-.+-java-\d+\.\d+.*""" | ||
} | ||
} |