Unverified Commit 232f8cfa authored by Marten Seemann's avatar Marten Seemann Committed by GitHub

Merge pull request #176 from multiformats/webtransport

add WebTransport multiaddr components
parents f5adc3b7 adec8516
...@@ -4,6 +4,7 @@ go 1.17 ...@@ -4,6 +4,7 @@ go 1.17
require ( require (
github.com/ipfs/go-cid v0.0.7 github.com/ipfs/go-cid v0.0.7
github.com/multiformats/go-multibase v0.0.3
github.com/multiformats/go-multihash v0.0.14 github.com/multiformats/go-multihash v0.0.14
github.com/multiformats/go-varint v0.0.6 github.com/multiformats/go-varint v0.0.6
github.com/stretchr/testify v1.7.0 github.com/stretchr/testify v1.7.0
...@@ -16,7 +17,6 @@ require ( ...@@ -16,7 +17,6 @@ require (
github.com/mr-tron/base58 v1.1.3 // indirect github.com/mr-tron/base58 v1.1.3 // indirect
github.com/multiformats/go-base32 v0.0.3 // indirect github.com/multiformats/go-base32 v0.0.3 // indirect
github.com/multiformats/go-base36 v0.1.0 // indirect github.com/multiformats/go-base36 v0.1.0 // indirect
github.com/multiformats/go-multibase v0.0.3 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8 // indirect golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8 // indirect
......
...@@ -74,6 +74,8 @@ func TestConstructFails(t *testing.T) { ...@@ -74,6 +74,8 @@ func TestConstructFails(t *testing.T) {
"/ip4/127.0.0.1/tcp/jfodsajfidosajfoidsa", "/ip4/127.0.0.1/tcp/jfodsajfidosajfoidsa",
"/ip4/127.0.0.1/tcp", "/ip4/127.0.0.1/tcp",
"/ip4/127.0.0.1/quic/1234", "/ip4/127.0.0.1/quic/1234",
"/ip4/127.0.0.1/udp/1234/quic/webtransport/certhash",
"/ip4/127.0.0.1/udp/1234/quic/webtransport/certhash/b2uaraocy6yrdblb4sfptaddgimjmmp", // 1 character missing from certhash
"/ip4/127.0.0.1/ipfs", "/ip4/127.0.0.1/ipfs",
"/ip4/127.0.0.1/ipfs/tcp", "/ip4/127.0.0.1/ipfs/tcp",
"/ip4/127.0.0.1/p2p", "/ip4/127.0.0.1/p2p",
...@@ -157,6 +159,9 @@ func TestConstructSucceeds(t *testing.T) { ...@@ -157,6 +159,9 @@ func TestConstructSucceeds(t *testing.T) {
"/ip4/127.0.0.1/tcp/1234", "/ip4/127.0.0.1/tcp/1234",
"/ip4/127.0.0.1/tcp/1234/", "/ip4/127.0.0.1/tcp/1234/",
"/ip4/127.0.0.1/udp/1234/quic", "/ip4/127.0.0.1/udp/1234/quic",
"/ip4/127.0.0.1/udp/1234/quic/webtransport",
"/ip4/127.0.0.1/udp/1234/quic/webtransport/certhash/b2uaraocy6yrdblb4sfptaddgimjmmpy",
"/ip4/127.0.0.1/udp/1234/quic/webtransport/certhash/b2uaraocy6yrdblb4sfptaddgimjmmpy/certhash/zQmbWTwYGcmdyK9CYfNBcfs9nhZs17a6FQ4Y8oea278xx41",
"/ip4/127.0.0.1/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC", "/ip4/127.0.0.1/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC",
"/ip4/127.0.0.1/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234", "/ip4/127.0.0.1/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234",
"/ip4/127.0.0.1/ipfs/k2k4r8oqamigqdo6o7hsbfwd45y70oyynp98usk7zmyfrzpqxh1pohl7", "/ip4/127.0.0.1/ipfs/k2k4r8oqamigqdo6o7hsbfwd45y70oyynp98usk7zmyfrzpqxh1pohl7",
...@@ -542,6 +547,7 @@ func TestRoundTrip(t *testing.T) { ...@@ -542,6 +547,7 @@ func TestRoundTrip(t *testing.T) {
"/ip4/127.0.0.1/tcp/123/tls", "/ip4/127.0.0.1/tcp/123/tls",
"/ip4/127.0.0.1/udp/123", "/ip4/127.0.0.1/udp/123",
"/ip4/127.0.0.1/udp/123/ip6/::", "/ip4/127.0.0.1/udp/123/ip6/::",
"/ip4/127.0.0.1/udp/1234/quic/webtransport/certhash/uEiDDq4_xNyDorZBH3TlGazyJdOWSwvo4PUo5YHFMrvDE8g",
"/p2p/QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP", "/p2p/QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP",
"/p2p/QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP/unix/a/b/c", "/p2p/QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP/unix/a/b/c",
} { } {
......
...@@ -15,6 +15,8 @@ const ( ...@@ -15,6 +15,8 @@ const (
P_IP6ZONE = 0x002A P_IP6ZONE = 0x002A
P_IPCIDR = 0x002B P_IPCIDR = 0x002B
P_QUIC = 0x01CC P_QUIC = 0x01CC
P_WEBTRANSPORT = 0x01D1
P_CERTHASH = 0x01D2
P_SCTP = 0x0084 P_SCTP = 0x0084
P_CIRCUIT = 0x0122 P_CIRCUIT = 0x0122
P_UDT = 0x012D P_UDT = 0x012D
...@@ -178,6 +180,18 @@ var ( ...@@ -178,6 +180,18 @@ var (
Code: P_QUIC, Code: P_QUIC,
VCode: CodeToVarint(P_QUIC), VCode: CodeToVarint(P_QUIC),
} }
protoWEBTRANSPORT = Protocol{
Name: "webtransport",
Code: P_WEBTRANSPORT,
VCode: CodeToVarint(P_WEBTRANSPORT),
}
protoCERTHASH = Protocol{
Name: "certhash",
Code: P_CERTHASH,
VCode: CodeToVarint(P_CERTHASH),
Size: LengthPrefixedVarSize,
Transcoder: TranscoderCertHash,
}
protoHTTP = Protocol{ protoHTTP = Protocol{
Name: "http", Name: "http",
Code: P_HTTP, Code: P_HTTP,
...@@ -257,6 +271,8 @@ func init() { ...@@ -257,6 +271,8 @@ func init() {
protoUTP, protoUTP,
protoUDT, protoUDT,
protoQUIC, protoQUIC,
protoWEBTRANSPORT,
protoCERTHASH,
protoHTTP, protoHTTP,
protoHTTPS, protoHTTPS,
protoP2P, protoP2P,
......
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"strings" "strings"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"github.com/multiformats/go-multibase"
mh "github.com/multiformats/go-multihash" mh "github.com/multiformats/go-multihash"
) )
...@@ -373,3 +374,20 @@ func dnsStB(s string) ([]byte, error) { ...@@ -373,3 +374,20 @@ func dnsStB(s string) ([]byte, error) {
func dnsBtS(b []byte) (string, error) { func dnsBtS(b []byte) (string, error) {
return string(b), nil return string(b), nil
} }
var TranscoderCertHash = NewTranscoderFromFunctions(certHashStB, certHashBtS, nil)
func certHashStB(s string) ([]byte, error) {
_, data, err := multibase.Decode(s)
if err != nil {
return nil, err
}
if _, err := mh.Decode(data); err != nil {
return nil, err
}
return data, nil
}
func certHashBtS(b []byte) (string, error) {
return multibase.Encode(multibase.Base64url, b)
}
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