pinokiod 3.8.147 → 3.8.148
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 +8 -9
- package/kernel/loader.js +4 -4
- package/kernel/peer.js +5 -3
- package/kernel/procs.js +1 -1
- package/kernel/router/connector.js +5 -3
- package/kernel/router/index.js +68 -82
- package/kernel/router/localhost_home_router.js +1 -0
- package/kernel/router/localhost_port_router.js +0 -1
- package/kernel/router/localhost_variable_router.js +0 -1
- package/kernel/router/peer_home_router.js +0 -1
- package/kernel/router/peer_peer_router.js +0 -2
- package/kernel/router/peer_port_router.js +0 -4
- package/kernel/router/peer_variable_router.js +0 -4
- package/kernel/util.js +2 -2
- package/package.json +1 -1
- package/server/index.js +95 -58
- package/server/views/network.ejs +47 -22
package/kernel/index.js
CHANGED
|
@@ -204,7 +204,6 @@ class Kernel {
|
|
|
204
204
|
if (this.router.port_mapping && Object.keys(this.router.port_mapping).length > 0) {
|
|
205
205
|
let max_caddy_port = Math.max(...Object.values(this.router.port_mapping))
|
|
206
206
|
let start_port = Math.max(42003, max_caddy_port + 1)
|
|
207
|
-
console.log({ start_port })
|
|
208
207
|
return start_port
|
|
209
208
|
} else {
|
|
210
209
|
return 42003
|
|
@@ -267,35 +266,35 @@ class Kernel {
|
|
|
267
266
|
if (env && env.PINOKIO_NETWORK_ACTIVE && (env.PINOKIO_NETWORK_ACTIVE==="1" || env.PINOKIO_NETWORK_ACTIVE.toLowerCase()==="true")) {
|
|
268
267
|
active = true
|
|
269
268
|
}
|
|
270
|
-
console.log("kernel.refresh", { active, notify_peers })
|
|
269
|
+
// console.log("kernel.refresh", { active, notify_peers })
|
|
271
270
|
if (active) {
|
|
272
271
|
|
|
273
272
|
// 1. get the process list
|
|
274
|
-
console.log("Step 1: Get process list")
|
|
273
|
+
// console.log("Step 1: Get process list")
|
|
275
274
|
await this.processes.refresh()
|
|
276
|
-
console.log("Process info", this.processes.info)
|
|
275
|
+
// console.log("Process info", this.processes.info)
|
|
277
276
|
|
|
278
277
|
// 2. refresh peer info to reflect the proc info
|
|
279
278
|
await this.peer.refresh()
|
|
280
279
|
|
|
281
280
|
// 3. set current local host router info
|
|
282
|
-
console.log("Step 3: Set current local host router")
|
|
281
|
+
// console.log("Step 3: Set current local host router")
|
|
283
282
|
await this.router.local()
|
|
284
|
-
console.log("router mapping after step 3", this.router.info)
|
|
283
|
+
// console.log("router mapping after step 3", this.router.info)
|
|
285
284
|
|
|
286
285
|
// 4. refresh peer info to reflect the updated router info
|
|
287
286
|
await this.peer.refresh()
|
|
288
287
|
|
|
289
288
|
// 4. tell peers to refresh
|
|
290
289
|
if (notify_peers) {
|
|
291
|
-
console.log("Step 4: notify peers to refresh")
|
|
290
|
+
// console.log("Step 4: notify peers to refresh")
|
|
292
291
|
await this.peer.notify_peers()
|
|
293
292
|
}
|
|
294
293
|
|
|
295
294
|
// 4. update remote router
|
|
296
|
-
console.log("Step 5: Set remote routers")
|
|
295
|
+
// console.log("Step 5: Set remote routers")
|
|
297
296
|
await this.router.remote()
|
|
298
|
-
console.log("router mapping after step 5", this.router.info)
|
|
297
|
+
// console.log("router mapping after step 5", this.router.info)
|
|
299
298
|
|
|
300
299
|
await this.router.update()
|
|
301
300
|
|
package/kernel/loader.js
CHANGED
|
@@ -40,7 +40,7 @@ class Loader {
|
|
|
40
40
|
resolved = null
|
|
41
41
|
}
|
|
42
42
|
} catch (e) {
|
|
43
|
-
console.log(`[load
|
|
43
|
+
console.log(`[did not load] ${_path}`)
|
|
44
44
|
resolved = null
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -49,21 +49,21 @@ class Loader {
|
|
|
49
49
|
async requireJSON(filepath) {
|
|
50
50
|
let config
|
|
51
51
|
try { config = require(filepath) } catch (e) {
|
|
52
|
-
console.log(`[load
|
|
52
|
+
console.log(`[did not load] ${filepath}`)
|
|
53
53
|
}
|
|
54
54
|
return config
|
|
55
55
|
}
|
|
56
56
|
async requireJS(filepath) {
|
|
57
57
|
let config
|
|
58
58
|
try { config = require(filepath) } catch (e) {
|
|
59
|
-
console.log(`[load
|
|
59
|
+
console.log(`[did not load] ${filepath}`)
|
|
60
60
|
}
|
|
61
61
|
try {
|
|
62
62
|
// if the required module is a class, return the instantiated object
|
|
63
63
|
return new config();
|
|
64
64
|
} catch (e) {
|
|
65
65
|
// otherwise return normally
|
|
66
|
-
console.log(`[load
|
|
66
|
+
console.log(`[did not load] ${filepath}`)
|
|
67
67
|
return config
|
|
68
68
|
}
|
|
69
69
|
}
|
package/kernel/peer.js
CHANGED
|
@@ -86,7 +86,7 @@ class PeerDiscovery {
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
async _broadcast(host) {
|
|
89
|
-
console.log("peer _broadcast", host)
|
|
89
|
+
// console.log("peer _broadcast", host)
|
|
90
90
|
try {
|
|
91
91
|
let res = await axios.post(`http://${host}:${this.default_port}/pinokio/peer/refresh`, {
|
|
92
92
|
timeout: 2000
|
|
@@ -108,6 +108,7 @@ class PeerDiscovery {
|
|
|
108
108
|
// refresh peer info
|
|
109
109
|
async refresh(peers) {
|
|
110
110
|
if (this.active) {
|
|
111
|
+
this.refreshing = true
|
|
111
112
|
let refresh_peers
|
|
112
113
|
if (peers) {
|
|
113
114
|
refresh_peers = peers
|
|
@@ -118,7 +119,7 @@ class PeerDiscovery {
|
|
|
118
119
|
let peer_info = await Promise.all(refresh_peers.map((host) => {
|
|
119
120
|
return this._refresh(host)
|
|
120
121
|
}))
|
|
121
|
-
console.log({ peer_info })
|
|
122
|
+
// console.log({ peer_info })
|
|
122
123
|
for(let i=0; i<peer_info.length; i++) {
|
|
123
124
|
let peer = peer_info[i]
|
|
124
125
|
if (peer) {
|
|
@@ -128,7 +129,8 @@ class PeerDiscovery {
|
|
|
128
129
|
}
|
|
129
130
|
}
|
|
130
131
|
}
|
|
131
|
-
console.log("REFRESH", this.info)
|
|
132
|
+
// console.log("REFRESH", this.info)
|
|
133
|
+
this.refreshing = false
|
|
132
134
|
return this.info
|
|
133
135
|
}
|
|
134
136
|
}
|
package/kernel/procs.js
CHANGED
|
@@ -107,7 +107,7 @@ class Procs {
|
|
|
107
107
|
// list = list.filter((item) => {
|
|
108
108
|
// return !["caddy", "caddy.exe"].includes(item.name.toLowerCase())
|
|
109
109
|
// })
|
|
110
|
-
console.log("#LIST", { list, size: list.length })
|
|
110
|
+
// console.log("#LIST", { list, size: list.length })
|
|
111
111
|
resolve(list)
|
|
112
112
|
});
|
|
113
113
|
});
|
|
@@ -3,11 +3,12 @@ class Connector {
|
|
|
3
3
|
this.router = router
|
|
4
4
|
}
|
|
5
5
|
handle ({ match, connector, dial, }) {
|
|
6
|
-
console.log("connector.handle", { match, connector, dial })
|
|
6
|
+
// console.log("connector.handle", { match, connector, dial })
|
|
7
7
|
let connector_name = connector.host + ":" + connector.port
|
|
8
8
|
let listener = "0.0.0.0:PORT_PLACEHOLDER_" + connector_name
|
|
9
9
|
let listener_pointer = connector.host + ":PORT_PLACEHOLDER_" + connector_name
|
|
10
|
-
|
|
10
|
+
let port_placeholder = "PORT_PLACEHOLDER_" + connector_name
|
|
11
|
+
// console.log("CONNECTING", { listener, dial, listener_pointer, match })
|
|
11
12
|
if(!this.router.config.apps.http.servers[connector_name]) {
|
|
12
13
|
this.router.config.apps.http.servers[connector_name] = {
|
|
13
14
|
"listen": [listener],
|
|
@@ -103,8 +104,9 @@ class Connector {
|
|
|
103
104
|
// }
|
|
104
105
|
]
|
|
105
106
|
})
|
|
106
|
-
console.log("Router.add", { host: connector.host, dial: listener_pointer, match })
|
|
107
107
|
this.router.add({ host: connector.host, dial: listener_pointer, match })
|
|
108
|
+
// this.router._tree[connector_name] = dial
|
|
109
|
+
// this.router._tree[connector_name] = dial
|
|
108
110
|
}
|
|
109
111
|
}
|
|
110
112
|
module.exports = Connector
|
package/kernel/router/index.js
CHANGED
|
@@ -50,7 +50,6 @@ class Router {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
console.log("BEFORE REPLACING", mapping)
|
|
54
53
|
|
|
55
54
|
let host_mapping = mapping[this.kernel.peer.host]
|
|
56
55
|
if (host_mapping) {
|
|
@@ -60,7 +59,7 @@ class Router {
|
|
|
60
59
|
let transformed = key.replace(":" + cache_key, '')
|
|
61
60
|
let port = this.port_cache[cache_key]
|
|
62
61
|
host_mapping[transformed + ":" + port] = host_mapping[key]
|
|
63
|
-
console.log("replacing", transformed + ":" + port, "with", host_mapping[key])
|
|
62
|
+
// console.log("replacing", transformed + ":" + port, "with", host_mapping[key])
|
|
64
63
|
delete host_mapping[key]
|
|
65
64
|
}
|
|
66
65
|
}
|
|
@@ -75,9 +74,10 @@ class Router {
|
|
|
75
74
|
// let m = JSON.parse(json)
|
|
76
75
|
//
|
|
77
76
|
// mapping[this.kernel.peer.host] = m
|
|
78
|
-
console.log("AFTER REPLACING", mapping)
|
|
77
|
+
// console.log("AFTER REPLACING", mapping)
|
|
79
78
|
}
|
|
80
79
|
|
|
80
|
+
|
|
81
81
|
return mapping
|
|
82
82
|
|
|
83
83
|
// let json = JSON.stringify(mapping)
|
|
@@ -105,17 +105,17 @@ class Router {
|
|
|
105
105
|
*/
|
|
106
106
|
published() {
|
|
107
107
|
let pub = {}
|
|
108
|
-
console.log("published info", this.info)
|
|
108
|
+
// console.log("published info", this.info)
|
|
109
109
|
if (this.info) {
|
|
110
110
|
let routes = this.info[this.kernel.peer.host]
|
|
111
111
|
for(let dial in routes) {
|
|
112
112
|
let matches = routes[dial]
|
|
113
113
|
// current host => the single source of truth
|
|
114
|
-
if (dial.startsWith(this.kernel.peer.host)) {
|
|
114
|
+
// if (dial.startsWith(this.kernel.peer.host)) {
|
|
115
115
|
pub[dial] = matches
|
|
116
|
-
}
|
|
116
|
+
// }
|
|
117
117
|
}
|
|
118
|
-
console.log({ pub })
|
|
118
|
+
// console.log({ pub })
|
|
119
119
|
}
|
|
120
120
|
return pub
|
|
121
121
|
}
|
|
@@ -143,14 +143,10 @@ class Router {
|
|
|
143
143
|
}
|
|
144
144
|
*/
|
|
145
145
|
|
|
146
|
-
|
|
147
|
-
console.log("^^^^^^^^", { count , matches })
|
|
148
|
-
|
|
149
146
|
let new_config
|
|
150
147
|
|
|
151
148
|
if (count > 0) {
|
|
152
149
|
let ports = await this.kernel.ports(count)
|
|
153
|
-
console.log("Filling with port cache", JSON.stringify({ port_cache: this.port_cache, config: this.config }, null, 2))
|
|
154
150
|
let response = Util.fill_object(this.config, /PORT_PLACEHOLDER_.+/, ports, this.port_cache)
|
|
155
151
|
this.config = response.result
|
|
156
152
|
let replaced_map = response.replaced_map
|
|
@@ -170,7 +166,7 @@ class Router {
|
|
|
170
166
|
|
|
171
167
|
//let original_port = key.replace("PORT_PLACEHOLDER_", "")
|
|
172
168
|
this.port_mapping[original_port] = replaced_map[key]
|
|
173
|
-
console.log("set port_mapping", { original_port, key, replaced_map })
|
|
169
|
+
// console.log("set port_mapping", { original_port, key, replaced_map })
|
|
174
170
|
}
|
|
175
171
|
this.port_cache = replaced_map
|
|
176
172
|
}
|
|
@@ -181,59 +177,49 @@ class Router {
|
|
|
181
177
|
// set local config
|
|
182
178
|
async local() {
|
|
183
179
|
this._mapping = {}
|
|
184
|
-
|
|
180
|
+
// this._tree = {}
|
|
185
181
|
this.localhost_home_router.handle()
|
|
186
|
-
console.log("after 1", this._mapping)
|
|
187
182
|
this.localhost_variable_router.handle(this.kernel.memory.local)
|
|
188
|
-
console.log("after 2", this._mapping)
|
|
189
183
|
for(let proc of this.kernel.processes.info) {
|
|
190
184
|
this.localhost_port_router.handle(proc)
|
|
191
185
|
}
|
|
192
|
-
console.log("after 3", this._mapping)
|
|
193
186
|
//this.mapping = this._mapping
|
|
194
187
|
|
|
195
188
|
|
|
196
189
|
for(let host in this.kernel.peer.info) {
|
|
197
190
|
let peer = this.kernel.peer.info[host]
|
|
198
191
|
if (peer.host === this.kernel.peer.host) {
|
|
199
|
-
console.log("peer.host === kernel.peer.host", peer.host)
|
|
200
192
|
this.peer_home_router.handle(peer)
|
|
201
|
-
console.log("after 4", this._mapping)
|
|
202
193
|
this.peer_variable_router.handle(peer)
|
|
203
|
-
console.log("after 5", this._mapping)
|
|
204
194
|
this.peer_port_router.handle(peer)
|
|
205
|
-
console.log("after 6", this._mapping)
|
|
206
195
|
}
|
|
207
196
|
}
|
|
208
|
-
console.log("after 7", this._mapping)
|
|
209
197
|
await this.fill()
|
|
210
|
-
console.log("after 8", this._mapping)
|
|
211
198
|
this.mapping = this._mapping
|
|
199
|
+
// this.tree = this._tree
|
|
212
200
|
}
|
|
213
201
|
|
|
214
202
|
// set remote config
|
|
215
203
|
async remote() {
|
|
216
|
-
console.log("Before remote", this.kernel.peer.info)
|
|
217
204
|
for(let host in this.kernel.peer.info) {
|
|
218
205
|
let peer = this.kernel.peer.info[host]
|
|
219
206
|
if (peer.host !== this.kernel.peer.host) {
|
|
220
207
|
this.peer_peer_router.handle(peer)
|
|
221
208
|
}
|
|
222
209
|
}
|
|
223
|
-
console.log("After remote", this.kernel.peer.info)
|
|
224
210
|
//await this.fill()
|
|
225
211
|
this.mapping = this._mapping
|
|
212
|
+
// this.tree = this._tree
|
|
226
213
|
this.info = this._info()
|
|
214
|
+
// console.log("TREE", JSON.stringify(this.tree, null, 2))
|
|
227
215
|
}
|
|
228
216
|
|
|
229
217
|
// update caddy config
|
|
230
218
|
async update() {
|
|
231
|
-
// console.log("this.config", JSON.stringify(this.config))
|
|
232
|
-
// console.log("this.old_config", JSON.stringify(this.old_config))
|
|
233
219
|
if (JSON.stringify(this.config) === JSON.stringify(this.old_config)) {
|
|
234
|
-
console.log("config hasn't updated")
|
|
220
|
+
// console.log("config hasn't updated")
|
|
235
221
|
} else {
|
|
236
|
-
console.log("config has updated")
|
|
222
|
+
console.log("caddy config has updated")
|
|
237
223
|
let response = await axios.post('http://127.0.0.1:2019/load', this.config, {
|
|
238
224
|
headers: { 'Content-Type': 'application/json' }
|
|
239
225
|
}).catch((e) => {
|
|
@@ -244,59 +230,59 @@ class Router {
|
|
|
244
230
|
}
|
|
245
231
|
}
|
|
246
232
|
|
|
247
|
-
async refresh() {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
this._mapping = {}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
let old_config = this.config
|
|
257
|
-
|
|
258
|
-
// 1. Localhost handling
|
|
259
|
-
this.localhost_home_router.handle()
|
|
260
|
-
this.localhost_variable_router.handle(this.kernel.memory.local)
|
|
261
|
-
for(let proc of this.kernel.processes.info) {
|
|
262
|
-
this.localhost_port_router.handle(proc)
|
|
263
|
-
}
|
|
264
|
-
this.mapping = this._mapping
|
|
265
|
-
|
|
266
|
-
// 2. Peers handling
|
|
267
|
-
for(let host in this.kernel.peer.info) {
|
|
268
|
-
let peer = this.kernel.peer.info[host]
|
|
269
|
-
if (peer.host === this.kernel.peer.host) {
|
|
270
|
-
this.peer_home_router.handle(peer)
|
|
271
|
-
this.peer_variable_router.handle(peer)
|
|
272
|
-
this.peer_port_router.handle(peer)
|
|
273
|
-
} else {
|
|
274
|
-
this.peer_peer_router.handle(peer)
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
// replace :PORT_PLACEHOLDER with available ports
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
await this.fill()
|
|
281
|
-
this.mapping = this._mapping
|
|
282
|
-
console.timeEnd("router.refresh")
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
// compare old config with new config
|
|
286
|
-
// if it hasn't changed, don't do anything
|
|
287
|
-
// if it has changed, refresh
|
|
288
|
-
|
|
289
|
-
if (JSON.stringify(this.config) === JSON.stringify(old_config)) {
|
|
290
|
-
console.log("config hasn't updated")
|
|
291
|
-
} else {
|
|
292
|
-
console.log("config has updated")
|
|
293
|
-
let response = await axios.post('http://127.0.0.1:2019/load', this.config, {
|
|
294
|
-
headers: { 'Content-Type': 'application/json' }
|
|
295
|
-
}).catch((e) => {
|
|
296
|
-
console.log("EEEEEEEEEEEEE", e.message)
|
|
297
|
-
})
|
|
298
|
-
console.log("Caddy Response", { response })
|
|
299
|
-
}
|
|
300
|
-
}
|
|
233
|
+
// async refresh() {
|
|
234
|
+
//// console.log("router.refresh")
|
|
235
|
+
//// console.time("router.refresh")
|
|
236
|
+
//// console.log("> procs", this.kernel.processes.info)
|
|
237
|
+
//// console.log("> peers", this.kernel.peer.info)
|
|
238
|
+
// this._mapping = {}
|
|
239
|
+
//// this.port_mapping = {} // 127.0.0.1 => 192.168,..
|
|
240
|
+
//// this.local_network_mapping = {}
|
|
241
|
+
//
|
|
242
|
+
// let old_config = this.config
|
|
243
|
+
//
|
|
244
|
+
// // 1. Localhost handling
|
|
245
|
+
// this.localhost_home_router.handle()
|
|
246
|
+
// this.localhost_variable_router.handle(this.kernel.memory.local)
|
|
247
|
+
// for(let proc of this.kernel.processes.info) {
|
|
248
|
+
// this.localhost_port_router.handle(proc)
|
|
249
|
+
// }
|
|
250
|
+
// this.mapping = this._mapping
|
|
251
|
+
//
|
|
252
|
+
// // 2. Peers handling
|
|
253
|
+
// for(let host in this.kernel.peer.info) {
|
|
254
|
+
// let peer = this.kernel.peer.info[host]
|
|
255
|
+
// if (peer.host === this.kernel.peer.host) {
|
|
256
|
+
// this.peer_home_router.handle(peer)
|
|
257
|
+
// this.peer_variable_router.handle(peer)
|
|
258
|
+
// this.peer_port_router.handle(peer)
|
|
259
|
+
// } else {
|
|
260
|
+
// this.peer_peer_router.handle(peer)
|
|
261
|
+
// }
|
|
262
|
+
// }
|
|
263
|
+
// // replace :PORT_PLACEHOLDER with available ports
|
|
264
|
+
//
|
|
265
|
+
//
|
|
266
|
+
// await this.fill()
|
|
267
|
+
// this.mapping = this._mapping
|
|
268
|
+
// console.timeEnd("router.refresh")
|
|
269
|
+
//
|
|
270
|
+
//
|
|
271
|
+
// // compare old config with new config
|
|
272
|
+
// // if it hasn't changed, don't do anything
|
|
273
|
+
// // if it has changed, refresh
|
|
274
|
+
//
|
|
275
|
+
// if (JSON.stringify(this.config) === JSON.stringify(old_config)) {
|
|
276
|
+
// console.log("config hasn't updated")
|
|
277
|
+
// } else {
|
|
278
|
+
// console.log("config has updated")
|
|
279
|
+
// let response = await axios.post('http://127.0.0.1:2019/load', this.config, {
|
|
280
|
+
// headers: { 'Content-Type': 'application/json' }
|
|
281
|
+
// }).catch((e) => {
|
|
282
|
+
// console.log("EEEEEEEEEEEEE", e.message)
|
|
283
|
+
// })
|
|
284
|
+
// console.log("Caddy Response", { response })
|
|
285
|
+
// }
|
|
286
|
+
// }
|
|
301
287
|
}
|
|
302
288
|
module.exports = Router
|
|
@@ -3,6 +3,7 @@ class LocalhostHomeRouter {
|
|
|
3
3
|
this.router = router
|
|
4
4
|
}
|
|
5
5
|
handle () {
|
|
6
|
+
this.router.add({ host: this.router.kernel.peer.host, dial: this.router.default_host + ":" + this.router.default_port, match: this.router.default_match })
|
|
6
7
|
this.router.config = {
|
|
7
8
|
"apps": {
|
|
8
9
|
"http": {
|
|
@@ -8,7 +8,6 @@ class LocalhostVariableRouter extends Processor {
|
|
|
8
8
|
this.common = new Common(router)
|
|
9
9
|
}
|
|
10
10
|
handle (local) {
|
|
11
|
-
console.log("LocalhostVariableRouter", local)
|
|
12
11
|
for(let script_path in local) {
|
|
13
12
|
let local_variables_for_script = local[script_path]
|
|
14
13
|
for(let key in local_variables_for_script) {
|
|
@@ -5,7 +5,6 @@ class PeerHomeRouter {
|
|
|
5
5
|
this.common = new Common(router)
|
|
6
6
|
}
|
|
7
7
|
handle(peer) {
|
|
8
|
-
console.log("PeerHomeRouter", peer)
|
|
9
8
|
this.common.handle({
|
|
10
9
|
match: `${this.router.default_prefix}.${peer.name}.${this.router.default_suffix}`,
|
|
11
10
|
dial: `${peer.host}:${this.router.default_port}`,
|
|
@@ -5,7 +5,6 @@ class PeerPeerRouter {
|
|
|
5
5
|
this.common = new Common(router)
|
|
6
6
|
}
|
|
7
7
|
handle(peer) {
|
|
8
|
-
console.log("PeerPeerRouter", peer)
|
|
9
8
|
for(let dial in peer.router) {
|
|
10
9
|
let matches = peer.router[dial]
|
|
11
10
|
let exposed_matches = matches.filter((m) => {
|
|
@@ -15,7 +14,6 @@ class PeerPeerRouter {
|
|
|
15
14
|
let port = chunks[chunks.length-1]
|
|
16
15
|
let exposed_dial = `${peer.host}:${port}` // exposed_dial :- 192.168...
|
|
17
16
|
for(let match of exposed_matches) {
|
|
18
|
-
console.log("common.handle", { match, exposed_dial, host: peer.host })
|
|
19
17
|
this.common.handle({
|
|
20
18
|
match,
|
|
21
19
|
dial: exposed_dial,
|
|
@@ -8,13 +8,9 @@ class PeerPortRouter extends Processor {
|
|
|
8
8
|
this.connector = new Connector(router)
|
|
9
9
|
}
|
|
10
10
|
handle(peer) {
|
|
11
|
-
console.log("PeerPortRouter", peer)
|
|
12
11
|
let https_domains_mapping = this.router.info[peer.host]
|
|
13
|
-
console.log({ https_domains_mapping })
|
|
14
12
|
for(let dial in https_domains_mapping) {
|
|
15
|
-
console.log({ dial })
|
|
16
13
|
let parsed_dial = this.parse_ip(dial)
|
|
17
|
-
console.log("Parsed dial", parsed_dial)
|
|
18
14
|
|
|
19
15
|
if (parsed_dial.host !== peer.host) {
|
|
20
16
|
// ONLY connect for 127.0.0.1 or localhost
|
|
@@ -8,19 +8,15 @@ class PeerVariableRouter extends Processor {
|
|
|
8
8
|
this.connector = new Connector(router)
|
|
9
9
|
}
|
|
10
10
|
handle(peer) {
|
|
11
|
-
console.log("PeerVariableRouter", JSON.stringify(peer, null, 2))
|
|
12
11
|
for(let script_path in peer.memory.local) {
|
|
13
12
|
let local_variables = peer.memory.local[script_path]
|
|
14
13
|
for(let key in local_variables) {
|
|
15
14
|
let val = local_variables[key]
|
|
16
|
-
console.log({ key, val })
|
|
17
15
|
if (val.startsWith("http")) {
|
|
18
16
|
let dial = val.replace(/https?:\/\//, '')
|
|
19
17
|
let name = this.api_name(peer.platform, peer.home, script_path)
|
|
20
|
-
console.log({ dial, name, has_port: this.has_port(dial), parsed_dial: this.parse_ip(dial) })
|
|
21
18
|
if (this.has_port(dial)) {
|
|
22
19
|
let parsed_dial = this.parse_ip(dial)
|
|
23
|
-
console.log("PeerVariable", { parsed_dial })
|
|
24
20
|
if (key === "url") {
|
|
25
21
|
this.connector.handle({
|
|
26
22
|
match: `${name}.${peer.name}.localhost`.toLowerCase(),
|
package/kernel/util.js
CHANGED
|
@@ -317,12 +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
|
+
// console.log("filling with cache", { match, replaced: replaced_map[match] })
|
|
321
321
|
} else {
|
|
322
322
|
if (index >= list.length) throw new Error("Not enough items provided");
|
|
323
323
|
map[match] = list[index++];
|
|
324
324
|
replaced_map[match] = map[match]
|
|
325
|
-
console.log("filling with new", { match, replaced: replaced_map[match] })
|
|
325
|
+
// console.log("filling with new", { match, replaced: replaced_map[match] })
|
|
326
326
|
}
|
|
327
327
|
}
|
|
328
328
|
return map[match];
|
package/package.json
CHANGED
package/server/index.js
CHANGED
|
@@ -1933,6 +1933,85 @@ class Server {
|
|
|
1933
1933
|
}
|
|
1934
1934
|
console.log("FINISHED MV")
|
|
1935
1935
|
}
|
|
1936
|
+
getPeerInfo() {
|
|
1937
|
+
let list = []
|
|
1938
|
+
let peers_info = {}
|
|
1939
|
+
if (this.kernel.peer.info) {
|
|
1940
|
+
peers_info = this.kernel.peer.info
|
|
1941
|
+
let remote_peers = Object.keys(this.kernel.peer.info).filter(x => x !== this.kernel.peer.host)
|
|
1942
|
+
let nodes = [this.kernel.peer.host].concat(remote_peers)
|
|
1943
|
+
for(let host of nodes) {
|
|
1944
|
+
let processes = []
|
|
1945
|
+
try {
|
|
1946
|
+
let procs = this.kernel.peer.info[host].proc
|
|
1947
|
+
let router = this.kernel.peer.info[host].router
|
|
1948
|
+
let port_mapping = this.kernel.peer.info[host].port_mapping
|
|
1949
|
+
for(let proc of procs) {
|
|
1950
|
+
let chunks = proc.ip.split(":")
|
|
1951
|
+
let internal_port = chunks[chunks.length-1]
|
|
1952
|
+
let internal_host = chunks.slice(0, chunks.length-1).join(":")
|
|
1953
|
+
let external_port = port_mapping[internal_port]
|
|
1954
|
+
|
|
1955
|
+
let merged
|
|
1956
|
+
let external_ip
|
|
1957
|
+
if (external_port) {
|
|
1958
|
+
external_ip = `${host}:${external_port}`
|
|
1959
|
+
// merged = Array.from(new Set(router[external_ip].concat(router[proc.ip])))
|
|
1960
|
+
} else {
|
|
1961
|
+
// merged = router[proc.ip]
|
|
1962
|
+
}
|
|
1963
|
+
processes.push({
|
|
1964
|
+
external_router: router[external_ip] || [],
|
|
1965
|
+
internal_router: router[proc.ip] || [],
|
|
1966
|
+
//router: merged || [],
|
|
1967
|
+
external_ip,
|
|
1968
|
+
external_port: parseInt(external_port),
|
|
1969
|
+
internal_port: parseInt(internal_port),
|
|
1970
|
+
...proc
|
|
1971
|
+
})
|
|
1972
|
+
//if (external_port) {
|
|
1973
|
+
// let external_ip = `${host}:${external_port}`
|
|
1974
|
+
// // merge router
|
|
1975
|
+
// let merged = Array.from(new Set(router[external_ip].concat(router[proc.ip))
|
|
1976
|
+
// processes.push({
|
|
1977
|
+
// //proxy: this.kernel.caddy.mapping[item.ip] || [],
|
|
1978
|
+
// //router: router[external_ip] || [],
|
|
1979
|
+
// router: merged || [],
|
|
1980
|
+
// external_ip,
|
|
1981
|
+
// external_port: parseInt(external_port),
|
|
1982
|
+
// internal_port: parseInt(internal_port),
|
|
1983
|
+
// ...proc
|
|
1984
|
+
// })
|
|
1985
|
+
//} else {
|
|
1986
|
+
// processes.push({
|
|
1987
|
+
// router: [],
|
|
1988
|
+
// external_port: parseInt(external_port),
|
|
1989
|
+
// internal_port: parseInt(internal_port),
|
|
1990
|
+
// ...proc
|
|
1991
|
+
// })
|
|
1992
|
+
//}
|
|
1993
|
+
}
|
|
1994
|
+
// merge processes
|
|
1995
|
+
// 1.
|
|
1996
|
+
processes.sort((a, b) => {
|
|
1997
|
+
return b.external_port-a.external_port
|
|
1998
|
+
})
|
|
1999
|
+
list.push({
|
|
2000
|
+
host,
|
|
2001
|
+
name: this.kernel.peer.info[host].name,
|
|
2002
|
+
platform: this.kernel.peer.info[host].platform,
|
|
2003
|
+
processes
|
|
2004
|
+
})
|
|
2005
|
+
} catch (e) {
|
|
2006
|
+
console.log(">>e", e)
|
|
2007
|
+
console.log({ host, info: this.kernel.peer.info })
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
// console.log("Loaded yet?", nodes.length, Object.keys(peers_info).length, nodes.length === Object.keys(peers_info).length)
|
|
2011
|
+
}
|
|
2012
|
+
return list
|
|
2013
|
+
}
|
|
2014
|
+
|
|
1936
2015
|
|
|
1937
2016
|
async syncConfig() {
|
|
1938
2017
|
|
|
@@ -2625,67 +2704,26 @@ class Server {
|
|
|
2625
2704
|
id: req.params.id
|
|
2626
2705
|
})
|
|
2627
2706
|
}))
|
|
2628
|
-
this.app.get("/
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
let nodes = [this.kernel.peer.host].concat(remote_peers)
|
|
2639
|
-
for(let host of nodes) {
|
|
2640
|
-
let processes = []
|
|
2641
|
-
try {
|
|
2642
|
-
let procs = this.kernel.peer.info[host].proc
|
|
2643
|
-
let router = this.kernel.peer.info[host].router
|
|
2644
|
-
console.log({ router })
|
|
2645
|
-
let port_mapping = this.kernel.peer.info[host].port_mapping
|
|
2646
|
-
for(let proc of procs) {
|
|
2647
|
-
let internal_port = proc.ip.split(":")[1]
|
|
2648
|
-
let external_port = port_mapping[internal_port]
|
|
2649
|
-
if (external_port) {
|
|
2650
|
-
let external_ip = `${host}:${external_port}`
|
|
2651
|
-
console.log({ internal_port, external_port, external_ip })
|
|
2652
|
-
processes.push({
|
|
2653
|
-
//proxy: this.kernel.caddy.mapping[item.ip] || [],
|
|
2654
|
-
router: router[external_ip] || [],
|
|
2655
|
-
external_ip,
|
|
2656
|
-
external_port: parseInt(external_port),
|
|
2657
|
-
internal_port: parseInt(internal_port),
|
|
2658
|
-
...proc
|
|
2659
|
-
})
|
|
2660
|
-
} else {
|
|
2661
|
-
processes.push({
|
|
2662
|
-
router: [],
|
|
2663
|
-
external_port: parseInt(external_port),
|
|
2664
|
-
internal_port: parseInt(internal_port),
|
|
2665
|
-
...proc
|
|
2666
|
-
})
|
|
2667
|
-
}
|
|
2668
|
-
}
|
|
2669
|
-
processes.sort((a, b) => {
|
|
2670
|
-
return b.external_port-a.external_port
|
|
2671
|
-
})
|
|
2672
|
-
list.push({
|
|
2673
|
-
host,
|
|
2674
|
-
name: this.kernel.peer.info[host].name,
|
|
2675
|
-
platform: this.kernel.peer.info[host].platform,
|
|
2676
|
-
processes
|
|
2677
|
-
})
|
|
2678
|
-
} catch (e) {
|
|
2679
|
-
console.log(">>e", e)
|
|
2680
|
-
console.log({ host, info: this.kernel.peer.info })
|
|
2681
|
-
}
|
|
2707
|
+
this.app.get("/peer_check", ex(async (req, res) => {
|
|
2708
|
+
if (this.kernel.peer.refreshing) {
|
|
2709
|
+
res.json({ updated: false })
|
|
2710
|
+
} else {
|
|
2711
|
+
let list = this.getPeerInfo()
|
|
2712
|
+
if (JSON.stringify(this.last_list) !== JSON.stringify(list)) {
|
|
2713
|
+
this.last_list = list
|
|
2714
|
+
res.json({ updated: true })
|
|
2715
|
+
} else {
|
|
2716
|
+
res.json({ updated: false })
|
|
2682
2717
|
}
|
|
2683
2718
|
}
|
|
2684
|
-
|
|
2719
|
+
}))
|
|
2720
|
+
this.app.get("/network", ex(async (req, res) => {
|
|
2721
|
+
let list = this.getPeerInfo()
|
|
2722
|
+
|
|
2685
2723
|
|
|
2686
2724
|
let peers = []
|
|
2687
|
-
for(let host in
|
|
2688
|
-
let peer_info =
|
|
2725
|
+
for(let host in this.kernel.peer.info) {
|
|
2726
|
+
let peer_info = this.kernel.peer.info[host]
|
|
2689
2727
|
peers.push({
|
|
2690
2728
|
host,
|
|
2691
2729
|
name: peer_info.name,
|
|
@@ -3308,7 +3346,6 @@ class Server {
|
|
|
3308
3346
|
res.json({ success: true })
|
|
3309
3347
|
}))
|
|
3310
3348
|
this.app.get("/pinokio/peer", ex(async (req, res) => {
|
|
3311
|
-
console.log("/pinokio/peer", { proc: this.kernel.processes.info })
|
|
3312
3349
|
// await this.kernel.refresh()
|
|
3313
3350
|
res.json({
|
|
3314
3351
|
home: this.kernel.homedir,
|
package/server/views/network.ejs
CHANGED
|
@@ -136,6 +136,12 @@ body.dark .browser-options-row {
|
|
|
136
136
|
color: royalblue;
|
|
137
137
|
text-decoration: none;
|
|
138
138
|
}
|
|
139
|
+
a.ln[href^=https] {
|
|
140
|
+
color: #56ad00;
|
|
141
|
+
}
|
|
142
|
+
a.ln:hover {
|
|
143
|
+
color: red !important;
|
|
144
|
+
}
|
|
139
145
|
.line.align-top h3 {
|
|
140
146
|
/*
|
|
141
147
|
align-items: flex-start;
|
|
@@ -167,9 +173,8 @@ body.dark .browser-options-row {
|
|
|
167
173
|
font-weight: bold;
|
|
168
174
|
}
|
|
169
175
|
.header-label-sub {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
padding: 10px;
|
|
176
|
+
font-size: 16px;
|
|
177
|
+
padding: 10px 0;
|
|
173
178
|
border-bottom: 1px solid rgba(0,0,0,0.1);
|
|
174
179
|
}
|
|
175
180
|
.header-label-sub .s {
|
|
@@ -207,7 +212,6 @@ body.dark .browser-options-row {
|
|
|
207
212
|
}
|
|
208
213
|
.container-row table {
|
|
209
214
|
width: 100%;
|
|
210
|
-
margin-top: 20px;
|
|
211
215
|
}
|
|
212
216
|
table a {
|
|
213
217
|
text-decoration: none;
|
|
@@ -216,19 +220,26 @@ table a {
|
|
|
216
220
|
td:first-child, th:first-child {
|
|
217
221
|
max-width: 100px;
|
|
218
222
|
}
|
|
219
|
-
.container-row th {
|
|
220
|
-
text-align: left;
|
|
223
|
+
.container-row th h2 {
|
|
221
224
|
font-size: 18px;
|
|
222
|
-
|
|
225
|
+
margin: 0;
|
|
223
226
|
text-transform: uppercase;
|
|
224
227
|
}
|
|
228
|
+
.container-row th {
|
|
229
|
+
border-bottom: 1px solid rgba(0,0,0,0.05);
|
|
230
|
+
text-align: left;
|
|
231
|
+
padding: 20px 0;
|
|
232
|
+
font-weight: normal;
|
|
233
|
+
font-size: 12px;
|
|
234
|
+
margin-bottom: 10px;
|
|
235
|
+
}
|
|
225
236
|
.container-row td.title {
|
|
226
237
|
overflow-wrap: break-word;
|
|
227
238
|
}
|
|
228
239
|
.container-row td {
|
|
229
240
|
vertical-align: top;
|
|
230
241
|
font-size: 14px;
|
|
231
|
-
padding: 2px;
|
|
242
|
+
padding: 5px 2px;
|
|
232
243
|
}
|
|
233
244
|
|
|
234
245
|
.config {
|
|
@@ -404,41 +415,46 @@ input:checked + .slider:before {
|
|
|
404
415
|
-->
|
|
405
416
|
<% if (current_host === host) { %>
|
|
406
417
|
<div class='header-label-sub'>
|
|
407
|
-
<h1><i class="fa-solid fa-podcast"></i> <%=name
|
|
408
|
-
<div class='s'><i class="fa-brands fa-<%=brands[platform]%>"></i> <%=platform%> <%=host
|
|
418
|
+
<h1><i class="fa-solid fa-podcast"></i> <%=name%> (localhost)</h1>
|
|
419
|
+
<div class='s'><i class="fa-brands fa-<%=brands[platform]%>"></i> <%=platform%> <%=host%></div>
|
|
409
420
|
</div>
|
|
410
421
|
<% } else { %>
|
|
411
422
|
<div class='header-label-sub'>
|
|
412
423
|
<h1><i class="fa-solid fa-wifi"></i> <%=name%></h1>
|
|
413
|
-
<div class='s'><i class="fa-brands fa-<%=brands[platform]%>"></i> <%=platform%> <%=host
|
|
424
|
+
<div class='s'><i class="fa-brands fa-<%=brands[platform]%>"></i> <%=platform%> <%=host%></div>
|
|
414
425
|
</div>
|
|
415
426
|
<% } %>
|
|
416
427
|
<table>
|
|
417
428
|
<tr>
|
|
418
|
-
<th>Server</th>
|
|
419
|
-
<th>
|
|
420
|
-
<th>
|
|
429
|
+
<th><h2>Server</h2><div>Running apps</div></th>
|
|
430
|
+
<th><h2>Shared</h2><div>Use on any machine on the network</div></th>
|
|
431
|
+
<th><h2>Local</h2><div>Use on this machine</div></th>
|
|
421
432
|
</tr>
|
|
422
433
|
<% processes.forEach((item) => { %>
|
|
423
434
|
<tr>
|
|
424
435
|
<td class='title'><%=item.name%></td>
|
|
425
436
|
<td>
|
|
426
|
-
<% item.
|
|
437
|
+
<% item.external_router.forEach((domain) => { %>
|
|
427
438
|
<div>
|
|
428
|
-
<a target="_blank" href="https://<%=domain%>">https://<%=domain%></a>
|
|
439
|
+
<a class='ln' target="_blank" href="https://<%=domain%>">https://<%=domain%></a>
|
|
429
440
|
</div>
|
|
430
441
|
<% }) %>
|
|
431
|
-
</td>
|
|
432
|
-
<td>
|
|
433
|
-
<div>
|
|
434
|
-
<a target="_blank" href="http://localhost:<%=item.port%>">http://localhost:<%=item.port%></a>
|
|
435
|
-
</div>
|
|
436
442
|
<% if (item.external_ip) { %>
|
|
437
443
|
<div>
|
|
438
|
-
<a target="_blank" href="http://<%=item.external_ip%>">http://<%=item.external_ip%></a>
|
|
444
|
+
<a class='ln' target="_blank" href="http://<%=item.external_ip%>">http://<%=item.external_ip%></a>
|
|
439
445
|
</div>
|
|
440
446
|
<% } %>
|
|
441
447
|
</td>
|
|
448
|
+
<td>
|
|
449
|
+
<% item.internal_router.forEach((domain) => { %>
|
|
450
|
+
<div>
|
|
451
|
+
<a class='ln' target="_blank" href="https://<%=domain%>">https://<%=domain%></a>
|
|
452
|
+
</div>
|
|
453
|
+
<% }) %>
|
|
454
|
+
<div>
|
|
455
|
+
<a class='ln' target="_blank" href="http://localhost:<%=item.port%>">http://localhost:<%=item.port%></a>
|
|
456
|
+
</div>
|
|
457
|
+
</td>
|
|
442
458
|
</tr>
|
|
443
459
|
<% }) %>
|
|
444
460
|
</table>
|
|
@@ -696,6 +712,15 @@ if (document.querySelector("#wifi")) {
|
|
|
696
712
|
})
|
|
697
713
|
}
|
|
698
714
|
<% } %>
|
|
715
|
+
setInterval(() => {
|
|
716
|
+
fetch("/peer_check").then((res) => {
|
|
717
|
+
return res.json()
|
|
718
|
+
}).then((res) => {
|
|
719
|
+
if (res.updated) {
|
|
720
|
+
location.href = location.href
|
|
721
|
+
}
|
|
722
|
+
})
|
|
723
|
+
}, 2000)
|
|
699
724
|
</script>
|
|
700
725
|
</body>
|
|
701
726
|
</html>
|