Skip to content

Commit

Permalink
fix!: remove deprecated transports and do not append peer ids (#155)
Browse files Browse the repository at this point in the history
Removes support for parsing old p2p-webrtc-direct and p2p-websocket-star
addresses into URLs.

Also removes support for appending `/p2p/Qmfoo`/`/ipfs/Qmfoo` to URLs
automatically - we have `/http-path` now so if this is required, we should
use that.

BREAKING CHANGE: p2p-webrtc-direct/p2p-websocket-star support has been removed
  • Loading branch information
achingbrain authored Nov 8, 2024
1 parent b82d7c0 commit 161329c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 66 deletions.
25 changes: 2 additions & 23 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ const interpreters: Record<string, Interpreter> = {
if (tailProto == null) {
throw new Error('Unexpected end of multiaddr')
}
return `${interpretNext(tailProto[0], tailProto[1] ?? '', restMa)}/ipfs/${value}`
return `${interpretNext(tailProto[0], tailProto[1] ?? '', restMa)}`
},
p2p: (value: string, restMa: StringTuple[]) => {
const tailProto = restMa.pop()
if (tailProto == null) {
throw new Error('Unexpected end of multiaddr')
}
return `${interpretNext(tailProto[0], tailProto[1] ?? '', restMa)}/p2p/${value}`
return `${interpretNext(tailProto[0], tailProto[1] ?? '', restMa)}`
},
http: (value: string, restMa: StringTuple[]) => {
const maHasTLS = hasTLS(restMa)
Expand Down Expand Up @@ -213,27 +213,6 @@ const interpreters: Record<string, Interpreter> = {
// We are reinterpreting the base as http, so we need to remove the tcp:// if it's there
baseVal = baseVal.replace('tcp://', '')
return `wss://${baseVal}`
},
'p2p-websocket-star': (value: string, restMa: StringTuple[]) => {
const tailProto = restMa.pop()
if (tailProto == null) {
throw new Error('Unexpected end of multiaddr')
}
return `${interpretNext(tailProto[0], tailProto[1] ?? '', restMa)}/p2p-websocket-star`
},
'p2p-webrtc-star': (value: string, restMa: StringTuple[]) => {
const tailProto = restMa.pop()
if (tailProto == null) {
throw new Error('Unexpected end of multiaddr')
}
return `${interpretNext(tailProto[0], tailProto[1] ?? '', restMa)}/p2p-webrtc-star`
},
'p2p-webrtc-direct': (value: string, restMa: StringTuple[]) => {
const tailProto = restMa.pop()
if (tailProto == null) {
throw new Error('Unexpected end of multiaddr')
}
return `${interpretNext(tailProto[0], tailProto[1] ?? '', restMa)}/p2p-webrtc-direct`
}
}

Expand Down
46 changes: 3 additions & 43 deletions test/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,61 +41,21 @@ describe('multiaddr-to-uri', () => {
['/ip4/1.2.3.4/tcp/1234/tls/sni/ipfs.io/ws', 'wss://ipfs.io:1234'],
['/ip4/1.2.3.4/tcp/3456/wss', 'wss://1.2.3.4:3456'],
['/ip6/::/tcp/0/wss', 'wss://[::]:0'],
[
'/ip4/1.2.3.4/tcp/3456/ws/p2p-webrtc-star/ipfs/QmWo6sLpfuhLnPNF1d2X6s9PXC5NvsRbC69uvHAJhZW9bk',
'ws://1.2.3.4:3456/p2p-webrtc-star/p2p/QmWo6sLpfuhLnPNF1d2X6s9PXC5NvsRbC69uvHAJhZW9bk'
],
[
'/dnsaddr/ipfs.io/ws/p2p-webrtc-star/ipfs/QmcNwyju7SWoizsAuf6kjaaRoxe762ovsT3hz6qt3xxcsK',
'ws://ipfs.io/p2p-webrtc-star/p2p/QmcNwyju7SWoizsAuf6kjaaRoxe762ovsT3hz6qt3xxcsK'
],
[
'/dnsaddr/ipfs.io/wss/p2p-webrtc-star/ipfs/QmcNwyju7SWoizsAuf6kjaaRoxe762ovsT3hz6qt3xxcsK',
'wss://ipfs.io/p2p-webrtc-star/p2p/QmcNwyju7SWoizsAuf6kjaaRoxe762ovsT3hz6qt3xxcsK'
],
[
'/ip6/::/tcp/0/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo5',
'ws://[::]:0/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo5'
],
[
'/dns4/wrtc-star.discovery.libp2p.io/tcp/443/wss/p2p-webrtc-star/ipfs/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79',
'wss://wrtc-star.discovery.libp2p.io/p2p-webrtc-star/p2p/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79'
],
['/ip4/1.2.3.4/tcp/3456/http/p2p-webrtc-direct', 'http://1.2.3.4:3456/p2p-webrtc-direct'],
['/ip6/::/tcp/0/http/p2p-webrtc-direct', 'http://[::]:0/p2p-webrtc-direct'],
['/ip4/1.2.3.4/tcp/3456/ws/p2p-websocket-star', 'ws://1.2.3.4:3456/p2p-websocket-star'],
['/ip6/::/tcp/0/ws/p2p-websocket-star', 'ws://[::]:0/p2p-websocket-star'],
[
'/dnsaddr/localhost/ws/p2p-websocket-star/ipfs/QmcNwyju7SWoizsAuf6kjaaRoxe762ovsT3hz6qt3xxcsK',
'ws://localhost/p2p-websocket-star/p2p/QmcNwyju7SWoizsAuf6kjaaRoxe762ovsT3hz6qt3xxcsK'
],
[
'/ip4/1.2.3.4/tcp/3456/ws/p2p-websocket-star/ipfs/QmcNwyju7SWoizsAuf6kjaaRoxe762ovsT3hz6qt3xxcsK',
'ws://1.2.3.4:3456/p2p-websocket-star/p2p/QmcNwyju7SWoizsAuf6kjaaRoxe762ovsT3hz6qt3xxcsK'
],
[
'/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star/ipfs/QmP3vadpN9dqZ7j6KtmwP5Y4prg7XqdS7ixgZMWtXxBAbp',
'wss://ws-star.discovery.libp2p.io/p2p-websocket-star/p2p/QmP3vadpN9dqZ7j6KtmwP5Y4prg7XqdS7ixgZMWtXxBAbp'
],
[
'/ip4/127.0.0.1/tcp/20008/ws/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj',
'ws://127.0.0.1:20008/p2p/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj'
],
[
'/ip4/1.2.3.4/tcp/3456/ws/p2p-webrtc-star/ipfs/QmcNwyju7SWoizsAuf6kjaaRoxe762ovsT3hz6qt3xxcsK',
'ws://1.2.3.4:3456/p2p-webrtc-star/p2p/QmcNwyju7SWoizsAuf6kjaaRoxe762ovsT3hz6qt3xxcsK'
'ws://127.0.0.1:20008'
],
[
'/ip4/1.2.3.4/tcp/3456/ipfs/QmcNwyju7SWoizsAuf6kjaaRoxe762ovsT3hz6qt3xxcsK',
'tcp://1.2.3.4:3456/p2p/QmcNwyju7SWoizsAuf6kjaaRoxe762ovsT3hz6qt3xxcsK'
'tcp://1.2.3.4:3456'
],
[
'/ip4/1.2.3.4/tcp/3456/http/http-path/foo%2fbar',
'http://1.2.3.4:3456/foo/bar'
],
[
'/ip4/1.2.3.4/tcp/3456/p2p/QmcNwyju7SWoizsAuf6kjaaRoxe762ovsT3hz6qt3xxcsK',
'tcp://1.2.3.4:3456/p2p/QmcNwyju7SWoizsAuf6kjaaRoxe762ovsT3hz6qt3xxcsK'
'tcp://1.2.3.4:3456'
]
]

Expand Down

0 comments on commit 161329c

Please sign in to comment.