Coder Social home page Coder Social logo

payene / ilp-protocol-stream Goto Github PK

View Code? Open in Web Editor NEW

This project forked from interledgerjs/ilp-protocol-stream

0.0 1.0 0.0 2.43 MB

Interledger Transport Protocol for sending multiple streams of money and data over ILP

Home Page: https://github.com/interledger/rfcs/blob/master/0029-stream/0029-stream.md

JavaScript 1.31% TypeScript 98.69%

ilp-protocol-stream's Introduction

ILP/STREAM

Interledger Transport Protocol for sending multiple streams of money and data over ILP.

NPM Package CircleCI codecov JavaScript Style Guide Known Vulnerabilities Greenkeeper badge FOSSA Status

STREAM is the recommended Transport Protocol to use for most Interledger applications.

The protocol allows a "client" and "server" to establish a bidirectional connection through Interledger that can be used to send money and data. This module handles authentication, encryption, flow control (making sure one party doesn't send more than the other can handle at once), and congestion control (avoiding sending more packets than the network can handle).

Install

Requires Node >= v8.10.

npm install ilp-protocol-stream

Usage

These snippets assume you are running a local moneyd.

You'll need ilp-plugin to run the example.

npm install ilp-plugin

See example.js for a runnable example, or paste the snippets into your own node project below. You'll need to provide a means of getting the shared secret from Server to Client.

Client:

Clients connect with the destinationAccount and sharedSecret generated by a Server.

const { createConnection } = require('ilp-protocol-stream')
const getPlugin = require('ilp-plugin')

const { destinationAccount, sharedSecret } = getThisFromTheServerSomehow()

async function run () {
  const connection = await createConnection({
    plugin: getPlugin(),
    destinationAccount,
    sharedSecret
  })

  const stream = connection.createStream()
  stream.write('hello\n')
  stream.write('here is some more data')
  await stream.sendTotal(100)
  await stream.sendTotal(200)
  stream.end()
}

run().catch((err) => console.log(err))

Server:

const { createServer } = require('ilp-protocol-stream')
const getPlugin = require('ilp-plugin')

async function run () {
  const server = await createServer({
    plugin: getPlugin()
  })

  // These need to be passed to the client through an authenticated communication channel
  const { destinationAccount, sharedSecret } = server.generateAddressAndSecret()

  server.on('connection', (connection) => {
    connection.on('stream', (stream) => {

      // Set the maximum amount of money this stream can receive
      stream.setReceiveMax(10000)

      stream.on('money', (amount) => {
        console.log(`got money: ${amount} on stream ${stream.id}`)
      })

      stream.on('data', (chunk) => {
        console.log(`got data on stream ${stream.id}: ${chunk.toString('utf8')}`)
      })

      stream.on('end', () => {
        console.log('stream closed')
      })
    })
  })
}

run().catch((err) => console.log(err))

API

See the full API docs at: https://interledgerjs.github.io/ilp-protocol-stream

The most important functions and classes to look at are:

  • createConnection - open a Connection to a Server
  • Server - class used to listen for incoming Connections
  • Connection - class that manages the communication between a Client and a Server
  • DataAndMoneyStream - stream class that can be used to send/receive data and money

Contribute

PRs, new ideas, and questions are very welcome!

Please feel free to open issues to discuss any problems you run into or suggestions you have.

License

Apache-2.0

FOSSA Status

ilp-protocol-stream's People

Contributors

emschwartz avatar traviscrist avatar sentientwaffle avatar greenkeeper[bot] avatar adrianhopebailie avatar njlie avatar khoslaventures avatar fossabot avatar

Watchers

payene denis kombate avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.