Skip to content

An Interface to exchange a single request/response with another peer (ex handshake for webrtc)

License

Notifications You must be signed in to change notification settings

mkg20001/interface-data-exchange

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

An Interface to exchange a single request/response with another peer (ex handshake for webrtc)

Resources

License

Stars

Watchers

Forks

Packages

No packages published