https://github.com/swift-libp2p/swift-libp2p-identify
Peer Identification Protocols (Embedded)
https://github.com/swift-libp2p/swift-libp2p-identify
identify ipfs libp2p p2p swift
Last synced: about 1 month ago
JSON representation
Peer Identification Protocols (Embedded)
- Host: GitHub
- URL: https://github.com/swift-libp2p/swift-libp2p-identify
- Owner: swift-libp2p
- License: mit
- Created: 2022-06-21T16:06:06.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-03-06T22:58:06.000Z (over 1 year ago)
- Last Synced: 2025-03-20T06:22:33.949Z (about 1 year ago)
- Topics: identify, ipfs, libp2p, p2p, swift
- Language: Swift
- Homepage:
- Size: 146 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Identify (Embedded)
[](https://breth.app)
[](http://libp2p.io/)
[](https://github.com/apple/swift-package-manager)

> A core set of protocols used for `Identify`ing peers within libp2p
## Table of Contents
- [Overview](#overview)
- [Install](#install)
- [Usage](#usage)
- [Example](#example)
- [API](#api)
- [Contributing](#contributing)
- [Credits](#credits)
- [License](#license)
## 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.
#### For more details see
- [Multiformats / Mulitbase Spec](https://github.com/multiformats/multibase/blob/master/README.md)
## Install
> [!CAUTION]
> This package is embedded into [swift-libp2p](https://github.com/swift-libp2p/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
```Swift
let package = Package(
...
dependencies: [
...
.package(url: "https://github.com/swift-libp2p/swift-libp2p-identify.git", .upToNextMinor(from: "0.1.0"))
],
...
.target(
...
dependencies: [
...
.product(name: "LibP2PIdentify", package: "swift-libp2p-identify"),
]),
...
)
```
## Usage
> [!CAUTION]
> This package is embedded into [swift-libp2p](https://github.com/swift-libp2p/swift-libp2p) . There's no need to include this package as a dependency in your swift-libp2p project.
```Swift
/// Tell swift-libp2p to use Identify (the standard swift-libp2p implementation does this automatically)
app.identityManager.use(.default)
```
### Example
```Swift
/// Manually ping a peer
app.identify.ping(peer: peerID).map {
print("Latency: \($0)")
}
// or asynchronously
let ping = try await app.identify.ping(peer: peerID)
/// Manually ping a multiaddr
app.identify.ping(addr: multiaddr).map {
print("Latency: \($0)")
}
// or asynchronously
let ping = try await app.identify.ping(peer: multiaddr)
```
### API
```Swift
/// Attempts to Ping a Peer, returns the time it took to receive a response.
public func ping(peer: PeerID) -> EventLoopFuture
public func ping(peer: PeerID) async throws -> TimeAmount
/// Attempts to Ping a Multiaddr, returns the time it took to receive a response.
public func ping(addr: Multiaddr) -> EventLoopFuture
public func ping(addr: Multiaddr) async throws -> 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 critiques, are welcome!
Let's make this code better together! 🤝
## Credits
- [Identify Spec](https://github.com/libp2p/specs/blob/master/identify/README.md)
## License
[MIT](LICENSE) © 2022 Breth Inc.