mafmt

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2019 License: MIT Imports: 2 Imported by: 122

README

multiaddr format

A validation checker for multiaddrs. Some basic validators for common address types are provided, but creating your own combinations is easy.

Usage:

a, _ := ma.NewMultiaddr("/ip4/5.2.67.3/tcp/1708")
TCP.Matches(a) // returns true

Making your own validators is easy, for example, the Reliable multiaddr is defined as follows:

// Define IP as either ipv4 or ipv6
var IP = Or(Base(ma.P_IP4), Base(ma.P_IP6))

// Define TCP as 'tcp' on top of either ipv4 or ipv6
var TCP = And(IP, Base(ma.P_TCP))

// Define UDP as 'udp' on top of either ipv4 or ipv6
var UDP = And(IP, Base(ma.P_UDP))

// Define UTP as 'utp' on top of udp (on top of ipv4 or ipv6)
var UTP = And(UDP, Base(ma.P_UTP))

// Now define a Reliable transport as either tcp or utp
var Reliable = Or(TCP, UTP)

// From here, we can easily define multiaddrs for protocols that can run on top
// of any 'reliable' transport (such as ipfs)

NOTE: the above patterns are already implemented in package

Documentation

Index

Constants

This section is empty.

Variables

Define a dnsaddr, dns, dns4 or dns6 format multiaddr

View Source
var DNS4 = Base(ma.P_DNS4)

Define a dns4 format multiaddr

View Source
var DNS6 = Base(ma.P_DNS6)

Define a dns6 format multiaddr

View Source
var HTTP = Or(
	And(TCP, Base(ma.P_HTTP)),
	And(IP, Base(ma.P_HTTP)),
	And(DNS, Base(ma.P_HTTP)),
)

Define http over TCP or DNS or http over DNS format multiaddr

Define https over TCP or DNS or https over DNS format multiaddr

Define IP as either ipv4 or ipv6

View Source
var IPFS = P2P

IPFS can run over any reliable underlying transport protocol

Deprecated: use P2P

P2P can run over any reliable underlying transport protocol

View Source
var QUIC = And(UDP, Base(ma.P_QUIC))

Define QUIC as 'quic' on top of udp (on top of ipv4 or ipv6)

View Source
var Reliable = Or(TCP, UTP, QUIC)

Now define a Reliable transport as either tcp or utp or quic

View Source
var TCP = Or(
	And(DNS, Base(ma.P_TCP)),
	And(IP, Base(ma.P_TCP)),
)

Define TCP as 'tcp' on top of either ipv4 or ipv6, or dns equivalents.

View Source
var UDP = Or(
	And(DNS, Base(ma.P_UDP)),
	And(IP, Base(ma.P_UDP)),
)

Define UDP as 'udp' on top of either ipv4 or ipv6, or dns equivalents.

View Source
var UTP = And(UDP, Base(ma.P_UTP))

Define UTP as 'utp' on top of udp (on top of ipv4 or ipv6).

View Source
var Unreliable = Or(UDP)

Define unreliable transport as udp

Define p2p-webrtc-direct over HTTP or p2p-webrtc-direct over HTTPS format multiaddr

Functions

This section is empty.

Types

type Base

type Base int

func (Base) Matches

func (p Base) Matches(a ma.Multiaddr) bool

func (Base) String

func (p Base) String() string

type Pattern

type Pattern interface {
	Matches(ma.Multiaddr) bool

	String() string
	// contains filtered or unexported methods
}

func And

func And(ps ...Pattern) Pattern

func Or

func Or(ps ...Pattern) Pattern

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL