Documentation for Distri-Node
EventEmitter
new DistriServer(opts).server : Object.solutions : number.userCount : number.session : Array.<DistriProblem>.remaining : Array.pending : number.addWork(work).CheckPercentage(solutions, percentage, resolve, reject)"all_work_complete""work_submitted" (work, solution, resolve, reject)"workgroup_complete" (work, solutions, resolve, reject)"workgroup_accepted" (work, solution)"workgroup_rejected" (work, solutions)new DistriClient(host).client : WebSocket~DistriProblem : ObjectEventEmitterConstructor 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
EventEmitter
new DistriServer(opts).server : Object.solutions : number.userCount : number.session : Array.<DistriProblem>.remaining : Array.pending : number.addWork(work).CheckPercentage(solutions, percentage, resolve, reject)"all_work_complete""work_submitted" (work, solution, resolve, reject)"workgroup_complete" (work, solutions, resolve, reject)"workgroup_accepted" (work, solution)"workgroup_rejected" (work, solutions)new DistriServer(opts)Throws:
TypeError Options sent to the constructor are not in a single object.| 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 : ObjectThe WebSocket server for all of Distri’s work
Kind: instance property of DistriServer
distriServer.solutions : numberThe number of solutions that have been submitted for a single session. Resets when all work is finished.
Kind: instance property of DistriServer
distriServer.userCount : numberThe 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 : ArrayAn array of indexes that have not been solved yet.
Kind: instance property of DistriServer
distriServer.pending : numberHow 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:
TypeError Work supplied is not an array.| 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
A Node.js client for Distri.
Kind: inner class of Distri-Node
new DistriClient(host).client : WebSocketnew DistriClient(host)Throws:
TypeError Host is not a string.| Param | Type | Description |
|---|---|---|
| host | string |
WebSocket link for the Distri server. |
distriClient.client : WebSocketThe WebSocket session for the client.
Kind: instance property of DistriClient
Distri-Node~DistriProblem : ObjectKind: 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. |