Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

computes-mesh

Package Overview
Dependencies
Maintainers
2
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

computes-mesh

Computes core, kernel, and messaging engine

latest
Source
npmnpm
Version
1.0.41
Version published
Weekly downloads
84
4100%
Maintainers
2
Weekly downloads
 
Created
Source

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

Keywords

computes

FAQs

Package last updated on 08 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts