Skip to content

Commit 20076b1

Browse files
authored
feat: support webtransport multiaddrs (#148)
fixes #147
1 parent ca7cf5a commit 20076b1

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/index.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const UDP = and(IP, base('udp'))
3333
export const UTP = and(UDP, base('utp'))
3434

3535
export const QUIC = and(UDP, base('quic'))
36+
export const QUICV1 = and(UDP, base('quic-v1'))
3637

3738
export const WebSockets = or(
3839
and(TCP, base('ws')),
@@ -64,6 +65,12 @@ export const WebRTCDirect = or(
6465
_WebRTCDirect
6566
)
6667

68+
const _WebTransport = and(QUICV1, base('webtransport'), base('certhash'), base('certhash'))
69+
export const WebTransport = or(
70+
and(_WebTransport, base('p2p')),
71+
_WebTransport
72+
)
73+
6774
/**
6875
* @deprecated
6976
*/
@@ -102,7 +109,8 @@ export const Reliable = or(
102109
UTP,
103110
QUIC,
104111
DNS,
105-
WebRTCDirect
112+
WebRTCDirect,
113+
WebTransport
106114
)
107115

108116
// Unlike ws-star, stardust can run over any transport thus removing the requirement for websockets (but don't even think about running a stardust server over webrtc-star ;) )
@@ -116,6 +124,7 @@ const _P2P = or(
116124
P2PWebRTCStar,
117125
P2PWebRTCDirect,
118126
WebRTCDirect,
127+
WebTransport,
119128
base('p2p')
120129
)
121130

test/index.spec.ts

+23
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,24 @@ describe('multiaddr validation', function () {
212212
'/ip4/0.0.0.0/tcp/12345/udp/2222/wss/webrtc'
213213
]
214214

215+
const goodWebTransport = [
216+
'/ip4/10.5.0.2/udp/4001/quic-v1/webtransport/certhash/uEiDWmsTxXe55Mbwnvd1qrPZAcE5Jtc0tE9WtGXD_NpMERg/certhash/uEiCoik2HBeT5oc9Jib3SQJzNjn9AnznMDpQWcOeKSuEc9A/p2p/12D3KooWQF6Q3i1QkziJQ9mkNNcyFD8GPQz6R6oEvT75wgsVXm4v',
217+
'/ip4/127.0.0.1/udp/4001/quic-v1/webtransport/certhash/uEiDWmsTxXe55Mbwnvd1qrPZAcE5Jtc0tE9WtGXD_NpMERg/certhash/uEiCoik2HBeT5oc9Jib3SQJzNjn9AnznMDpQWcOeKSuEc9A/p2p/12D3KooWQF6Q3i1QkziJQ9mkNNcyFD8GPQz6R6oEvT75wgsVXm4v',
218+
'/ip4/97.126.16.119/udp/4001/quic-v1/webtransport/certhash/uEiDWmsTxXe55Mbwnvd1qrPZAcE5Jtc0tE9WtGXD_NpMERg/certhash/uEiCoik2HBeT5oc9Jib3SQJzNjn9AnznMDpQWcOeKSuEc9A/p2p/12D3KooWQF6Q3i1QkziJQ9mkNNcyFD8GPQz6R6oEvT75wgsVXm4v',
219+
'/ip6/::1/udp/4001/quic-v1/webtransport/certhash/uEiDWmsTxXe55Mbwnvd1qrPZAcE5Jtc0tE9WtGXD_NpMERg/certhash/uEiCoik2HBeT5oc9Jib3SQJzNjn9AnznMDpQWcOeKSuEc9A/p2p/12D3KooWQF6Q3i1QkziJQ9mkNNcyFD8GPQz6R6oEvT75wgsVXm4v'
220+
]
221+
222+
const badWebTransport = [
223+
// quic instead of quic-v1
224+
'/ip4/10.5.0.2/udp/4001/quic/webtransport/certhash/uEiDWmsTxXe55Mbwnvd1qrPZAcE5Jtc0tE9WtGXD_NpMERg/certhash/uEiCoik2HBeT5oc9Jib3SQJzNjn9AnznMDpQWcOeKSuEc9A/p2p/12D3KooWQF6Q3i1QkziJQ9mkNNcyFD8GPQz6R6oEvT75wgsVXm4v',
225+
// missing second certhash value
226+
'/ip4/10.5.0.2/udp/4001/quic-v1/webtransport/certhash/uEiDWmsTxXe55Mbwnvd1qrPZAcE5Jtc0tE9WtGXD_NpMERg/certhash/p2p/12D3KooWQF6Q3i1QkziJQ9mkNNcyFD8GPQz6R6oEvT75wgsVXm4v',
227+
// missing webtransport/certhash base
228+
'/ip4/10.5.0.2/udp/4001/quic-v1/webtransport/p2p/12D3KooWQF6Q3i1QkziJQ9mkNNcyFD8GPQz6R6oEvT75wgsVXm4v',
229+
// missing value for base 'webtransport/certhash' `${value}/certhash/${value}`
230+
'/ip4/10.5.0.2/udp/4001/quic-v1/webtransport/certhash/p2p/12D3KooWQF6Q3i1QkziJQ9mkNNcyFD8GPQz6R6oEvT75wgsVXm4v'
231+
]
232+
215233
function assertMatches (p: Mafmt, ...tests: string[][]): void {
216234
tests.forEach(function (test) {
217235
test.forEach(function (testcase) {
@@ -355,4 +373,9 @@ describe('multiaddr validation', function () {
355373
assertMatches(mafmt.WebRTC, goodWebRTC)
356374
assertMismatches(mafmt.WebRTC, badWebRTC)
357375
})
376+
377+
it('WebTransport validation', function () {
378+
assertMatches(mafmt.WebTransport, goodWebTransport)
379+
assertMismatches(mafmt.WebTransport, badWebTransport)
380+
})
358381
})

0 commit comments

Comments
 (0)