pinokiod 3.8.150 → 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/index.js +46 -6
- package/kernel/peer.js +5 -3
- package/kernel/router/index.js +19 -7
- package/package.json +1 -1
- package/server/index.js +2 -1
- package/server/views/network.ejs +30 -5
package/kernel/index.js
CHANGED
|
@@ -246,16 +246,23 @@ class Kernel {
|
|
|
246
246
|
}
|
|
247
247
|
async refresh(notify_peers) {
|
|
248
248
|
let env = await Environment.get(this.homedir)
|
|
249
|
-
let
|
|
249
|
+
let peer_active = false
|
|
250
250
|
// if PINOKIO_NETWORK_SHARE is 0 or false, turn it off
|
|
251
251
|
if (env && env.PINOKIO_NETWORK_ACTIVE && (env.PINOKIO_NETWORK_ACTIVE==="1" || env.PINOKIO_NETWORK_ACTIVE.toLowerCase()==="true")) {
|
|
252
|
-
|
|
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
|
|
253
257
|
}
|
|
254
258
|
// console.log("kernel.refresh", { active, notify_peers })
|
|
255
259
|
|
|
256
|
-
let
|
|
257
|
-
|
|
258
|
-
|
|
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) {
|
|
259
266
|
|
|
260
267
|
// 1. get the process list
|
|
261
268
|
await this.processes.refresh()
|
|
@@ -285,8 +292,41 @@ class Kernel {
|
|
|
285
292
|
|
|
286
293
|
// 9. announce self to the peer network
|
|
287
294
|
this.peer.announce()
|
|
295
|
+
|
|
296
|
+
// }
|
|
288
297
|
|
|
289
|
-
|
|
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
|
+
//}
|
|
290
330
|
}
|
|
291
331
|
async clearLog(group) {
|
|
292
332
|
let relativePath = path.relative(this.homedir, group)
|
package/kernel/peer.js
CHANGED
|
@@ -21,7 +21,9 @@ class PeerDiscovery {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
announce() {
|
|
24
|
-
this.socket
|
|
24
|
+
if (this.socket) {
|
|
25
|
+
this.socket.send(this.message, 0, this.message.length, this.port, '192.168.1.255');
|
|
26
|
+
}
|
|
25
27
|
}
|
|
26
28
|
async start(kernel) {
|
|
27
29
|
let env = await Environment.get(kernel.homedir)
|
|
@@ -104,7 +106,7 @@ class PeerDiscovery {
|
|
|
104
106
|
}
|
|
105
107
|
// refresh peer info
|
|
106
108
|
async refresh(peers) {
|
|
107
|
-
if (this.active) {
|
|
109
|
+
// if (this.active) {
|
|
108
110
|
this.refreshing = true
|
|
109
111
|
let refresh_peers
|
|
110
112
|
if (peers) {
|
|
@@ -127,7 +129,7 @@ class PeerDiscovery {
|
|
|
127
129
|
}
|
|
128
130
|
this.refreshing = false
|
|
129
131
|
return this.info
|
|
130
|
-
}
|
|
132
|
+
// }
|
|
131
133
|
}
|
|
132
134
|
_isLocalLAN(ip) {
|
|
133
135
|
return ip.startsWith('192.168.');
|
package/kernel/router/index.js
CHANGED
|
@@ -9,6 +9,7 @@ const PeerHomeRouter = require('./peer_home_router')
|
|
|
9
9
|
const PeerVariableRouter = require('./peer_variable_router')
|
|
10
10
|
const PeerPortRouter = require('./peer_port_router')
|
|
11
11
|
const PeerPeerRouter = require('./peer_peer_router')
|
|
12
|
+
const Environment = require("../environment")
|
|
12
13
|
class Router {
|
|
13
14
|
constructor(kernel) {
|
|
14
15
|
this.kernel = kernel
|
|
@@ -68,6 +69,14 @@ class Router {
|
|
|
68
69
|
this.custom_routers[port] = config[port]
|
|
69
70
|
}
|
|
70
71
|
}
|
|
72
|
+
|
|
73
|
+
let env = await Environment.get(this.kernel.homedir)
|
|
74
|
+
this.active = false
|
|
75
|
+
if (env && env.PINOKIO_HTTPS_ACTIVE && (env.PINOKIO_HTTPS_ACTIVE==="1" || env.PINOKIO_HTTPS_ACTIVE.toLowerCase()==="true")) {
|
|
76
|
+
this.active = true
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
71
80
|
}
|
|
72
81
|
async add({ host, match, dial }) {
|
|
73
82
|
if (!this._mapping[host]) {
|
|
@@ -169,16 +178,19 @@ class Router {
|
|
|
169
178
|
for(let proc of this.kernel.processes.info) {
|
|
170
179
|
this.localhost_port_router.handle(proc)
|
|
171
180
|
}
|
|
172
|
-
|
|
173
|
-
let
|
|
174
|
-
|
|
175
|
-
this.
|
|
176
|
-
|
|
177
|
-
|
|
181
|
+
if (this.kernel.peer.active) {
|
|
182
|
+
for(let host in this.kernel.peer.info) {
|
|
183
|
+
let peer = this.kernel.peer.info[host]
|
|
184
|
+
if (peer.host === this.kernel.peer.host) {
|
|
185
|
+
this.peer_home_router.handle(peer)
|
|
186
|
+
this.peer_variable_router.handle(peer)
|
|
187
|
+
this.peer_port_router.handle(peer)
|
|
188
|
+
}
|
|
178
189
|
}
|
|
190
|
+
await this.fill()
|
|
179
191
|
}
|
|
180
|
-
await this.fill()
|
|
181
192
|
this.mapping = this._mapping
|
|
193
|
+
console.log("after local()", JSON.stringify(this.mapping, null, 2))
|
|
182
194
|
}
|
|
183
195
|
|
|
184
196
|
// set remote config
|
package/package.json
CHANGED
package/server/index.js
CHANGED
|
@@ -2622,7 +2622,8 @@ class Server {
|
|
|
2622
2622
|
peers,
|
|
2623
2623
|
list,
|
|
2624
2624
|
name: this.kernel.peer.name,
|
|
2625
|
-
|
|
2625
|
+
https_active: this.kernel.router.active,
|
|
2626
|
+
peer_active: this.kernel.peer.active,
|
|
2626
2627
|
port_mapping: this.kernel.router.port_mapping,
|
|
2627
2628
|
// port_mapping: this.kernel.caddy.port_mapping,
|
|
2628
2629
|
// ip_mapping: this.kernel.caddy.ip_mapping,
|
package/server/views/network.ejs
CHANGED
|
@@ -381,16 +381,25 @@ input:checked + .slider:before {
|
|
|
381
381
|
</div>
|
|
382
382
|
<div class='config-body'>
|
|
383
383
|
<div class='config-row'>
|
|
384
|
-
<div class='label'>
|
|
385
|
-
<
|
|
384
|
+
<div class='label'>Instant HTTPS</div>
|
|
385
|
+
<label class="switcher">
|
|
386
|
+
<input id='https_active' type="checkbox" <%=https_active ? 'checked' : ''%>>
|
|
387
|
+
<span class="slider"></span>
|
|
388
|
+
</label>
|
|
386
389
|
</div>
|
|
390
|
+
</div>
|
|
391
|
+
<div class='config-body'>
|
|
387
392
|
<div class='config-row'>
|
|
388
393
|
<div class='label'>Network Share</div>
|
|
389
394
|
<label class="switcher">
|
|
390
|
-
<input id='
|
|
395
|
+
<input id='peer_active' type="checkbox" <%=peer_active ? 'checked' : ''%>>
|
|
391
396
|
<span class="slider"></span>
|
|
392
397
|
</label>
|
|
393
398
|
</div>
|
|
399
|
+
<div class='config-row' id='network_name'>
|
|
400
|
+
<div class='label'>Network Name</div>
|
|
401
|
+
<input id='name' type='text' value="<%=name%>">
|
|
402
|
+
</div>
|
|
394
403
|
<div class='flexible'></div>
|
|
395
404
|
<button class='btn save'>Save</button>
|
|
396
405
|
</div>
|
|
@@ -540,6 +549,21 @@ input:checked + .slider:before {
|
|
|
540
549
|
</div>
|
|
541
550
|
</main>
|
|
542
551
|
<script>
|
|
552
|
+
if (document.querySelector("#peer_active").checked) {
|
|
553
|
+
console.log("checked")
|
|
554
|
+
document.querySelector("#network_name").classList.remove("hidden")
|
|
555
|
+
} else {
|
|
556
|
+
console.log("not checked")
|
|
557
|
+
document.querySelector("#network_name").classList.add("hidden")
|
|
558
|
+
}
|
|
559
|
+
document.querySelector("#peer_active").addEventListener("change", (e)=> {
|
|
560
|
+
console.log(e.target.checked)
|
|
561
|
+
if (e.target.checked) {
|
|
562
|
+
document.querySelector("#network_name").classList.remove("hidden")
|
|
563
|
+
} else {
|
|
564
|
+
document.querySelector("#network_name").classList.add("hidden")
|
|
565
|
+
}
|
|
566
|
+
})
|
|
543
567
|
document.querySelector("main").addEventListener("click", async (e) => {
|
|
544
568
|
let target
|
|
545
569
|
|
|
@@ -551,8 +575,9 @@ document.querySelector("main").addEventListener("click", async (e) => {
|
|
|
551
575
|
|
|
552
576
|
if (target) {
|
|
553
577
|
let body = {
|
|
554
|
-
PINOKIO_NETWORK_NAME: document.querySelector("#
|
|
555
|
-
PINOKIO_NETWORK_ACTIVE: (document.querySelector("#
|
|
578
|
+
PINOKIO_NETWORK_NAME: document.querySelector("#network_name").value,
|
|
579
|
+
PINOKIO_NETWORK_ACTIVE: (document.querySelector("#peer_active").checked ? "1": "0"),
|
|
580
|
+
PINOKIO_HTTPS_ACTIVE: (document.querySelector("#https_active").checked ? "1": "0")
|
|
556
581
|
}
|
|
557
582
|
console.log(body)
|
|
558
583
|
debugger
|