dcp-client 4.2.30 → 4.2.32
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.
- package/dcp-client.js +72 -22
- package/dist/dcp-client-bundle.js +1 -1
- package/generated/sandbox-definitions.json +1 -1
- package/index.js +1 -0
- package/libexec/sandbox/access-lists.js +68 -25
- package/libexec/sandbox/bravojs-env.js +52 -46
- package/libexec/sandbox/calculate-capabilities.js +3 -2
- package/libexec/sandbox/event-loop-virtualization.js +32 -64
- package/libexec/sandbox/timer-classes.js +226 -0
- package/libexec/sandbox/unique-timing.js +163 -0
- package/libexec/sandbox/webgpu-worker-environment.js +3 -1
- package/package.json +5 -7
- package/libexec/sandbox/gpu-timers.js +0 -84
package/dcp-client.js
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
* @author Wes Garland, wes@kingsds.network
|
|
13
13
|
* @date Aug 2019
|
|
14
14
|
*/
|
|
15
|
+
'use strict';
|
|
15
16
|
(function namespaceIIFE() {
|
|
16
17
|
|
|
17
18
|
console.log(`%c
|
|
@@ -50,40 +51,82 @@ https://distributed.computer/`, "font-weight: bold; font-size: 1.2em; color: #00
|
|
|
50
51
|
dcpConfigHref = thisScriptURL.origin + thisScriptURL.pathname.replace(/\/dcp-client\/dcp-client.js$/, '/etc/dcp-config.js') + thisScriptURL.search;
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
/** Load dcp-config.
|
|
54
|
-
function loadConfig()
|
|
54
|
+
/** Load dcp-config.js from scheduler, and merge with running dcpConfig */
|
|
55
|
+
function loadConfig()
|
|
56
|
+
{
|
|
55
57
|
configScript = document.createElement('SCRIPT');
|
|
56
58
|
configScript.setAttribute('type', 'text/javascript');
|
|
57
59
|
configScript.setAttribute('src', dcpConfigHref);
|
|
58
60
|
configScript.setAttribute('id', '_dcp_config');
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
61
|
+
|
|
62
|
+
if (!thisScript.id)
|
|
63
|
+
thisScript.id = '_dcp_client_loader';
|
|
64
|
+
|
|
65
|
+
let html = configScript.outerHTML;
|
|
66
|
+
|
|
67
|
+
/* If we know about an alternate scheduler location - by any means but usually script attribute -
|
|
68
|
+
* add it into our local configuration delta; generate this delta as-needed.
|
|
69
|
+
*/
|
|
70
|
+
if (schedulerURL)
|
|
71
|
+
{
|
|
72
|
+
if (!_dcpConfig)
|
|
73
|
+
_dcpConfig = {};
|
|
74
|
+
if (!_dcpConfig.scheduler)
|
|
75
|
+
_dcpConfig.scheduler = {};
|
|
76
|
+
_dcpConfig.scheduler.location = schedulerURL;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* Preserve the config delta so that it can be merged on top of the remote config, before the
|
|
80
|
+
* bundle is completely initialized. The global dcpConfig is replaced by this new script.
|
|
81
|
+
*/
|
|
82
|
+
if (_dcpConfig)
|
|
83
|
+
{
|
|
84
|
+
thisScript.mergeConfig = mergeConfig;
|
|
85
|
+
html += `<script>document.getElementById('${thisScript.id}').mergeConfig();</scr` + 'ipt>';
|
|
74
86
|
}
|
|
87
|
+
|
|
88
|
+
document.write(html);
|
|
75
89
|
configScript.onerror = (function(e) {
|
|
76
90
|
alert('Error DCP-1001: Could not load or parse scheduler configuration from URL ("' + configScript.getAttribute('src') + '")');
|
|
77
91
|
console.error('dcpConfig load error: ', e);
|
|
78
92
|
}).toString();
|
|
79
93
|
}
|
|
80
94
|
|
|
95
|
+
function mergeConfig()
|
|
96
|
+
{
|
|
97
|
+
const mergedConf = leafMerge(dcpConfig, _dcpConfig);
|
|
98
|
+
Object.assign(dcpConfig, mergedConf);
|
|
99
|
+
|
|
100
|
+
function leafMerge() /* lifted from dcp-client obj-merge.js c32e780fae88071df1bb4aebe3282220d518260e */
|
|
101
|
+
{
|
|
102
|
+
var target = {};
|
|
103
|
+
|
|
104
|
+
for (let i=0; i < arguments.length; i++)
|
|
105
|
+
{
|
|
106
|
+
let neo = arguments[i];
|
|
107
|
+
if (neo === undefined)
|
|
108
|
+
continue;
|
|
109
|
+
|
|
110
|
+
for (let prop in neo)
|
|
111
|
+
{
|
|
112
|
+
if (!neo.hasOwnProperty(prop))
|
|
113
|
+
continue;
|
|
114
|
+
if (typeof neo[prop] === 'object' && neo[prop] !== null && !Array.isArray(neo[prop]) && ['Function','Object'].includes(neo[prop].constructor.name))
|
|
115
|
+
target[prop] = leafMerge(target[prop], neo[prop]);
|
|
116
|
+
else
|
|
117
|
+
target[prop] = neo[prop];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return target;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
81
125
|
/* Shim to make CommonJS Modules/2.0d8 environment (BravoJS, NobleJS) work with dcpClient in requireNative mode */
|
|
82
126
|
function loadCJS2Shim()
|
|
83
127
|
{
|
|
84
128
|
var shimScript = document.createElement('SCRIPT');
|
|
85
129
|
var shimSrc = thisScript.getAttribute("shim") || (thisScript.src.replace('/dcp-client.js', '/cjs2-shim.js'));
|
|
86
|
-
var tmp;
|
|
87
130
|
|
|
88
131
|
shimScript.setAttribute('type', 'text/javascript');
|
|
89
132
|
shimScript.setAttribute('src', shimSrc);
|
|
@@ -102,8 +145,9 @@ https://distributed.computer/`, "font-weight: bold; font-size: 1.2em; color: #00
|
|
|
102
145
|
function bundleReadyIIFE() {
|
|
103
146
|
const configScript = document.getElementById("_dcp_config");
|
|
104
147
|
const bundleScript = document.getElementById("_dcp_client_bundle");
|
|
105
|
-
|
|
106
|
-
|
|
148
|
+
const ready = bundleScript.getAttribute('onready');
|
|
149
|
+
const dcp = bundleScript.exports;
|
|
150
|
+
const KVIN = new dcp.kvin.KVIN();
|
|
107
151
|
|
|
108
152
|
if (typeof module !== 'undefined' && typeof module.declare !== 'undefined')
|
|
109
153
|
require('/internal/dcp/cjs2-shim').init(bundleScript.exports); /* CommonJS Modules/2.0d8 environment (BravoJS, NobleJS) */
|
|
@@ -112,7 +156,14 @@ https://distributed.computer/`, "font-weight: bold; font-size: 1.2em; color: #00
|
|
|
112
156
|
|
|
113
157
|
/** Let protocol know where we got out config from, so origin can be reasoned about vis a vis security */
|
|
114
158
|
dcp.protocol.setSchedulerConfigLocation_fromScript(configScript);
|
|
115
|
-
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Slide baked-in config underneath the remote config to provide default values.
|
|
162
|
+
*/
|
|
163
|
+
KVIN.userCtors.dcpUrl$$DcpURL = dcp['dcp-url'].DcpURL;
|
|
164
|
+
KVIN.userCtors.dcpEth$$Address = dcp.wallet.Address;
|
|
165
|
+
dcpConfig = dcp['dcp-config'] = dcp.utils.leafMerge(KVIN.unmarshal(dcp['dcp-default-config']), dcp['dcp-config']);
|
|
166
|
+
|
|
116
167
|
/**
|
|
117
168
|
* Transform instances of Address-like values into Addresses. Necessary since
|
|
118
169
|
* the config can't access the Address class before the bundle is loaded.
|
|
@@ -130,7 +181,6 @@ https://distributed.computer/`, "font-weight: bold; font-size: 1.2em; color: #00
|
|
|
130
181
|
function loadBundle(shimCallback) {
|
|
131
182
|
var bundleScript = document.createElement('SCRIPT');
|
|
132
183
|
var bundleSrc = thisScript.getAttribute("bundle") || (thisScript.src.replace('/dcp-client.js', '/dist/dcp-client-bundle.js'));
|
|
133
|
-
var tmp;
|
|
134
184
|
|
|
135
185
|
bundleScript.setAttribute('type', 'text/javascript');
|
|
136
186
|
bundleScript.setAttribute('src', bundleSrc);
|