Giter Site home page Giter Site logo

swiftmultiaddr's Introduction

Swift Multiaddr

Carthage compatible

A Multiaddr implementation in Swift.

Table of Contents

Install

Carthage

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

Requirements

  • Swift 3

Usage

Add the SwiftMultiaddr.framework to your Xcode project:

  • Select your target's Build Phases tab.

  • Select the Embed Frameworks, select the Destination Frameworks and click the + to Add 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.

Example

Simple

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

Protocols

/// 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])] 

En/decapsulate

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

Tunneling

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

Maintainers

Captain: @NeoTeo.

Contribute

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.

License

MIT © Matteo Sartori

swiftmultiaddr's People

Contributors

neoteo avatar richardlitt avatar

Forkers

thexdesk

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.