Skip to content

Commit 74e82e2

Browse files
committed
merge branch 'master' into feat/dns-webrtc-direct
2 parents 53297ec + 3844c4b commit 74e82e2

File tree

4 files changed

+123
-126
lines changed

4 files changed

+123
-126
lines changed

.gx/lastpubver

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.2.7: QmQscWDtDBDsWAM58aY6gU2KtxyFFmvvZgdfJExYPLgtXA
1+
1.2.11: QmUrZZavcArYChpibtP8KgQXsAEpvgzUk73B2oj3HLbWc4

.travis.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
os:
2+
- linux
3+
4+
language: go
5+
6+
go:
7+
- 1.11.x
8+
9+
env:
10+
global:
11+
- GOTFLAGS="-race"
12+
- IPFS_REUSEPORT=false
13+
matrix:
14+
- BUILD_DEPTYPE=gx
15+
- BUILD_DEPTYPE=gomod
16+
17+
18+
# disable travis install
19+
install:
20+
- true
21+
22+
script:
23+
- bash <(curl -s https://raw.githubusercontent.com/ipfs/ci-helpers/master/travis-ci/run-standard-tests.sh)
24+
25+
26+
cache:
27+
directories:
28+
- $GOPATH/src/gx
29+
- $GOPATH/pkg/mod
30+
- /home/travis/.cache/go-build
31+
32+
notifications:
33+
email: false

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
"gxDependencies": [
88
{
99
"author": "whyrusleeping",
10-
"hash": "QmYmsdtJ3HsodkePE3eU3TsCaP2YvPZJ4LoXnNkDE5Tpt7",
10+
"hash": "QmTZBfrPJmjWsCvHEtX5FE6KimVJhsJg5sBbqEFYf4UZtL",
1111
"name": "go-multiaddr",
12-
"version": "1.3.0"
12+
"version": "1.4.1"
1313
}
1414
],
1515
"gxVersion": "0.6.0",
@@ -19,6 +19,6 @@
1919
"license": "",
2020
"name": "mafmt",
2121
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
22-
"version": "1.2.7"
22+
"version": "1.2.11"
2323
}
2424

patterns_test.go

Lines changed: 86 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,91 @@ import (
66
ma "github.com/multiformats/go-multiaddr"
77
)
88

9+
type testVector struct {
10+
Pattern Pattern
11+
Good []string
12+
Bad []string
13+
}
14+
15+
var TestVectors = map[string]*testVector{
16+
"IP": {
17+
Pattern: IP,
18+
Good: []string{"/ip4/0.0.0.0", "/ip6/fc00::"},
19+
Bad: []string{"/ip4/0.0.0.0/tcp/555", "/udp/789/ip6/fc00::"},
20+
},
21+
"TCP": {
22+
Pattern: TCP,
23+
Good: []string{"/ip4/0.0.7.6/tcp/1234", "/ip6/::/tcp/0"},
24+
Bad: []string{"/tcp/12345", "/ip6/fc00::/udp/5523/tcp/9543"},
25+
},
26+
"UDP": {
27+
Pattern: UDP,
28+
Good: []string{"/ip4/0.0.7.6/udp/1234", "/ip6/::/udp/0"},
29+
Bad: []string{"/udp/12345", "/ip6/fc00::/tcp/5523/udp/9543"},
30+
},
31+
"UTP": {
32+
Pattern: UTP,
33+
Good: []string{"/ip4/1.2.3.4/udp/3456/utp", "/ip6/::/udp/0/utp"},
34+
Bad: []string{"/ip4/0.0.0.0/tcp/12345/utp", "/ip6/1.2.3.4/ip4/0.0.0.0/udp/1234/utp", "/utp"},
35+
},
36+
"QUIC": {
37+
Pattern: QUIC,
38+
Good: []string{"/ip4/1.2.3.4/udp/1234/quic", "/ip6/::/udp/1234/quic"},
39+
Bad: []string{"/ip4/0.0.0.0/tcp/12345/quic", "/ip6/1.2.3.4/ip4/0.0.0.0/udp/1234/quic", "/quic"},
40+
},
41+
"IPFS": {
42+
Pattern: IPFS,
43+
Good: []string{
44+
"/ip4/1.2.3.4/tcp/1234/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
45+
"/ip6/::/tcp/1234/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
46+
"/ip6/::/udp/1234/utp/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
47+
"/ip4/0.0.0.0/udp/1234/utp/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ"},
48+
Bad: []string{
49+
"/ip4/1.2.3.4/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
50+
"/ip6/::/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
51+
"/tcp/123/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
52+
"/ip6/::/udp/1234/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
53+
"/ip6/::/utp/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
54+
"/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ"}},
55+
"DNS": {
56+
Pattern: DNS,
57+
Good: []string{"/dnsaddr/ipfs.io", "/dns4/ipfs.io", "/dns4/libp2p.io", "/dns6/protocol.ai"},
58+
Bad: []string{"/ip4/127.0.0.1"},
59+
},
60+
}
61+
62+
func TestProtocolMatching(t *testing.T) {
63+
for name, tc := range TestVectors {
64+
t.Run(name, func(t *testing.T) {
65+
t.Parallel()
66+
67+
assertMatches(t, tc.Pattern, tc.Good)
68+
69+
bad := [][]string{tc.Bad}
70+
for _, other := range TestVectors {
71+
if other == tc {
72+
continue
73+
}
74+
bad = append(bad, other.Good)
75+
}
76+
assertMismatches(t, tc.Pattern, bad...)
77+
})
78+
}
79+
}
80+
81+
func TestReliableGroup(t *testing.T) {
82+
assertMatches(t, Reliable, TestVectors["UTP"].Good, TestVectors["TCP"].Good, TestVectors["QUIC"].Good)
83+
assertMismatches(t, Reliable, TestVectors["IP"].Good, TestVectors["UDP"].Good, TestVectors["IPFS"].Good)
84+
}
85+
86+
func TestUnreliableGroup(t *testing.T) {
87+
assertMatches(t, Unreliable, TestVectors["UDP"].Good)
88+
assertMismatches(t, Unreliable, TestVectors["IP"].Good, TestVectors["TCP"].Good, TestVectors["UTP"].Good, TestVectors["IPFS"].Good, TestVectors["QUIC"].Good)
89+
}
90+
991
func assertMatches(t *testing.T, p Pattern, args ...[]string) {
92+
t.Helper()
93+
1094
t.Logf("testing assertions for %q", p)
1195
for _, argset := range args {
1296
for _, s := range argset {
@@ -23,6 +107,8 @@ func assertMatches(t *testing.T, p Pattern, args ...[]string) {
23107
}
24108

25109
func assertMismatches(t *testing.T, p Pattern, args ...[]string) {
110+
t.Helper()
111+
26112
for _, argset := range args {
27113
for _, s := range argset {
28114
addr, err := ma.NewMultiaddr(s)
@@ -36,125 +122,3 @@ func assertMismatches(t *testing.T, p Pattern, args ...[]string) {
36122
}
37123
}
38124
}
39-
40-
func TestBasicMatching(t *testing.T) {
41-
good_dns := []string{
42-
"/dnsaddr/ipfs.io",
43-
"/dns4/ipfs.io",
44-
"/dns4/libp2p.io",
45-
"/dns6/protocol.ai",
46-
}
47-
48-
bad_dns := []string{
49-
"/ip4/127.0.0.1",
50-
}
51-
52-
good_ip := []string{
53-
"/ip4/0.0.0.0",
54-
"/ip6/fc00::",
55-
}
56-
57-
bad_ip := []string{
58-
"/ip4/0.0.0.0/tcp/555",
59-
"/udp/789/ip6/fc00::",
60-
}
61-
62-
good_tcp := []string{
63-
"/ip4/0.0.7.6/tcp/1234",
64-
"/ip6/::/tcp/0",
65-
"/dns4/protocol.ai/tcp/80",
66-
"/dns6/protocol.ai/tcp/80",
67-
"/dnsaddr/protocol.ai/tcp/8",
68-
}
69-
70-
bad_tcp := []string{
71-
"/tcp/12345",
72-
"/ip6/fc00::/udp/5523/tcp/9543",
73-
}
74-
75-
good_udp := []string{
76-
"/ip4/0.0.7.6/udp/1234",
77-
"/ip6/::/udp/0",
78-
"/dns4/protocol.ai/udp/80",
79-
"/dns6/protocol.ai/udp/80",
80-
"/dnsaddr/protocol.ai/udp/8",
81-
}
82-
83-
bad_udp := []string{
84-
"/udp/12345",
85-
"/ip6/fc00::/tcp/5523/udp/9543",
86-
}
87-
88-
good_utp := []string{
89-
"/ip4/1.2.3.4/udp/3456/utp",
90-
"/ip6/::/udp/0/utp",
91-
}
92-
93-
bad_utp := []string{
94-
"/ip4/0.0.0.0/tcp/12345/utp",
95-
"/ip6/1.2.3.4/ip4/0.0.0.0/udp/1234/utp",
96-
"/utp",
97-
}
98-
99-
good_quic := []string{
100-
"/ip4/1.2.3.4/udp/1234/quic",
101-
"/ip6/::/udp/1234/quic",
102-
}
103-
104-
bad_quic := []string{
105-
"/ip4/0.0.0.0/tcp/12345/quic",
106-
"/ip6/1.2.3.4/ip4/0.0.0.0/udp/1234/quic",
107-
"/quic",
108-
}
109-
110-
good_webrtcdirect := []string{
111-
"/ip4/1.2.3.4/tcp/3456/http/p2p-webrtc-direct",
112-
"/ip6/::/tcp/0/http/p2p-webrtc-direct",
113-
}
114-
115-
good_ipfs := []string{
116-
"/ip4/1.2.3.4/tcp/1234/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
117-
"/ip6/::/tcp/1234/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
118-
"/ip6/::/udp/1234/utp/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
119-
"/ip4/0.0.0.0/udp/1234/utp/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
120-
}
121-
122-
bad_ipfs := []string{
123-
"/ip4/1.2.3.4/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
124-
"/ip6/::/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
125-
"/tcp/123/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
126-
"/ip6/::/udp/1234/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
127-
"/ip6/::/utp/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
128-
"/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
129-
}
130-
131-
assertMatches(t, DNS, good_dns)
132-
assertMismatches(t, DNS, bad_dns, bad_ip)
133-
134-
assertMatches(t, IP, good_ip)
135-
assertMismatches(t, IP, bad_ip, good_tcp)
136-
137-
assertMatches(t, TCP, good_tcp)
138-
assertMismatches(t, TCP, bad_tcp, good_ip)
139-
140-
assertMatches(t, UDP, good_udp)
141-
assertMismatches(t, UDP, bad_udp, good_ip, good_tcp, good_ipfs, good_utp, good_quic)
142-
143-
assertMatches(t, UTP, good_utp)
144-
assertMismatches(t, UTP, bad_utp, good_ip, good_tcp, good_udp, good_quic)
145-
146-
assertMatches(t, QUIC, good_quic)
147-
assertMismatches(t, QUIC, bad_quic, good_ip, good_tcp, good_udp, good_utp)
148-
149-
assertMatches(t, Reliable, good_utp, good_tcp, good_quic)
150-
assertMismatches(t, Reliable, good_ip, good_udp, good_ipfs)
151-
152-
assertMatches(t, Unreliable, good_udp)
153-
assertMismatches(t, Unreliable, good_ip, good_tcp, good_utp, good_ipfs, good_quic)
154-
155-
assertMatches(t, WebRTCDirect, good_webrtcdirect)
156-
assertMismatches(t, WebRTCDirect, good_ip, good_udp)
157-
158-
assertMatches(t, IPFS, good_ipfs)
159-
assertMismatches(t, IPFS, bad_ipfs, good_ip, good_tcp, good_utp, good_udp, good_quic)
160-
}

0 commit comments

Comments
 (0)