Commit 74e82e2a authored by Raúl Kripalani's avatar Raúl Kripalani

merge branch 'master' into feat/dns-webrtc-direct

parents 53297ecb 3844c4be
1.2.7: QmQscWDtDBDsWAM58aY6gU2KtxyFFmvvZgdfJExYPLgtXA
1.2.11: QmUrZZavcArYChpibtP8KgQXsAEpvgzUk73B2oj3HLbWc4
os:
- linux
language: go
go:
- 1.11.x
env:
global:
- GOTFLAGS="-race"
- IPFS_REUSEPORT=false
matrix:
- BUILD_DEPTYPE=gx
- BUILD_DEPTYPE=gomod
# disable travis install
install:
- true
script:
- bash <(curl -s https://raw.githubusercontent.com/ipfs/ci-helpers/master/travis-ci/run-standard-tests.sh)
cache:
directories:
- $GOPATH/src/gx
- $GOPATH/pkg/mod
- /home/travis/.cache/go-build
notifications:
email: false
......@@ -7,9 +7,9 @@
"gxDependencies": [
{
"author": "whyrusleeping",
"hash": "QmYmsdtJ3HsodkePE3eU3TsCaP2YvPZJ4LoXnNkDE5Tpt7",
"hash": "QmTZBfrPJmjWsCvHEtX5FE6KimVJhsJg5sBbqEFYf4UZtL",
"name": "go-multiaddr",
"version": "1.3.0"
"version": "1.4.1"
}
],
"gxVersion": "0.6.0",
......@@ -19,6 +19,6 @@
"license": "",
"name": "mafmt",
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
"version": "1.2.7"
"version": "1.2.11"
}
......@@ -6,7 +6,91 @@ import (
ma "github.com/multiformats/go-multiaddr"
)
type testVector struct {
Pattern Pattern
Good []string
Bad []string
}
var TestVectors = map[string]*testVector{
"IP": {
Pattern: IP,
Good: []string{"/ip4/0.0.0.0", "/ip6/fc00::"},
Bad: []string{"/ip4/0.0.0.0/tcp/555", "/udp/789/ip6/fc00::"},
},
"TCP": {
Pattern: TCP,
Good: []string{"/ip4/0.0.7.6/tcp/1234", "/ip6/::/tcp/0"},
Bad: []string{"/tcp/12345", "/ip6/fc00::/udp/5523/tcp/9543"},
},
"UDP": {
Pattern: UDP,
Good: []string{"/ip4/0.0.7.6/udp/1234", "/ip6/::/udp/0"},
Bad: []string{"/udp/12345", "/ip6/fc00::/tcp/5523/udp/9543"},
},
"UTP": {
Pattern: UTP,
Good: []string{"/ip4/1.2.3.4/udp/3456/utp", "/ip6/::/udp/0/utp"},
Bad: []string{"/ip4/0.0.0.0/tcp/12345/utp", "/ip6/1.2.3.4/ip4/0.0.0.0/udp/1234/utp", "/utp"},
},
"QUIC": {
Pattern: QUIC,
Good: []string{"/ip4/1.2.3.4/udp/1234/quic", "/ip6/::/udp/1234/quic"},
Bad: []string{"/ip4/0.0.0.0/tcp/12345/quic", "/ip6/1.2.3.4/ip4/0.0.0.0/udp/1234/quic", "/quic"},
},
"IPFS": {
Pattern: IPFS,
Good: []string{
"/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"},
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"}},
"DNS": {
Pattern: DNS,
Good: []string{"/dnsaddr/ipfs.io", "/dns4/ipfs.io", "/dns4/libp2p.io", "/dns6/protocol.ai"},
Bad: []string{"/ip4/127.0.0.1"},
},
}
func TestProtocolMatching(t *testing.T) {
for name, tc := range TestVectors {
t.Run(name, func(t *testing.T) {
t.Parallel()
assertMatches(t, tc.Pattern, tc.Good)
bad := [][]string{tc.Bad}
for _, other := range TestVectors {
if other == tc {
continue
}
bad = append(bad, other.Good)
}
assertMismatches(t, tc.Pattern, bad...)
})
}
}
func TestReliableGroup(t *testing.T) {
assertMatches(t, Reliable, TestVectors["UTP"].Good, TestVectors["TCP"].Good, TestVectors["QUIC"].Good)
assertMismatches(t, Reliable, TestVectors["IP"].Good, TestVectors["UDP"].Good, TestVectors["IPFS"].Good)
}
func TestUnreliableGroup(t *testing.T) {
assertMatches(t, Unreliable, TestVectors["UDP"].Good)
assertMismatches(t, Unreliable, TestVectors["IP"].Good, TestVectors["TCP"].Good, TestVectors["UTP"].Good, TestVectors["IPFS"].Good, TestVectors["QUIC"].Good)
}
func assertMatches(t *testing.T, p Pattern, args ...[]string) {
t.Helper()
t.Logf("testing assertions for %q", p)
for _, argset := range args {
for _, s := range argset {
......@@ -23,6 +107,8 @@ func assertMatches(t *testing.T, p Pattern, args ...[]string) {
}
func assertMismatches(t *testing.T, p Pattern, args ...[]string) {
t.Helper()
for _, argset := range args {
for _, s := range argset {
addr, err := ma.NewMultiaddr(s)
......@@ -36,125 +122,3 @@ func assertMismatches(t *testing.T, p Pattern, args ...[]string) {
}
}
}
func TestBasicMatching(t *testing.T) {
good_dns := []string{
"/dnsaddr/ipfs.io",
"/dns4/ipfs.io",
"/dns4/libp2p.io",
"/dns6/protocol.ai",
}
bad_dns := []string{
"/ip4/127.0.0.1",
}
good_ip := []string{
"/ip4/0.0.0.0",
"/ip6/fc00::",
}
bad_ip := []string{
"/ip4/0.0.0.0/tcp/555",
"/udp/789/ip6/fc00::",
}
good_tcp := []string{
"/ip4/0.0.7.6/tcp/1234",
"/ip6/::/tcp/0",
"/dns4/protocol.ai/tcp/80",
"/dns6/protocol.ai/tcp/80",
"/dnsaddr/protocol.ai/tcp/8",
}
bad_tcp := []string{
"/tcp/12345",
"/ip6/fc00::/udp/5523/tcp/9543",
}
good_udp := []string{
"/ip4/0.0.7.6/udp/1234",
"/ip6/::/udp/0",
"/dns4/protocol.ai/udp/80",
"/dns6/protocol.ai/udp/80",
"/dnsaddr/protocol.ai/udp/8",
}
bad_udp := []string{
"/udp/12345",
"/ip6/fc00::/tcp/5523/udp/9543",
}
good_utp := []string{
"/ip4/1.2.3.4/udp/3456/utp",
"/ip6/::/udp/0/utp",
}
bad_utp := []string{
"/ip4/0.0.0.0/tcp/12345/utp",
"/ip6/1.2.3.4/ip4/0.0.0.0/udp/1234/utp",
"/utp",
}
good_quic := []string{
"/ip4/1.2.3.4/udp/1234/quic",
"/ip6/::/udp/1234/quic",
}
bad_quic := []string{
"/ip4/0.0.0.0/tcp/12345/quic",
"/ip6/1.2.3.4/ip4/0.0.0.0/udp/1234/quic",
"/quic",
}
good_webrtcdirect := []string{
"/ip4/1.2.3.4/tcp/3456/http/p2p-webrtc-direct",
"/ip6/::/tcp/0/http/p2p-webrtc-direct",
}
good_ipfs := []string{
"/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",
}
bad_ipfs := []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",
}
assertMatches(t, DNS, good_dns)
assertMismatches(t, DNS, bad_dns, bad_ip)
assertMatches(t, IP, good_ip)
assertMismatches(t, IP, bad_ip, good_tcp)
assertMatches(t, TCP, good_tcp)
assertMismatches(t, TCP, bad_tcp, good_ip)
assertMatches(t, UDP, good_udp)
assertMismatches(t, UDP, bad_udp, good_ip, good_tcp, good_ipfs, good_utp, good_quic)
assertMatches(t, UTP, good_utp)
assertMismatches(t, UTP, bad_utp, good_ip, good_tcp, good_udp, good_quic)
assertMatches(t, QUIC, good_quic)
assertMismatches(t, QUIC, bad_quic, good_ip, good_tcp, good_udp, good_utp)
assertMatches(t, Reliable, good_utp, good_tcp, good_quic)
assertMismatches(t, Reliable, good_ip, good_udp, good_ipfs)
assertMatches(t, Unreliable, good_udp)
assertMismatches(t, Unreliable, good_ip, good_tcp, good_utp, good_ipfs, good_quic)
assertMatches(t, WebRTCDirect, good_webrtcdirect)
assertMismatches(t, WebRTCDirect, good_ip, good_udp)
assertMatches(t, IPFS, good_ipfs)
assertMismatches(t, IPFS, bad_ipfs, good_ip, good_tcp, good_utp, good_udp, good_quic)
}
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