libp2p-exchange-direct
v0.0.3
Published
Data Exchange component that uses the swarm to directly dial the taget peer if it is connected
Downloads
2
Maintainers
Readme
libp2p-exchange-direct
Data Exchange component that uses the swarm to directly dial the taget peer if it is connected
Use-Case
The use case for this exchange component is to allow quick upgrades of a libp2p-circuit connection using transports that require the data-exchange component.
Example
'use strict'
const Exchange = require('libp2p-exchange-direct')
const exchangeA = new Exchange(swarmA)
const exchangeB = new Exchange(swarmB)
exchangeA.start(() => {})
exchangeB.start(() => {})
exchangeB.listen('example', (data, cb) => {
return cb(null, data.reverse())
})
swarmA.dial(swarmB.peerInfo, err => {
if (err) throw err
exchangeA.request(swarmB.peerInfo.id, 'example', Buffer.from('Hello World!'), console.log)
})