From ff4b568e38775519fdd0ed9d697ff509a82b3f61 Mon Sep 17 00:00:00 2001 From: Brandon <32753167+btoms20@users.noreply.github.com> Date: Thu, 6 Mar 2025 14:19:25 -0800 Subject: [PATCH 1/4] Bumped swift-libp2p to 0.2.0 for multiaddr update --- Package.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Package.swift b/Package.swift index 2f7b06e..d4636c2 100644 --- a/Package.swift +++ b/Package.swift @@ -29,9 +29,11 @@ let package = Package( ], dependencies: [ // Dependencies declare other packages that this package depends on. - .package(url: "https://github.com/swift-libp2p/swift-libp2p.git", .upToNextMajor(from: "0.1.0")), - .package(url: "https://github.com/swift-libp2p/swift-libp2p-mplex.git", .upToNextMajor(from: "0.1.0")), - .package(url: "https://github.com/swift-libp2p/swift-libp2p-noise.git", .upToNextMajor(from: "0.1.0")), + .package(url: "https://github.com/swift-libp2p/swift-libp2p.git", .upToNextMinor(from: "0.2.0")), + + // Test Dependencies + .package(url: "https://github.com/swift-libp2p/swift-libp2p-mplex.git", .upToNextMinor(from: "0.1.0")), + .package(url: "https://github.com/swift-libp2p/swift-libp2p-noise.git", .upToNextMinor(from: "0.1.0")), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. From 55c4de034b5d5a41266a9b8e4addf187e38f651d Mon Sep 17 00:00:00 2001 From: Brandon <32753167+btoms20@users.noreply.github.com> Date: Thu, 6 Mar 2025 14:20:36 -0800 Subject: [PATCH 2/4] Moved away from deprecated bytes to id --- Sources/LibP2PIdentify/LibP2PIdentify.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/LibP2PIdentify/LibP2PIdentify.swift b/Sources/LibP2PIdentify/LibP2PIdentify.swift index 773205c..94e03ad 100644 --- a/Sources/LibP2PIdentify/LibP2PIdentify.swift +++ b/Sources/LibP2PIdentify/LibP2PIdentify.swift @@ -364,7 +364,7 @@ extension Identify { // - TODO: This doesn't handle multiple parallel outbound pings to the same peer func initiateOutboundPingTo(peer: PeerID) -> EventLoopFuture { el.flatSubmit { - if let outstandingPing = self.pingCache[peer.bytes] { + if let outstandingPing = self.pingCache[peer.id] { // If the outstanding ping has been in flight for more than 3 seconds, fail the promise if DispatchTime.now().uptimeNanoseconds - outstandingPing.startTime > 3_000_000_000 { print("We have an outstanding ping thats older than 3 seconds") @@ -373,11 +373,11 @@ extension Identify { // If the outstanding ping hasn't timed out yet, just return the results of the existing promise return promise.futureResult } - self.pingCache.removeValue(forKey: peer.bytes) + self.pingCache.removeValue(forKey: peer.id) } //guard self.pingCache[peer.bytes] == nil else { return application!.eventLoopGroup.next().makeFailedFuture(Errors.timedOut) } let promise = self.application!.eventLoopGroup.next().makePromise(of: TimeAmount.self) - self.pingCache[peer.bytes] = PendingPing( + self.pingCache[peer.id] = PendingPing( peer: "", startTime: DispatchTime.now().uptimeNanoseconds, promise: promise @@ -394,7 +394,7 @@ extension Identify { self.logger.warning("Identify::Failed to ping addr `\(addr)`. A valid peerID is neccessary") return self.el.makeFailedFuture(Errors.timedOut) } - if let outstandingPing = self.pingCache[peer.bytes] { + if let outstandingPing = self.pingCache[peer.id] { // If the outstanding ping has been in flight for more than 3 seconds, fail the promise if DispatchTime.now().uptimeNanoseconds - outstandingPing.startTime > 3_000_000_000 { print("We have an outstanding ping thats older than 3 seconds") @@ -403,11 +403,11 @@ extension Identify { // If the outstanding ping hasn't timed out yet, just return the results of the existing promise return promise.futureResult } - self.pingCache.removeValue(forKey: peer.bytes) + self.pingCache.removeValue(forKey: peer.id) } //guard self.pingCache[peer.bytes] == nil else { return application!.eventLoopGroup.next().makeFailedFuture(Errors.timedOut) } let promise = self.application!.eventLoopGroup.next().makePromise(of: TimeAmount.self) - self.pingCache[peer.bytes] = PendingPing( + self.pingCache[peer.id] = PendingPing( peer: "", startTime: DispatchTime.now().uptimeNanoseconds, promise: promise From 1ec8e64bdb3b69c4a3dc5154f8f27861ce13bc3e Mon Sep 17 00:00:00 2001 From: Brandon <32753167+btoms20@users.noreply.github.com> Date: Thu, 6 Mar 2025 14:21:05 -0800 Subject: [PATCH 3/4] Using the new getPeerID function --- Sources/LibP2PIdentify/LibP2PIdentify.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/LibP2PIdentify/LibP2PIdentify.swift b/Sources/LibP2PIdentify/LibP2PIdentify.swift index 94e03ad..d67cba7 100644 --- a/Sources/LibP2PIdentify/LibP2PIdentify.swift +++ b/Sources/LibP2PIdentify/LibP2PIdentify.swift @@ -390,7 +390,7 @@ extension Identify { // - TODO: This doesn't handle multiple parallel outbound pings to the same peer func initiateOutboundPingTo(addr: Multiaddr) -> EventLoopFuture { el.flatSubmit { - guard let cid = addr.getPeerID(), let peer = try? PeerID(cid: cid) else { + guard let peer = try? addr.getPeerID() else { self.logger.warning("Identify::Failed to ping addr `\(addr)`. A valid peerID is neccessary") return self.el.makeFailedFuture(Errors.timedOut) } @@ -427,7 +427,7 @@ extension Identify { let startTime = DispatchTime.now().uptimeNanoseconds /// Check to see if this ping was initiated by our IndetifyManager... el.execute { - if let initiatedPing = self.pingCache.removeValue(forKey: remotePeer.bytes) { + if let initiatedPing = self.pingCache.removeValue(forKey: remotePeer.id) { self.pingCache[bytes] = PendingPing( peer: remotePeer.b58String, startTime: startTime, From 0b096385f1075d07229a0bdfee885926ad00cdaa Mon Sep 17 00:00:00 2001 From: Brandon <32753167+btoms20@users.noreply.github.com> Date: Thu, 6 Mar 2025 14:21:26 -0800 Subject: [PATCH 4/4] Removed unused allTests var --- Tests/LibP2PIdentifyTests/LibP2PIdentifyTests.swift | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/Tests/LibP2PIdentifyTests/LibP2PIdentifyTests.swift b/Tests/LibP2PIdentifyTests/LibP2PIdentifyTests.swift index c26bc57..eb562e5 100644 --- a/Tests/LibP2PIdentifyTests/LibP2PIdentifyTests.swift +++ b/Tests/LibP2PIdentifyTests/LibP2PIdentifyTests.swift @@ -414,18 +414,6 @@ final class LibP2PIdentifyTests: XCTestCase { XCTAssertEqual(latency1, latency2) XCTAssertEqual(latency2, latency3) } - - static var allTests = [ - ("testIPFSIdentifyPayload", testIPFSIdentifyPayload), - ("testIPFSIdentifyPushPayloadJSClient", testIPFSIdentifyPushPayloadJSClient), - ("testIDPushRecordDecoding", testIDPushRecordDecoding), - ("testLibP2PInternalPingMultiaddr", testLibP2PInternalPingMultiaddr), - ("testLibP2PInternalPingPeer", testLibP2PInternalPingPeer), - ( - "testLibP2PInternalPingPeerCascadeMultipleInflightPings", - testLibP2PInternalPingPeerCascadeMultipleInflightPings - ), - ] } struct Fixtures {