Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

Commit

Permalink
fix: now properly handles legacy libp2p-webrtc-multiaddrs
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Sep 4, 2017
1 parent 2ea7964 commit b0b8167
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,18 @@ class WebRTCStar {
log('Peer Discovered:', maStr)
const legacy = '/libp2p-webrtc-star'
if (maStr.indexOf(legacy) !== -1) {
maStr.substring(legacy.length, maStr.length)
maStr = maStr.substring(legacy.length, maStr.length)
let ma = multiaddr(maStr)
const tuppleIPFS = ma.stringTuples().filter((tupple) => {
return tupple[0] === 421 // ipfs code
})[0]

ma = ma.decapsulate('ipfs')
ma = ma.encapsulate('p2p-webrtc-star')
ma = ma.encapsulate(`/ipfs/${tuppleIPFS[1]}`)
maStr = ma.toString()
}

const split = maStr.split('/ipfs/')
const peerIdStr = split[split.length - 1]
const peerId = PeerId.createFromB58String(peerIdStr)
Expand Down

0 comments on commit b0b8167

Please sign in to comment.