interface-data-exchange
v0.1.0
Published
An Interface to exchange a single request/response with another peer (ex handshake for webrtc)
Downloads
10
Maintainers
Readme
interface-data-exchange
A test suite and interface you can use to implement a libp2p data-exchange. A libp2p data-exchange is understood as something that offers an encrypted way to exchange a single request/response in order to establish a connection over a transport such as WebRTC.
Why?
I've made » some slides to explain what it does and why it does it
Modules that implement the interface
How to use the battery of tests
Node.js
Create a new testfile test/exchange.spec.js
and bootstrap it off this template. Then tweak it for your needs.
'use strict'
const tests = require('interface-data-exchange/src/test')
tests({
opt: {
peerA: {
addrs: [], // addresses for peer (can be left empty if peer should only listen on circuit)
lp2pOpt: { // additional libp2p options (such as enabling relay)
relay: {
enabled: true
}
}
},
peerB: {},
peerM: {
addrs: ['/ip4/127.0.0.1/tcp/5394/ws'], // this ws-server address will get faked in the browser
lp2pOpt: {
relay: { // enable relay & active hop. usefull for testing exchanges over circuit
enabled: true,
hop: {
enabled: true,
active: true
}
}
}
}
},
before: (eA, eB, eM, cb) => {
/* run actions such as connecting peers with each other */
cb()
},
Exchange: require('../src') // include the exchange itself here
})
Go
WIP
API
A valid (read: that follows the interface defined) exchange, must implement the following API.
Table of contents:
- type:
Exchange
new Exchange(swarm, [options])
exchange.request(id, ns, requestData, [options], callback)
exchange.handle(ns, handlerFunction)
exchange.unhandle(ns, handlerFunction)
exchange.start(callback)
exchange.stop(callback)