atoulme commented on a change in pull request #38: v5 UDP packet handling
URL: https://github.com/apache/incubator-tuweni/pull/38#discussion_r335444703
##########
File path:
devp2p/src/main/kotlin/org/apache/tuweni/devp2p/v5/internal/DefaultNodeDiscoveryService.kt
##########
@@ -0,0 +1,55 @@
+package org.apache.tuweni.devp2p.v5.internal
+
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
+import org.apache.tuweni.bytes.Bytes
+import org.apache.tuweni.crypto.Hash
+import org.apache.tuweni.crypto.SECP256K1
+import org.apache.tuweni.devp2p.EthereumNodeRecord
+import org.apache.tuweni.devp2p.parseEnodeUri
+import org.apache.tuweni.devp2p.v5.NodeDiscoveryService
+import org.apache.tuweni.devp2p.v5.UdpConnector
+import org.apache.tuweni.devp2p.v5.packet.RandomMessage
+import org.apache.tuweni.io.Base64URLSafe
+import java.net.InetSocketAddress
+import java.time.Instant
+import kotlin.coroutines.CoroutineContext
+
+class DefaultNodeDiscoveryService(
+ private val keyPair: SECP256K1.KeyPair,
+ private val localPort: Int,
+ private val bindAddress: InetSocketAddress = InetSocketAddress(localPort),
+ private val bootstrapENRList: List<String> = emptyList(),
+ private val enrSeq: Long = Instant.now().toEpochMilli(),
+ private val selfENR: Bytes = EthereumNodeRecord.toRLP(keyPair, enrSeq,
emptyMap(), bindAddress.address, null, bindAddress.port),
+ private val nodeId: Bytes = Hash.sha2_256(selfENR),
+ private val connector: UdpConnector = DefaultUdpConnector(nodeId,
bindAddress),
+ override val coroutineContext: CoroutineContext = Dispatchers.Default
+) : NodeDiscoveryService, CoroutineScope {
+
+ override fun start() {
+ connector.start()
+ launch { bootstrap() }
+ }
+
+ override fun terminate() {
+ connector.terminate()
+ }
+
+ private fun bootstrap() {
+ bootstrapENRList.map {
+ val encodedEnr = it.substringAfter("enr:")
Review comment:
unguarded - what if the string is invalid?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]