0.0.3 • Published 6 years ago

libp2p-exchange-direct v0.0.3

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

libp2p-exchange-direct

npm.io

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