Skip to content

Data Exchange component that uses the swarm to directly dial the taget peer if it is connected

License

Notifications You must be signed in to change notification settings

mkg20001/libp2p-exchange-direct

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Data Exchange component that uses the swarm to directly dial the taget peer if it is connected

Resources

License

Stars

Watchers

Forks

Packages

No packages published