From 5447a095c464d3d6d0d0749e54554c28748eff78 Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Thu, 26 Sep 2024 09:50:37 +0100 Subject: [PATCH 1/7] Dependency sweep --- build.gradle.kts | 6 +++--- libp2p/build.gradle.kts | 2 +- versions.gradle | 18 +++++++++--------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 631b74340..6914e9f63 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -13,15 +13,15 @@ plugins { id("org.jetbrains.kotlin.jvm") version kotlinVersion apply false - id("com.github.ben-manes.versions").version("0.48.0") + id("com.github.ben-manes.versions").version("0.51.0") id("idea") id("io.gitlab.arturbosch.detekt").version("1.22.0") id("java") id("maven-publish") id("org.jetbrains.dokka").version("1.9.20") - id("com.diffplug.spotless").version("6.21.0") + id("com.diffplug.spotless").version("6.25.0") id("java-test-fixtures") - id("io.spring.dependency-management").version("1.1.3") + id("io.spring.dependency-management").version("1.1.6") id("org.jetbrains.kotlin.android") version kotlinVersion apply false id("com.android.application") version "7.4.2" apply false diff --git a/libp2p/build.gradle.kts b/libp2p/build.gradle.kts index 7b8a8e982..4810f6745 100644 --- a/libp2p/build.gradle.kts +++ b/libp2p/build.gradle.kts @@ -1,6 +1,6 @@ plugins { id("com.google.protobuf").version("0.9.4") - id("me.champeau.jmh").version("0.7.1") + id("me.champeau.jmh").version("0.7.2") } // https://docs.gradle.org/current/userguide/java_testing.html#ex-disable-publishing-of-test-fixtures-variants diff --git a/versions.gradle b/versions.gradle index 222ee08a8..b8bc0ff32 100644 --- a/versions.gradle +++ b/versions.gradle @@ -6,23 +6,23 @@ dependencyManagement { dependencies { dependency "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4" - dependency "com.google.guava:guava:32.1.2-jre" + dependency "com.google.guava:guava:33.3.1-jre" - dependency "org.slf4j:slf4j-api:2.0.9" - dependencySet(group: 'org.apache.logging.log4j', version: '2.20.0') { + dependency "org.slf4j:slf4j-api:2.0.16" + dependencySet(group: 'org.apache.logging.log4j', version: '2.24.0') { entry 'log4j-core' entry 'log4j-slf4j2-impl' } - dependencySet(group: 'org.junit.jupiter', version: '5.10.0') { + dependencySet(group: 'org.junit.jupiter', version: '5.11.1') { entry 'junit-jupiter-api' entry 'junit-jupiter-engine' entry 'junit-jupiter-params' } - dependency "io.mockk:mockk:1.13.3" - dependency "org.assertj:assertj-core:3.24.2" + dependency "io.mockk:mockk:1.13.12" + dependency "org.assertj:assertj-core:3.26.3" - dependencySet(group: "org.openjdk.jmh", version: "1.36") { + dependencySet(group: "org.openjdk.jmh", version: "1.37") { entry 'jmh-core' entry 'jmh-generator-annprocess' } @@ -31,7 +31,7 @@ dependencyManagement { entry 'protobuf-java' entry 'protoc' } - dependencySet(group: "io.netty", version: "4.1.108.Final") { + dependencySet(group: "io.netty", version: "4.1.113.Final") { entry 'netty-common' entry 'netty-handler' entry 'netty-transport' @@ -41,7 +41,7 @@ dependencyManagement { } dependency "com.github.multiformats:java-multibase:v1.1.1" dependency "tech.pegasys:noise-java:22.1.0" - dependencySet(group: "org.bouncycastle", version: "1.76") { + dependencySet(group: "org.bouncycastle", version: "1.78.1") { entry 'bcprov-jdk18on' entry 'bcpkix-jdk18on' entry 'bctls-jdk18on' From 27e1685b6564de6461bb7f8e2f0b17e0ddfc86d9 Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Thu, 26 Sep 2024 10:25:41 +0100 Subject: [PATCH 2/7] fix spotless --- build.gradle.kts | 6 +++++- .../kotlin/io/libp2p/example/chat/ChatProtocol.kt | 4 ++-- .../io/libp2p/core/multistream/NegotiatedProtocol.kt | 2 +- .../src/main/kotlin/io/libp2p/crypto/Libp2pCrypto.kt | 2 +- libp2p/src/main/kotlin/io/libp2p/crypto/keys/Rsa.kt | 4 ++-- .../io/libp2p/etc/util/netty/AbstractChildChannel.kt | 5 ++++- libp2p/src/main/kotlin/io/libp2p/pubsub/SeenCache.kt | 4 +++- .../transport/implementation/ConnectionOverNetty.kt | 8 ++++++-- .../kotlin/io/libp2p/tools/P2pdRunner.kt | 2 +- .../kotlin/io/libp2p/simulate/stats/StatsFactory.kt | 2 +- .../libp2p/simulate/stream/Libp2pConnectionImpl.kt | 3 +-- .../main/kotlin/io/libp2p/simulate/util/NumExt.kt | 12 +++++++++--- 12 files changed, 36 insertions(+), 18 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 6914e9f63..0b002b337 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -115,7 +115,11 @@ configure( "ktlint_standard_no-wildcard-imports" to "disabled", "ktlint_standard_enum-entry-name-case" to "disabled", "ktlint_standard_trailing-comma-on-call-site" to "disabled", - "ktlint_standard_trailing-comma-on-declaration-site" to "disabled" + "ktlint_standard_trailing-comma-on-declaration-site" to "disabled", + "ktlint_standard_value-parameter-comment" to "disabled", + "ktlint_standard_value-argument-comment" to "disabled", + "ktlint_standard_property-naming" to "disabled", + "ktlint_standard_function-naming" to "disabled" ) ) } diff --git a/examples/chatter/src/main/kotlin/io/libp2p/example/chat/ChatProtocol.kt b/examples/chatter/src/main/kotlin/io/libp2p/example/chat/ChatProtocol.kt index 4517cde87..6674f8db8 100644 --- a/examples/chatter/src/main/kotlin/io/libp2p/example/chat/ChatProtocol.kt +++ b/examples/chatter/src/main/kotlin/io/libp2p/example/chat/ChatProtocol.kt @@ -19,9 +19,9 @@ typealias OnChatMessage = (PeerId, String) -> Unit class Chat(chatCallback: OnChatMessage) : ChatBinding(ChatProtocol(chatCallback)) -const val protocolId: ProtocolId = "/example/chat/0.1.0" +const val PROTOCOL_ID: ProtocolId = "/example/chat/0.1.0" -open class ChatBinding(echo: ChatProtocol) : StrictProtocolBinding(protocolId, echo) +open class ChatBinding(echo: ChatProtocol) : StrictProtocolBinding(PROTOCOL_ID, echo) open class ChatProtocol( private val chatCallback: OnChatMessage diff --git a/libp2p/src/main/kotlin/io/libp2p/core/multistream/NegotiatedProtocol.kt b/libp2p/src/main/kotlin/io/libp2p/core/multistream/NegotiatedProtocol.kt index e0b04d655..294fd1f6e 100644 --- a/libp2p/src/main/kotlin/io/libp2p/core/multistream/NegotiatedProtocol.kt +++ b/libp2p/src/main/kotlin/io/libp2p/core/multistream/NegotiatedProtocol.kt @@ -6,7 +6,7 @@ import java.util.concurrent.CompletableFuture /** * Represents [ProtocolBinding] with exact protocol version which was agreed on */ -open class NegotiatedProtocol> ( +open class NegotiatedProtocol>( val binding: TBinding, val protocol: ProtocolId ) { diff --git a/libp2p/src/main/kotlin/io/libp2p/crypto/Libp2pCrypto.kt b/libp2p/src/main/kotlin/io/libp2p/crypto/Libp2pCrypto.kt index daa6ff4d2..d11cf44c5 100644 --- a/libp2p/src/main/kotlin/io/libp2p/crypto/Libp2pCrypto.kt +++ b/libp2p/src/main/kotlin/io/libp2p/crypto/Libp2pCrypto.kt @@ -23,7 +23,7 @@ import org.bouncycastle.crypto.params.KeyParameter * that's smaller than 512 bits. Keys need to be larger enough to sign a 256bit * hash so this is a reasonable absolute minimum. */ -const val ErrRsaKeyTooSmall = "rsa keys must be >= 512 bits to be useful" +const val ERR_RSA_KEY_TOO_SMALL = "rsa keys must be >= 512 bits to be useful" const val RSA_ALGORITHM = "RSA" const val SHA_ALGORITHM = "SHA-256" diff --git a/libp2p/src/main/kotlin/io/libp2p/crypto/keys/Rsa.kt b/libp2p/src/main/kotlin/io/libp2p/crypto/keys/Rsa.kt index 4e0e14f47..752a23cff 100644 --- a/libp2p/src/main/kotlin/io/libp2p/crypto/keys/Rsa.kt +++ b/libp2p/src/main/kotlin/io/libp2p/crypto/keys/Rsa.kt @@ -16,7 +16,7 @@ import crypto.pb.Crypto import io.libp2p.core.Libp2pException import io.libp2p.core.crypto.PrivKey import io.libp2p.core.crypto.PubKey -import io.libp2p.crypto.ErrRsaKeyTooSmall +import io.libp2p.crypto.ERR_RSA_KEY_TOO_SMALL import io.libp2p.crypto.KEY_PKCS8 import io.libp2p.crypto.Libp2pCrypto import io.libp2p.crypto.RSA_ALGORITHM @@ -100,7 +100,7 @@ class RsaPublicKey(private val k: JavaPublicKey) : PubKey(Crypto.KeyType.RSA) { @JvmOverloads fun generateRsaKeyPair(bits: Int, random: SecureRandom = SecureRandom()): Pair { if (bits < 2048) { - throw Libp2pException(ErrRsaKeyTooSmall) + throw Libp2pException(ERR_RSA_KEY_TOO_SMALL) } val kp: KeyPair = with( diff --git a/libp2p/src/main/kotlin/io/libp2p/etc/util/netty/AbstractChildChannel.kt b/libp2p/src/main/kotlin/io/libp2p/etc/util/netty/AbstractChildChannel.kt index d914e2a48..260606240 100644 --- a/libp2p/src/main/kotlin/io/libp2p/etc/util/netty/AbstractChildChannel.kt +++ b/libp2p/src/main/kotlin/io/libp2p/etc/util/netty/AbstractChildChannel.kt @@ -20,7 +20,10 @@ import java.net.SocketAddress */ abstract class AbstractChildChannel(parent: Channel, id: ChannelId?) : AbstractChannel(parent, id) { private enum class State { - OPEN, ACTIVE, INACTIVE, CLOSED + OPEN, + ACTIVE, + INACTIVE, + CLOSED } private val parentCloseFuture = parent.closeFuture() diff --git a/libp2p/src/main/kotlin/io/libp2p/pubsub/SeenCache.kt b/libp2p/src/main/kotlin/io/libp2p/pubsub/SeenCache.kt index 676ba5f21..9136899ac 100644 --- a/libp2p/src/main/kotlin/io/libp2p/pubsub/SeenCache.kt +++ b/libp2p/src/main/kotlin/io/libp2p/pubsub/SeenCache.kt @@ -51,7 +51,9 @@ class SimpleSeenCache : SeenCache { override fun put(msg: PubsubMessage, value: TValue) { map[msg.messageId] = value } - override fun remove(messageId: MessageId) { map -= messageId } + override fun remove(messageId: MessageId) { + map -= messageId + } } class LRUSeenCache(val delegate: SeenCache, private val maxSize: Int) : SeenCache by delegate { diff --git a/libp2p/src/main/kotlin/io/libp2p/transport/implementation/ConnectionOverNetty.kt b/libp2p/src/main/kotlin/io/libp2p/transport/implementation/ConnectionOverNetty.kt index f6617cc03..90c1d824f 100644 --- a/libp2p/src/main/kotlin/io/libp2p/transport/implementation/ConnectionOverNetty.kt +++ b/libp2p/src/main/kotlin/io/libp2p/transport/implementation/ConnectionOverNetty.kt @@ -30,8 +30,12 @@ open class ConnectionOverNetty( ch.attr(CONNECTION).set(this) } - fun setMuxerSession(ms: StreamMuxer.Session) { muxerSession = ms } - fun setSecureSession(ss: SecureChannel.Session) { secureSession = ss } + fun setMuxerSession(ms: StreamMuxer.Session) { + muxerSession = ms + } + fun setSecureSession(ss: SecureChannel.Session) { + secureSession = ss + } override fun muxerSession() = muxerSession override fun secureSession() = secureSession diff --git a/libp2p/src/testFixtures/kotlin/io/libp2p/tools/P2pdRunner.kt b/libp2p/src/testFixtures/kotlin/io/libp2p/tools/P2pdRunner.kt index dd204b7d2..2045ff671 100644 --- a/libp2p/src/testFixtures/kotlin/io/libp2p/tools/P2pdRunner.kt +++ b/libp2p/src/testFixtures/kotlin/io/libp2p/tools/P2pdRunner.kt @@ -14,7 +14,7 @@ class P2pdRunner(val execNames: List = listOf("p2pd", "p2pd.exe"), val e fun findP2pdExe(): String? = (predefinedSearchPaths + execSearchPaths) .flatMap { path -> execNames.map { File(path, it) } } - .firstOrNull() { it.canExecute() } + .firstOrNull { it.canExecute() } ?.absoluteFile?.canonicalPath fun launcher() = findP2pdExe()?.let { DaemonLauncher(it) } diff --git a/tools/simulator/src/main/kotlin/io/libp2p/simulate/stats/StatsFactory.kt b/tools/simulator/src/main/kotlin/io/libp2p/simulate/stats/StatsFactory.kt index ded5f14ae..5eb94f547 100644 --- a/tools/simulator/src/main/kotlin/io/libp2p/simulate/stats/StatsFactory.kt +++ b/tools/simulator/src/main/kotlin/io/libp2p/simulate/stats/StatsFactory.kt @@ -17,7 +17,7 @@ interface StatsFactory { override fun toString() = "" } - var DEFAULT: StatsFactory = object : StatsFactory { + val DEFAULT: StatsFactory = object : StatsFactory { override fun createStats(name: String) = DescriptiveStatsImpl() } } diff --git a/tools/simulator/src/main/kotlin/io/libp2p/simulate/stream/Libp2pConnectionImpl.kt b/tools/simulator/src/main/kotlin/io/libp2p/simulate/stream/Libp2pConnectionImpl.kt index 3976b9c61..3ca752706 100644 --- a/tools/simulator/src/main/kotlin/io/libp2p/simulate/stream/Libp2pConnectionImpl.kt +++ b/tools/simulator/src/main/kotlin/io/libp2p/simulate/stream/Libp2pConnectionImpl.kt @@ -9,8 +9,7 @@ import io.libp2p.simulate.util.NullTransport import io.libp2p.transport.implementation.ConnectionOverNetty class Libp2pConnectionImpl( - val remoteAddr: - Multiaddr, + val remoteAddr: Multiaddr, isInitiator: Boolean, localPubkey: PubKey, remotePubkey: PubKey, diff --git a/tools/simulator/src/main/kotlin/io/libp2p/simulate/util/NumExt.kt b/tools/simulator/src/main/kotlin/io/libp2p/simulate/util/NumExt.kt index fae6fd791..be3113ac1 100644 --- a/tools/simulator/src/main/kotlin/io/libp2p/simulate/util/NumExt.kt +++ b/tools/simulator/src/main/kotlin/io/libp2p/simulate/util/NumExt.kt @@ -22,11 +22,15 @@ fun Collection.groupByRangesBy( where TKey : Number, TKey : Comparable = groupByRangesBy(keyExtractor, { it }, *ranges) -fun Collection>.groupByRanges(vararg ranges: ClosedRange): Map, List> +fun Collection>.groupByRanges( + vararg ranges: ClosedRange +): Map, List> where T : Number, T : Comparable = groupByRangesBy({ it.first }, { it.second }, *ranges) -fun Collection.countByRanges(vararg ranges: ClosedRange): List +fun Collection.countByRanges( + vararg ranges: ClosedRange +): List where T : Number, T : Comparable { val v = this .map { it to it } @@ -35,7 +39,9 @@ fun Collection.countByRanges(vararg ranges: ClosedRange): List return ranges.map { v[it]?.size ?: 0 } } -fun Collection.countByRanges(ranges: List>): List +fun Collection.countByRanges( + ranges: List> +): List where T : Number, T : Comparable = countByRanges(*ranges.toTypedArray()) From 8b5de4a2dcfeabd16afde29079b2917de6055584 Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Thu, 26 Sep 2024 10:27:21 +0100 Subject: [PATCH 3/7] nit --- libp2p/src/main/kotlin/io/libp2p/crypto/Libp2pCrypto.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libp2p/src/main/kotlin/io/libp2p/crypto/Libp2pCrypto.kt b/libp2p/src/main/kotlin/io/libp2p/crypto/Libp2pCrypto.kt index d11cf44c5..7cb7b0e71 100644 --- a/libp2p/src/main/kotlin/io/libp2p/crypto/Libp2pCrypto.kt +++ b/libp2p/src/main/kotlin/io/libp2p/crypto/Libp2pCrypto.kt @@ -19,7 +19,7 @@ import org.bouncycastle.crypto.macs.HMac import org.bouncycastle.crypto.params.KeyParameter /** - * ErrRsaKeyTooSmall is returned when trying to generate or parse an RSA key + * ERR_RSA_KEY_TOO_SMALL is returned when trying to generate or parse an RSA key * that's smaller than 512 bits. Keys need to be larger enough to sign a 256bit * hash so this is a reasonable absolute minimum. */ From 073bcda14df384c0d2148a814b88d864e6618ea5 Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Thu, 26 Sep 2024 10:40:13 +0100 Subject: [PATCH 4/7] revert mockk version --- versions.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/versions.gradle b/versions.gradle index b8bc0ff32..aab39fdee 100644 --- a/versions.gradle +++ b/versions.gradle @@ -19,7 +19,7 @@ dependencyManagement { entry 'junit-jupiter-engine' entry 'junit-jupiter-params' } - dependency "io.mockk:mockk:1.13.12" + dependency "io.mockk:mockk:1.13.3" dependency "org.assertj:assertj-core:3.26.3" dependencySet(group: "org.openjdk.jmh", version: "1.37") { From ceecc2084254f66ac6c5b031caf5ca175139f254 Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Thu, 26 Sep 2024 10:49:32 +0100 Subject: [PATCH 5/7] revert slf4j version --- versions.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/versions.gradle b/versions.gradle index aab39fdee..78d438797 100644 --- a/versions.gradle +++ b/versions.gradle @@ -8,7 +8,7 @@ dependencyManagement { dependency "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4" dependency "com.google.guava:guava:33.3.1-jre" - dependency "org.slf4j:slf4j-api:2.0.16" + dependency "org.slf4j:slf4j-api:2.0.10" dependencySet(group: 'org.apache.logging.log4j', version: '2.24.0') { entry 'log4j-core' entry 'log4j-slf4j2-impl' From 04568797a3f237bd6dbca7d5298b2c0c6547dc6b Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Thu, 26 Sep 2024 11:02:27 +0100 Subject: [PATCH 6/7] revert more slf4j --- versions.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/versions.gradle b/versions.gradle index 78d438797..677439928 100644 --- a/versions.gradle +++ b/versions.gradle @@ -8,7 +8,7 @@ dependencyManagement { dependency "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4" dependency "com.google.guava:guava:33.3.1-jre" - dependency "org.slf4j:slf4j-api:2.0.10" + dependency "org.slf4j:slf4j-api:2.0.9" dependencySet(group: 'org.apache.logging.log4j', version: '2.24.0') { entry 'log4j-core' entry 'log4j-slf4j2-impl' From 76072812442dfc21703873146e6f8f42b4b029ef Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Thu, 26 Sep 2024 13:37:57 +0100 Subject: [PATCH 7/7] fix android --- examples/android-chatter/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/android-chatter/build.gradle b/examples/android-chatter/build.gradle index fdf829839..41dd1bfcd 100644 --- a/examples/android-chatter/build.gradle +++ b/examples/android-chatter/build.gradle @@ -24,6 +24,7 @@ android { packagingOptions { exclude 'META-INF/io.netty.versions.properties' exclude 'META-INF/INDEX.LIST' + exclude 'META-INF/versions/9/OSGI-INF/MANIFEST.MF' } kotlinOptions { jvmTarget = "11"