pinokiod 3.8.131 → 3.8.133
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/bin/index.js +2 -0
- package/kernel/index.js +18 -2
- package/kernel/procs.js +11 -8
- package/kernel/router/index.js +57 -29
- package/kernel/router/peer_port_router.js +31 -23
- package/kernel/router/peer_variable_router.js +1 -0
- package/kernel/util.js +2 -0
- package/package.json +1 -1
- package/server/index.js +10 -10
- package/server/views/network.ejs +7 -2
package/kernel/bin/index.js
CHANGED
|
@@ -670,7 +670,9 @@ class Bin {
|
|
|
670
670
|
async install2(req, ondata) {
|
|
671
671
|
let { requirements, install_required, requirements_pending, error } = await this.check_bin()
|
|
672
672
|
req.params = JSON.stringify(requirements)
|
|
673
|
+
console.log(">>>>> 1")
|
|
673
674
|
if (this.install_required) {
|
|
675
|
+
console.log(">>>>> 2")
|
|
674
676
|
let res = await this.install(req, ondata)
|
|
675
677
|
return res
|
|
676
678
|
}
|
package/kernel/index.js
CHANGED
|
@@ -280,7 +280,7 @@ class Kernel {
|
|
|
280
280
|
// 3. set current local host router info
|
|
281
281
|
console.log("Step 3: Set current local host router")
|
|
282
282
|
await this.router.local()
|
|
283
|
-
console.log("router mapping after step 3", this.router.info
|
|
283
|
+
console.log("router mapping after step 3", this.router.info)
|
|
284
284
|
|
|
285
285
|
// 4. refresh peer info to reflect the updated router info
|
|
286
286
|
await this.peer.refresh()
|
|
@@ -294,7 +294,7 @@ class Kernel {
|
|
|
294
294
|
// 4. update remote router
|
|
295
295
|
console.log("Step 5: Set remote routers")
|
|
296
296
|
await this.router.remote()
|
|
297
|
-
console.log("router mapping after step 5", this.router.info
|
|
297
|
+
console.log("router mapping after step 5", this.router.info)
|
|
298
298
|
|
|
299
299
|
await this.router.update()
|
|
300
300
|
|
|
@@ -520,6 +520,10 @@ class Kernel {
|
|
|
520
520
|
// }
|
|
521
521
|
}
|
|
522
522
|
}
|
|
523
|
+
kill(pid) {
|
|
524
|
+
console.log("Kill", pid)
|
|
525
|
+
kill(pid, 'SIGKILL', true)
|
|
526
|
+
}
|
|
523
527
|
async init(options) {
|
|
524
528
|
|
|
525
529
|
let home = this.store.get("home")
|
|
@@ -666,7 +670,9 @@ class Kernel {
|
|
|
666
670
|
if (this.homedir) {
|
|
667
671
|
this.shell.init().then(async () => {
|
|
668
672
|
this.bin.check_bin()
|
|
673
|
+
console.log(">>>> 1")
|
|
669
674
|
if (this.envs) {
|
|
675
|
+
console.log(">>>> 2")
|
|
670
676
|
this.template.update({
|
|
671
677
|
env: this.envs,
|
|
672
678
|
envs: this.envs,
|
|
@@ -715,6 +721,7 @@ class Kernel {
|
|
|
715
721
|
}
|
|
716
722
|
}
|
|
717
723
|
}
|
|
724
|
+
console.log(">>>>>> d")
|
|
718
725
|
clearInterval(interval)
|
|
719
726
|
setTimeout(() => {
|
|
720
727
|
this.launch_complete = true
|
|
@@ -757,6 +764,15 @@ class Kernel {
|
|
|
757
764
|
|
|
758
765
|
|
|
759
766
|
await this.proto.init()
|
|
767
|
+
|
|
768
|
+
// refresh every 5 second
|
|
769
|
+
if (this.refresh_interval) {
|
|
770
|
+
clearInterval(this.refresh_interval)
|
|
771
|
+
}
|
|
772
|
+
this.refresh_interval = setInterval(() => {
|
|
773
|
+
this.refresh()
|
|
774
|
+
}, 5000)
|
|
775
|
+
|
|
760
776
|
}
|
|
761
777
|
|
|
762
778
|
} catch (e) {
|
package/kernel/procs.js
CHANGED
|
@@ -80,7 +80,6 @@ class Procs {
|
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
async refresh() {
|
|
83
|
-
console.time("Get list")
|
|
84
83
|
let map = {}
|
|
85
84
|
let list = await new Promise((resolve, reject) => {
|
|
86
85
|
this.getPortPidList((err, portPidList) => {
|
|
@@ -98,17 +97,21 @@ class Procs {
|
|
|
98
97
|
let list = portPidList.map(({ port, pid, ip }) => {
|
|
99
98
|
const fullname = pidToName[pid] || 'Unknown';
|
|
100
99
|
const name = fullname.split(path.sep).pop()
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
100
|
+
if (["caddy", "caddy.exe"].includes(name)) {
|
|
101
|
+
return null
|
|
102
|
+
} else {
|
|
103
|
+
map["" + pid] = fullname
|
|
104
|
+
return { port, pid , name, fullname, ip }
|
|
105
|
+
}
|
|
106
|
+
}).filter((x) => { return x })
|
|
107
|
+
// list = list.filter((item) => {
|
|
108
|
+
// return !["caddy", "caddy.exe"].includes(item.name.toLowerCase())
|
|
109
|
+
// })
|
|
110
|
+
console.log("#LIST", { list, size: list.length })
|
|
107
111
|
resolve(list)
|
|
108
112
|
});
|
|
109
113
|
});
|
|
110
114
|
})
|
|
111
|
-
console.timeEnd("Get list")
|
|
112
115
|
this.info = list
|
|
113
116
|
this.map = map
|
|
114
117
|
}
|
package/kernel/router/index.js
CHANGED
|
@@ -24,6 +24,7 @@ class Router {
|
|
|
24
24
|
this.default_port = "42000"
|
|
25
25
|
this.default_host = "127.0.0.1"
|
|
26
26
|
|
|
27
|
+
this.info = {}
|
|
27
28
|
this.mapping = {}
|
|
28
29
|
this.port_mapping = {} // 127.0.0.1 => 192.168,..
|
|
29
30
|
this.local_network_mapping = {}
|
|
@@ -37,7 +38,7 @@ class Router {
|
|
|
37
38
|
}
|
|
38
39
|
this._mapping[host][dial].add(match)
|
|
39
40
|
}
|
|
40
|
-
|
|
41
|
+
_info() {
|
|
41
42
|
let mapping = {}
|
|
42
43
|
for(let host in this.mapping) {
|
|
43
44
|
let internal_maps = this.mapping[host]
|
|
@@ -53,16 +54,28 @@ class Router {
|
|
|
53
54
|
|
|
54
55
|
let host_mapping = mapping[this.kernel.peer.host]
|
|
55
56
|
if (host_mapping) {
|
|
56
|
-
let
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
for(let key in host_mapping) {
|
|
58
|
+
for(let cache_key in this.port_cache) {
|
|
59
|
+
if (key.endsWith(cache_key)) {
|
|
60
|
+
let transformed = key.replace(":" + cache_key, '')
|
|
61
|
+
let port = this.port_cache[cache_key]
|
|
62
|
+
host_mapping[transformed + ":" + port] = host_mapping[key]
|
|
63
|
+
console.log("replacing", transformed + ":" + port, "with", host_mapping[key])
|
|
64
|
+
delete host_mapping[key]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
60
67
|
}
|
|
61
|
-
|
|
62
|
-
let
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
mapping[this.kernel.peer.host] = host_mapping
|
|
69
|
+
// let json = JSON.stringify(host_mapping)
|
|
70
|
+
// for(let key in this.port_cache) {
|
|
71
|
+
// console.log("replacing", key, "with", this.port_cache[key])
|
|
72
|
+
// json = json.replaceAll(key, this.port_cache[key])
|
|
73
|
+
// }
|
|
74
|
+
// console.log("json", json)
|
|
75
|
+
// let m = JSON.parse(json)
|
|
76
|
+
//
|
|
77
|
+
// mapping[this.kernel.peer.host] = m
|
|
78
|
+
console.log("AFTER REPLACING", mapping)
|
|
66
79
|
}
|
|
67
80
|
|
|
68
81
|
return mapping
|
|
@@ -91,18 +104,19 @@ class Router {
|
|
|
91
104
|
}
|
|
92
105
|
*/
|
|
93
106
|
published() {
|
|
94
|
-
let info = this.info()
|
|
95
|
-
console.log("published info", info)
|
|
96
107
|
let pub = {}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
let
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
108
|
+
console.log("published info", this.info)
|
|
109
|
+
if (this.info) {
|
|
110
|
+
let routes = this.info[this.kernel.peer.host]
|
|
111
|
+
for(let dial in routes) {
|
|
112
|
+
let matches = routes[dial]
|
|
113
|
+
// current host => the single source of truth
|
|
114
|
+
if (dial.startsWith(this.kernel.peer.host)) {
|
|
115
|
+
pub[dial] = matches
|
|
116
|
+
}
|
|
103
117
|
}
|
|
118
|
+
console.log({ pub })
|
|
104
119
|
}
|
|
105
|
-
console.log({ pub })
|
|
106
120
|
return pub
|
|
107
121
|
}
|
|
108
122
|
async fill() {
|
|
@@ -113,7 +127,7 @@ class Router {
|
|
|
113
127
|
|
|
114
128
|
// iterate through them and see if the port already exists
|
|
115
129
|
let count = matches ? new Set(matches).size : 0
|
|
116
|
-
console.log("fill matches", { matches, count })
|
|
130
|
+
//console.log("fill matches", { matches, count })
|
|
117
131
|
/*
|
|
118
132
|
let count = 0
|
|
119
133
|
if (matches) {
|
|
@@ -130,14 +144,14 @@ class Router {
|
|
|
130
144
|
*/
|
|
131
145
|
|
|
132
146
|
|
|
147
|
+
console.log("^^^^^^^^", { count , matches })
|
|
133
148
|
|
|
134
149
|
let new_config
|
|
135
150
|
|
|
136
151
|
if (count > 0) {
|
|
137
152
|
let ports = await this.kernel.ports(count)
|
|
138
|
-
console.log("Filling with port cache", { port_cache: this.port_cache, config: this.config })
|
|
153
|
+
console.log("Filling with port cache", JSON.stringify({ port_cache: this.port_cache, config: this.config }, null, 2))
|
|
139
154
|
let response = Util.fill_object(this.config, /PORT_PLACEHOLDER_.+/, ports, this.port_cache)
|
|
140
|
-
console.log("fill_object response", response)
|
|
141
155
|
this.config = response.result
|
|
142
156
|
let replaced_map = response.replaced_map
|
|
143
157
|
for(let key in replaced_map) {
|
|
@@ -167,41 +181,55 @@ class Router {
|
|
|
167
181
|
// set local config
|
|
168
182
|
async local() {
|
|
169
183
|
this._mapping = {}
|
|
184
|
+
console.log("Processing local")
|
|
170
185
|
this.localhost_home_router.handle()
|
|
186
|
+
console.log("after 1", this._mapping)
|
|
171
187
|
this.localhost_variable_router.handle(this.kernel.memory.local)
|
|
188
|
+
console.log("after 2", this._mapping)
|
|
172
189
|
for(let proc of this.kernel.processes.info) {
|
|
173
190
|
this.localhost_port_router.handle(proc)
|
|
174
191
|
}
|
|
192
|
+
console.log("after 3", this._mapping)
|
|
175
193
|
//this.mapping = this._mapping
|
|
176
194
|
|
|
195
|
+
|
|
177
196
|
for(let host in this.kernel.peer.info) {
|
|
178
197
|
let peer = this.kernel.peer.info[host]
|
|
179
198
|
if (peer.host === this.kernel.peer.host) {
|
|
199
|
+
console.log("peer.host === kernel.peer.host", peer.host)
|
|
180
200
|
this.peer_home_router.handle(peer)
|
|
201
|
+
console.log("after 4", this._mapping)
|
|
181
202
|
this.peer_variable_router.handle(peer)
|
|
203
|
+
console.log("after 5", this._mapping)
|
|
182
204
|
this.peer_port_router.handle(peer)
|
|
205
|
+
console.log("after 6", this._mapping)
|
|
183
206
|
}
|
|
184
207
|
}
|
|
208
|
+
console.log("after 7", this._mapping)
|
|
185
209
|
await this.fill()
|
|
210
|
+
console.log("after 8", this._mapping)
|
|
186
211
|
this.mapping = this._mapping
|
|
187
212
|
}
|
|
188
213
|
|
|
189
214
|
// set remote config
|
|
190
215
|
async remote() {
|
|
216
|
+
console.log("Before remote", this.kernel.peer.info)
|
|
191
217
|
for(let host in this.kernel.peer.info) {
|
|
192
218
|
let peer = this.kernel.peer.info[host]
|
|
193
219
|
if (peer.host !== this.kernel.peer.host) {
|
|
194
220
|
this.peer_peer_router.handle(peer)
|
|
195
221
|
}
|
|
196
222
|
}
|
|
223
|
+
console.log("After remote", this.kernel.peer.info)
|
|
197
224
|
//await this.fill()
|
|
198
225
|
this.mapping = this._mapping
|
|
226
|
+
this.info = this._info()
|
|
199
227
|
}
|
|
200
228
|
|
|
201
229
|
// update caddy config
|
|
202
230
|
async update() {
|
|
203
|
-
console.log("this.config", this.config)
|
|
204
|
-
console.log("this.old_config", this.old_config)
|
|
231
|
+
// console.log("this.config", JSON.stringify(this.config))
|
|
232
|
+
// console.log("this.old_config", JSON.stringify(this.old_config))
|
|
205
233
|
if (JSON.stringify(this.config) === JSON.stringify(this.old_config)) {
|
|
206
234
|
console.log("config hasn't updated")
|
|
207
235
|
} else {
|
|
@@ -211,16 +239,16 @@ class Router {
|
|
|
211
239
|
}).catch((e) => {
|
|
212
240
|
console.log("EEEEEEEEEEEEE", e.message)
|
|
213
241
|
})
|
|
214
|
-
console.log("Caddy Response", { response })
|
|
242
|
+
// console.log("Caddy Response", { response })
|
|
215
243
|
this.old_config = this.config
|
|
216
244
|
}
|
|
217
245
|
}
|
|
218
246
|
|
|
219
247
|
async refresh() {
|
|
220
|
-
console.log("router.refresh")
|
|
221
|
-
console.time("router.refresh")
|
|
222
|
-
console.log("> procs", this.kernel.processes.info)
|
|
223
|
-
console.log("> peers", this.kernel.peer.info)
|
|
248
|
+
// console.log("router.refresh")
|
|
249
|
+
// console.time("router.refresh")
|
|
250
|
+
// console.log("> procs", this.kernel.processes.info)
|
|
251
|
+
// console.log("> peers", this.kernel.peer.info)
|
|
224
252
|
this._mapping = {}
|
|
225
253
|
// this.port_mapping = {} // 127.0.0.1 => 192.168,..
|
|
226
254
|
// this.local_network_mapping = {}
|
|
@@ -9,35 +9,43 @@ class PeerPortRouter extends Processor {
|
|
|
9
9
|
}
|
|
10
10
|
handle(peer) {
|
|
11
11
|
console.log("PeerPortRouter", peer)
|
|
12
|
-
let https_domains_mapping = this.router.info
|
|
12
|
+
let https_domains_mapping = this.router.info[peer.host]
|
|
13
|
+
console.log({ https_domains_mapping })
|
|
13
14
|
for(let dial in https_domains_mapping) {
|
|
15
|
+
console.log({ dial })
|
|
14
16
|
let parsed_dial = this.parse_ip(dial)
|
|
17
|
+
console.log("Parsed dial", parsed_dial)
|
|
15
18
|
|
|
19
|
+
if (parsed_dial.host !== peer.host) {
|
|
20
|
+
// ONLY connect for 127.0.0.1 or localhost
|
|
21
|
+
// DO NOT connect if it's the actual host => because it will keep creating proxies forever recursively. only need to create proxies for localhost
|
|
22
|
+
let https_domains = https_domains_mapping[dial]
|
|
16
23
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
// 1. if https_domains is made up of one item <port>.localhost,
|
|
25
|
+
// add <port>.<account>.localhost
|
|
26
|
+
// 2. if https_domains is made up of two items <port>.localhost and <port>.<account>.localhost, don't do anything
|
|
27
|
+
for(let https_domain of https_domains) {
|
|
28
|
+
// insert the $account value right before the last part (1234.localhost => 1234.x.localhost)
|
|
29
|
+
let match
|
|
30
|
+
if (https_domain.endsWith(`${peer.name}.localhost`)) {
|
|
31
|
+
match = https_domain
|
|
32
|
+
} else {
|
|
33
|
+
let chunks = https_domain.split(".")
|
|
34
|
+
chunks.splice(chunks.length - 1, 0, peer.name)
|
|
35
|
+
match = chunks.join(".")
|
|
36
|
+
}
|
|
37
|
+
this.connector.handle({
|
|
38
|
+
match,
|
|
39
|
+
connector: {
|
|
40
|
+
host: peer.host,
|
|
41
|
+
port: parsed_dial.port
|
|
42
|
+
},
|
|
43
|
+
dial,
|
|
44
|
+
})
|
|
31
45
|
}
|
|
32
|
-
this.connector.handle({
|
|
33
|
-
match,
|
|
34
|
-
connector: {
|
|
35
|
-
host: peer.host,
|
|
36
|
-
port: parsed_dial.port
|
|
37
|
-
},
|
|
38
|
-
dial,
|
|
39
|
-
})
|
|
40
46
|
}
|
|
47
|
+
|
|
48
|
+
|
|
41
49
|
}
|
|
42
50
|
}
|
|
43
51
|
}
|
|
@@ -20,6 +20,7 @@ class PeerVariableRouter extends Processor {
|
|
|
20
20
|
console.log({ dial, name, has_port: this.has_port(dial), parsed_dial: this.parse_ip(dial) })
|
|
21
21
|
if (this.has_port(dial)) {
|
|
22
22
|
let parsed_dial = this.parse_ip(dial)
|
|
23
|
+
console.log("PeerVariable", { parsed_dial })
|
|
23
24
|
if (key === "url") {
|
|
24
25
|
this.connector.handle({
|
|
25
26
|
match: `${name}.${peer.name}.localhost`.toLowerCase(),
|
package/kernel/util.js
CHANGED
|
@@ -317,10 +317,12 @@ function fill_object(obj, pattern, list, cache) {
|
|
|
317
317
|
if (!(match in map)) {
|
|
318
318
|
if (replaced_map[match]) {
|
|
319
319
|
map[match] = replaced_map[match]
|
|
320
|
+
console.log("filling with cache", { match, replaced: replaced_map[match] })
|
|
320
321
|
} else {
|
|
321
322
|
if (index >= list.length) throw new Error("Not enough items provided");
|
|
322
323
|
map[match] = list[index++];
|
|
323
324
|
replaced_map[match] = map[match]
|
|
325
|
+
console.log("filling with new", { match, replaced: replaced_map[match] })
|
|
324
326
|
}
|
|
325
327
|
}
|
|
326
328
|
return map[match];
|
package/package.json
CHANGED
package/server/index.js
CHANGED
|
@@ -2761,7 +2761,7 @@ class Server {
|
|
|
2761
2761
|
}
|
|
2762
2762
|
|
|
2763
2763
|
res.render("network", {
|
|
2764
|
-
|
|
2764
|
+
current_host: this.kernel.peer.host,
|
|
2765
2765
|
peers,
|
|
2766
2766
|
list,
|
|
2767
2767
|
name: this.kernel.peer.name,
|
|
@@ -3980,15 +3980,15 @@ class Server {
|
|
|
3980
3980
|
// process.exit()
|
|
3981
3981
|
//});
|
|
3982
3982
|
})
|
|
3983
|
-
process.on('exit', () => {
|
|
3984
|
-
console.log("[Exit event]")
|
|
3985
|
-
kill(process.pid, 'SIGKILL', true)
|
|
3986
|
-
//let map = this.kernel.processes.map || {}
|
|
3987
|
-
//kill(process.pid, map, 'SIGKILL', () => {
|
|
3988
|
-
// console.log("child procs killed for", process.pid)
|
|
3989
|
-
// process.exit()
|
|
3990
|
-
//});
|
|
3991
|
-
})
|
|
3983
|
+
// process.on('exit', () => {
|
|
3984
|
+
// console.log("[Exit event]")
|
|
3985
|
+
// kill(process.pid, 'SIGKILL', true)
|
|
3986
|
+
// //let map = this.kernel.processes.map || {}
|
|
3987
|
+
// //kill(process.pid, map, 'SIGKILL', () => {
|
|
3988
|
+
// // console.log("child procs killed for", process.pid)
|
|
3989
|
+
// // process.exit()
|
|
3990
|
+
// //});
|
|
3991
|
+
// })
|
|
3992
3992
|
// process.on('exit', () => {
|
|
3993
3993
|
// console.log("exit Event")
|
|
3994
3994
|
// if (this.kernel && this.kernel.shell) {
|
package/server/views/network.ejs
CHANGED
|
@@ -194,6 +194,11 @@ body.dark .browser-options-row {
|
|
|
194
194
|
padding: 15px 30px;
|
|
195
195
|
box-sizing: border-box;
|
|
196
196
|
}
|
|
197
|
+
.container-row.current {
|
|
198
|
+
}
|
|
199
|
+
.container-row.current .header-label-sub {
|
|
200
|
+
color: royalblue;
|
|
201
|
+
}
|
|
197
202
|
.desc {
|
|
198
203
|
/*
|
|
199
204
|
text-align:center;
|
|
@@ -393,11 +398,11 @@ input:checked + .slider:before {
|
|
|
393
398
|
<div class='container'>
|
|
394
399
|
<% let brands = { win32: "windows", darwin: "apple", linux: "Linux" } %>
|
|
395
400
|
<% list.forEach(({ host, name, platform, processes }, index) => { %>
|
|
396
|
-
<div class='container-row'>
|
|
401
|
+
<div class='container-row <%=current_host === host ? 'current' : ''%>'>
|
|
397
402
|
<!--
|
|
398
403
|
<div class='header-label-sub'><i class="fa-solid fa-microchip"></i> System</div>
|
|
399
404
|
-->
|
|
400
|
-
<% if (
|
|
405
|
+
<% if (current_host === host) { %>
|
|
401
406
|
<div class='header-label-sub'>
|
|
402
407
|
<h1><i class="fa-solid fa-podcast"></i> <%=name%></h1>
|
|
403
408
|
<div class='s'><i class="fa-brands fa-<%=brands[platform]%>"></i> <%=platform%> <%=host%> (this machine)</div>
|