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 8bcb82c agreedSubprotocol->agreedSubprotocolVersion new 67bca09 Merge pull request #361 from atoulme/subprotocol_id 8bcb82c is described below commit 8bcb82cdc023e79c58e62935e88c83595513065c Author: Antoine Toulme <anto...@lunar-ocean.com> AuthorDate: Fri Jan 14 22:50:08 2022 -0800 agreedSubprotocol->agreedSubprotocolVersion --- .../org/apache/tuweni/devp2p/eth/EthClient.kt | 12 ++++++------ .../org/apache/tuweni/devp2p/eth/EthClient66.kt | 22 +++++++++++----------- .../org/apache/tuweni/devp2p/eth/EthHandler.kt | 14 +++++++------- .../org/apache/tuweni/devp2p/eth/EthHandler66.kt | 6 +++--- .../org/apache/tuweni/devp2p/eth/EthHandlerTest.kt | 12 ++++++------ .../apache/tuweni/rlpx/wire/WireConnection.java | 4 ++-- 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/devp2p-eth/src/main/kotlin/org/apache/tuweni/devp2p/eth/EthClient.kt b/devp2p-eth/src/main/kotlin/org/apache/tuweni/devp2p/eth/EthClient.kt index 5a784c4..fb56e3e 100644 --- a/devp2p-eth/src/main/kotlin/org/apache/tuweni/devp2p/eth/EthClient.kt +++ b/devp2p-eth/src/main/kotlin/org/apache/tuweni/devp2p/eth/EthClient.kt @@ -61,7 +61,7 @@ open class EthClient( transactionReceiptRequests.computeIfAbsent(conn.uri()) { service.send( - conn.agreedSubprotocol(EthSubprotocol.ETH65), + conn.agreedSubprotocolVersion(EthSubprotocol.ETH65.name()), MessageType.GetReceipts.code, conn, GetReceipts(blockHashes).toBytes() @@ -88,7 +88,7 @@ open class EthClient( val completion = AsyncResult.incomplete<List<BlockHeader>>() headerRequests.computeIfAbsent(connection.uri() + blockHash.toHexString()) { service.send( - conn.agreedSubprotocol(EthSubprotocol.ETH65), + conn.agreedSubprotocolVersion(EthSubprotocol.ETH65.name()), MessageType.GetBlockHeaders.code, conn, GetBlockHeaders(blockHash, maxHeaders, skip, reverse).toBytes() @@ -109,7 +109,7 @@ open class EthClient( val completion = AsyncResult.incomplete<List<BlockHeader>>() headerRequests.computeIfAbsent(connection.uri() + blockNumberBytes.toHexString()) { service.send( - connection.agreedSubprotocol(EthSubprotocol.ETH65), + connection.agreedSubprotocolVersion(EthSubprotocol.ETH65.name()), MessageType.GetBlockHeaders.code, connection, GetBlockHeaders(blockNumberBytes, maxHeaders, skip, reverse).toBytes() @@ -129,7 +129,7 @@ open class EthClient( override fun requestBlockHeader(blockHash: Hash, connection: WireConnection): AsyncResult<BlockHeader> { val request = headerRequests.computeIfAbsent(connection.uri() + blockHash.toHexString()) { service.send( - connection.agreedSubprotocol(EthSubprotocol.ETH62), + connection.agreedSubprotocolVersion(EthSubprotocol.ETH62.name()), MessageType.GetBlockHeaders.code, connection, GetBlockHeaders(blockHash, 1, 0, false).toBytes() @@ -146,7 +146,7 @@ open class EthClient( val oldRequest = bodiesRequests.computeIfAbsent(connection.uri()) { oldRequestPresent = false service.send( - connection.agreedSubprotocol(EthSubprotocol.ETH65), + connection.agreedSubprotocolVersion(EthSubprotocol.ETH65.name()), MessageType.GetBlockBodies.code, connection, GetBlockBodies(blockHashes).toBytes() @@ -202,7 +202,7 @@ open class EthClient( val conns = service.repository().asIterable(EthSubprotocol.ETH65) conns.forEach { conn -> service.send( - conn.agreedSubprotocol(EthSubprotocol.ETH65), + conn.agreedSubprotocolVersion(EthSubprotocol.ETH65.name()), MessageType.NewPooledTransactionHashes.code, conn, GetBlockBodies(hashes).toBytes() diff --git a/devp2p-eth/src/main/kotlin/org/apache/tuweni/devp2p/eth/EthClient66.kt b/devp2p-eth/src/main/kotlin/org/apache/tuweni/devp2p/eth/EthClient66.kt index 63a43e4..130376f 100644 --- a/devp2p-eth/src/main/kotlin/org/apache/tuweni/devp2p/eth/EthClient66.kt +++ b/devp2p-eth/src/main/kotlin/org/apache/tuweni/devp2p/eth/EthClient66.kt @@ -81,7 +81,7 @@ class EthClient66( connection: WireConnection, ): AsyncResult<List<BlockHeader>> { logger.info("Requesting headers hash: $blockHash maxHeaders: $maxHeaders skip: $skip reverse: $reverse") - if (connection.agreedSubprotocol(EthSubprotocol.ETH66) != EthSubprotocol.ETH66) { + if (connection.agreedSubprotocolVersion(EthSubprotocol.ETH66.name()) != EthSubprotocol.ETH66) { return super.requestBlockHeaders(blockHash, maxHeaders, skip, reverse, connection) } val completion = AsyncResult.incomplete<List<BlockHeader>>() @@ -107,14 +107,14 @@ class EthClient66( reverse: Boolean, connection: WireConnection, ): AsyncResult<List<BlockHeader>> { - if (connection.agreedSubprotocol(EthSubprotocol.ETH66) != EthSubprotocol.ETH66) { + if (connection.agreedSubprotocolVersion(EthSubprotocol.ETH66.name()) != EthSubprotocol.ETH66) { return super.requestBlockHeaders(blockNumber, maxHeaders, skip, reverse, connection) } val blockNumberBytes = UInt256.valueOf(blockNumber) val completion = AsyncResult.incomplete<List<BlockHeader>>() headerRequests.computeIfAbsent(UInt64.random().toBytes()) { key -> service.send( - connection.agreedSubprotocol(EthSubprotocol.ETH62), + connection.agreedSubprotocolVersion(EthSubprotocol.ETH62.name()), MessageType.GetBlockHeaders.code, connection, RLP.encodeList { @@ -132,19 +132,19 @@ class EthClient66( blockHashes: List<Hash>, connection: WireConnection, ): AsyncResult<List<BlockHeader>> { - if (connection.agreedSubprotocol(EthSubprotocol.ETH66) != EthSubprotocol.ETH66) { + if (connection.agreedSubprotocolVersion(EthSubprotocol.ETH66.name()) != EthSubprotocol.ETH66) { return super.requestBlockHeaders(blockHashes, connection) } return AsyncResult.combine(blockHashes.stream().map { requestBlockHeader(it) }) } override fun requestBlockHeader(blockHash: Hash, connection: WireConnection): AsyncResult<BlockHeader> { - if (connection.agreedSubprotocol(EthSubprotocol.ETH66) != EthSubprotocol.ETH66) { + if (connection.agreedSubprotocolVersion(EthSubprotocol.ETH66.name()) != EthSubprotocol.ETH66) { return super.requestBlockHeader(blockHash, connection) } val request = headerRequests.computeIfAbsent(UInt64.random().toBytes()) { key -> service.send( - connection.agreedSubprotocol(EthSubprotocol.ETH62), + connection.agreedSubprotocolVersion(EthSubprotocol.ETH62.name()), MessageType.GetBlockHeaders.code, connection, RLP.encodeList { @@ -159,13 +159,13 @@ class EthClient66( } override fun requestBlockBodies(blockHashes: List<Hash>, connection: WireConnection): AsyncResult<List<BlockBody>> { - if (connection.agreedSubprotocol(EthSubprotocol.ETH66) != EthSubprotocol.ETH66) { + if (connection.agreedSubprotocolVersion(EthSubprotocol.ETH66.name()) != EthSubprotocol.ETH66) { return super.requestBlockBodies(blockHashes, connection) } val handle = AsyncResult.incomplete<List<BlockBody>>() bodiesRequests.compute(UInt64.random().toBytes()) { key, _ -> service.send( - connection.agreedSubprotocol(EthSubprotocol.ETH62), + connection.agreedSubprotocolVersion(EthSubprotocol.ETH62.name()), MessageType.GetBlockBodies.code, connection, RLP.encodeList { @@ -179,7 +179,7 @@ class EthClient66( } override fun requestBlock(blockHash: Hash, connection: WireConnection): AsyncResult<Block> { - if (connection.agreedSubprotocol(EthSubprotocol.ETH66) != EthSubprotocol.ETH66) { + if (connection.agreedSubprotocolVersion(EthSubprotocol.ETH66.name()) != EthSubprotocol.ETH66) { return super.requestBlock(blockHash, connection) } val headerRequest = requestBlockHeader(blockHash) @@ -222,7 +222,7 @@ class EthClient66( val conns = service.repository().asIterable(EthSubprotocol.ETH66) conns.forEach { conn -> service.send( - conn.agreedSubprotocol(EthSubprotocol.ETH66), + conn.agreedSubprotocolVersion(EthSubprotocol.ETH66.name()), MessageType.NewPooledTransactionHashes.code, conn, RLP.encodeList { @@ -235,7 +235,7 @@ class EthClient66( val conns65 = service.repository().asIterable(EthSubprotocol.ETH65) conns65.forEach { conn -> service.send( - conn.agreedSubprotocol(EthSubprotocol.ETH65), + conn.agreedSubprotocolVersion(EthSubprotocol.ETH65.name()), MessageType.NewPooledTransactionHashes.code, conn, GetBlockBodies(hashes).toBytes() diff --git a/devp2p-eth/src/main/kotlin/org/apache/tuweni/devp2p/eth/EthHandler.kt b/devp2p-eth/src/main/kotlin/org/apache/tuweni/devp2p/eth/EthHandler.kt index 73bac4f..2169599 100644 --- a/devp2p-eth/src/main/kotlin/org/apache/tuweni/devp2p/eth/EthHandler.kt +++ b/devp2p-eth/src/main/kotlin/org/apache/tuweni/devp2p/eth/EthHandler.kt @@ -146,7 +146,7 @@ internal class EthHandler( } if (missingTx.size == MAX_POOLED_TX) { service.send( - connection.agreedSubprotocol(ETH65), + connection.agreedSubprotocolVersion(ETH65.name()), MessageType.GetPooledTransactions.code, connection, message.toBytes() @@ -157,7 +157,7 @@ internal class EthHandler( } if (!missingTx.isEmpty()) { service.send( - connection.agreedSubprotocol(ETH65), + connection.agreedSubprotocolVersion(ETH65.name()), MessageType.GetPooledTransactions.code, connection, message.toBytes() @@ -172,7 +172,7 @@ internal class EthHandler( private suspend fun handleGetReceipts(connection: WireConnection, getReceipts: GetReceipts) { service.send( - connection.agreedSubprotocol(ETH62), + connection.agreedSubprotocolVersion(ETH62.name()), MessageType.Receipts.code, connection, Receipts(controller.findTransactionReceipts(getReceipts.hashes)).toBytes() @@ -181,7 +181,7 @@ internal class EthHandler( private suspend fun handleGetNodeData(connection: WireConnection, nodeData: GetNodeData) { service.send( - connection.agreedSubprotocol(ETH65), + connection.agreedSubprotocolVersion(ETH65.name()), MessageType.NodeData.code, connection, NodeData(controller.findNodeData(nodeData.hashes)).toBytes() @@ -198,7 +198,7 @@ internal class EthHandler( private suspend fun handleGetBlockBodies(connection: WireConnection, message: GetBlockBodies) { service.send( - connection.agreedSubprotocol(ETH62), + connection.agreedSubprotocolVersion(ETH62.name()), MessageType.BlockBodies.code, connection, BlockBodies(controller.findBlockBodies(message.hashes)).toBytes() @@ -216,7 +216,7 @@ internal class EthHandler( blockHeaderRequest.skip, blockHeaderRequest.reverse ) - service.send(connection.agreedSubprotocol(ETH62), MessageType.BlockHeaders.code, connection, BlockHeaders(headers).toBytes()) + service.send(connection.agreedSubprotocolVersion(ETH62.name()), MessageType.BlockHeaders.code, connection, BlockHeaders(headers).toBytes()) } private suspend fun handleNewBlockHashes(message: NewBlockHashes) { @@ -225,7 +225,7 @@ internal class EthHandler( override fun handleNewPeerConnection(connection: WireConnection): AsyncCompletion { val newPeer = pendingStatus.computeIfAbsent(connection.uri()) { PeerInfo() } - val ethSubProtocol = connection.agreedSubprotocol(EthSubprotocol.ETH65) + val ethSubProtocol = connection.agreedSubprotocolVersion(EthSubprotocol.ETH65.name()) if (ethSubProtocol == null) { newPeer.cancel() return newPeer.ready diff --git a/devp2p-eth/src/main/kotlin/org/apache/tuweni/devp2p/eth/EthHandler66.kt b/devp2p-eth/src/main/kotlin/org/apache/tuweni/devp2p/eth/EthHandler66.kt index dd128d4..05bfcef 100644 --- a/devp2p-eth/src/main/kotlin/org/apache/tuweni/devp2p/eth/EthHandler66.kt +++ b/devp2p-eth/src/main/kotlin/org/apache/tuweni/devp2p/eth/EthHandler66.kt @@ -51,7 +51,7 @@ internal class EthHandler66( } override fun handle(connection: WireConnection, messageType: Int, message: Bytes): AsyncCompletion { - if (connection.agreedSubprotocol(EthSubprotocol.ETH66) != EthSubprotocol.ETH66) { + if (connection.agreedSubprotocolVersion(EthSubprotocol.ETH66.name()) != EthSubprotocol.ETH66) { return ethHandler.handle(connection, messageType, message) } return asyncCompletion { @@ -269,11 +269,11 @@ internal class EthHandler66( } override fun handleNewPeerConnection(connection: WireConnection): AsyncCompletion { - if (connection.agreedSubprotocol(EthSubprotocol.ETH66) != EthSubprotocol.ETH66) { + if (connection.agreedSubprotocolVersion(EthSubprotocol.ETH66.name()) != EthSubprotocol.ETH66) { return ethHandler.handleNewPeerConnection(connection) } val newPeer = pendingStatus.computeIfAbsent(connection.uri()) { PeerInfo() } - val ethSubProtocol = connection.agreedSubprotocol(EthSubprotocol.ETH66) + val ethSubProtocol = connection.agreedSubprotocolVersion(EthSubprotocol.ETH66.name()) if (ethSubProtocol == null) { newPeer.cancel() return newPeer.ready diff --git a/devp2p-eth/src/test/kotlin/org/apache/tuweni/devp2p/eth/EthHandlerTest.kt b/devp2p-eth/src/test/kotlin/org/apache/tuweni/devp2p/eth/EthHandlerTest.kt index 5881a67..3351244 100644 --- a/devp2p-eth/src/test/kotlin/org/apache/tuweni/devp2p/eth/EthHandlerTest.kt +++ b/devp2p-eth/src/test/kotlin/org/apache/tuweni/devp2p/eth/EthHandlerTest.kt @@ -185,7 +185,7 @@ class EthHandlerTest { @Test fun testGetHeaders() = runBlocking { val conn = mock(WireConnection::class.java) - `when`(conn.agreedSubprotocol(eq(ETH62))).thenReturn(ETH64) + `when`(conn.agreedSubprotocolVersion(eq(ETH62.name()))).thenReturn(ETH64) handler.handle( conn, MessageType.GetBlockHeaders.code, @@ -205,7 +205,7 @@ class EthHandlerTest { @Test fun testGetHeadersTooMany() = runBlocking { val conn = mock(WireConnection::class.java) - `when`(conn.agreedSubprotocol(eq(ETH62))).thenReturn(ETH64) + `when`(conn.agreedSubprotocolVersion(eq(ETH62.name()))).thenReturn(ETH64) handler.handle( conn, MessageType.GetBlockHeaders.code, @@ -222,7 +222,7 @@ class EthHandlerTest { @Test fun testGetHeadersDifferentSkip() = runBlocking { val conn = mock(WireConnection::class.java) - `when`(conn.agreedSubprotocol(eq(ETH62))).thenReturn(ETH64) + `when`(conn.agreedSubprotocolVersion(eq(ETH62.name()))).thenReturn(ETH64) handler.handle( conn, MessageType.GetBlockHeaders.code, @@ -242,7 +242,7 @@ class EthHandlerTest { @Test fun testGetBodies() = runBlocking { val conn = mock(WireConnection::class.java) - `when`(conn.agreedSubprotocol(eq(ETH62))).thenReturn(ETH64) + `when`(conn.agreedSubprotocolVersion(eq(ETH62.name()))).thenReturn(ETH64) handler.handle( conn, MessageType.GetBlockBodies.code, @@ -260,8 +260,8 @@ class EthHandlerTest { @Test fun testGetReceipts() = runBlocking { val conn = mock(WireConnection::class.java) - `when`(conn.agreedSubprotocol(eq(ETH62))).thenReturn(ETH64) - `when`(conn.agreedSubprotocol(eq(ETH62))).thenReturn(ETH64) + `when`(conn.agreedSubprotocolVersion(eq(ETH62.name()))).thenReturn(ETH64) + `when`(conn.agreedSubprotocolVersion(eq(ETH62.name()))).thenReturn(ETH64) val hashes = repository.findBlockByHashOrNumber(UInt256.valueOf(7).toBytes()) val block7 = repository.retrieveBlock(hashes[0]) val txReceipt = repository.retrieveTransactionReceipt(hashes[0], 0) diff --git a/rlpx/src/main/java/org/apache/tuweni/rlpx/wire/WireConnection.java b/rlpx/src/main/java/org/apache/tuweni/rlpx/wire/WireConnection.java index 5335d2a..674cd1c 100644 --- a/rlpx/src/main/java/org/apache/tuweni/rlpx/wire/WireConnection.java +++ b/rlpx/src/main/java/org/apache/tuweni/rlpx/wire/WireConnection.java @@ -59,9 +59,9 @@ public interface WireConnection { * * @return the subprotocol, or null if no such subprotocol was present. */ - default SubProtocolIdentifier agreedSubprotocol(SubProtocolIdentifier subProtocolIdentifier) { + default SubProtocolIdentifier agreedSubprotocolVersion(String name) { for (SubProtocolIdentifier sp : agreedSubprotocols()) { - if (sp.name().equals(subProtocolIdentifier.name())) { + if (sp.name().equals(name)) { return sp; } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@tuweni.apache.org For additional commands, e-mail: commits-h...@tuweni.apache.org