Swiftpack.co - swift-libp2p/swift-libp2p-identify as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by swift-libp2p.
swift-libp2p/swift-libp2p-identify 0.0.3
Peer Identification Protocols (Embedded)
⭐️ 0
🕓 39 weeks ago
macOS
.package(url: "https://github.com/swift-libp2p/swift-libp2p-identify.git", from: "0.0.3")

Identify (Embedded)

Swift Package Manager compatible Build & Test (macos and linux)

A core set of protocols used for Identifying peers within libp2p

Table of Contents

Overview

Identify consists of a set of protocols used to help identify remote peers within the libp2p ecosystem. The protocols included within Identify are...

  • /ipfs/id
    • This protocol exchanges Signed Peer Records used for confirming a remote Peer is who they claim to be, the addresses they're listening on and the protocols they speak.
  • /ipfs/id/push
    • An extension of /ipfs/id that pushes changes to a Peers listening addresses and protocols as they update in realtime.
  • /ipfs/id/delta
    • An extension of /ipfs/id that pushes delta (partial) Peer Records that contain changes since an initial /ipfs/id Peer Record exchange
  • /ipfs/ping
    • A ping protocol that allows for quick and easy pings to libp2p Peers for measuring latency, testing liveness/connectivity, etc.

Heads up ‼️

  • This package is embedded into swift-libp2p . There's no need to include this package as a dependency in your swift-libp2p project.

For more details see

Install

Heads up ‼️

  • This package is embedded into swift-libp2p . There's no need to include this package as a dependency in your swift-libp2p project. Include the following dependency in your Package.swift file
let package = Package(
    ...
    dependencies: [
        ...
        .package(url: "https://github.com/swift-libp2p/swift-libp2p-identify.git", .upToNextMajor(from: "0.0.1"))
    ],
    ...
        .target(
            ...
            dependencies: [
                ...
                .product(name: "LibP2PIdentify", package: "swift-libp2p-identify"),
            ]),
    ...
)

Usage

Heads up ‼️

  • This package is embedded into swift-libp2p . There's no need to include this package as a dependency in your swift-libp2p project.

/// Tell swift-libp2p to use Identify (the standard swift-libp2p implementation does this automatically)
app.identityManager.use(.default)

Example


/// Manually ping a peer
app.identify.ping(peer: PeerID).map { 
    print("Latency: \($0)")
}

/// Manually ping a multiaddr
app.identify.ping(addr: Multiaddr).map { 
    print("Latency: \($0)")
}

API


/// Attempts to Ping a Peer, returns the time it took to receive a response.
public func ping(peer:PeerID) -> EventLoopFuture<TimeAmount> 

/// Attempts to Ping a Multiaddr, returns the time it took to receive a response.
public func ping(addr:Multiaddr) -> EventLoopFuture<TimeAmount>

Contributing

Contributions are welcomed! This code is very much a proof of concept. I can guarantee you there's a better / safer way to accomplish the same results. Any suggestions, improvements, or even just critques, are welcome!

Let's make this code better together! 🤝

Credits

License

MIT © 2022 Breth Inc.

GitHub

link
Stars: 0
Last commit: 38 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics