pinokiod 3.8.38 → 3.8.39
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/caddy.js +125 -105
- package/kernel/peer.js +1 -0
- package/package.json +1 -1
- package/server/index.js +3 -2
package/kernel/caddy.js
CHANGED
|
@@ -369,113 +369,122 @@ class Caddy {
|
|
|
369
369
|
let account = this.kernel.peer.account(ip)
|
|
370
370
|
console.log({ account })
|
|
371
371
|
|
|
372
|
-
//
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
// create a proxy proxy
|
|
380
|
-
// 1. create an exposed port listening on 0.0.0.0
|
|
381
|
-
// 2. the exposed port points to the internal ip
|
|
382
|
-
let chunks = internal_ip.split(":")
|
|
383
|
-
let INTERNAL_HOST = chunks[0]
|
|
384
|
-
let INTERNAL_PORT = chunks[1]
|
|
372
|
+
// if ip === current_lan_ip
|
|
373
|
+
// => trust the info on itself only
|
|
374
|
+
// => only use the current info, ignore the rest
|
|
375
|
+
// ip ip !== current_lan_ip => just pick one
|
|
376
|
+
// => trust the info coming from ip only
|
|
377
|
+
// => only use the info for that node
|
|
385
378
|
|
|
386
|
-
this.ip_mapping[INTERNAL_PORT] = ip
|
|
387
379
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
380
|
+
// caddy_mapping := { IP => HTTPS_DOMAIN }
|
|
381
|
+
|
|
382
|
+
// get the mapping for the current node
|
|
383
|
+
// for current node, only trust the info from the current node
|
|
384
|
+
// for other nodes, just use the first one to avoid registering duplicates
|
|
385
|
+
|
|
386
|
+
let https_domains_mapping = this.mapping(ip)[ip]
|
|
387
|
+
console.log({ https_domains_mapping, ip })
|
|
388
|
+
for(let internal_ip in https_domains_mapping) {
|
|
389
|
+
|
|
390
|
+
// create a proxy proxy
|
|
391
|
+
// 1. create an exposed port listening on 0.0.0.0
|
|
392
|
+
// 2. the exposed port points to the internal ip
|
|
393
|
+
let chunks = internal_ip.split(":")
|
|
394
|
+
let INTERNAL_HOST = chunks[0]
|
|
395
|
+
let INTERNAL_PORT = chunks[1]
|
|
396
|
+
|
|
397
|
+
this.ip_mapping[INTERNAL_PORT] = ip
|
|
398
|
+
|
|
399
|
+
payload.apps.http.servers[":" + INTERNAL_PORT] = {
|
|
400
|
+
"listen": ["0.0.0.0:PORT_PLACEHOLDER_" + ip + ":" + INTERNAL_PORT],
|
|
401
|
+
"routes": [{
|
|
402
|
+
"handle": [
|
|
403
|
+
{
|
|
404
|
+
"handler": "reverse_proxy",
|
|
405
|
+
"upstreams": [{ "dial": internal_ip }]
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
"handler": "headers",
|
|
409
|
+
"response": {
|
|
410
|
+
"set": {
|
|
411
|
+
"Access-Control-Allow-Origin": ["*"],
|
|
412
|
+
"Access-Control-Allow-Methods": ["GET, POST, OPTIONS, PUT, DELETE"],
|
|
413
|
+
"Access-Control-Allow-Headers": ["*"],
|
|
414
|
+
"Vary": ["Origin"]
|
|
405
415
|
}
|
|
406
416
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
}
|
|
417
|
+
}
|
|
418
|
+
]
|
|
419
|
+
}]
|
|
420
|
+
}
|
|
410
421
|
|
|
411
422
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
423
|
+
//let https_domains = caddy_mapping[internal_ip]
|
|
424
|
+
let https_domains = https_domains_mapping[internal_ip]
|
|
425
|
+
console.log(">>>>>>>> https_domains", https_domains)
|
|
426
|
+
|
|
427
|
+
// 1. if https_domains is made up of one item <port>.localhost,
|
|
428
|
+
// add <port>.<account>.localhost
|
|
429
|
+
// 2. if https_domains is made up of two items <port>.localhost and <port>.<account>.localhost, don't do anything
|
|
430
|
+
for(let https_domain of https_domains) {
|
|
431
|
+
// insert the $account value right before the last part (1234.localhost => 1234.x.localhost)
|
|
432
|
+
let chunks = https_domain.split(".")
|
|
433
|
+
let namespaced_url
|
|
434
|
+
if (chunks.length === 3) {
|
|
435
|
+
namespaced_url = https_domain
|
|
436
|
+
} else if (chunks.length === 2) {
|
|
437
|
+
chunks.splice(chunks.length - 1, 0, account)
|
|
438
|
+
namespaced_url = chunks.join(".")
|
|
439
|
+
}
|
|
440
|
+
console.log("##x", { chunks, namespaced_url, https_domain })
|
|
430
441
|
|
|
431
442
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
443
|
+
//if (!this._mapping[internal_ip]) {
|
|
444
|
+
// this._mapping[internal_ip] = new Set()
|
|
445
|
+
//}
|
|
446
|
+
//console.log("this.mapping", this._mapping)
|
|
447
|
+
//console.log("internal_ip", internal_ip)
|
|
448
|
+
//console.log("result", this._mapping[internal_ip])
|
|
449
|
+
//this._mapping[internal_ip].add(namespaced_url)
|
|
450
|
+
//console.log({ namespaced_url, https_domain, internal_ip })
|
|
440
451
|
|
|
441
452
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
}
|
|
453
|
+
let current_lan_ip = ip
|
|
454
|
+
let current_lan_username = this.kernel.peer.account(current_lan_ip)
|
|
455
|
+
if (!this._mapping[current_lan_ip]) {
|
|
456
|
+
this._mapping[current_lan_ip] = {}
|
|
457
|
+
}
|
|
458
|
+
if (!this._mapping[current_lan_ip][internal_ip]) {
|
|
459
|
+
this._mapping[current_lan_ip][internal_ip] = new Set()
|
|
460
|
+
}
|
|
461
|
+
this._mapping[current_lan_ip][internal_ip].add(namespaced_url)
|
|
462
|
+
console.log("Adding", current_lan_ip, internal_ip, namespaced_url)
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
// 1. point proxy URL to the 127.0.0.1:EXPOSED_PORT
|
|
466
|
+
payload.apps.http.servers.main.routes.push({
|
|
467
|
+
"match": [{
|
|
468
|
+
"host": [namespaced_url],
|
|
469
|
+
}],
|
|
470
|
+
"handle": [
|
|
471
|
+
{
|
|
472
|
+
"handler": "reverse_proxy",
|
|
473
|
+
"upstreams": [{ "dial": ip + ":PORT_PLACEHOLDER_" + ip + ":" + INTERNAL_PORT }]
|
|
474
|
+
},
|
|
475
|
+
{
|
|
476
|
+
"handler": "headers",
|
|
477
|
+
"response": {
|
|
478
|
+
"set": {
|
|
479
|
+
"Access-Control-Allow-Origin": ["*"],
|
|
480
|
+
"Access-Control-Allow-Methods": ["GET, POST, OPTIONS, PUT, DELETE"],
|
|
481
|
+
"Access-Control-Allow-Headers": ["*"],
|
|
482
|
+
"Vary": ["Origin"]
|
|
473
483
|
}
|
|
474
484
|
}
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
}
|
|
478
|
-
|
|
485
|
+
}
|
|
486
|
+
]
|
|
487
|
+
})
|
|
479
488
|
}
|
|
480
489
|
}
|
|
481
490
|
}
|
|
@@ -619,19 +628,30 @@ class Caddy {
|
|
|
619
628
|
this.port_cache = replaced_map
|
|
620
629
|
}
|
|
621
630
|
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
let internal_maps = this._mapping[lan_ip]
|
|
625
|
-
if (!this.mapping[lan_ip]) {
|
|
626
|
-
this.mapping[lan_ip] = {}
|
|
627
|
-
}
|
|
628
|
-
for(let url in internal_maps) {
|
|
629
|
-
this.mapping[lan_ip][url] = Array.from(internal_maps[url])
|
|
630
|
-
}
|
|
631
|
-
}
|
|
631
|
+
|
|
632
|
+
|
|
632
633
|
|
|
633
634
|
|
|
634
635
|
return payload
|
|
635
636
|
}
|
|
637
|
+
mapping (ip) {
|
|
638
|
+
let current_lan_ip = this.kernel.peer.current_ip
|
|
639
|
+
if (!ip || current_lan_ip === ip) {
|
|
640
|
+
let mapping = {}
|
|
641
|
+
for(let lan_ip in this._mapping) {
|
|
642
|
+
let internal_maps = this._mapping[lan_ip]
|
|
643
|
+
if (!mapping[lan_ip]) {
|
|
644
|
+
mapping[lan_ip] = {}
|
|
645
|
+
}
|
|
646
|
+
for(let url in internal_maps) {
|
|
647
|
+
mapping[lan_ip][url] = Array.from(internal_maps[url])
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
return mapping
|
|
651
|
+
} else {
|
|
652
|
+
return this.kernel.peer.caddy(ip)
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
|
|
636
656
|
}
|
|
637
657
|
module.exports = Caddy
|
package/kernel/peer.js
CHANGED
|
@@ -39,6 +39,7 @@ class PeerDiscovery {
|
|
|
39
39
|
let interval = setInterval(() => {
|
|
40
40
|
axios.get(`http://${ip}:42000/pinokio/mem`).then((res) => {
|
|
41
41
|
this.data[ip] = res.data
|
|
42
|
+
console.log("this.data", { ip, data: this.data[ip] })
|
|
42
43
|
if (res.data.proxy) {
|
|
43
44
|
// clearInterval(interval)
|
|
44
45
|
}
|
package/package.json
CHANGED
package/server/index.js
CHANGED
|
@@ -2662,10 +2662,11 @@ class Server {
|
|
|
2662
2662
|
await this.kernel.caddy.update()
|
|
2663
2663
|
let list = await this.kernel.processes.refresh()
|
|
2664
2664
|
let current_lan_ip = this.kernel.peer.current_ip
|
|
2665
|
+
console.log("this.kernel.caddy.mapping", this.kernel.caddy.mapping())
|
|
2665
2666
|
list = list.map((item) => {
|
|
2666
2667
|
return {
|
|
2667
2668
|
//proxy: this.kernel.caddy.mapping[item.ip] || [],
|
|
2668
|
-
proxy: this.kernel.caddy.mapping[current_lan_ip][item.ip] || [],
|
|
2669
|
+
proxy: this.kernel.caddy.mapping()[current_lan_ip][item.ip] || [],
|
|
2669
2670
|
...item
|
|
2670
2671
|
}
|
|
2671
2672
|
})
|
|
@@ -3293,7 +3294,7 @@ class Server {
|
|
|
3293
3294
|
res.json({
|
|
3294
3295
|
homedir: this.kernel.homedir,
|
|
3295
3296
|
account: this.kernel.peer.current_account,
|
|
3296
|
-
proxy: this.kernel.caddy.mapping, // mapping: { IP => https_domain }
|
|
3297
|
+
proxy: this.kernel.caddy.mapping(), // mapping: { IP => https_domain }
|
|
3297
3298
|
ports: this.kernel.caddy.port_mapping,
|
|
3298
3299
|
lan: this.kernel.caddy.local_network_mapping,
|
|
3299
3300
|
ips: this.kernel.caddy.ip_mapping,
|