1.0.41 • Published 7 years ago

computes-mesh v1.0.41

Weekly downloads
130
License
All Rights Reserv...
Repository
github
Last release
7 years ago

Computes Mesh

NPM module for creating, connecting, computing, and messaging on the computes.io supercomputer mesh network. Node module includes Kernel + Core + Messaging Engine in each node. (more details)

Install

$ npm install computes-mesh

Use

This version requires the go-ipfs daemon running in pubsub mode:

$ ipfs daemon --enable-pubsub-experiment

Here's the Node.JS code:

const computes = require('computes-mesh');
var job = computes.connect("domain-key-provided-by-computes.io");

API

job.on('ready', () => {})

Event fires when node is successfully connected to computes mesh network.

job.compute(operation, data)

Sends computes request to next available core in the network. Operations can be Javascript text strings or a URL such as a raw gist or an IPFS hash or an NPM URL

job.on('result', (result) => {})

Listens for results from computes requests. The result contains the core's computational result.

job.message(domain, message)

Sends message (string or buffer) to all nodes on the domain or to a specific nodeID.

job.on('message', (data) => {})

Listens for messages. data is an object containing the following properties:

  • from (string): peer id
  • message (Buffer): message content

job.peers(domain)

Returns array of peers attached to domain.

job.disconnect()

Leaves domain.

job.exit()

Leaves domain, stopping everything.

Example

This example echos 1 to 1000 across all of the nodes on the mesh network. It also demonstrates the message API:

const computes = require('computes-mesh');
var job = computes.connect("domain-key-provided-by-computes.io");

var operation = "(function(data) { var result = data; return result; })";

job.on("ready", function (){
  console.log("connected to ipfs...");
  for(var data = 0; data < 1000; data++) {
    job.compute(operation, data);
  }
});

// Fires as cores return results
job.on("result", function (result){
  console.log(result);
  // Demo broadcasting message with result
  job.message("domain-key-provided-by-computes.io", result);
});

// Fires when messages are received
job.on("message", function (msg){
  console.log(msg);
});

Notes:

Operations can also be a URL such as a raw gist or an IPFS hash or an NPM URL i.e.

https://gist.githubusercontent.com/computes/df86808c4a9d0a0d489a/raw/11c92b86662a4df5b5db585a1442796333bd1934/test.js

ipfs://QmSqy94jGEQ1DDx2exb9iMZS4augJnR3Tc2aofKATqrQMD

npm://find-hashtags@latest

1.0.41

7 years ago

1.0.40

7 years ago

1.0.39

7 years ago

1.0.38

7 years ago

1.0.37

7 years ago

1.0.36

7 years ago

1.0.35

7 years ago

1.0.34

7 years ago

1.0.33

7 years ago

1.0.32

7 years ago

1.0.31

7 years ago

1.0.30

7 years ago

1.0.29

7 years ago

1.0.28

7 years ago

1.0.27

7 years ago

1.0.26

7 years ago

1.0.25

7 years ago

1.0.24

7 years ago

1.0.23

7 years ago

1.0.22

7 years ago

1.0.21

7 years ago

1.0.20

7 years ago

1.0.19

7 years ago

1.0.18

7 years ago

1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago