Skip to content

Commit 4d24f0d

Browse files
authored
Merge pull request #1 from multiformats/feat/dns-webrtc-direct
Define DNS, WebRTC Direct and HTTP formats + gomod support
2 parents 3844c4b + 896bfff commit 4d24f0d

File tree

5 files changed

+104
-10
lines changed

5 files changed

+104
-10
lines changed

Diff for: go.mod

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module github.com/whyrusleeping/mafmt
2+
3+
require (
4+
github.com/multiformats/go-multiaddr v0.0.1
5+
github.com/multiformats/go-multiaddr-dns v0.0.2
6+
)

Diff for: go.sum

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
github.com/gxed/hashland/keccakpg v0.0.1 h1:wrk3uMNaMxbXiHibbPO4S0ymqJMm41WiudyFSs7UnsU=
2+
github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU=
3+
github.com/gxed/hashland/murmur3 v0.0.1 h1:SheiaIt0sda5K+8FLz952/1iWS9zrnKsEJaOJu4ZbSc=
4+
github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48=
5+
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g=
6+
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ=
7+
github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16 h1:5W7KhL8HVF3XCFOweFD3BNESdnO8ewyYTFT2R+/b8FQ=
8+
github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U=
9+
github.com/mr-tron/base58 v1.1.0 h1:Y51FGVJ91WBqCEabAi5OPUz38eAx8DakuAm5svLcsfQ=
10+
github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8=
11+
github.com/multiformats/go-multiaddr v0.0.1 h1:/QUV3VBMDI6pi6xfiw7lr6xhDWWvQKn9udPn68kLSdY=
12+
github.com/multiformats/go-multiaddr v0.0.1/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44=
13+
github.com/multiformats/go-multiaddr-dns v0.0.2 h1:/Bbsgsy3R6e3jf2qBahzNHzww6usYaZ0NhNH3sqdFS8=
14+
github.com/multiformats/go-multiaddr-dns v0.0.2/go.mod h1:9kWcqw/Pj6FwxAwW38n/9403szc57zJPs45fmnznu3Q=
15+
github.com/multiformats/go-multihash v0.0.1 h1:HHwN1K12I+XllBCrqKnhX949Orn4oawPkegHMu2vDqQ=
16+
github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U=
17+
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 h1:ng3VDlRp5/DHpSWl02R4rM9I+8M2rhmsuLwAMmkLQWE=
18+
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
19+
golang.org/x/sys v0.0.0-20190219092855-153ac476189d h1:Z0Ahzd7HltpJtjAHHxX8QFP3j1yYgiuvjbjRzDj/KH0=
20+
golang.org/x/sys v0.0.0-20190219092855-153ac476189d/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=

Diff for: package.json

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,28 @@
22
"author": "whyrusleeping",
33
"bugs": {},
44
"gx": {
5-
"dvcsimport": "github.com/whyrusleeping/mafmt"
5+
"dvcsimport": "github.com/multiformats/go-multiaddr-fmt"
66
},
77
"gxDependencies": [
88
{
99
"author": "whyrusleeping",
1010
"hash": "QmTZBfrPJmjWsCvHEtX5FE6KimVJhsJg5sBbqEFYf4UZtL",
1111
"name": "go-multiaddr",
1212
"version": "1.4.1"
13+
},
14+
{
15+
"author": "lgierth",
16+
"hash": "QmR1T4gAM6XCHQugKnPZgZVPzo8WkuvSpL57EKQFgFbwfd",
17+
"name": "go-multiaddr-dns",
18+
"version": "0.3.2"
1319
}
1420
],
1521
"gxVersion": "0.6.0",
1622
"gx_version": "0.4.0",
17-
"issues_url": "https://github.com/whyrusleeping/mafmt",
23+
"issues_url": "https://github.com/multiformats/go-multiaddr-fmt",
1824
"language": "go",
1925
"license": "",
20-
"name": "mafmt",
26+
"name": "go-multiaddr-fmt",
2127
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
2228
"version": "1.2.11"
2329
}

Diff for: patterns.go

+44-5
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,38 @@ import (
44
"strings"
55

66
ma "github.com/multiformats/go-multiaddr"
7+
madns "github.com/multiformats/go-multiaddr-dns"
8+
)
9+
10+
// Define a dns4 format multiaddr
11+
var DNS4 = Base(madns.P_DNS4)
12+
13+
// Define a dns6 format multiaddr
14+
var DNS6 = Base(madns.P_DNS6)
15+
16+
// Define a dnsaddr, dns4 or dns6 format multiaddr
17+
var DNS = Or(
18+
Base(madns.P_DNSADDR),
19+
DNS4,
20+
DNS6,
721
)
822

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

12-
// Define TCP as 'tcp' on top of either ipv4 or ipv6
13-
var TCP = And(IP, Base(ma.P_TCP))
26+
// Define TCP as 'tcp' on top of either ipv4 or ipv6, or dns equivalents.
27+
var TCP = Or(
28+
And(DNS, Base(ma.P_TCP)),
29+
And(IP, Base(ma.P_TCP)),
30+
)
1431

15-
// Define UDP as 'udp' on top of either ipv4 or ipv6
16-
var UDP = And(IP, Base(ma.P_UDP))
32+
// Define UDP as 'udp' on top of either ipv4 or ipv6, or dns equivalents.
33+
var UDP = Or(
34+
And(DNS, Base(ma.P_UDP)),
35+
And(IP, Base(ma.P_UDP)),
36+
)
1737

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

2141
// Define QUIC as 'quic' on top of udp (on top of ipv4 or ipv6)
@@ -30,6 +50,25 @@ var Reliable = Or(TCP, UTP, QUIC)
3050
// IPFS can run over any reliable underlying transport protocol
3151
var IPFS = And(Reliable, Base(ma.P_IPFS))
3252

53+
// Define http over TCP or DNS or http over DNS format multiaddr
54+
var HTTP = Or(
55+
And(TCP, Base(ma.P_HTTP)),
56+
And(IP, Base(ma.P_HTTP)),
57+
And(DNS, Base(ma.P_HTTP)),
58+
)
59+
60+
// Define https over TCP or DNS or https over DNS format multiaddr
61+
var HTTPS = Or(
62+
And(TCP, Base(ma.P_HTTPS)),
63+
And(IP, Base(ma.P_HTTPS)),
64+
And(DNS, Base(ma.P_HTTPS)),
65+
)
66+
67+
// Define p2p-webrtc-direct over HTTP or p2p-webrtc-direct over HTTPS format multiaddr
68+
var WebRTCDirect = Or(
69+
And(HTTP, Base(ma.P_P2P_WEBRTC_DIRECT)),
70+
And(HTTPS, Base(ma.P_P2P_WEBRTC_DIRECT)))
71+
3372
const (
3473
or = iota
3574
and = iota

Diff for: patterns_test.go

+25-2
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,37 @@ var TestVectors = map[string]*testVector{
4444
"/ip4/1.2.3.4/tcp/1234/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
4545
"/ip6/::/tcp/1234/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
4646
"/ip6/::/udp/1234/utp/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
47-
"/ip4/0.0.0.0/udp/1234/utp/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ"},
47+
"/ip4/0.0.0.0/udp/1234/utp/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
48+
},
4849
Bad: []string{
4950
"/ip4/1.2.3.4/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
5051
"/ip6/::/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
5152
"/tcp/123/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
5253
"/ip6/::/udp/1234/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
5354
"/ip6/::/utp/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
54-
"/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ"}},
55+
"/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
56+
},
57+
},
58+
"DNS": {
59+
Pattern: DNS,
60+
Good: []string{"/dnsaddr/example.io", "/dns4/example.io", "/dns6/example.io"},
61+
Bad: []string{"/ip4/127.0.0.1"},
62+
},
63+
"WebRTCDirect": {
64+
Pattern: WebRTCDirect,
65+
Good: []string{"/ip4/1.2.3.4/tcp/3456/http/p2p-webrtc-direct", "/ip6/::/tcp/0/http/p2p-webrtc-direct"},
66+
Bad: []string{"/ip4/0.0.0.0", "/ip6/fc00::", "/udp/12345", "/ip6/fc00::/tcp/5523/udp/9543"},
67+
},
68+
"HTTP": {
69+
Pattern: HTTP,
70+
Good: []string{"/ip4/1.2.3.4/http", "/dns4/example.io/http", "/dns6/::/tcp/7011/http", "/dnsaddr/example.io/http", "/ip6/fc00::/http"},
71+
Bad: []string{"/ip4/1.2.3.4/https", "/ip4/0.0.0.0/tcp/12345/quic", "/ip6/fc00::/tcp/5523"},
72+
},
73+
"HTTPS": {
74+
Pattern: HTTPS,
75+
Good: []string{"/ip4/1.2.3.4/https", "/dns4/example.io/https", "/dns6/::/tcp/7011/https", "/ip6/fc00::/https"},
76+
Bad: []string{"/ip4/1.2.3.4/http", "/ip4/0.0.0.0/tcp/12345/quic", "/ip6/fc00::/tcp/5523"},
77+
},
5578
}
5679

5780
func TestProtocolMatching(t *testing.T) {

0 commit comments

Comments
 (0)