A zero-dependency P2P mesh networking library for iOS and macOS with local and remote relay support, plus a cross-platform transport for Android interop, by Olib AI
Used in StealthOS, the privacy-focused operating environment.
ConnectionPool is a Swift package that builds a secure mesh network with three transport modes:
- Local mode: MultipeerConnectivity over Wi-Fi and Bluetooth. No internet required.
- Remote mode: WebSocket transport via StealthRelay, a self-hosted Rust relay server. Connect from anywhere.
- Cross-platform mode: Bonjour/mDNS plus TCP with a platform-neutral wire protocol, interoperable with Android peers. Swift and Kotlin devices join the same session over the local network.
Every mode enforces end-to-end encryption, authenticates joiners with pool codes or invitation tokens, and protects relay envelopes with HMAC-SHA256. The library was built for StealthOS, where "privacy by default" is not a feature, it is the architecture.
Zero external dependencies. Everything ships in one Swift package.
| Document | Contents |
|---|---|
| Features | Full capability list for the local mesh, the remote relay transport, and Android interop |
| Architecture | Component layout, mesh message flow, remote relay handshake flow |
| Security | DTLS, pool codes, brute-force protection, envelope HMAC, loop prevention, host-offline persistence, tunnel exit |
| Installation | Swift Package Manager, XcodeGen, requirements, entitlements |
| Quick Start | Hosting, joining, messaging, remote pools, tunnel exit, auto-rejoin |
| Configuration | Injecting a logger, encrypted block list storage, encrypted remote pool state |
| Relay Server | Self-hosting StealthRelay with Docker or Cloudflare Tunnel |
| API Reference | Services, models, protocols, enumerations |
- Mesh networking with multi-hop relay: BFS shortest-path routing over a distributed neighbor map, with TTL, hop-path loop detection, and a bounded dedup cache
- Encrypted everywhere: DTLS on every
MCSession, AES-GCM over the relay WebSocket, ChaCha20-Poly1305 on the cross-platform transport, HMAC-SHA256 on routing metadata - Authenticated joins: pool codes that never touch Bonjour metadata, Ed25519-signed invitation URLs, proof-of-work anti-DoS, session tokens for privileged operations
- Hardened by default: brute-force auto-blocking, per-peer rate limits, 10 MB inbound cap, 1 MB WebSocket frame cap, persistent block list
- Survives host disconnect: pools live on the relay past the host's WebSocket drop, and approved members rejoin without the host being online
- Tunnel exit: route TCP/UDP through the relay so its IP is the visible exit address, with TLS still end-to-end to the destination
- Multiplayer game service: invitations, ready checks, state sync, forfeit handling, disconnect recovery
- Zero external dependencies: only
MultipeerConnectivity,CryptoKit,Combine,Foundation, andos
See Features for the complete list.
dependencies: [
.package(url: "https://github.com/Olib-AI/ConnectionPool.git", from: "1.6.0")
]XcodeGen setup, platform requirements, and the entitlements MultipeerConnectivity needs are in Installation.
import ConnectionPool
let manager = ConnectionPoolManager.shared
manager.startHosting(configuration: PoolConfiguration(
name: "My Room",
maxPeers: 8,
requireEncryption: true,
generatePoolCode: true
))
if let code = manager.currentSession?.poolCode {
print("Share this code: \(code)")
}
manager.sendChat("Hello, pool!")Browsing, joining, receiving, remote pools, and tunnel streams are covered in Quick Start.
iOS 17.0+, macOS 14.0+, Swift 6.0+, Xcode 16+. Details in Installation.
MIT License. Copyright (c) 2025 Olib AI. See LICENSE for the full text.
- Olib AI: package maintainer and StealthOS developer
- StealthRelay: self-hosted Rust relay server for remote pool connections
- Apple MultipeerConnectivity: local transport layer
- Apple CryptoKit: HMAC-SHA256, HKDF key derivation, Ed25519 signing
Contributions are welcome. See CONTRIBUTING.md, and please ensure:
- Code compiles under Swift 6 strict concurrency
- All public APIs are documented
- Actor isolation is maintained for thread safety
- No use of
@preconcurrencyescape hatches unless unavoidable and documented
If you discover a security vulnerability, please report it privately to security@olib.ai rather than opening a public issue. See SECURITY.md.