Skip to content

Commit 232f8cf

Browse files
Merge pull request #176 from multiformats/webtransport
add WebTransport multiaddr components
2 parents f5adc3b + adec851 commit 232f8cf

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.17
44

55
require (
66
github.com/ipfs/go-cid v0.0.7
7+
github.com/multiformats/go-multibase v0.0.3
78
github.com/multiformats/go-multihash v0.0.14
89
github.com/multiformats/go-varint v0.0.6
910
github.com/stretchr/testify v1.7.0
@@ -16,7 +17,6 @@ require (
1617
github.com/mr-tron/base58 v1.1.3 // indirect
1718
github.com/multiformats/go-base32 v0.0.3 // indirect
1819
github.com/multiformats/go-base36 v0.1.0 // indirect
19-
github.com/multiformats/go-multibase v0.0.3 // indirect
2020
github.com/pmezard/go-difflib v1.0.0 // indirect
2121
github.com/spaolacci/murmur3 v1.1.0 // indirect
2222
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8 // indirect

multiaddr_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ func TestConstructFails(t *testing.T) {
7474
"/ip4/127.0.0.1/tcp/jfodsajfidosajfoidsa",
7575
"/ip4/127.0.0.1/tcp",
7676
"/ip4/127.0.0.1/quic/1234",
77+
"/ip4/127.0.0.1/udp/1234/quic/webtransport/certhash",
78+
"/ip4/127.0.0.1/udp/1234/quic/webtransport/certhash/b2uaraocy6yrdblb4sfptaddgimjmmp", // 1 character missing from certhash
7779
"/ip4/127.0.0.1/ipfs",
7880
"/ip4/127.0.0.1/ipfs/tcp",
7981
"/ip4/127.0.0.1/p2p",
@@ -157,6 +159,9 @@ func TestConstructSucceeds(t *testing.T) {
157159
"/ip4/127.0.0.1/tcp/1234",
158160
"/ip4/127.0.0.1/tcp/1234/",
159161
"/ip4/127.0.0.1/udp/1234/quic",
162+
"/ip4/127.0.0.1/udp/1234/quic/webtransport",
163+
"/ip4/127.0.0.1/udp/1234/quic/webtransport/certhash/b2uaraocy6yrdblb4sfptaddgimjmmpy",
164+
"/ip4/127.0.0.1/udp/1234/quic/webtransport/certhash/b2uaraocy6yrdblb4sfptaddgimjmmpy/certhash/zQmbWTwYGcmdyK9CYfNBcfs9nhZs17a6FQ4Y8oea278xx41",
160165
"/ip4/127.0.0.1/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC",
161166
"/ip4/127.0.0.1/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234",
162167
"/ip4/127.0.0.1/ipfs/k2k4r8oqamigqdo6o7hsbfwd45y70oyynp98usk7zmyfrzpqxh1pohl7",
@@ -542,6 +547,7 @@ func TestRoundTrip(t *testing.T) {
542547
"/ip4/127.0.0.1/tcp/123/tls",
543548
"/ip4/127.0.0.1/udp/123",
544549
"/ip4/127.0.0.1/udp/123/ip6/::",
550+
"/ip4/127.0.0.1/udp/1234/quic/webtransport/certhash/uEiDDq4_xNyDorZBH3TlGazyJdOWSwvo4PUo5YHFMrvDE8g",
545551
"/p2p/QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP",
546552
"/p2p/QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP/unix/a/b/c",
547553
} {

protocols.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const (
1515
P_IP6ZONE = 0x002A
1616
P_IPCIDR = 0x002B
1717
P_QUIC = 0x01CC
18+
P_WEBTRANSPORT = 0x01D1
19+
P_CERTHASH = 0x01D2
1820
P_SCTP = 0x0084
1921
P_CIRCUIT = 0x0122
2022
P_UDT = 0x012D
@@ -178,6 +180,18 @@ var (
178180
Code: P_QUIC,
179181
VCode: CodeToVarint(P_QUIC),
180182
}
183+
protoWEBTRANSPORT = Protocol{
184+
Name: "webtransport",
185+
Code: P_WEBTRANSPORT,
186+
VCode: CodeToVarint(P_WEBTRANSPORT),
187+
}
188+
protoCERTHASH = Protocol{
189+
Name: "certhash",
190+
Code: P_CERTHASH,
191+
VCode: CodeToVarint(P_CERTHASH),
192+
Size: LengthPrefixedVarSize,
193+
Transcoder: TranscoderCertHash,
194+
}
181195
protoHTTP = Protocol{
182196
Name: "http",
183197
Code: P_HTTP,
@@ -257,6 +271,8 @@ func init() {
257271
protoUTP,
258272
protoUDT,
259273
protoQUIC,
274+
protoWEBTRANSPORT,
275+
protoCERTHASH,
260276
protoHTTP,
261277
protoHTTPS,
262278
protoP2P,

transcoders.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"strings"
1212

1313
"github.com/ipfs/go-cid"
14+
"github.com/multiformats/go-multibase"
1415
mh "github.com/multiformats/go-multihash"
1516
)
1617

@@ -373,3 +374,20 @@ func dnsStB(s string) ([]byte, error) {
373374
func dnsBtS(b []byte) (string, error) {
374375
return string(b), nil
375376
}
377+
378+
var TranscoderCertHash = NewTranscoderFromFunctions(certHashStB, certHashBtS, nil)
379+
380+
func certHashStB(s string) ([]byte, error) {
381+
_, data, err := multibase.Decode(s)
382+
if err != nil {
383+
return nil, err
384+
}
385+
if _, err := mh.Decode(data); err != nil {
386+
return nil, err
387+
}
388+
return data, nil
389+
}
390+
391+
func certHashBtS(b []byte) (string, error) {
392+
return multibase.Encode(multibase.Base64url, b)
393+
}

0 commit comments

Comments
 (0)