@hackage multiaddr0.1.0
A network address format
Categories
License
BSD-3-Clause
Maintainer
Micxjo Funkcio <micxjo@fastmail.com>
Links
Versions
Installation
Dependencies (7)
- attoparsec >=0.13.0.1 && <0.14
- base >=4.7 && <5
- bytestring >=0.10.6.0 && <0.11
- cereal >=0.5.1.0 && <0.6
- errors >=2.1.2 && <2.2
- hashable >=1.2.4.0 && <1.3 Show all…
Dependents (1)
@hackage/acme-everything
hs-multiaddr
A multiaddr implementation in Haskell. Multiaddr is a self-describing network address format supporting a variety of protocols, with both string and binary representations.
Installation
Just clone and stack build. Will be uploaded to Hackage soon!
Usage
import Network.Multiaddr
let Just somewhere = readMultiaddr "/ip4/8.8.8.8/tcp/80"
protocolNames somewhere -- ["ip4", "tcp"]
-- Encapsulation
-- Multiaddr is a monoid, `encapsulate` is just an alias for (<>)
let Just proxy = readMultiaddr "/ip6/::1/tcp/443"
let proxied = proxy `encapsulate` somewhere
toText proxied -- "/ip6/::1/tcp/443/ip4/8.8.8.8/tcp/80"
hasIPv6 proxied -- True
-- Grab an individual part of the address
parts proxied !! 2 -- "/ip4/8.8.8.8"
-- Encode into a ByteString
let bytes = encode proxied
-- Decode and get back the original!
let Just decoded = decode bytes
decoded == proxied -- True