This project is no longer maintained and has been archived.
A Multiaddr implementation in Swift.
Add the following to your Cartfile
github "multiformats/Swiftmultiaddr"
And in the root of your project type:
carthage update .
For more information on how to install via Carthage see the README
- Swift 5
Add the SwiftMultiaddr.framework to your Xcode project:
-
Select your target's
Build Phases
tab. -
Select the
Embed Frameworks
, select the DestinationFrameworks
and click the+
toAdd Other...
buttons. -
Navigate to the Carthage/Build/Mac directory in your project root and select all the frameworks in the folder.
In your code, import SwiftMultiaddr.
import SwiftMultiaddr
/// This does not handle try throwing errors. You should.
/// Construct a Multiaddr from a string.
let addr = try! newMultiaddr("/ip4/127.0.0.1/udp/1234")
/// Construct a Multiaddr from bytes
let addr2 = try! newMultiaddrBytes(addr.bytes())
/// true
try! addr.string() == "/ip4/127.0.0.1/udp/1234"
try! addr.string() == addr2.string()
addr.bytes() == addr2.bytes()
addr == addr2
/// Assuming the previous addr exists
addr.protocols()
/// [SwiftMultiaddr.Protocol(
/// code: 4, size: 32, name: "ip4", vCode: [4]),
///SwiftMultiaddr.Protocol(
/// code: 17, size: 16, name: "udp", vCode: [17])]
try! addr.encapsulate(newMultiaddr("/sctp/5678"))
/// Returns a SwiftMultiaddr /ip4/127.0.0.1/udp/1234/sctp/5678
try! addr.decapsulate(newMultiaddr("/udp/1234"))
/// Returns a SwiftMultiaddr /ip4/127.0.0.1
Multiaddr allows expressing tunnels in a very readable fashion.
let printer = try! newMultiaddr("/ip4/192.168.0.13/tcp/80")
let proxy = try! newMultiaddr("/ip4/10.20.30.40/tcp/443")
let printerOverProxy = proxy.encapsulate(printer)
/// /ip4/10.20.30.40/tcp/443/ip4/192.168.0.13/tcp/80
let proxyAgain = printerOverProxy.decapsulate(printer)
/// /ip4/10.20.30.40/tcp/443
Captain: @NeoTeo.
Contributions are welcome! Check out the issues.
Check out our contributing document for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS Code of Conduct.
If editing this README, note that this README should be standard-readme compatible.