Skip to content

michaelfakhri/ds2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DS2

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.

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

Usage

This library is available through the following sources:

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

Examples

// Create a new instance and start it
// MetadataHandler is a metadata storage class that implements MetadataHandler interface.
let node = new DS2(new MetadataHandler())
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, {fileMetadata: ‘this is some metadata’})
.then((fileHash) => {
  // Do something with hash of file contents
})
.catch((err) => {
  // operation failed with error err
})

Development prerequisites


Install

npm install

Test

npm test

Lint

npm run lint

About

A peer-to-peer framework that allows users to connect to each other and share files and their metadata.

Resources

License

Stars

Watchers

Forks

Packages

No packages published