pinokiod 3.8.99 → 3.8.101
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/index.js +42 -14
- package/kernel/procs.js +0 -2
- package/kernel/router/connector.js +6 -6
- package/kernel/router/index.js +59 -13
- package/kernel/util.js +0 -1
- package/package.json +1 -1
- package/server/index.js +3 -3
package/kernel/index.js
CHANGED
|
@@ -266,28 +266,56 @@ class Kernel {
|
|
|
266
266
|
if (env && env.PINOKIO_NETWORK_ACTIVE && (env.PINOKIO_NETWORK_ACTIVE==="1" || env.PINOKIO_NETWORK_ACTIVE.toLowerCase()==="true")) {
|
|
267
267
|
active = true
|
|
268
268
|
}
|
|
269
|
-
|
|
270
|
-
console.log("kernel.refresh", { active, notify_peers })
|
|
269
|
+
console.log("kernel.refresh", { active, notify_peers })
|
|
271
270
|
if (active) {
|
|
272
271
|
|
|
272
|
+
// 1. get the process list
|
|
273
|
+
console.log("Step 1: Get process list")
|
|
274
|
+
await this.processes.refresh()
|
|
275
|
+
console.log("Process info", this.processes.info)
|
|
276
|
+
|
|
277
|
+
// 2. refresh peer info to reflect the proc info
|
|
278
|
+
await this.peer.refresh()
|
|
279
|
+
|
|
280
|
+
// 3. set current local host router info
|
|
281
|
+
console.log("Step 3: Set current local host router")
|
|
282
|
+
await this.router.local()
|
|
283
|
+
console.log("router mapping after step 3", this.router.info())
|
|
273
284
|
|
|
274
|
-
|
|
275
|
-
// refresh proc info
|
|
276
|
-
this.processes.refresh(),
|
|
277
|
-
// refresh peer info
|
|
278
|
-
this.peer.refresh()
|
|
279
|
-
])
|
|
280
|
-
console.log("proc info", this.processes.info)
|
|
281
|
-
console.log("peer info", this.peer.info)
|
|
282
|
-
// refresh router info
|
|
283
|
-
await this.router.refresh()
|
|
284
|
-
console.log("router info", this.router.published())
|
|
285
|
+
// 4. refresh peer info to reflect the updated router info
|
|
285
286
|
await this.peer.refresh()
|
|
286
287
|
|
|
288
|
+
// 4. tell peers to refresh
|
|
287
289
|
if (notify_peers) {
|
|
288
|
-
|
|
290
|
+
console.log("Step 4: notify peers to refresh")
|
|
289
291
|
await this.peer.notify_peers()
|
|
290
292
|
}
|
|
293
|
+
|
|
294
|
+
// 4. update remote router
|
|
295
|
+
console.log("Step 5: Set remote routers")
|
|
296
|
+
await this.router.remote()
|
|
297
|
+
console.log("router mapping after step 5", this.router.info())
|
|
298
|
+
|
|
299
|
+
await this.router.update()
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
// await Promise.all([
|
|
303
|
+
// // refresh proc info
|
|
304
|
+
// this.processes.refresh(),
|
|
305
|
+
// // refresh peer info
|
|
306
|
+
// this.peer.refresh()
|
|
307
|
+
// ])
|
|
308
|
+
// console.log("proc info", this.processes.info)
|
|
309
|
+
// console.log("peer info", this.peer.info)
|
|
310
|
+
// // refresh router info
|
|
311
|
+
// await this.router.refresh()
|
|
312
|
+
// console.log("router info", this.router.published())
|
|
313
|
+
//// await this.peer.refresh()
|
|
314
|
+
//
|
|
315
|
+
// if (notify_peers) {
|
|
316
|
+
// // broadcast to peers to refresh
|
|
317
|
+
// await this.peer.notify_peers()
|
|
318
|
+
// }
|
|
291
319
|
}
|
|
292
320
|
}
|
|
293
321
|
async clearLog(group) {
|
package/kernel/procs.js
CHANGED
|
@@ -17,7 +17,6 @@ class Procs {
|
|
|
17
17
|
const lines = stdout.trim().split('\n');
|
|
18
18
|
|
|
19
19
|
lines.forEach(line => {
|
|
20
|
-
console.log({ line })
|
|
21
20
|
if (isWin) {
|
|
22
21
|
// Skip headers
|
|
23
22
|
if (!line.startsWith(' TCP')) return;
|
|
@@ -107,7 +106,6 @@ class Procs {
|
|
|
107
106
|
});
|
|
108
107
|
});
|
|
109
108
|
})
|
|
110
|
-
console.log( { list } )
|
|
111
109
|
console.timeEnd("Get list")
|
|
112
110
|
this.info = list
|
|
113
111
|
}
|
|
@@ -16,12 +16,12 @@ class Connector {
|
|
|
16
16
|
"handler": "reverse_proxy",
|
|
17
17
|
"upstreams": [{ "dial": dial }],
|
|
18
18
|
"headers": {
|
|
19
|
-
"request": {
|
|
20
|
-
"set": {
|
|
21
|
-
"X-Forwarded-Proto": ["https"],
|
|
22
|
-
"X-Forwarded-Host": ["{http.request.host}"]
|
|
23
|
-
}
|
|
24
|
-
},
|
|
19
|
+
// "request": {
|
|
20
|
+
// "set": {
|
|
21
|
+
// "X-Forwarded-Proto": ["https"],
|
|
22
|
+
// "X-Forwarded-Host": ["{http.request.host}"]
|
|
23
|
+
// }
|
|
24
|
+
// },
|
|
25
25
|
"response": {
|
|
26
26
|
"set": {
|
|
27
27
|
"Access-Control-Allow-Origin": ["*"],
|
package/kernel/router/index.js
CHANGED
|
@@ -36,12 +36,8 @@ class Router {
|
|
|
36
36
|
this._mapping[host][dial] = new Set()
|
|
37
37
|
}
|
|
38
38
|
this._mapping[host][dial].add(match)
|
|
39
|
-
console.log(">this._mapping", this._mapping)
|
|
40
39
|
}
|
|
41
40
|
info() {
|
|
42
|
-
console.log("#### this.mapping", this.mapping)
|
|
43
|
-
|
|
44
|
-
|
|
45
41
|
let mapping = {}
|
|
46
42
|
for(let host in this.mapping) {
|
|
47
43
|
let internal_maps = this.mapping[host]
|
|
@@ -53,14 +49,12 @@ class Router {
|
|
|
53
49
|
}
|
|
54
50
|
}
|
|
55
51
|
|
|
56
|
-
console.log("mapping", mapping)
|
|
57
52
|
let json = JSON.stringify(mapping)
|
|
58
53
|
for(let key in this.port_cache) {
|
|
59
54
|
console.log("replacing", key, "with", this.port_cache[key])
|
|
60
55
|
json = json.replaceAll(key, this.port_cache[key])
|
|
61
56
|
}
|
|
62
57
|
let m = JSON.parse(json)
|
|
63
|
-
console.log({ m })
|
|
64
58
|
return m
|
|
65
59
|
// return mapping
|
|
66
60
|
}
|
|
@@ -89,16 +83,18 @@ class Router {
|
|
|
89
83
|
pub[dial] = matches
|
|
90
84
|
}
|
|
91
85
|
}
|
|
86
|
+
console.log({ pub })
|
|
92
87
|
return pub
|
|
93
88
|
}
|
|
94
89
|
async fill() {
|
|
95
90
|
const jsonString = JSON.stringify(this.config)
|
|
96
91
|
// find all PORT_PLACEHOLDER patterns
|
|
97
92
|
const matches = jsonString.match(/:PORT_PLACEHOLDER_[0-9.:]+/g)
|
|
98
|
-
|
|
93
|
+
|
|
99
94
|
|
|
100
95
|
// iterate through them and see if the port already exists
|
|
101
96
|
let count = matches ? new Set(matches).size : 0
|
|
97
|
+
console.log("fill matches", { matches, count })
|
|
102
98
|
/*
|
|
103
99
|
let count = 0
|
|
104
100
|
if (matches) {
|
|
@@ -114,15 +110,14 @@ class Router {
|
|
|
114
110
|
}
|
|
115
111
|
*/
|
|
116
112
|
|
|
117
|
-
|
|
113
|
+
|
|
118
114
|
|
|
119
115
|
let new_config
|
|
120
116
|
|
|
121
117
|
if (count > 0) {
|
|
122
118
|
let ports = await this.kernel.ports(count)
|
|
123
|
-
console.log({ count, ports })
|
|
124
|
-
console.log("PORT_CACHE", this.port_cache)
|
|
125
119
|
let response = Util.fill_object(this.config, /PORT_PLACEHOLDER_.+/, ports, this.port_cache)
|
|
120
|
+
console.log("fill_object response", response)
|
|
126
121
|
this.config = response.result
|
|
127
122
|
let replaced_map = response.replaced_map
|
|
128
123
|
for(let key in replaced_map) {
|
|
@@ -132,7 +127,6 @@ class Router {
|
|
|
132
127
|
let local_share_ip = chunks[0]
|
|
133
128
|
let original_port = chunks[1]
|
|
134
129
|
let local_share_port = replaced_map[key]
|
|
135
|
-
console.log({ local_share_ip, local_share_port })
|
|
136
130
|
if (!this.local_network_mapping[local_share_ip]) {
|
|
137
131
|
this.local_network_mapping[local_share_ip] = {}
|
|
138
132
|
}
|
|
@@ -141,14 +135,66 @@ class Router {
|
|
|
141
135
|
|
|
142
136
|
//let original_port = key.replace("PORT_PLACEHOLDER_", "")
|
|
143
137
|
this.port_mapping[original_port] = replaced_map[key]
|
|
138
|
+
console.log("set port_mapping", { original_port, key, replaced_map })
|
|
144
139
|
}
|
|
145
140
|
this.port_cache = replaced_map
|
|
146
141
|
}
|
|
147
|
-
console.log("port_cache", this.port_cache)
|
|
148
|
-
console.log("port_mapping", this.port_mapping)
|
|
149
142
|
|
|
150
143
|
}
|
|
151
144
|
|
|
145
|
+
|
|
146
|
+
// set local config
|
|
147
|
+
async local() {
|
|
148
|
+
this._mapping = {}
|
|
149
|
+
this.localhost_home_router.handle()
|
|
150
|
+
this.localhost_variable_router.handle(this.kernel.memory.local)
|
|
151
|
+
for(let proc of this.kernel.processes.info) {
|
|
152
|
+
this.localhost_port_router.handle(proc)
|
|
153
|
+
}
|
|
154
|
+
//this.mapping = this._mapping
|
|
155
|
+
|
|
156
|
+
for(let host in this.kernel.peer.info) {
|
|
157
|
+
let peer = this.kernel.peer.info[host]
|
|
158
|
+
if (peer.host === this.kernel.peer.host) {
|
|
159
|
+
this.peer_home_router.handle(peer)
|
|
160
|
+
this.peer_variable_router.handle(peer)
|
|
161
|
+
this.peer_port_router.handle(peer)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
await this.fill()
|
|
165
|
+
this.mapping = this._mapping
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// set remote config
|
|
169
|
+
async remote() {
|
|
170
|
+
for(let host in this.kernel.peer.info) {
|
|
171
|
+
let peer = this.kernel.peer.info[host]
|
|
172
|
+
if (peer.host !== this.kernel.peer.host) {
|
|
173
|
+
this.peer_peer_router.handle(peer)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
//await this.fill()
|
|
177
|
+
this.mapping = this._mapping
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// update caddy config
|
|
181
|
+
async update() {
|
|
182
|
+
console.log("this.config", this.config)
|
|
183
|
+
console.log("this.old_config", this.old_config)
|
|
184
|
+
if (JSON.stringify(this.config) === JSON.stringify(this.old_config)) {
|
|
185
|
+
console.log("config hasn't updated")
|
|
186
|
+
} else {
|
|
187
|
+
console.log("config has updated")
|
|
188
|
+
let response = await axios.post('http://127.0.0.1:2019/load', this.config, {
|
|
189
|
+
headers: { 'Content-Type': 'application/json' }
|
|
190
|
+
}).catch((e) => {
|
|
191
|
+
console.log("EEEEEEEEEEEEE", e.message)
|
|
192
|
+
})
|
|
193
|
+
console.log("Caddy Response", { response })
|
|
194
|
+
this.old_config = this.config
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
152
198
|
async refresh() {
|
|
153
199
|
console.log("router.refresh")
|
|
154
200
|
console.time("router.refresh")
|
package/kernel/util.js
CHANGED
|
@@ -307,7 +307,6 @@ const update_env = async (filepath, changes) => {
|
|
|
307
307
|
await fs.promises.writeFile(filepath, newval)
|
|
308
308
|
};
|
|
309
309
|
function fill_object(obj, pattern, list, cache) {
|
|
310
|
-
console.log("FILL_OBJECT", { obj, pattern, list, cache })
|
|
311
310
|
const map = {};
|
|
312
311
|
const replaced_map = cache || {}
|
|
313
312
|
let index = 0;
|
package/package.json
CHANGED
package/server/index.js
CHANGED
|
@@ -1377,7 +1377,6 @@ class Server {
|
|
|
1377
1377
|
}
|
|
1378
1378
|
})
|
|
1379
1379
|
|
|
1380
|
-
console.log("ITEMS", items)
|
|
1381
1380
|
|
|
1382
1381
|
// if (req.query && req.query.mode === "task") {
|
|
1383
1382
|
// running = running.filter((x) => {
|
|
@@ -2260,6 +2259,7 @@ class Server {
|
|
|
2260
2259
|
|
|
2261
2260
|
|
|
2262
2261
|
await this.kernel.init({ port: this.port})
|
|
2262
|
+
this.kernel.peer.start(this.kernel)
|
|
2263
2263
|
|
|
2264
2264
|
|
|
2265
2265
|
if (needInitHome) {
|
|
@@ -3882,7 +3882,7 @@ class Server {
|
|
|
3882
3882
|
console.log({ peer_info: this.kernel.peer.info })
|
|
3883
3883
|
console.time("check_peer")
|
|
3884
3884
|
let ready = true
|
|
3885
|
-
if (this.kernel.peer.info) {
|
|
3885
|
+
if (this.kernel.peer.info && Object.keys(this.kernel.peer.info).length > 0) {
|
|
3886
3886
|
for(let host in this.kernel.peer.info) {
|
|
3887
3887
|
let info = this.kernel.peer.info[host]
|
|
3888
3888
|
if (info.router && Object.keys(info.router).length > 0) {
|
|
@@ -3996,7 +3996,7 @@ class Server {
|
|
|
3996
3996
|
server: this.listening
|
|
3997
3997
|
});
|
|
3998
3998
|
})
|
|
3999
|
-
this.kernel.peer.start(this.kernel)
|
|
3999
|
+
// this.kernel.peer.start(this.kernel)
|
|
4000
4000
|
|
|
4001
4001
|
|
|
4002
4002
|
}
|