Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: Rename WebRTCDirect to P2PWebRTCDirect and deprecate #146

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
"release": "aegir release"
},
"dependencies": {
"@multiformats/multiaddr": "^11.0.0"
"@multiformats/multiaddr": "^12.0.0"
},
"devDependencies": {
"aegir": "^37.5.3",
Expand Down
34 changes: 23 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,16 @@ export const HTTPS = or(
and(DNS, base('https'))
)

const _WebRTC = and(UDP, base('webrtc'), base('certhash'))
export const WebRTC = or(
and(_WebRTC, base('p2p')),
_WebRTC
const _WebRTCDirect = and(UDP, base('webrtc-direct'), base('certhash'))
export const WebRTCDirect = or(
and(_WebRTCDirect, base('p2p')),
_WebRTCDirect
)

export const WebRTCStar = or(
/**
* @deprecated
*/
export const P2PWebRTCStar = or(
and(WebSockets, base('p2p-webrtc-star'), base('p2p')),
and(WebSocketsSecure, base('p2p-webrtc-star'), base('p2p')),
and(WebSockets, base('p2p-webrtc-star')),
Expand All @@ -78,7 +81,10 @@ export const WebSocketStar = or(
and(WebSocketsSecure, base('p2p-websocket-star'))
)

export const WebRTCDirect = or(
/**
* @deprecated
*/
export const P2PWebRTCDirect = or(
and(HTTP, base('p2p-webrtc-direct'), base('p2p')),
and(HTTPS, base('p2p-webrtc-direct'), base('p2p')),
and(HTTP, base('p2p-webrtc-direct')),
Expand All @@ -90,13 +96,13 @@ export const Reliable = or(
WebSocketsSecure,
HTTP,
HTTPS,
WebRTCStar,
WebRTCDirect,
P2PWebRTCStar,
P2PWebRTCDirect,
TCP,
UTP,
QUIC,
DNS,
WebRTC
WebRTCDirect
achingbrain marked this conversation as resolved.
Show resolved Hide resolved
)

// 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 ;) )
Expand All @@ -107,9 +113,9 @@ export const Stardust = or(

const _P2P = or(
and(Reliable, base('p2p')),
WebRTCStar,
P2PWebRTCStar,
P2PWebRTCDirect,
WebRTCDirect,
WebRTC,
base('p2p')
)

Expand Down Expand Up @@ -139,6 +145,12 @@ export const P2P = or(

export const IPFS = P2P

export const WebRTC = or(
and(Circuit, base('webrtc')),
and(Reliable, base('webrtc')),
base('webrtc')
)

/*
* Validation funcs
*/
Expand Down
42 changes: 29 additions & 13 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('multiaddr validation', function () {
'/ip6/::/tcp/0/tls/ws'
]

const goodWebRTCStar = [
const goodP2PWebRTCStar = [
'/ip4/1.2.3.4/tcp/3456/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
'/dnsaddr/ipfs.io/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
'/dnsaddr/ipfs.io/wss/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
Expand All @@ -118,7 +118,7 @@ describe('multiaddr validation', function () {
'/dns/wrtc-star.discovery.libp2p.io/tcp/443/wss/p2p-webrtc-star/ipfs/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79'
]

const goodWebRTCDirect = [
const goodP2PWebRTCDirect = [
'/ip4/1.2.3.4/tcp/3456/http/p2p-webrtc-direct',
'/ip6/::/tcp/0/http/p2p-webrtc-direct'
]
Expand Down Expand Up @@ -190,15 +190,26 @@ describe('multiaddr validation', function () {
'/dns6/nyc-2.bootstrap.libp2p.io/tcp/443/wss/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64'
].concat(goodCircuit)

const goodWebRTCDirect = [
'/ip4/0.0.0.0/udp/4004/webrtc-direct/certhash/uEiAeP0OEmBbGVTH5Bhnm3WopwRNSQ0et46xNkn2dIagnGw',
'/ip4/0.0.0.0/udp/4004/webrtc-direct/certhash/uEiAeP0OEmBbGVTH5Bhnm3WopwRNSQ0et46xNkn2dIagnGw/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64'
]

const badWebRTCDirect = [
'/ip4/0.0.0.0/udp/4004/webrtc-direct',
'/ip4/0.0.0.0/tcp/4004/webrtc-direct',
'/ip4/0.0.0.0/udp/4004/webrtc-direct/uEiAeP0OEmBbGVTH5Bhnm3WopwRNSQ0et46xNkn2dIagnGw/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64'
]

const goodWebRTC = [
'/ip4/0.0.0.0/udp/4004/webrtc/certhash/uEiAeP0OEmBbGVTH5Bhnm3WopwRNSQ0et46xNkn2dIagnGw',
'/ip4/0.0.0.0/udp/4004/webrtc/certhash/uEiAeP0OEmBbGVTH5Bhnm3WopwRNSQ0et46xNkn2dIagnGw/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64'
'/ip4/0.0.0.0/udp/4004/webrtc-direct/certhash/uEiAeP0OEmBbGVTH5Bhnm3WopwRNSQ0et46xNkn2dIagnGw/webrtc',
achingbrain marked this conversation as resolved.
Show resolved Hide resolved
'/p2p-circuit/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/webrtc',
'/webrtc'
]

const badWebRTC = [
'/ip4/0.0.0.0/udp/4004/webrtc',
'/ip4/0.0.0.0/tcp/4004/webrtc',
'/ip4/0.0.0.0/udp/4004/webrtc/uEiAeP0OEmBbGVTH5Bhnm3WopwRNSQ0et46xNkn2dIagnGw/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64'
'/ip4/0.0.0.0/udp/webrtc',
'/ip4/0.0.0.0/tcp/12345/udp/2222/wss/webrtc'
]

function assertMatches (p: Mafmt, ...tests: string[][]) {
Expand Down Expand Up @@ -316,14 +327,14 @@ describe('multiaddr validation', function () {
assertMismatches(mafmt.Stardust, goodIP, goodUDP, badWS)
})

it('WebRTCStar validation', function () {
assertMatches(mafmt.WebRTCStar, goodWebRTCStar)
assertMismatches(mafmt.WebRTCStar, goodIP, goodUDP, badWSS)
it('P2PWebRTCStar validation', function () {
assertMatches(mafmt.P2PWebRTCStar, goodP2PWebRTCStar)
assertMismatches(mafmt.P2PWebRTCStar, goodIP, goodUDP, badWSS)
})

it('WebRTCDirect validation', function () {
assertMatches(mafmt.WebRTCDirect, goodWebRTCDirect)
assertMismatches(mafmt.WebRTCDirect, goodIP, goodUDP, badWS)
it('P2PWebRTCDirect validation', function () {
assertMatches(mafmt.P2PWebRTCDirect, goodP2PWebRTCDirect)
assertMismatches(mafmt.P2PWebRTCDirect, goodIP, goodUDP, badWS)
})

it('Circuit validation', function () {
Expand All @@ -335,6 +346,11 @@ describe('multiaddr validation', function () {
assertMatches(mafmt.IPFS, goodIPFS)
})

it('WebRTCDirect validation', function () {
assertMatches(mafmt.WebRTCDirect, goodWebRTCDirect)
assertMismatches(mafmt.WebRTCDirect, badWebRTCDirect)
})

it('WebRTC validation', function () {
assertMatches(mafmt.WebRTC, goodWebRTC)
assertMismatches(mafmt.WebRTC, badWebRTC)
Expand Down