Skip to content

Multiaddr Update #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 8 additions & 8 deletions Sources/LibP2PIdentify/LibP2PIdentify.swift
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ extension Identify {
// - TODO: This doesn't handle multiple parallel outbound pings to the same peer
func initiateOutboundPingTo(peer: PeerID) -> EventLoopFuture<TimeAmount> {
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")
Expand All @@ -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
Expand All @@ -390,11 +390,11 @@ extension Identify {
// - TODO: This doesn't handle multiple parallel outbound pings to the same peer
func initiateOutboundPingTo(addr: Multiaddr) -> EventLoopFuture<TimeAmount> {
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)
}
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")
Expand All @@ -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
Expand All @@ -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,
Expand Down
12 changes: 0 additions & 12 deletions Tests/LibP2PIdentifyTests/LibP2PIdentifyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down