Skip to content

Data Exchange component that uses other peers to exchange requests/responses

License

Notifications You must be signed in to change notification settings

mkg20001/libp2p-exchange-rendezvous

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libp2p-exchange-rendezvous

Data Exchange component that uses other peers to exchange requests/responses

Use-Case

The use case for this exchange component is to allow exchanges between two peers that are not directly connected but share one or more rendezvous peers.

Example

'use strict'

const Exchange = require('libp2p-exchange-direct')

const exchangeA = new Exchange(swarmA)
const exchangeB = new Exchange(swarmB)
const exchangeM = new Exchange(swarmM, {enableServer: true})

exchangeA.start(() => {})
exchangeB.start(() => {})
exchangeM.start(() => {})

exchangeB.listen('example', (data, cb) => {
  return cb(null, data.reverse())
})

swarmA.dial(swarmM.peerInfo, err => {
  if (err) throw err

  swarmB.dial(swarmM.peerInfo, err => {
    if (err) throw err

    exchangeA.request(swarmB.peerInfo.id, 'example', Buffer.from('Hello World!'), console.log)
  })
})

About

Data Exchange component that uses other peers to exchange requests/responses

Resources

License

Stars

Watchers

Forks

Packages

No packages published