libp2p-exchange-direct

0.0.3 • Public • Published

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)
})

Package Sidebar

Install

npm i libp2p-exchange-direct

Weekly Downloads

0

Version

0.0.3

License

MIT

Unpacked Size

7.09 kB

Total Files

8

Last publish

Collaborators

  • mkg20001