Skip to content

Latest commit

 

History

History
76 lines (57 loc) · 2.26 KB

README.md

File metadata and controls

76 lines (57 loc) · 2.26 KB

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 signalling-based 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: async (eA, eB, eM) => {
    /* run actions such as connecting peers with each other */
  },
  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])
    • async exchange.request(id, ns, requestData, [options])
    • exchange.handle(ns, asyncHandlerFunction)
    • exchange.unhandle(ns, asyncHandlerFunction)
    • async exchange.start()
    • async exchange.stop()