Node API

Documentation for Distri-Node

Distri-Node

Distri-Node~DistriServer ⇐ EventEmitter

Constructor for DistriServer.

Kind: inner class of Distri-Node Extends: EventEmitter
Emits: DistriServer#event:work_submitted, DistriServer#event:workgroup_complete, DistriServer#event:workgroup_accepted, DistriServer#event:workgroup_rejected, DistriServer#event:all_work_complete

new DistriServer(opts)

Throws:

Param Type Description
opts Object The object passed to the constructor.
opts.connection Object Options for a ws.Server constructor. (websockets/ws)
opts.verificationStrength number How many solutions must be submitted for a problem to be considered complete. Security measure to help keep clients from spamming incorrect answers.
opts.files Object URL’s to files for Distri clients to fetch.
opts.files.node string File to fetch for Node.js clients, not prepended with ‘http(s)://’.
opts.files.javascript string File to fetch for JavaScript clients, not prepended with ‘http(s)://’.

distriServer.server : Object

The WebSocket server for all of Distri’s work

Kind: instance property of DistriServer

distriServer.solutions : number

The number of solutions that have been submitted for a single session. Resets when all work is finished.

Kind: instance property of DistriServer

distriServer.userCount : number

The number of currently connected clients.

Kind: instance property of DistriServer

distriServer.session : Array.<DistriProblem>

An array of objects that contains all work, solutions, and other metadata.

Kind: instance property of DistriServer

distriServer.remaining : Array

An array of indexes that have not been solved yet.

Kind: instance property of DistriServer

distriServer.pending : number

How many problems are undergoing verification.

Kind: instance property of DistriServer

distriServer.addWork(work)

A function that adds work to the work queue.

Kind: instance method of DistriServer Throws:

Param Type Description
work Array Work to be added to the work queue.

distriServer.CheckPercentage(solutions, percentage, resolve, reject)

A built-in verification function for Distri that checks to see if a set of solutions contains one solution that occurs more than a certain percentage of the time.

Kind: instance method of DistriServer
See: DistriServer#workgroup_complete

Param Type Description
solutions Array The solutions that are being checked.
percentage number The percent of time a certain solution must occur equal to or more than.
resolve function A callback function that will be called with the accepted answer. Good to use with the resolve() function in workgroup_complete.
reject function A callback function that will be called if none of the solutions satisfy the percentage. Good to use with the reject() function in workgroup_complete.

"work_submitted" (work, solution, resolve, reject)

Fires when a single user submits work. Useful for authentication the user. Do not use for verifying work, use workgroup_complete instead. If a listener is attached to this event, a resolve() and reject() function will be emitted, and one of them must be called in order for Distri to know what to do with the work.

Kind: event emitted by DistriServer See: DistriServer#workgroup_complete

Param Type Description
work Any Work the client was sent.
solution Any Solution the client sent back.
socket WebSocket WebSocket session of the user.
resolve function Function from a Promise. When called, the client’s work is accepted and put into the solution pool.
reject function Function from a Promise. When called, the client’s work is rejected.

"workgroup_complete" (work, solutions, resolve, reject)

Fires when a piece of work has the required amount of solutions, set by the verification strength. If no listener is attached to this event, the first solution is automatically accepted.

Kind: event emitted by DistriServer

Param Type Description
work Any The work sent to all of the clients.
solutions Array An array of the solutions each client sent back. Note that this will still be an array even if the verification strength is only one.
resolve function A function that accepts the solution given to it. Be sure to give it just one solution, and not the entire array.
reject function A function that takes no parameters and rejects the entire workgroup, starting it over.

"workgroup_accepted" (work, solution)

Fires when a piece of work has a solution accepted for it.

Kind: event emitted by DistriServer

Param Type Description
work Any The work sent to the clients.
solution Any The accepted solution.

"workgroup_rejected" (work, solutions)

Fires when a workgroup is rejected.

Kind: event emitted by DistriServer

Param Type Description
work Any The work the clients were sent.
solutions Array The solutions that were sent in for the problem.

"all_work_complete"

Fires when all work is complete. No parameters are given.

Kind: event emitted by DistriServer

Distri-Node~DistriClient

A Node.js client for Distri.

Kind: inner class of Distri-Node

new DistriClient(host)

Throws:

Param Type Description
host string WebSocket link for the Distri server.

distriClient.client : WebSocket

The WebSocket session for the client.

Kind: instance property of DistriClient

Distri-Node~DistriProblem : Object

Kind: inner typedef of Distri-Node Properties

Name Type Description
work Any The work for that problem.
workers number The number of clients currently working on the problem.
solutions Array The submitted solutions for the problem.

This project is maintained by