Unverified Commit 4d24f0db authored by Raúl Kripalani's avatar Raúl Kripalani Committed by GitHub

Merge pull request #1 from multiformats/feat/dns-webrtc-direct

Define DNS, WebRTC Direct and HTTP formats + gomod support
parents 3844c4be 896bfffc
github.com/gxed/hashland/keccakpg v0.0.1 h1:wrk3uMNaMxbXiHibbPO4S0ymqJMm41WiudyFSs7UnsU=
github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU=
github.com/gxed/hashland/murmur3 v0.0.1 h1:SheiaIt0sda5K+8FLz952/1iWS9zrnKsEJaOJu4ZbSc=
github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48=
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g=
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ=
github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16 h1:5W7KhL8HVF3XCFOweFD3BNESdnO8ewyYTFT2R+/b8FQ=
github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U=
github.com/mr-tron/base58 v1.1.0 h1:Y51FGVJ91WBqCEabAi5OPUz38eAx8DakuAm5svLcsfQ=
github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8=
github.com/multiformats/go-multiaddr v0.0.1 h1:/QUV3VBMDI6pi6xfiw7lr6xhDWWvQKn9udPn68kLSdY=
github.com/multiformats/go-multiaddr v0.0.1/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44=
github.com/multiformats/go-multiaddr-dns v0.0.2 h1:/Bbsgsy3R6e3jf2qBahzNHzww6usYaZ0NhNH3sqdFS8=
github.com/multiformats/go-multiaddr-dns v0.0.2/go.mod h1:9kWcqw/Pj6FwxAwW38n/9403szc57zJPs45fmnznu3Q=
github.com/multiformats/go-multihash v0.0.1 h1:HHwN1K12I+XllBCrqKnhX949Orn4oawPkegHMu2vDqQ=
github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U=
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 h1:ng3VDlRp5/DHpSWl02R4rM9I+8M2rhmsuLwAMmkLQWE=
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/sys v0.0.0-20190219092855-153ac476189d h1:Z0Ahzd7HltpJtjAHHxX8QFP3j1yYgiuvjbjRzDj/KH0=
golang.org/x/sys v0.0.0-20190219092855-153ac476189d/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
......@@ -2,7 +2,7 @@
"author": "whyrusleeping",
"bugs": {},
"gx": {
"dvcsimport": "github.com/whyrusleeping/mafmt"
"dvcsimport": "github.com/multiformats/go-multiaddr-fmt"
},
"gxDependencies": [
{
......@@ -10,14 +10,20 @@
"hash": "QmTZBfrPJmjWsCvHEtX5FE6KimVJhsJg5sBbqEFYf4UZtL",
"name": "go-multiaddr",
"version": "1.4.1"
},
{
"author": "lgierth",
"hash": "QmR1T4gAM6XCHQugKnPZgZVPzo8WkuvSpL57EKQFgFbwfd",
"name": "go-multiaddr-dns",
"version": "0.3.2"
}
],
"gxVersion": "0.6.0",
"gx_version": "0.4.0",
"issues_url": "https://github.com/whyrusleeping/mafmt",
"issues_url": "https://github.com/multiformats/go-multiaddr-fmt",
"language": "go",
"license": "",
"name": "mafmt",
"name": "go-multiaddr-fmt",
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
"version": "1.2.11"
}
......
......@@ -4,18 +4,38 @@ import (
"strings"
ma "github.com/multiformats/go-multiaddr"
madns "github.com/multiformats/go-multiaddr-dns"
)
// Define a dns4 format multiaddr
var DNS4 = Base(madns.P_DNS4)
// Define a dns6 format multiaddr
var DNS6 = Base(madns.P_DNS6)
// Define a dnsaddr, dns4 or dns6 format multiaddr
var DNS = Or(
Base(madns.P_DNSADDR),
DNS4,
DNS6,
)
// 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 TCP as 'tcp' on top of either ipv4 or ipv6, or dns equivalents.
var TCP = Or(
And(DNS, Base(ma.P_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 UDP as 'udp' on top of either ipv4 or ipv6, or dns equivalents.
var UDP = Or(
And(DNS, Base(ma.P_UDP)),
And(IP, Base(ma.P_UDP)),
)
// Define UTP as 'utp' on top of udp (on top of ipv4 or ipv6)
// Define UTP as 'utp' on top of udp (on top of ipv4 or ipv6).
var UTP = And(UDP, Base(ma.P_UTP))
// Define QUIC as 'quic' on top of udp (on top of ipv4 or ipv6)
......@@ -30,6 +50,25 @@ var Reliable = Or(TCP, UTP, QUIC)
// IPFS can run over any reliable underlying transport protocol
var IPFS = And(Reliable, Base(ma.P_IPFS))
// Define http over TCP or DNS or http over DNS format multiaddr
var HTTP = Or(
And(TCP, Base(ma.P_HTTP)),
And(IP, Base(ma.P_HTTP)),
And(DNS, Base(ma.P_HTTP)),
)
// Define https over TCP or DNS or https over DNS format multiaddr
var HTTPS = Or(
And(TCP, Base(ma.P_HTTPS)),
And(IP, Base(ma.P_HTTPS)),
And(DNS, Base(ma.P_HTTPS)),
)
// Define p2p-webrtc-direct over HTTP or p2p-webrtc-direct over HTTPS format multiaddr
var WebRTCDirect = Or(
And(HTTP, Base(ma.P_P2P_WEBRTC_DIRECT)),
And(HTTPS, Base(ma.P_P2P_WEBRTC_DIRECT)))
const (
or = iota
and = iota
......
......@@ -44,14 +44,37 @@ var TestVectors = map[string]*testVector{
"/ip4/1.2.3.4/tcp/1234/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
"/ip6/::/tcp/1234/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
"/ip6/::/udp/1234/utp/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
"/ip4/0.0.0.0/udp/1234/utp/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ"},
"/ip4/0.0.0.0/udp/1234/utp/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
},
Bad: []string{
"/ip4/1.2.3.4/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
"/ip6/::/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
"/tcp/123/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
"/ip6/::/udp/1234/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
"/ip6/::/utp/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
"/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ"}},
"/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
},
},
"DNS": {
Pattern: DNS,
Good: []string{"/dnsaddr/example.io", "/dns4/example.io", "/dns6/example.io"},
Bad: []string{"/ip4/127.0.0.1"},
},
"WebRTCDirect": {
Pattern: WebRTCDirect,
Good: []string{"/ip4/1.2.3.4/tcp/3456/http/p2p-webrtc-direct", "/ip6/::/tcp/0/http/p2p-webrtc-direct"},
Bad: []string{"/ip4/0.0.0.0", "/ip6/fc00::", "/udp/12345", "/ip6/fc00::/tcp/5523/udp/9543"},
},
"HTTP": {
Pattern: HTTP,
Good: []string{"/ip4/1.2.3.4/http", "/dns4/example.io/http", "/dns6/::/tcp/7011/http", "/dnsaddr/example.io/http", "/ip6/fc00::/http"},
Bad: []string{"/ip4/1.2.3.4/https", "/ip4/0.0.0.0/tcp/12345/quic", "/ip6/fc00::/tcp/5523"},
},
"HTTPS": {
Pattern: HTTPS,
Good: []string{"/ip4/1.2.3.4/https", "/dns4/example.io/https", "/dns6/::/tcp/7011/https", "/ip6/fc00::/https"},
Bad: []string{"/ip4/1.2.3.4/http", "/ip4/0.0.0.0/tcp/12345/quic", "/ip6/fc00::/tcp/5523"},
},
}
func TestProtocolMatching(t *testing.T) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment