0.0.2 • Published 7 years ago

mongo-idb-ds2 v0.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

Greenkeeper badge js-standard-style

Description

This module represents a node in a peer-to-peer network. It is capable of establishing connections to other peers, storing files and their metadata (information about the file), copying files from connected peers and querying the files in the connected network that are at a distance of n hops away. Connections to peers are established using WebRTC using the libp2p networking stack. The module offers complete control over established connections and allows users to control the data they store on their local node. This module was designed mainly for browser operation but could be extended for Node.js operation in the future. This module uses a mongo based query syntax which is applied to a Dexie IndexedDB table in the MetadataHandler class that implements the MetadataHandler interface.

Network model

There is no peer-discovery mechanism. Peers are expected to exchange identities in any suitable communication medium. This offers maximum control over who you connect to and who is connected to you. Querying is done through flooding of the network through your connected peers in a similar fashion to early Gnutella protocol versions. The network model and API are derived from work on the (DS)2 thesis by Alan Davoust which can be found here.

API

The API is documented here. The query syntax is defined here.

Usage

This library is available through the following sources:

  • npm registry mongo-idb-ds2
  • UNPKG https://unpkg.com/mongo-idb-ds2/dist/index.min.js

Examples

// Create a new instance and start it
let node = new MongoIdbDs2('stamps', 'hash, name, country, year')
node.start()
.then(() => {
  // Node has started
})

// After node is started, you can connect to node known as ‘QmUserID’
node.connect(‘QmUserID’)
.then(() => {
  // User is connected
})
.catch((err) => {
  // Operation failed with error err
})

// After node is started, you can publish a file with contents=fileContents of type ArrayBuffer and with metadata={fileMetadata: ‘this is some metadata’}. The ArrayBuffer is usually created using a FileReader invoking readAsArrayBuffer method on a File Object obtained from a HTML5 submitted form.
node.publish(fileContents : ArrayBuffer, {name: ‘stamp 1’, country: 'Canada', year: 2017})
.then((fileHash) => {
  // Do something with hash of file contents
})
.catch((err) => {
  // operation failed with error err
})

Development prerequisites

npm.io npm.io

Install

npm install

Test

npm test

Lint

npm run lint