dcp-client 4.2.20 → 4.2.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,47 +1,81 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html lang="en">
|
|
3
|
-
<!--
|
|
4
|
-
--
|
|
5
|
-
--
|
|
6
|
-
--
|
|
7
|
-
-- @author Wes Garland, wes@kingsds.network
|
|
8
|
-
-- @date Aug 2019
|
|
3
|
+
<!--
|
|
4
|
+
-- @file dcp-worker.html - Sample web page showing how to implement a
|
|
5
|
+
-- trivial DCP worker.
|
|
9
6
|
--
|
|
7
|
+
-- @author Wes Garland <wes@distributive.network>
|
|
8
|
+
-- @author Bryan Hoang <bryan@distributive.network>
|
|
9
|
+
-- @date Aug. 2019, Sept. 2022
|
|
10
10
|
-->
|
|
11
|
-
<head
|
|
12
|
-
<
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
11
|
+
<head>
|
|
12
|
+
<meta charset="utf-8" />
|
|
13
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
14
|
+
|
|
15
|
+
<script src="https://scheduler.distributed.computer/dcp-client/dcp-client.js"></script>
|
|
16
|
+
<script type="module">
|
|
17
|
+
const {
|
|
18
|
+
wallet,
|
|
19
|
+
worker: { Worker: DCPWorker },
|
|
20
|
+
} = window.dcp;
|
|
21
|
+
|
|
22
|
+
// The maximum number of sanxboxes to have working in parallel.
|
|
23
|
+
const defaultMaxSliceCount = 1;
|
|
24
|
+
|
|
25
|
+
// What bank account the worker will send its earned funds to.
|
|
26
|
+
const paymentAddress = (await wallet.get()).address;
|
|
27
|
+
|
|
28
|
+
// What identity the worker will use to communicate to the scheduler.
|
|
29
|
+
const identity = await wallet.getId();
|
|
30
|
+
|
|
31
|
+
const worker = new DCPWorker({
|
|
32
|
+
defaultMaxSliceCount,
|
|
33
|
+
paymentAddress,
|
|
34
|
+
// TODO: Change to `identityAddress` once the API is updated.
|
|
35
|
+
identity,
|
|
31
36
|
});
|
|
32
37
|
|
|
33
|
-
|
|
34
|
-
|
|
38
|
+
// Attaching event listeners to see what's going on.
|
|
39
|
+
worker.on('start', () => {
|
|
40
|
+
console.log('Worker started working!');
|
|
35
41
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
42
|
+
|
|
43
|
+
worker.on('sandbox', (sandbox) => {
|
|
44
|
+
sandbox.on('ready', (event) => {
|
|
45
|
+
console.log('sandbox ready', event);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
sandbox.on('start', ({ sandbox, job }) => {
|
|
49
|
+
const { name = '', description = '', link = '' } = job;
|
|
50
|
+
console.log(
|
|
51
|
+
`Sandbox ${sandbox.id} started slice for job with`,
|
|
52
|
+
`Name: "${name}",`,
|
|
53
|
+
`Description: "${description}", and`,
|
|
54
|
+
`Link: "${link}"`,
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
sandbox.on('sliceProgress', (event) => {
|
|
59
|
+
console.log(`Sandbox ${sandbox.id} progress`, event);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const sandboxEmit = sandbox.emit.bind(sandbox);
|
|
39
63
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
64
|
+
|
|
65
|
+
worker.on('payment', ({ accepted, payment }) => {
|
|
66
|
+
if (accepted) {
|
|
67
|
+
console.log(`You earned ${payment} DCC!`);
|
|
68
|
+
} else {
|
|
69
|
+
console.log('the result you computed was not accepted.');
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// Starting the worker.
|
|
74
|
+
await worker.start();
|
|
75
|
+
</script>
|
|
76
|
+
</head>
|
|
77
|
+
<body>
|
|
78
|
+
This is a minimal vanilla web DCP Worker example. Look in your browser's
|
|
79
|
+
console for output.
|
|
80
|
+
</body>
|
|
47
81
|
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dcp-client",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.22",
|
|
4
4
|
"description": "Core libraries for accessing DCP network",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dcp"
|
|
@@ -36,16 +36,16 @@
|
|
|
36
36
|
"http-proxy-agent": "^4.0.1",
|
|
37
37
|
"https-agent": "^1.0.0",
|
|
38
38
|
"https-proxy-agent": "^5.0.0",
|
|
39
|
-
"kvin": "^1.2.
|
|
39
|
+
"kvin": "^1.2.13",
|
|
40
40
|
"nanoid": "^3.2.0",
|
|
41
41
|
"node-localstorage": "^2.1.5",
|
|
42
42
|
"physical-cpu-count": "^2.0.0",
|
|
43
43
|
"polyfill-crypto.getrandomvalues": "^1.0.0",
|
|
44
44
|
"regedit": "^3.0.3",
|
|
45
45
|
"semver": "^7.3.5",
|
|
46
|
-
"webpack": "^5.
|
|
46
|
+
"webpack": "^5.75.0",
|
|
47
47
|
"webpack-cli": "^4.7.2",
|
|
48
|
-
"xmlhttprequest-ssl": "
|
|
48
|
+
"xmlhttprequest-ssl": "git+https://github.com/Distributed-Compute-Labs/node-XMLHttpRequest.git#bugfix/populate-responseText-once",
|
|
49
49
|
"yargs": "16.2.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<!-- @file simple-worker.html
|
|
4
|
-
--
|
|
5
|
-
-- Sample web page showing how to implement a trivial DCP worker.
|
|
6
|
-
--
|
|
7
|
-
-- @author Wes Garland, wes@kingsds.network
|
|
8
|
-
-- @date Aug 2019
|
|
9
|
-
--
|
|
10
|
-
-->
|
|
11
|
-
<head><meta charset="utf-8">
|
|
12
|
-
<script src="/bravojs/bravo.js"></script>
|
|
13
|
-
<script src="/etc/dcp-config.js"></script>
|
|
14
|
-
<!--script src="../../dcp-client.js"></script-->
|
|
15
|
-
<style type="text/css">
|
|
16
|
-
H1, H3 {
|
|
17
|
-
text-align: left;
|
|
18
|
-
}
|
|
19
|
-
</style>
|
|
20
|
-
</head>
|
|
21
|
-
<body onload="module.main.start()">
|
|
22
|
-
<h1>DCP Worker</h1>
|
|
23
|
-
<h3 id='connected'></h3>
|
|
24
|
-
Number of Workers: <input type="number" value='1' onchange='module.main.setWorkerCount(this.value)'>
|
|
25
|
-
<script>
|
|
26
|
-
|
|
27
|
-
require.paths.unshift('/wes.office.kingsds.network/git/dcp-client')
|
|
28
|
-
console.log('apths=', require.paths)
|
|
29
|
-
module.declare([require.paths[0] + '/dcp-client'], function mainModuleWrapper(require, exports, module) {
|
|
30
|
-
let numberOfWorkers = 1
|
|
31
|
-
let supervisor
|
|
32
|
-
|
|
33
|
-
exports.main = function main() {
|
|
34
|
-
supervisor = compute.work(numberOfWorkers)
|
|
35
|
-
supervisor.on('readystatechange', function(ev) {
|
|
36
|
-
console.log('rsc', ev, this)
|
|
37
|
-
})
|
|
38
|
-
supervisor.on('payment', function(ev) {
|
|
39
|
-
console.log('dcc', ev, this)
|
|
40
|
-
})
|
|
41
|
-
supervisor.on('sandbox', function(sandbox) {
|
|
42
|
-
console.log(`Supervisor launched sandbox ${sandbox.serial}`, sandbox)
|
|
43
|
-
sandbox.on('ready', function(ev) {
|
|
44
|
-
console.log('sandbox ready', ev, this)
|
|
45
|
-
})
|
|
46
|
-
sandbox.on('taskStart', function(task) {
|
|
47
|
-
console.log(`Started task ${task.serial} for job ${task.job.publicName||""} ${task.job.publicDescription||""} ${task.job.publicLink||""}`)
|
|
48
|
-
})
|
|
49
|
-
sandbox.on('progress', function(ev) {
|
|
50
|
-
console.log('progress', ev, this)
|
|
51
|
-
})
|
|
52
|
-
})
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
exports.setWorkerCount = function setWorkerCount(num) {
|
|
56
|
-
numberOfWorkers = num
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
exports.start = function start() {
|
|
60
|
-
require('dcp-client').init().then(exports.main)
|
|
61
|
-
}
|
|
62
|
-
})
|
|
63
|
-
</script>
|
|
64
|
-
</body>
|
|
65
|
-
</html>
|