Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
mf
go-multiaddr-fmt
Commits
528c6065
Commit
528c6065
authored
Dec 20, 2018
by
backkem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add p2p-webrtc-direct pattern
parent
1dc32401
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
0 deletions
+64
-0
patterns.go
patterns.go
+39
-0
patterns_test.go
patterns_test.go
+25
-0
No files found.
patterns.go
View file @
528c6065
...
...
@@ -4,6 +4,25 @@ 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
)
var
_DNS
=
Or
(
Base
(
madns
.
P_DNSADDR
),
DNS4
,
DNS6
,
)
// Define a dns4 or dns6 format multiaddr
var
DNS
=
Or
(
And
(
_DNS
,
Base
(
ma
.
P_TCP
)),
_DNS
,
)
// Define IP as either ipv4 or ipv6
...
...
@@ -30,6 +49,26 @@ 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
)),
And
(
DNS
),
)
// 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
...
...
patterns_test.go
View file @
528c6065
...
...
@@ -38,6 +38,20 @@ 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"
,
"/dns4/protocol.ai/tcp/80"
,
"/dns6/protocol.ai/tcp/80"
,
"/dnsaddr/protocol.ai/tcp/8"
,
}
bad_dns
:=
[]
string
{
"/ip4/127.0.0.1"
,
}
good_ip
:=
[]
string
{
"/ip4/0.0.0.0"
,
"/ip6/fc00::"
,
...
...
@@ -90,6 +104,11 @@ func TestBasicMatching(t *testing.T) {
"/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"
,
...
...
@@ -106,6 +125,9 @@ func TestBasicMatching(t *testing.T) {
"/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
)
...
...
@@ -127,6 +149,9 @@ func TestBasicMatching(t *testing.T) {
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
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment