Coder Social home page Coder Social logo

deluge's Introduction

deluge

Send broadcast messages on top of p2p networks

Test Status Coverage JavaScript Style Guide standard-readme compliant

Made by GEUT

Install

$ npm install @geut/deluge

Usage

const { Deluge } = require('@geut/deluge')
const deluge = new Deluge()

// add your peers into deluge
deluge.addPeer(peer.id, {
  send (packet) {
    // send data
    peer.write(packet.buffer)
  },
  subscribe (next) {
    // subscribe for incoming data
    peer.on('data', next)

    // returns unsubscribe function
    return () => {
      peer.off('data', next)
    }
  }
})
deluge.addPeer(...)

// listen for incoming packets
deluge.on('packet', (packet) => {
  console.log(packet.data.toString()) // ping
})

// send a broadcast ping message in the channel = 0
deluge.send(0, Buffer.from('ping'))

API

deluge = new Deluge(opts?)

  • opts?: Object = {}
    • onPeer?: OnPeerCallback Callback to pre-process a new peer.
    • onPacket?: OnPacketCallback Async callback to filter incoming packets.
    • onSend?: OnSendCallback Async callback to filter peers before to send a packet.

deluge.ready() => Promise<any>

Wait for the deluge to be opened.

deluge.open(id?) => Promise<any>

Open deluge with a Buffer ID.

  • id?: Buffer = crypto.randomBytes(32)

deluge.onPeer(callback) => void

  • callback: OnPeerCallback

deluge.onPacket(callback) => void

  • callback: OnPacketCallback

deluge.onSend(callback) => void

  • callback: OnSendCallback

deluge.getPeer(key) => Peer | undefined

Get a peer by key.

  • key: Buffer | string

deluge.addPeer(key, handler) => Promise<Peer>

Add a new peer into the deluge network.

  • key: Buffer | string
  • handler: Peer.Handler

deluge.deletePeer(key) => Promise<any>

  • key: Buffer | string

deluge.send(channel, data) => Promise<Packet | undefined>

Broadcast a flooding message into the deluge network.

  • channel: number
  • data: Buffer

deluge.createDuplexStream(opts?) => Duplex

Create a new Duplex Streamx.

  • opts?: any = {}

deluge.id: Buffer | null

deluge.peers: Peer[] (R)

Handler: {}

  • send: (packet: any) > undefined
  • subscribe: (data: Buffer) > UnsubscribeFunction

packet = new Packet(opts)

  • opts: Object
    • origin: Buffer
    • data: Uint8Array
    • channel?: number = 0
    • seqno?: TimestampSeq
    • from?: Uint8Array
    • distance?: number = 0
    • buffer?: Buffer

timestampSeq = new TimestampSeq(timestamp, offset)

  • timestamp: any
  • offset: any

timestampSeq.compare(value) => number

Compare two TimestampSeq (self and value).

Returns: - 0 if they are equals. - 1 if self is major than value - -1 if self is minor than value

  • value: TimestampSeq

Issues

๐Ÿ› If you found an issue we encourage you to report it on github. Please specify your OS and the actions to reproduce it.

Contributing

๐Ÿ‘ฅ Ideas and contributions to the project are welcome. You must follow this guideline.

License

MIT ยฉ A GEUT project

deluge's People

Contributors

tinchoz49 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.