Skip to content

swift-libp2p/swift-libp2p-identify

Repository files navigation

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.