Send broadcast messages on top of p2p networks
$ npm install @geut/deluge
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'))
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.
Wait for the deluge to be opened.
Open deluge with a Buffer ID.
id?: Buffer = crypto.randomBytes(32)
callback: OnPeerCallback
callback: OnPacketCallback
callback: OnSendCallback
Get a peer by key.
key: Buffer | string
Add a new peer into the deluge network.
key: Buffer | string
handler: Peer.Handler
key: Buffer | string
Broadcast a flooding message into the deluge network.
channel: number
data: Buffer
Create a new Duplex Streamx.
opts?: any = {}
send: (packet: any) > undefined
subscribe: (data: Buffer) > UnsubscribeFunction
opts: Object
origin: Buffer
data: Uint8Array
channel?: number = 0
seqno?: TimestampSeq
from?: Uint8Array
distance?: number = 0
buffer?: Buffer
timestamp: any
offset: any
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
๐ If you found an issue we encourage you to report it on github. Please specify your OS and the actions to reproduce it.
๐ฅ Ideas and contributions to the project are welcome. You must follow this guideline.
MIT ยฉ A GEUT project