3.2.1 • Published 6 years ago

zdds v3.2.1

Weekly downloads
4
License
MIT
Repository
-
Last release
6 years ago

ZDDS

Zac's Decentralised Data Store

Web interface

I've created an interface to use ZDDS, take a look here:

What is ZDDS?

ZDDS is a data store that can be accessed over the internet. All data is synced to other nodes that the current node knows about.

What is a node?

A node is an instance of ZDDS.

Nodes can be run accross one computer, inside a local network, or over the internet.

There are currently two nodes on the internet:

Setup (inside a project)

ZDDS can be used as a standalone server, or within a project.

To use it inside a project, do the following:

yarn add zdds
const opts = {} // Add the options below as key/value pairs
const Node = require('zdds').Node
const node = new Node(opts)

Events

The Node class extends EventEmitter, it sends the follwoing events.

EventArgsWhen fired
createdOptions passed into new Node()On end of constructor()
startedportOn end on start()
stoppedportOne end of stop()
syncedTypes passed into sync()On end of sync()
pushed{key, value}On end of push()
deletedkeyOn end of delete()
request{path, method}On request to server

Setup (as a standalone server)

To deploy an instance, follow these steps:

This should run on windows as well, however I don't use windows so it might require different commands.

I recommend using yarn, however npm should work too.

If using npm, change yarn to npm in the below commands.

  • Install NodeJS and optionally Yarn
  • git clone https://gitlab.com/imzacm/Decentralise.git
  • cd Decentralise
  • yarn install
  • yarn start

To install it as a global node module instead, do the following:

yarn global add zdds
zdds

Update

To update ZDDS, there are two options:

If you installed it as a global node module, you can run yarn global upgrade zdds and then restart the server.

If you installed through git, you can run node update.js while the server is running and it will automatically restart.

Options

All options may be set as environment variables or passed in when running the program. For example:

export <var>=<value>
yarn start

Or

yarn start <var>=<value>

port

The default port is 3985 however this can be changed by setting the port option.

host

This is the hostname that the node can be accessed at.

Default

localhost

addInitalNodes

If this is set to a value other than 'true', then initial nodes will not be added before starting.

Default

true

updateTimeout

This is the number of milliseconds between syncing with the known nodes.

This will not stop other nodes from pushing the nodes and data they have to the instance if they know it exists.

Default

10000

startSecondNode

If this is set to true, a second node will be created and run as a publicly available node.

This will be entirely separate from the first node.

Default

true

webSocket

This is the port that a websocket will be opened on. The websocket will always send and receive an object with the following keys:

  • data: data object
  • nodes: nodes object

Default

3986

Available GET endpoints:

  • /info
  • /data
  • /nodes
  • / - loads this readme

Example of GET to /info

HEADERS:

Content-Type: 'application/json'

BODY:

{
  "id": A unique GUID generated the first time the server is started,
  "version": The version of ZDDS running the node,
  "appName": The name in package.json,
  "port": The port the server is running on,
  "protocol": The protocol the server is running on - http or https,
  "host": The ip/domain to access the server
}

Example of GET to /data

SEND HEADERS:

key: The key to retrieve from ZDDS, if undefined then all data will be returned

HEADERS:

Content-Type: 'application/json'

timestamp: 1517742716662

BODY:

{
  "key": {
    "value": <actaul value>,
    "timestamp": 1517742716662
  }
}

Example of GET to /nodes

SEND HEADERS:

nodeId: The id of a node to retrieve, if undefined then all nodes will be returned

HEADERS:

Content-Type: 'application/json'

timestamp: 1517742716662

BODY:

{
  "id": {
    "host": The ip/domain the host can be accessed on,
    "port": The port the server is running on,
    "protocol": The protocol the server is using - http or https
  }
}

Example of an error response:

HEADERS:

Content-Type: 'application/json'

timestamp: 1517742716662

BODY:

{
  "error": "Some error message"
}

Available POST endpoints:

  • /data
  • /nodes
  • /delete

Example of POST to /nodes:

BODY:

{
  "id": {
    "host": The ip/domain the host can be accessed on,
    "port": The port the server is running on,
    "protocol": The protocol the server is using - http or https
  }
}

HEADERS:

Content-Type: 'application/json'

timestamp: 1517742716662

BODY:

An object containing every node that this node knows about.

Example of POST to /data:

Reserved keys

The following keys are reserved:

  • postId
  • dataObj
  • timestamp

BODY:

{
  "aKey": "a value",
  "postId": The postId needed to overwrite an existing key
}

HEADERS:

Content-Type: 'application/json'

timestamp: 1517742716662

BODY:

{
  "keyThatWasSent": value,
  "postId": The postId needed to overwrite the key
}

Example of POST to /delete:

BODY:

{
  "aKey": "a value",
  "postId": The postId needed to overwrite an existing key
}

HEADERS:

Content-Type: 'application/json'

timestamp: 1517742716662

BODY:

{}
3.2.1

6 years ago

3.2.0

6 years ago

3.1.12

6 years ago

3.1.11

6 years ago

3.1.10

6 years ago

1.1.10

6 years ago

3.1.9

6 years ago

3.1.8

6 years ago

3.1.7

6 years ago

3.1.6

6 years ago

3.1.5

6 years ago

3.1.4

6 years ago

3.1.3

6 years ago

3.1.2

6 years ago

3.1.1

6 years ago

3.1.0

6 years ago

3.0.8

6 years ago

3.0.7

6 years ago

3.0.6

6 years ago

3.0.5

6 years ago

3.0.4

6 years ago

3.0.3

6 years ago

3.0.2

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.1.4

6 years ago

2.1.3

6 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago