-
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: Version info in Hello.clientId (#794)
- Loading branch information
Showing
9 changed files
with
289 additions
and
6 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,48 @@ | ||
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 | ||
* | ||
* Apparently ethstats expects either 4 parts or 5: | ||
* - client/version/os/compiler | ||
* - client/identity/version/os/compiler | ||
*/ | ||
def nodeName(maybeIdentity: Option[String] = None): String = { | ||
val app = { | ||
val name = BuildInfo.name | ||
val id = maybeIdentity.map("/" + _).getOrElse("") | ||
s"$name$id" | ||
} | ||
val version = { | ||
val version = BuildInfo.version | ||
val commit = BuildInfo.gitHeadCommit.map("-" + _.take(7)).getOrElse("") | ||
s"v$version$commit" | ||
} | ||
val os = { | ||
val name = norm(prop("os.name")) | ||
val arch = norm(prop("os.arch")) | ||
s"$name-$arch" | ||
} | ||
val vm = { | ||
val vendor = norm(prop("java.vendor")) | ||
val vmName = norm(prop("java.vm.name")) | ||
val version = prop("java.version") | ||
s"$vendor-$vmName-java-$version" | ||
} | ||
s"$app/$version/$os/$vm" | ||
} | ||
|
||
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.nodeName() | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
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,18 @@ | ||
package io.iohk.ethereum.utils | ||
|
||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class VersionInfoSpec extends AnyFlatSpec with Matchers { | ||
behavior of "nodeName" | ||
|
||
it should "match ethstats expected structure and preserve major and minor Java version" in { | ||
VersionInfo.nodeName() should fullyMatch regex """mantis/v\d(\.\d+)*-[a-z0-9]{7}/[^/]+-[^/]+/[^/]+-.[^/]+-java-\d+\.\d+[._0-9]*""" | ||
} | ||
|
||
it should "augment the name with an identity" in { | ||
val name = VersionInfo.nodeName(Some("iohk")) | ||
name should startWith("mantis/iohk/v") | ||
name.count(_ == '/') shouldBe 4 | ||
} | ||
} |