Swift LibP2P
The Swift implementation of the libp2p networking stack
Table of Contents
Overview
libp2p is a networking stack and library modularized out of The IPFS Project, and bundled separately for other tools to use.
libp2p is the product of a long, and arduous quest of understanding -- a deep dive into the internet's network stack, and plentiful peer-to-peer protocols from the past. Building large-scale peer-to-peer systems has been complex and difficult in the last 15 years, and libp2p is a way to fix that. It is a "network stack" -- a protocol suite -- that cleanly separates concerns, and enables sophisticated applications to only use the protocols they absolutely need, without giving up interoperability and upgradeability. libp2p grew out of IPFS, but it is built so that lots of people can use it, for lots of different projects.
Docs & Examples
Note:
To learn more, check out the following resources:
- the libp2p documentation
- the libp2p community discussion forum
- the libp2p specification
- the go-libp2p implementation
- the js-libp2p implementation
- the rust-libp2p implementation
Disclaimer
-
‼️ This is a work in progress‼️ -
‼️ Please don't use swift-libp2p in anything other than experimental projects until it reaches 1.0‼️ -
‼️ Help it get there sooner by contributing‼️
Install
Include the following dependency in your Package.swift file
let package = Package(
...
dependencies: [
...
.package(name: "LibP2P", url: "https://github.com/swift-libp2p/swift-libp2p.git", .upToNextMajor(from: "0.0.1"))
],
...
.target(
...
dependencies: [
...
.product(name: "LibP2P", package: "swift-libp2p"),
]),
...
)
Usage
Example
import LibP2P
import LibP2PNoise
import LibP2PMPLEX
/// Configure your Libp2p networking stack...
let lib = try Application(.development, peerID: PeerID(.Ed25519))
lib.security.use(.noise)
lib.muxers.use(.mplex)
lib.servers.use(.tcp(host: "127.0.0.1", port: 0))
/// Register your routes handlers...
/// - Note: Uses the same syntax as swift-vapor
try lib.routes()
/// Start libp2p
lib.start()
/// Do some networking stuff... 📡
/// At some later point, when you're done with libp2p...
lib.shutdown()
- Check out the libp2p-app-template repo for a bare-bones executable app ready to be customized
- Check out the Configure an Echo Server tutorial in the documentation for more info
Packages
- List of packages currently in existence for swift libp2p:
- Legend:
🟢 = kinda works,🟡 = doesn't really work yet,🔴 = not started yet, but on the radar
Name | Status | Description |
---|---|---|
Libp2p | ||
swift-libp2p |
|
swift-libp2p entry point |
swift-libp2p-core |
|
core interfaces, types, and abstractions |
Network | ||
swift-libp2p-mss |
|
MultistreamSelect transport upgrader |
Transport | ||
swift-libp2p-tcp |
|
TCP transport |
swift-libp2p-udp |
|
UDP transport |
swift-libp2p-ws |
|
WebSocket transport |
swift-libp2p-http |
|
HTTP1 transport |
swift-libp2p-http2 |
|
HTTP2 transport |
Encrypted Channels | ||
swift-libp2p-plaintext |
|
Plaintext channel |
swift-libp2p-noise |
|
Noise crypto channel |
swift-libp2p-tls |
|
TLS 1.3+ crypto channel |
Stream Muxers | ||
swift-libp2p-mplex |
|
MPLEX stream multiplexer |
swift-libp2p-yamux |
|
YAMUX stream multiplexer |
Private Network | ||
swift-libp2p-pnet |
|
reference private networking implementation |
NAT Traversal | ||
swift-libp2p-nat |
|
NAT Traversal |
Peerstore | ||
swift-libp2p-peerstore |
|
reference implementation of peer metadata storage component |
Connection Manager | ||
swift-libp2p-connection-manager |
|
reference implementation of connection manager |
Routing | ||
swift-libp2p-record |
|
record type and validator logic |
swift-libp2p-kad-dht |
|
Kademlia-like router |
swift-libp2p-kbucket |
|
Kademlia routing table helper types |
Pubsub | ||
swift-libp2p-pubsub |
|
multiple pubsub implementations |
RPC | ||
swift-libp2p-rpc |
|
a simple RPC library for libp2p |
Utilities/miscellaneous | ||
swift-libp2p-dbsaddr |
|
a dnsaddr resolver |
swift-libp2p-mdns |
|
MulticastDNS for LAN discovery |
Testing and examples | ||
swift-libp2p-testing |
|
a collection of testing utilities for libp2p |
API
/// TODO
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.