You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuweni.apache.org by to...@apache.org on 2022/01/19 15:16:28 UTC
[incubator-tuweni] branch main updated: validate enodes
This is an automated email from the ASF dual-hosted git repository.
toulmean pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-tuweni.git
The following commit(s) were added to refs/heads/main by this push:
new 8a1d465 validate enodes
new 80de212 Merge pull request #366 from atoulme/validate_enodes
8a1d465 is described below
commit 8a1d4653c0ecd8a93f3a7d7d9da59151073b457a
Author: Antoine Toulme <an...@lunar-ocean.com>
AuthorDate: Tue Jan 18 23:21:29 2022 -0800
validate enodes
---
.../org/apache/tuweni/ethclient/EthereumClientConfig.kt | 15 ++++++++++++++-
.../apache/tuweni/ethclient/EthereumClientConfigTest.kt | 7 +++++++
2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/eth-client/src/main/kotlin/org/apache/tuweni/ethclient/EthereumClientConfig.kt b/eth-client/src/main/kotlin/org/apache/tuweni/ethclient/EthereumClientConfig.kt
index 019a1d0..64c2d76 100644
--- a/eth-client/src/main/kotlin/org/apache/tuweni/ethclient/EthereumClientConfig.kt
+++ b/eth-client/src/main/kotlin/org/apache/tuweni/ethclient/EthereumClientConfig.kt
@@ -24,6 +24,7 @@ import org.apache.tuweni.config.PropertyValidator
import org.apache.tuweni.config.Schema
import org.apache.tuweni.config.SchemaBuilder
import org.apache.tuweni.crypto.SECP256K1
+import org.apache.tuweni.devp2p.parseEnodeUri
import org.apache.tuweni.eth.genesis.GenesisFile
import org.slf4j.LoggerFactory
import java.io.FileNotFoundException
@@ -231,7 +232,19 @@ class EthereumClientConfig(private var config: Configuration = Configuration.emp
dnsSection.addString("peerRepository", "default", "Peer repository to which records should go", null)
val staticPeers = SchemaBuilder.create()
- staticPeers.addListOfString("enodes", Collections.emptyList(), "Static enodes to connect to in enode://publickey@host:port format", null)
+ staticPeers.addListOfString(
+ "enodes", Collections.emptyList(), "Static enodes to connect to in enode://publickey@host:port format"
+ ) { _, position, value ->
+ val errors = mutableListOf<ConfigurationError>()
+ for (enode in value!!) {
+ try {
+ parseEnodeUri(URI.create(enode))
+ } catch (e: IllegalArgumentException) {
+ errors.add(ConfigurationError(position, e.message ?: "error validating enode"))
+ }
+ }
+ errors
+ }
staticPeers.addString("peerRepository", "default", "Peer repository to which static nodes should go", null)
val discoverySection = SchemaBuilder.create()
diff --git a/eth-client/src/test/kotlin/org/apache/tuweni/ethclient/EthereumClientConfigTest.kt b/eth-client/src/test/kotlin/org/apache/tuweni/ethclient/EthereumClientConfigTest.kt
index 2842f3c..ade603a 100644
--- a/eth-client/src/test/kotlin/org/apache/tuweni/ethclient/EthereumClientConfigTest.kt
+++ b/eth-client/src/test/kotlin/org/apache/tuweni/ethclient/EthereumClientConfigTest.kt
@@ -113,4 +113,11 @@ class EthereumClientConfigTest {
assertEquals("localhost:15000", config.proxies()[0].upstream())
assertEquals("", config.proxies()[0].downstream())
}
+
+ @Test
+ fun testInvalidPeers() {
+ val config = EthereumClientConfig.fromString("[static.default]\nenodes=[\"enode://foo:bar@localhost:303\"]")
+ val errors = config.validate()
+ assertEquals(1, errors.count())
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tuweni.apache.org
For additional commands, e-mail: commits-help@tuweni.apache.org