Skip to content

Commit

Permalink
feat: add QUIC support (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
fishmonger45 committed Jan 13, 2021
1 parent 38a1f1f commit ac7d10c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Where `<FORMAT>` may be:
| `IP` | an "ip4" or "ip6" format multiaddr | `/ip4/127.0.0.1` <br> `/ip6/fc00::` |
| `TCP` | a "tcp" over `IP` format multiaddr | `/ip4/0.0.7.6/tcp/1234` |
| `UDP` | a "udp" over `IP` format multiaddr | `/ip4/0.0.7.6/udp/1234` |
| `QUIC` | a "quic" over `UDP` format multiaddr | `/ip4/1.2.3.4/udp/1234/quic` |
| `UTP` | a "utp" over `UDP` format multiaddr | `/ip4/1.2.3.4/udp/3456/utp` |
| `Websockets` | a "ws" over `TCP` or "ws" over `DNS` format multiaddr | `/ip4/1.2.3.4/tcp/3456/ws` <br> `/dnsaddr/ipfs.io/ws` |
| `WebSocketsSecure` | a "wss" over `TCP` or "wss" over `DNS` format multiaddr | `/ip6/::/tcp/0/wss` <br> `/dnsaddr/ipfs.io/wss` |
Expand All @@ -50,7 +51,7 @@ Where `<FORMAT>` may be:
| `WebRTCStar` | a "p2p" over "p2p-webrtc-star" over `Websockets` or "p2p" over "p2p-webrtc-star" over `WebSocketsSecure` format multiaddr | `/dnsaddr/ipfs.io/wss/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4` |
| `WebSocketStar` | a "p2p" over "p2p-websocket-star" over `Websockets` or "p2p" over "p2p-websocket-star" over `WebSocketsSecure` or "p2p-websocket-star" over `Websockets` or "p2p-websocket-star" over `WebSocketsSecure` format multiaddr | `/ip4/1.2.3.4/tcp/3456/ws/p2p-websocket-star` <br> `/dnsaddr/localhost/ws/p2p-websocket-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4` |
| `WebRTCDirect` | a "p2p-webrtc-direct" over `HTTP` or "p2p-webrtc-direct" over `HTTPS` format multiaddr | `/ip4/1.2.3.4/tcp/3456/http/p2p-webrtc-direct` |
| `Reliable` | a `WebSockets` or `WebSocketsSecure` or `HTTP` or `HTTPS` or `WebRTCStar` or `WebRTCDirect` or `TCP` or `UTP` format multiaddr | `/dnsaddr/ipfs.io/wss` |
| `Reliable` | a `WebSockets` or `WebSocketsSecure` or `HTTP` or `HTTPS` or `WebRTCStar` or `WebRTCDirect` or `TCP` or `UTP` or `QUIC` format multiaddr | `/dnsaddr/ipfs.io/wss` |
| `Circuit` | | `/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit/p2p/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj` |
| `P2P` | "p2p", aka "ipfs", over `Reliable` or `WebRTCStar` or "p2p" format multiaddr | `/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4` <br> `/ip4/127.0.0.1/tcp/20008/ws/p2p/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj` |

Expand Down
1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const DNS6: Mafmt;
export const IP: Mafmt;
export const TCP: Mafmt;
export const UDP: Mafmt;
export const QUIC: Mafmt;
export const UTP: Mafmt;
export const HTTP: Mafmt;
export const HTTPS: Mafmt;
Expand Down
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const TCP = or(
const UDP = and(IP, base('udp'))
const UTP = and(UDP, base('utp'))

const QUIC = and(UDP, base('quic'))

const WebSockets = or(
and(TCP, base('ws')),
and(DNS, base('ws'))
Expand Down Expand Up @@ -75,6 +77,7 @@ const Reliable = or(
WebRTCDirect,
TCP,
UTP,
QUIC,
DNS
)

Expand Down Expand Up @@ -122,6 +125,7 @@ exports.DNSADDR = DNSADDR
exports.IP = IP
exports.TCP = TCP
exports.UDP = UDP
exports.QUIC = QUIC
exports.UTP = UTP
exports.HTTP = HTTP
exports.HTTPS = HTTPS
Expand Down
17 changes: 17 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ describe('multiaddr validation', function () {
'/ip6/fc00::/tcp/5523/udp/9543'
]

const goodQUIC = [
'/ip4/1.2.3.4/udp/1234/quic',
'/ip6/::/udp/1234/quic'
]

const badQUIC = [
'/ip4/0.0.0.0/tcp/12345/quic',
'/ip6/1.2.3.4/ip4/0.0.0.0/udp/1234/quic',
'/quic'
]

const goodUTP = [
'/ip4/1.2.3.4/udp/3456/utp',
'/ip6/::/udp/0/utp'
Expand Down Expand Up @@ -169,6 +180,7 @@ describe('multiaddr validation', function () {
'/ip4/127.0.0.1/tcp/20008/ws/p2p/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj',
'/ip4/1.2.3.4/tcp/3456/ws/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
'/ip4/1.2.3.4/tcp/3456/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
'/ip4/1.2.3.4/udp/1234/quic/p2p/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj',
'/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
'/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
'/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit',
Expand Down Expand Up @@ -250,6 +262,11 @@ describe('multiaddr validation', function () {
assertMismatches(mafmt.UDP, badUDP, goodIP, goodTCP, goodUTP)
})

it('QUIC validation', function () {
assertMatches(mafmt.QUIC, goodQUIC)
assertMismatches(mafmt.QUIC, badQUIC)
})

it('UTP validation', function () {
assertMatches(mafmt.UTP, goodUTP)
assertMismatches(mafmt.UTP, badUTP, goodIP, goodTCP, goodUDP)
Expand Down

0 comments on commit ac7d10c

Please sign in to comment.