mirror of
https://github.com/fluencelabs/js-mafmt
synced 2025-04-24 18:52:23 +00:00
feat: p2p and dns support (#42)
This commit is contained in:
parent
3fc9234f52
commit
09160b5167
@ -53,7 +53,7 @@ Where `<FORMAT>` may be:
|
||||
| `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` |
|
||||
| `Circuit` | | `/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj` |
|
||||
| `IPFS` | "ipfs" over `Reliable` or `WebRTCStar` or "ipfs" format multiaddr | `/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4` <br> `/ip4/127.0.0.1/tcp/20008/ws/ipfs/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` |
|
||||
|
||||
Where `multiaddr` may be:
|
||||
|
||||
|
@ -28,11 +28,11 @@
|
||||
"bugs": "https://github.com/multiformats/js-mafmt/issues",
|
||||
"homepage": "https://github.com/multiformats/js-mafmt#readme",
|
||||
"devDependencies": {
|
||||
"aegir": "^18.0.3",
|
||||
"aegir": "^20.0.0",
|
||||
"chai": "^4.2.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"multiaddr": "^6.0.4"
|
||||
"multiaddr": "^6.1.0"
|
||||
},
|
||||
"contributors": [
|
||||
"Alan Shaw <alan@tableflip.io>",
|
||||
|
46
src/index.js
46
src/index.js
@ -7,7 +7,8 @@ const multiaddr = require('multiaddr')
|
||||
*/
|
||||
const DNS4 = base('dns4')
|
||||
const DNS6 = base('dns6')
|
||||
const _DNS = or(
|
||||
const DNS = or(
|
||||
base('dns'),
|
||||
base('dnsaddr'),
|
||||
DNS4,
|
||||
DNS6
|
||||
@ -16,16 +17,11 @@ const _DNS = or(
|
||||
const IP = or(base('ip4'), base('ip6'))
|
||||
const TCP = or(
|
||||
and(IP, base('tcp')),
|
||||
and(_DNS, base('tcp'))
|
||||
and(DNS, base('tcp'))
|
||||
)
|
||||
const UDP = and(IP, base('udp'))
|
||||
const UTP = and(UDP, base('utp'))
|
||||
|
||||
const DNS = or(
|
||||
and(_DNS, base('tcp')),
|
||||
_DNS
|
||||
)
|
||||
|
||||
const WebSockets = or(
|
||||
and(TCP, base('ws')),
|
||||
and(DNS, base('ws'))
|
||||
@ -39,8 +35,7 @@ const WebSocketsSecure = or(
|
||||
const HTTP = or(
|
||||
and(TCP, base('http')),
|
||||
and(IP, base('http')),
|
||||
and(DNS, base('http')),
|
||||
and(DNS)
|
||||
and(DNS, base('http'))
|
||||
)
|
||||
|
||||
const HTTPS = or(
|
||||
@ -51,12 +46,16 @@ const HTTPS = or(
|
||||
|
||||
const WebRTCStar = or(
|
||||
and(WebSockets, base('p2p-webrtc-star'), base('ipfs')),
|
||||
and(WebSocketsSecure, base('p2p-webrtc-star'), base('ipfs'))
|
||||
and(WebSocketsSecure, base('p2p-webrtc-star'), base('ipfs')),
|
||||
and(WebSockets, base('p2p-webrtc-star'), base('p2p')),
|
||||
and(WebSocketsSecure, base('p2p-webrtc-star'), base('p2p'))
|
||||
)
|
||||
|
||||
const WebSocketStar = or(
|
||||
and(WebSockets, base('p2p-websocket-star'), base('ipfs')),
|
||||
and(WebSocketsSecure, base('p2p-websocket-star'), base('ipfs')),
|
||||
and(WebSockets, base('p2p-websocket-star'), base('p2p')),
|
||||
and(WebSocketsSecure, base('p2p-websocket-star'), base('p2p')),
|
||||
and(WebSockets, base('p2p-websocket-star')),
|
||||
and(WebSocketsSecure, base('p2p-websocket-star'))
|
||||
)
|
||||
@ -83,16 +82,18 @@ const Stardust = or(
|
||||
and(Reliable, base('p2p-stardust'))
|
||||
)
|
||||
|
||||
let _IPFS = or(
|
||||
const _P2P = or(
|
||||
and(Reliable, base('ipfs')),
|
||||
and(Reliable, base('p2p')),
|
||||
WebRTCStar,
|
||||
base('ipfs')
|
||||
base('ipfs'),
|
||||
base('p2p')
|
||||
)
|
||||
|
||||
const _Circuit = or(
|
||||
and(_IPFS, base('p2p-circuit'), _IPFS),
|
||||
and(_IPFS, base('p2p-circuit')),
|
||||
and(base('p2p-circuit'), _IPFS),
|
||||
and(_P2P, base('p2p-circuit'), _P2P),
|
||||
and(_P2P, base('p2p-circuit')),
|
||||
and(base('p2p-circuit'), _P2P),
|
||||
and(Reliable, base('p2p-circuit')),
|
||||
and(base('p2p-circuit'), Reliable),
|
||||
base('p2p-circuit')
|
||||
@ -105,12 +106,12 @@ const CircuitRecursive = () => or(
|
||||
|
||||
const Circuit = CircuitRecursive()
|
||||
|
||||
const IPFS = or(
|
||||
and(Circuit, _IPFS, Circuit),
|
||||
and(_IPFS, Circuit),
|
||||
and(Circuit, _IPFS),
|
||||
const P2P = or(
|
||||
and(Circuit, _P2P, Circuit),
|
||||
and(_P2P, Circuit),
|
||||
and(Circuit, _P2P),
|
||||
Circuit,
|
||||
_IPFS
|
||||
_P2P
|
||||
)
|
||||
|
||||
exports.DNS = DNS
|
||||
@ -130,7 +131,8 @@ exports.WebRTCDirect = WebRTCDirect
|
||||
exports.Reliable = Reliable
|
||||
exports.Stardust = Stardust
|
||||
exports.Circuit = Circuit
|
||||
exports.IPFS = IPFS
|
||||
exports.P2P = P2P
|
||||
exports.IPFS = P2P
|
||||
|
||||
/*
|
||||
* Validation funcs
|
||||
@ -145,7 +147,7 @@ function makeMatchesFunction (partialMatch) {
|
||||
return false // also if it's invalid it's propably not matching as well so return false
|
||||
}
|
||||
}
|
||||
let out = partialMatch(a.protoNames())
|
||||
const out = partialMatch(a.protoNames())
|
||||
if (out === null) {
|
||||
return false
|
||||
}
|
||||
|
@ -8,13 +8,11 @@ const multiaddr = require('multiaddr')
|
||||
|
||||
describe('multiaddr validation', function () {
|
||||
const goodDNS = [
|
||||
'/dns/ipfs.io',
|
||||
'/dnsaddr/ipfs.io',
|
||||
'/dns4/ipfs.io',
|
||||
'/dns4/libp2p.io',
|
||||
'/dns6/protocol.ai',
|
||||
'/dns4/protocol.ai/tcp/80',
|
||||
'/dns6/protocol.ai/tcp/80',
|
||||
'/dnsaddr/protocol.ai/tcp/80'
|
||||
'/dns6/protocol.ai'
|
||||
]
|
||||
|
||||
const badDNS = [
|
||||
@ -35,6 +33,7 @@ describe('multiaddr validation', function () {
|
||||
'/ip4/0.0.7.6/tcp/1234',
|
||||
'/ip6/::/tcp/0',
|
||||
'/dns4/protocol.ai/tcp/80',
|
||||
'/dns6/protocol.ai/tcp/80',
|
||||
'/dnsaddr/protocol.ai/tcp/80'
|
||||
]
|
||||
|
||||
@ -65,7 +64,6 @@ describe('multiaddr validation', function () {
|
||||
]
|
||||
|
||||
const goodHTTP = [
|
||||
'/dnsaddr/ipfs.io',
|
||||
'/dnsaddr/ipfs.io/http',
|
||||
'/dnsaddr/ipfs.io/tcp/3456/http',
|
||||
'/ip4/0.0.0.0/http',
|
||||
@ -100,7 +98,9 @@ describe('multiaddr validation', function () {
|
||||
'/dnsaddr/ipfs.io/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
|
||||
'/dnsaddr/ipfs.io/wss/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
|
||||
'/ip6/::/tcp/0/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo5',
|
||||
'/dns4/wrtc-star.discovery.libp2p.io/tcp/443/wss/p2p-webrtc-star/ipfs/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79'
|
||||
'/dns4/wrtc-star.discovery.libp2p.io/tcp/443/wss/p2p-webrtc-star/ipfs/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79',
|
||||
'/dns/wrtc-star.discovery.libp2p.io/wss/p2p-webrtc-star/ipfs/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79',
|
||||
'/dns/wrtc-star.discovery.libp2p.io/tcp/443/wss/p2p-webrtc-star/ipfs/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79'
|
||||
]
|
||||
|
||||
const goodWebRTCDirect = [
|
||||
@ -160,7 +160,12 @@ describe('multiaddr validation', function () {
|
||||
'/ip4/1.2.3.4/tcp/3456/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
|
||||
'/ip4/1.2.3.4/tcp/3456/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
|
||||
'/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit',
|
||||
'/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj'
|
||||
'/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj',
|
||||
'/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',
|
||||
'/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit',
|
||||
'/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit/p2p/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj'
|
||||
].concat(goodCircuit)
|
||||
|
||||
function assertMatches (p) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user