pinokiod 3.8.149 → 3.8.151
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/kernel/api/index.js +0 -10
- package/kernel/api/script/index.js +0 -2
- package/kernel/bin/caddy.js +0 -4
- package/kernel/bin/conda.js +2 -11
- package/kernel/bin/index.js +0 -46
- package/kernel/environment.js +16 -2
- package/kernel/index.js +54 -70
- package/kernel/info.js +0 -3
- package/kernel/kv.js +3 -0
- package/kernel/loader.js +0 -11
- package/kernel/peer.js +15 -18
- package/kernel/procs.js +0 -4
- package/kernel/router/common.js +1 -20
- package/kernel/router/connector.js +0 -39
- package/kernel/router/index.js +21 -126
- package/kernel/router/localhost_home_router.js +7 -18
- package/kernel/router/localhost_variable_router.js +0 -1
- package/kernel/router/processor.js +0 -3
- package/kernel/shell.js +0 -23
- package/kernel/shells.js +0 -16
- package/package.json +1 -1
- package/server/index.js +2 -2
- package/server/public/install.js +2 -2
- package/server/public/style.css +4 -0
- package/server/socket.js +0 -27
- package/server/views/bootstrap.ejs +6 -1
- package/server/views/download.ejs +7 -1
- package/server/views/editor.ejs +7 -3
- package/server/views/file_explorer.ejs +7 -1
- package/server/views/index.ejs +7 -1
- package/server/views/install.ejs +8 -5
- package/server/views/minterm.ejs +7 -3
- package/server/views/network.ejs +30 -5
- package/server/views/terminal.ejs +7 -4
- package/kernel/caddy2.js +0 -666
- package/kernel/peer2.js +0 -83
- package/kernel/router/root.js +0 -54
- package/kernel/tree-kill.js +0 -167
package/kernel/api/index.js
CHANGED
|
@@ -119,10 +119,8 @@ class Api {
|
|
|
119
119
|
return result
|
|
120
120
|
}
|
|
121
121
|
async stop(req, ondata) {
|
|
122
|
-
console.log(">>>>>>>>>>>>>>>>>> STOP")
|
|
123
122
|
// 1. set the "stop" flag for the uri, so the next execution in the queue for the uri will NOT queue another task
|
|
124
123
|
// 2. stream a message closing the socket
|
|
125
|
-
console.time("stop 1")
|
|
126
124
|
|
|
127
125
|
let requestPath = this.filePath(req.params.uri)
|
|
128
126
|
|
|
@@ -132,9 +130,6 @@ class Api {
|
|
|
132
130
|
await this.process(script.on.stop)
|
|
133
131
|
}
|
|
134
132
|
}
|
|
135
|
-
console.timeEnd("stop 1")
|
|
136
|
-
|
|
137
|
-
console.time("stop 2")
|
|
138
133
|
// reset modules
|
|
139
134
|
let modpath = this.resolvePath(cwd, req.params.uri)
|
|
140
135
|
console.log("STOP modpath", modpath)
|
|
@@ -160,15 +155,11 @@ class Api {
|
|
|
160
155
|
|
|
161
156
|
// stop all proxies
|
|
162
157
|
this.stopProxy({ script: requestPath })
|
|
163
|
-
console.timeEnd("stop 2")
|
|
164
158
|
|
|
165
159
|
// stop all cloudflare tunnels
|
|
166
160
|
|
|
167
|
-
console.time("stop 3")
|
|
168
161
|
await this.kernel.stopCloudflare({ path: requestPath })
|
|
169
|
-
console.timeEnd("stop 3")
|
|
170
162
|
|
|
171
|
-
console.time("stop 4")
|
|
172
163
|
|
|
173
164
|
// if there are any pending waiters, delete them
|
|
174
165
|
|
|
@@ -185,7 +176,6 @@ class Api {
|
|
|
185
176
|
id: requestPath,
|
|
186
177
|
type: "disconnect"
|
|
187
178
|
})
|
|
188
|
-
console.timeEnd("stop 4")
|
|
189
179
|
this.kernel.refresh(true)
|
|
190
180
|
return true
|
|
191
181
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const path = require('path')
|
|
2
2
|
class Script {
|
|
3
3
|
async start(req, ondata, kernel) {
|
|
4
|
-
console.log(">>>>>>>>> script.start", req)
|
|
5
4
|
let res = await this.run(req, ondata, kernel)
|
|
6
5
|
return res
|
|
7
6
|
}
|
|
@@ -44,7 +43,6 @@ class Script {
|
|
|
44
43
|
*/
|
|
45
44
|
// if already running, print that it's already running
|
|
46
45
|
let id = kernel.api.filePath(req.params.uri, req.cwd)
|
|
47
|
-
console.log({ id , uri: req.params.uri, cwd: req.cwd })
|
|
48
46
|
if (kernel.api.running[id]) {
|
|
49
47
|
let msg = `${req.params.uri} already running. Continuing...\r\n`
|
|
50
48
|
ondata({ raw: msg })
|
package/kernel/bin/caddy.js
CHANGED
|
@@ -79,7 +79,6 @@ class Caddy {
|
|
|
79
79
|
ondata(e)
|
|
80
80
|
})
|
|
81
81
|
} else {
|
|
82
|
-
console.log("req", req)
|
|
83
82
|
ondata({
|
|
84
83
|
title: "Password",
|
|
85
84
|
description: "Enter your system password to add the HTTPS certificate",
|
|
@@ -90,9 +89,7 @@ class Caddy {
|
|
|
90
89
|
placeholder: "System password",
|
|
91
90
|
}]
|
|
92
91
|
}, "input")
|
|
93
|
-
console.log("Wait until", id)
|
|
94
92
|
let response = await this.kernel.api.wait(id)
|
|
95
|
-
console.log({ response })
|
|
96
93
|
await this.kernel.exec({
|
|
97
94
|
message: `echo ${response.password} | sudo -S caddy trust`,
|
|
98
95
|
path: this.kernel.homedir
|
|
@@ -104,7 +101,6 @@ class Caddy {
|
|
|
104
101
|
// }
|
|
105
102
|
})
|
|
106
103
|
}
|
|
107
|
-
console.log("FINISHED")
|
|
108
104
|
}
|
|
109
105
|
async installed() {
|
|
110
106
|
let e = await this.kernel.exists(this.kernel.path("cache/XDG_DATA_HOME/caddy/pki/authorities/local/root.crt"))
|
package/kernel/bin/conda.js
CHANGED
|
@@ -120,10 +120,9 @@ report_errors: false`)
|
|
|
120
120
|
// }
|
|
121
121
|
async check() {
|
|
122
122
|
let res = await this.kernel.bin.exec({ message: `conda list` }, (stream) => {
|
|
123
|
-
process.stdout.write(stream.raw)
|
|
123
|
+
// process.stdout.write(stream.raw)
|
|
124
124
|
// console.log("conda list check", { stream })
|
|
125
125
|
})
|
|
126
|
-
console.log("2 conda list check", res)
|
|
127
126
|
|
|
128
127
|
let lines = res.response.split(/[\r\n]+/)
|
|
129
128
|
let conda_check = {}
|
|
@@ -179,7 +178,6 @@ report_errors: false`)
|
|
|
179
178
|
}
|
|
180
179
|
}
|
|
181
180
|
}
|
|
182
|
-
console.log("> Check", { conda_check, conda })
|
|
183
181
|
this.kernel.bin.installed.conda = conda
|
|
184
182
|
return conda_check.conda && conda_check.mamba && conda_check.sqlite
|
|
185
183
|
//return conda_check.conda && conda_check.mamba
|
|
@@ -253,21 +251,17 @@ report_errors: false`)
|
|
|
253
251
|
// 2. The pinned file says conda-libmamba-solver=24.11.1
|
|
254
252
|
// 3. so after conda update --all, it should be conda-libmamba-solver=24.11.1
|
|
255
253
|
|
|
256
|
-
console.log({ req })
|
|
257
|
-
|
|
258
|
-
|
|
259
254
|
let mods = this.kernel.bin.mods.filter((m) => {
|
|
260
255
|
return req.dependencies.includes(m.name)
|
|
261
256
|
// return ["zip", "uv", "node", "huggingface", "gxx", "git", "ffmpeg", "caddy"].includes(m.name)
|
|
262
257
|
}).map((m) => {
|
|
263
258
|
return m.mod.cmd()
|
|
264
259
|
}).join(" ")
|
|
265
|
-
console.log("
|
|
260
|
+
console.log("Conda dependencies to install", { mods })
|
|
266
261
|
|
|
267
262
|
let cmds = [
|
|
268
263
|
//"conda clean -y --index-cache",
|
|
269
264
|
"conda clean -y --all",
|
|
270
|
-
//"conda install -y -c conda-forge sqlite=3.47.2",
|
|
271
265
|
`conda install -y -c conda-forge sqlite=3.47.2 ${mods}`,
|
|
272
266
|
|
|
273
267
|
// `conda config --file ${this.kernel.path('condarc')} --set remote_connect_timeout_secs 20`,
|
|
@@ -381,9 +375,6 @@ report_errors: false`)
|
|
|
381
375
|
let e
|
|
382
376
|
for(let p of this.paths[this.kernel.platform]) {
|
|
383
377
|
let e = await this.kernel.bin.exists(p)
|
|
384
|
-
console.log("kernel.bin.conda.installed")
|
|
385
|
-
console.log("e", e)
|
|
386
|
-
console.log("correct_conda", this.kernel.bin.correct_conda)
|
|
387
378
|
if (e && this.kernel.bin.correct_conda) return true
|
|
388
379
|
}
|
|
389
380
|
return false
|
package/kernel/bin/index.js
CHANGED
|
@@ -345,11 +345,8 @@ class Bin {
|
|
|
345
345
|
this.correct_conda = false
|
|
346
346
|
} else {
|
|
347
347
|
res = await this.exec({ message: `conda list` }, (stream) => {
|
|
348
|
-
process.stdout.write(stream.raw)
|
|
349
348
|
// console.log("conda list check", { stream })
|
|
350
349
|
})
|
|
351
|
-
console.log("1 conda list check", res)
|
|
352
|
-
|
|
353
350
|
|
|
354
351
|
let lines = res.response.split(/[\r\n]+/)
|
|
355
352
|
for(let line of lines) {
|
|
@@ -402,7 +399,6 @@ class Bin {
|
|
|
402
399
|
}
|
|
403
400
|
}
|
|
404
401
|
}
|
|
405
|
-
console.log("conda_check", conda_check)
|
|
406
402
|
|
|
407
403
|
if (conda_check.conda && conda_check.mamba && conda_check.sqlite) {
|
|
408
404
|
//if (conda_check.conda && conda_check.mamba) {
|
|
@@ -646,15 +642,12 @@ class Bin {
|
|
|
646
642
|
bin: this.preset("ai")
|
|
647
643
|
})
|
|
648
644
|
req.params = JSON.stringify(requirements)
|
|
649
|
-
console.log(">>>>> 1")
|
|
650
645
|
if (this.install_required) {
|
|
651
|
-
console.log(">>>>> 2")
|
|
652
646
|
let res = await this.install(req, ondata)
|
|
653
647
|
return res
|
|
654
648
|
}
|
|
655
649
|
}
|
|
656
650
|
async install(req, ondata) {
|
|
657
|
-
console.time("kernel.bin.install")
|
|
658
651
|
/*
|
|
659
652
|
req.params := {
|
|
660
653
|
client: {
|
|
@@ -672,13 +665,7 @@ class Bin {
|
|
|
672
665
|
} else {
|
|
673
666
|
this.client = null
|
|
674
667
|
}
|
|
675
|
-
|
|
676
|
-
console.log("install", req)
|
|
677
|
-
|
|
678
668
|
let requirements = JSON.parse(req.params)
|
|
679
|
-
|
|
680
|
-
console.time("### Total Install")
|
|
681
|
-
|
|
682
669
|
for(let x=0; x<10; x++) {
|
|
683
670
|
console.log(`## Install Attempt ${x}`)
|
|
684
671
|
let i = 0;
|
|
@@ -692,9 +679,7 @@ class Bin {
|
|
|
692
679
|
console.log("already installed. skip.")
|
|
693
680
|
} else {
|
|
694
681
|
console.log("not installed. install.")
|
|
695
|
-
console.time("############# Install " +requirement.name)
|
|
696
682
|
await this.tryInstall(req.id, requirement, x, i, requirements.length, ondata)
|
|
697
|
-
console.timeEnd("############# Install " +requirement.name)
|
|
698
683
|
}
|
|
699
684
|
}
|
|
700
685
|
|
|
@@ -750,12 +735,10 @@ class Bin {
|
|
|
750
735
|
// }
|
|
751
736
|
// }
|
|
752
737
|
//}
|
|
753
|
-
console.timeEnd("### Total Install")
|
|
754
738
|
if (this.kernel.shell) {
|
|
755
739
|
console.log(">>> shell reset")
|
|
756
740
|
this.kernel.shell.reset()
|
|
757
741
|
}
|
|
758
|
-
console.timeEnd("kernel.bin.install")
|
|
759
742
|
await this.init()
|
|
760
743
|
}
|
|
761
744
|
async check_installed(r, dependencies) {
|
|
@@ -804,35 +787,6 @@ class Bin {
|
|
|
804
787
|
}
|
|
805
788
|
requirements(config) {
|
|
806
789
|
let requirements = config.bin.requirements
|
|
807
|
-
// let requirements = [
|
|
808
|
-
// { name: "conda", },
|
|
809
|
-
// { name: "git", },
|
|
810
|
-
//// { name: "zip", },
|
|
811
|
-
// { name: "node", },
|
|
812
|
-
// { name: "ffmpeg", },
|
|
813
|
-
// { name: "caddy", }
|
|
814
|
-
// ]
|
|
815
|
-
// let platform = os.platform()
|
|
816
|
-
// if (platform === "win32") {
|
|
817
|
-
// requirements.push({ name: "registry" })
|
|
818
|
-
// requirements.push({ name: "vs" })
|
|
819
|
-
// }
|
|
820
|
-
// if (platform === "darwin") {
|
|
821
|
-
// requirements.push({ name: "brew" })
|
|
822
|
-
// }
|
|
823
|
-
// if (platform === "linux") {
|
|
824
|
-
// requirements.push({ name: "gxx" })
|
|
825
|
-
// }
|
|
826
|
-
// if (this.kernel.gpu === "nvidia") {
|
|
827
|
-
// requirements.push({ name: "cuda", })
|
|
828
|
-
// }
|
|
829
|
-
// requirements = requirements.concat([
|
|
830
|
-
// { name: "cloudflared" },
|
|
831
|
-
//// { name: "playwright" },
|
|
832
|
-
// { name: "huggingface" },
|
|
833
|
-
// { name: "uv" },
|
|
834
|
-
// { name: "py" },
|
|
835
|
-
// ])
|
|
836
790
|
if (config.script && config.script.requires && config.script.requires.length > 0) {
|
|
837
791
|
/*********************************************************************
|
|
838
792
|
|
package/kernel/environment.js
CHANGED
|
@@ -447,7 +447,7 @@ const requirements = async (script, filepath, kernel) => {
|
|
|
447
447
|
let env = await get2(filepath, kernel)
|
|
448
448
|
for(let item of script.pre) {
|
|
449
449
|
if (item.env) {
|
|
450
|
-
|
|
450
|
+
// if index is not set, use 0 as default (for key)
|
|
451
451
|
if (!item.index) {
|
|
452
452
|
item.index = 0
|
|
453
453
|
}
|
|
@@ -464,7 +464,21 @@ const requirements = async (script, filepath, kernel) => {
|
|
|
464
464
|
item.val = env[item.env]
|
|
465
465
|
} else {
|
|
466
466
|
if (item.default) {
|
|
467
|
-
|
|
467
|
+
if (typeof item.default === 'object') {
|
|
468
|
+
if (item.default.key) {
|
|
469
|
+
const hasProtocol = /^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(item.default.key);
|
|
470
|
+
const url = new URL(hasProtocol ? item.default.key : `https://${item.default.key}`);
|
|
471
|
+
item.host = url.host
|
|
472
|
+
|
|
473
|
+
let index = item.default.index || 0
|
|
474
|
+
item.index = index
|
|
475
|
+
item.val = await kernel.kv.get(item.host, index)
|
|
476
|
+
} else {
|
|
477
|
+
item.host = ""
|
|
478
|
+
}
|
|
479
|
+
} else {
|
|
480
|
+
item.val = item.default
|
|
481
|
+
}
|
|
468
482
|
}
|
|
469
483
|
requires_instantiation = true
|
|
470
484
|
}
|
package/kernel/index.js
CHANGED
|
@@ -118,21 +118,6 @@ class Kernel {
|
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
-
// path_exists(...args) {
|
|
122
|
-
// return this.info.exists(...args)
|
|
123
|
-
// }
|
|
124
|
-
// path_resolve(...args) {
|
|
125
|
-
// return this.info.path(...args)
|
|
126
|
-
// }
|
|
127
|
-
// script_running(...args) {
|
|
128
|
-
// return this.info.running(...args)
|
|
129
|
-
// }
|
|
130
|
-
// script_local(...args) {
|
|
131
|
-
// return this.info.local(...args)
|
|
132
|
-
// }
|
|
133
|
-
// script_global(...args) {
|
|
134
|
-
// return this.info.global(...args)
|
|
135
|
-
// }
|
|
136
121
|
async env(...args) {
|
|
137
122
|
let folderpath
|
|
138
123
|
if (args) {
|
|
@@ -261,76 +246,87 @@ class Kernel {
|
|
|
261
246
|
}
|
|
262
247
|
async refresh(notify_peers) {
|
|
263
248
|
let env = await Environment.get(this.homedir)
|
|
264
|
-
let
|
|
249
|
+
let peer_active = false
|
|
265
250
|
// if PINOKIO_NETWORK_SHARE is 0 or false, turn it off
|
|
266
251
|
if (env && env.PINOKIO_NETWORK_ACTIVE && (env.PINOKIO_NETWORK_ACTIVE==="1" || env.PINOKIO_NETWORK_ACTIVE.toLowerCase()==="true")) {
|
|
267
|
-
|
|
252
|
+
peer_active = true
|
|
253
|
+
}
|
|
254
|
+
let https_active = false
|
|
255
|
+
if (env && env.PINOKIO_HTTPS_ACTIVE && (env.PINOKIO_HTTPS_ACTIVE==="1" || env.PINOKIO_HTTPS_ACTIVE.toLowerCase()==="true")) {
|
|
256
|
+
https_active = true
|
|
268
257
|
}
|
|
269
258
|
// console.log("kernel.refresh", { active, notify_peers })
|
|
270
|
-
|
|
259
|
+
|
|
260
|
+
// let caddy_installed = await this.bin.check_installed({ name: "caddy" })
|
|
261
|
+
|
|
262
|
+
// 1. https
|
|
263
|
+
// 2. https + local share
|
|
264
|
+
// console.log("caddy installed?", caddy_installed)
|
|
265
|
+
// if (caddy_installed && https_active) {
|
|
271
266
|
|
|
272
267
|
// 1. get the process list
|
|
273
|
-
// console.log("Step 1: Get process list")
|
|
274
|
-
console.log("> 1")
|
|
275
268
|
await this.processes.refresh()
|
|
276
|
-
// console.log("Process info", this.processes.info)
|
|
277
|
-
|
|
278
|
-
console.log("> 2")
|
|
279
269
|
|
|
280
270
|
// 2. refresh peer info to reflect the proc info
|
|
281
271
|
await this.peer.refresh()
|
|
282
272
|
|
|
283
|
-
|
|
284
|
-
console.log("> 3")
|
|
285
273
|
// 3. load custom routers from ~/pinokio/network
|
|
286
274
|
await this.router.init()
|
|
287
275
|
|
|
288
|
-
|
|
289
|
-
// 3. set current local host router info
|
|
290
|
-
// console.log("Step 3: Set current local host router")
|
|
276
|
+
// 4. set current local host router info
|
|
291
277
|
await this.router.local()
|
|
292
|
-
// console.log("router mapping after step 3", this.router.info)
|
|
293
278
|
|
|
294
|
-
|
|
295
|
-
// 4. refresh peer info to reflect the updated router info
|
|
279
|
+
// 5. refresh peer info to reflect the updated router info
|
|
296
280
|
await this.peer.refresh()
|
|
297
281
|
|
|
298
|
-
|
|
299
|
-
// 4. tell peers to refresh
|
|
282
|
+
// 6. tell peers to refresh
|
|
300
283
|
if (notify_peers) {
|
|
301
|
-
// console.log("Step 4: notify peers to refresh")
|
|
302
|
-
console.log("> 7")
|
|
303
284
|
await this.peer.notify_peers()
|
|
304
285
|
}
|
|
305
286
|
|
|
306
|
-
|
|
307
|
-
// 4. update remote router
|
|
308
|
-
// console.log("Step 5: Set remote routers")
|
|
287
|
+
// 7. update remote router
|
|
309
288
|
await this.router.remote()
|
|
310
|
-
// console.log("router mapping after step 5", this.router.info)
|
|
311
289
|
|
|
312
|
-
|
|
290
|
+
// 8. update caddy config
|
|
313
291
|
await this.router.update()
|
|
314
292
|
|
|
293
|
+
// 9. announce self to the peer network
|
|
294
|
+
this.peer.announce()
|
|
295
|
+
|
|
296
|
+
// }
|
|
315
297
|
|
|
316
|
-
//
|
|
317
|
-
|
|
318
|
-
//
|
|
319
|
-
//
|
|
320
|
-
|
|
321
|
-
//
|
|
322
|
-
//
|
|
323
|
-
|
|
324
|
-
//
|
|
325
|
-
//
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
//
|
|
329
|
-
|
|
330
|
-
//
|
|
331
|
-
//
|
|
332
|
-
|
|
333
|
-
|
|
298
|
+
//if (https_installed && peer_active) {
|
|
299
|
+
|
|
300
|
+
// // 1. get the process list
|
|
301
|
+
// await this.processes.refresh()
|
|
302
|
+
|
|
303
|
+
// // 2. refresh peer info to reflect the proc info
|
|
304
|
+
// await this.peer.refresh()
|
|
305
|
+
|
|
306
|
+
// // 3. load custom routers from ~/pinokio/network
|
|
307
|
+
// await this.router.init()
|
|
308
|
+
|
|
309
|
+
// // 4. set current local host router info
|
|
310
|
+
// await this.router.local()
|
|
311
|
+
|
|
312
|
+
// // 5. refresh peer info to reflect the updated router info
|
|
313
|
+
// await this.peer.refresh()
|
|
314
|
+
|
|
315
|
+
// // 6. tell peers to refresh
|
|
316
|
+
// if (notify_peers) {
|
|
317
|
+
// await this.peer.notify_peers()
|
|
318
|
+
// }
|
|
319
|
+
|
|
320
|
+
// // 7. update remote router
|
|
321
|
+
// await this.router.remote()
|
|
322
|
+
|
|
323
|
+
// // 8. update caddy config
|
|
324
|
+
// await this.router.update()
|
|
325
|
+
|
|
326
|
+
// // 9. announce self to the peer network
|
|
327
|
+
// this.peer.announce()
|
|
328
|
+
|
|
329
|
+
//}
|
|
334
330
|
}
|
|
335
331
|
async clearLog(group) {
|
|
336
332
|
let relativePath = path.relative(this.homedir, group)
|
|
@@ -542,25 +538,13 @@ class Kernel {
|
|
|
542
538
|
let home = this.store.get("home")
|
|
543
539
|
|
|
544
540
|
// reset shells if they exist
|
|
545
|
-
console.log("KERNEL INIT")
|
|
546
541
|
if (this.shell) {
|
|
547
|
-
console.log("> shell reset")
|
|
548
542
|
this.shell.reset()
|
|
549
543
|
}
|
|
550
544
|
if (this.peer) {
|
|
551
|
-
console.log("> peer stop")
|
|
552
545
|
this.peer.stop()
|
|
553
546
|
}
|
|
554
547
|
|
|
555
|
-
// // kill all processes just in case
|
|
556
|
-
// await new Promise((resolve, reject) => {
|
|
557
|
-
// console.log("killing child processes for", process.pid)
|
|
558
|
-
// kill(process.pid, {}, 'SIGKILL', () => {
|
|
559
|
-
// console.log("child procs killed for", process.pid)
|
|
560
|
-
// resolve()
|
|
561
|
-
// });
|
|
562
|
-
// })
|
|
563
|
-
|
|
564
548
|
this.info = new Info(this)
|
|
565
549
|
this.pipe = new Pipe(this)
|
|
566
550
|
this.proto = new Proto(this)
|
package/kernel/info.js
CHANGED
|
@@ -40,16 +40,13 @@ class Info {
|
|
|
40
40
|
running(...args) {
|
|
41
41
|
let cwd = path.dirname(this.caller())
|
|
42
42
|
let resolved_path = path.resolve(cwd, ...args)
|
|
43
|
-
console.log("api.running", this.kernel.api.running)
|
|
44
43
|
let running = this.kernel.api.running[resolved_path]
|
|
45
|
-
console.log("info.running", { cwd, resolved_path, running })
|
|
46
44
|
return running ? running : false
|
|
47
45
|
}
|
|
48
46
|
exists(...args) {
|
|
49
47
|
let cwd = path.dirname(this.caller())
|
|
50
48
|
let resolved_path = path.resolve(cwd, ...args)
|
|
51
49
|
let exists = fs.existsSync(resolved_path)
|
|
52
|
-
console.log("info.exists", { cwd, resolved_path, exists })
|
|
53
50
|
return exists ? exists: false
|
|
54
51
|
}
|
|
55
52
|
local(...args) {
|
package/kernel/kv.js
CHANGED
package/kernel/loader.js
CHANGED
|
@@ -6,14 +6,6 @@ const clearModule = require('clear-module');
|
|
|
6
6
|
|
|
7
7
|
class Loader {
|
|
8
8
|
async load(_path) {
|
|
9
|
-
|
|
10
|
-
// let exists = await new Promise(r=>fs.access(_path, fs.constants.F_OK, e => r(!e)))
|
|
11
|
-
// if (!exists) {
|
|
12
|
-
// console.log(`[load] ${_path} does not exist`)
|
|
13
|
-
// return { resolved: null }
|
|
14
|
-
// }
|
|
15
|
-
|
|
16
|
-
|
|
17
9
|
let resolved
|
|
18
10
|
let dirname
|
|
19
11
|
let extension = path.extname(_path)
|
|
@@ -51,21 +43,18 @@ class Loader {
|
|
|
51
43
|
async requireJSON(filepath) {
|
|
52
44
|
let config
|
|
53
45
|
try { config = require(filepath) } catch (e) {
|
|
54
|
-
// console.log(`[did not load] ${filepath}`)
|
|
55
46
|
}
|
|
56
47
|
return config
|
|
57
48
|
}
|
|
58
49
|
async requireJS(filepath) {
|
|
59
50
|
let config
|
|
60
51
|
try { config = require(filepath) } catch (e) {
|
|
61
|
-
// console.log(`[did not load] ${filepath}`)
|
|
62
52
|
}
|
|
63
53
|
try {
|
|
64
54
|
// if the required module is a class, return the instantiated object
|
|
65
55
|
return new config();
|
|
66
56
|
} catch (e) {
|
|
67
57
|
// otherwise return normally
|
|
68
|
-
// console.log(`[did not load] ${filepath}`)
|
|
69
58
|
return config
|
|
70
59
|
}
|
|
71
60
|
}
|
package/kernel/peer.js
CHANGED
|
@@ -10,6 +10,7 @@ class PeerDiscovery {
|
|
|
10
10
|
this.peers = new Set();
|
|
11
11
|
this.host = this._getLocalIPAddress()
|
|
12
12
|
this.default_port = 42000
|
|
13
|
+
this.peers.add(this.host)
|
|
13
14
|
// this.start();
|
|
14
15
|
}
|
|
15
16
|
stop() {
|
|
@@ -19,6 +20,11 @@ class PeerDiscovery {
|
|
|
19
20
|
this.socket.close()
|
|
20
21
|
}
|
|
21
22
|
}
|
|
23
|
+
announce() {
|
|
24
|
+
if (this.socket) {
|
|
25
|
+
this.socket.send(this.message, 0, this.message.length, this.port, '192.168.1.255');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
22
28
|
async start(kernel) {
|
|
23
29
|
let env = await Environment.get(kernel.homedir)
|
|
24
30
|
|
|
@@ -36,12 +42,9 @@ class PeerDiscovery {
|
|
|
36
42
|
|
|
37
43
|
if (this.active) {
|
|
38
44
|
// Listen for incoming pings
|
|
39
|
-
console.log("kernel.peer start")
|
|
40
45
|
this.socket = dgram.createSocket('udp4');
|
|
41
46
|
this.socket.on('message', (msg, rinfo) => {
|
|
42
|
-
// console.log("peer message", { msg, rinfo })
|
|
43
47
|
const ip = rinfo.address;
|
|
44
|
-
// console.log({rinfo})
|
|
45
48
|
if (msg.toString() === this.message.toString() && this._isLocalLAN(ip)) {
|
|
46
49
|
if (!this.peers.has(ip)) {
|
|
47
50
|
console.log(`Discovered peer: ${ip}`);
|
|
@@ -62,16 +65,13 @@ class PeerDiscovery {
|
|
|
62
65
|
|
|
63
66
|
this.socket.setBroadcast(true);
|
|
64
67
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
//
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
//console.log("sent to 255.255.255.255")
|
|
73
|
-
// console.log("sent message")
|
|
74
|
-
}, this.interval);
|
|
68
|
+
this.announce()
|
|
69
|
+
|
|
70
|
+
// // Send broadcast pings every interval
|
|
71
|
+
// this.interval_handle = setInterval(() => {
|
|
72
|
+
// //this.socket.send(this.message, 0, this.message.length, this.port, '255.255.255.255');
|
|
73
|
+
// this.socket.send(this.message, 0, this.message.length, this.port, '192.168.1.255');
|
|
74
|
+
// }, this.interval);
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
77
|
}
|
|
@@ -86,7 +86,6 @@ class PeerDiscovery {
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
async _broadcast(host) {
|
|
89
|
-
// console.log("peer _broadcast", host)
|
|
90
89
|
try {
|
|
91
90
|
let res = await axios.post(`http://${host}:${this.default_port}/pinokio/peer/refresh`, {
|
|
92
91
|
timeout: 2000
|
|
@@ -107,7 +106,7 @@ class PeerDiscovery {
|
|
|
107
106
|
}
|
|
108
107
|
// refresh peer info
|
|
109
108
|
async refresh(peers) {
|
|
110
|
-
if (this.active) {
|
|
109
|
+
// if (this.active) {
|
|
111
110
|
this.refreshing = true
|
|
112
111
|
let refresh_peers
|
|
113
112
|
if (peers) {
|
|
@@ -119,7 +118,6 @@ class PeerDiscovery {
|
|
|
119
118
|
let peer_info = await Promise.all(refresh_peers.map((host) => {
|
|
120
119
|
return this._refresh(host)
|
|
121
120
|
}))
|
|
122
|
-
// console.log({ peer_info })
|
|
123
121
|
for(let i=0; i<peer_info.length; i++) {
|
|
124
122
|
let peer = peer_info[i]
|
|
125
123
|
if (peer) {
|
|
@@ -129,10 +127,9 @@ class PeerDiscovery {
|
|
|
129
127
|
}
|
|
130
128
|
}
|
|
131
129
|
}
|
|
132
|
-
// console.log("REFRESH", this.info)
|
|
133
130
|
this.refreshing = false
|
|
134
131
|
return this.info
|
|
135
|
-
}
|
|
132
|
+
// }
|
|
136
133
|
}
|
|
137
134
|
_isLocalLAN(ip) {
|
|
138
135
|
return ip.startsWith('192.168.');
|
package/kernel/procs.js
CHANGED
|
@@ -105,10 +105,6 @@ class Procs {
|
|
|
105
105
|
return { port, pid , name, fullname, ip }
|
|
106
106
|
}
|
|
107
107
|
}).filter((x) => { return x })
|
|
108
|
-
// list = list.filter((item) => {
|
|
109
|
-
// return !["caddy", "caddy.exe"].includes(item.name.toLowerCase())
|
|
110
|
-
// })
|
|
111
|
-
// console.log("#LIST", { list, size: list.length })
|
|
112
108
|
resolve(list)
|
|
113
109
|
});
|
|
114
110
|
});
|
package/kernel/router/common.js
CHANGED
|
@@ -11,7 +11,6 @@ class Common extends Processor {
|
|
|
11
11
|
"headers": {
|
|
12
12
|
"request": {
|
|
13
13
|
"set": {
|
|
14
|
-
// "Origin": ["http://127.0.0.1:11434"],
|
|
15
14
|
"X-Forwarded-Proto": ["https"],
|
|
16
15
|
"X-Forwarded-Host": ["{http.request.host}"]
|
|
17
16
|
}
|
|
@@ -25,25 +24,7 @@ class Common extends Processor {
|
|
|
25
24
|
}
|
|
26
25
|
}
|
|
27
26
|
}
|
|
28
|
-
}
|
|
29
|
-
//{
|
|
30
|
-
// "handler": "headers",
|
|
31
|
-
// "request": {
|
|
32
|
-
// "set": {
|
|
33
|
-
// "X-Forwarded-Proto": ["https"],
|
|
34
|
-
// "X-Forwarded-Host": ["{http.request.host}"]
|
|
35
|
-
// }
|
|
36
|
-
// },
|
|
37
|
-
// "response": {
|
|
38
|
-
// "set": {
|
|
39
|
-
// "Access-Control-Allow-Origin": ["*"],
|
|
40
|
-
// "Access-Control-Allow-Methods": ["GET, POST, OPTIONS, PUT, DELETE"],
|
|
41
|
-
// "Access-Control-Allow-Headers": ["*"],
|
|
42
|
-
// "Vary": ["Origin"]
|
|
43
|
-
// }
|
|
44
|
-
// }
|
|
45
|
-
//}
|
|
46
|
-
]
|
|
27
|
+
}]
|
|
47
28
|
|
|
48
29
|
// if the dial port has been overridden by router.custom_routers, use that instead
|
|
49
30
|
let parsed_dial = this.parse_ip(dial)
|