pinokiod 3.8.62 → 3.8.63
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/router/connector.js +7 -3
- package/kernel/router/index.js +37 -8
- package/package.json +1 -1
|
@@ -3,10 +3,13 @@ class Connector {
|
|
|
3
3
|
this.router = router
|
|
4
4
|
}
|
|
5
5
|
handle ({ match, connector, dial, }) {
|
|
6
|
+
console.log("connector.handle", { match, connector, dial })
|
|
6
7
|
let connector_name = connector.host + ":" + connector.port
|
|
8
|
+
let listener = "0.0.0.0:PORT_PLACEHOLDER_" + connector_name
|
|
9
|
+
let listener_pointer = connector.host + ":PORT_PLACEHOLDER_" + connector_name
|
|
7
10
|
if(!this.router.config.apps.http.servers[connector_name]) {
|
|
8
11
|
this.router.config.apps.http.servers[connector_name] = {
|
|
9
|
-
"listen": [
|
|
12
|
+
"listen": [listener],
|
|
10
13
|
"routes": [{
|
|
11
14
|
"handle": [
|
|
12
15
|
{
|
|
@@ -35,7 +38,7 @@ class Connector {
|
|
|
35
38
|
"handle": [
|
|
36
39
|
{
|
|
37
40
|
"handler": "reverse_proxy",
|
|
38
|
-
"upstreams": [{ "dial":
|
|
41
|
+
"upstreams": [{ "dial": listener_pointer }]
|
|
39
42
|
},
|
|
40
43
|
{
|
|
41
44
|
"handler": "headers",
|
|
@@ -50,7 +53,8 @@ class Connector {
|
|
|
50
53
|
}
|
|
51
54
|
]
|
|
52
55
|
})
|
|
53
|
-
|
|
56
|
+
console.log("Router.add", { host: connector.host, dial: listener_pointer, match })
|
|
57
|
+
this.router.add({ host: connector.host, dial: listener_pointer, match })
|
|
54
58
|
}
|
|
55
59
|
}
|
|
56
60
|
module.exports = Connector
|
package/kernel/router/index.js
CHANGED
|
@@ -32,8 +32,12 @@ class Router {
|
|
|
32
32
|
this._mapping[host][dial] = new Set()
|
|
33
33
|
}
|
|
34
34
|
this._mapping[host][dial].add(match)
|
|
35
|
+
console.log(">this._mapping", this._mapping)
|
|
35
36
|
}
|
|
36
37
|
info() {
|
|
38
|
+
console.log("#### this._mapping", this._mapping)
|
|
39
|
+
|
|
40
|
+
|
|
37
41
|
let mapping = {}
|
|
38
42
|
for(let host in this._mapping) {
|
|
39
43
|
let internal_maps = this._mapping[host]
|
|
@@ -44,8 +48,31 @@ class Router {
|
|
|
44
48
|
mapping[host][url] = Array.from(internal_maps[url])
|
|
45
49
|
}
|
|
46
50
|
}
|
|
47
|
-
|
|
51
|
+
|
|
52
|
+
console.log("mapping", mapping)
|
|
53
|
+
let json = JSON.stringify(mapping)
|
|
54
|
+
for(let key in this.port_cache) {
|
|
55
|
+
console.log("replacing", key, "with", this.port_cache[key])
|
|
56
|
+
json = json.replaceAll(key, this.port_cache[key])
|
|
57
|
+
}
|
|
58
|
+
let m = JSON.parse(json)
|
|
59
|
+
console.log({ m })
|
|
60
|
+
return m
|
|
61
|
+
// return mapping
|
|
48
62
|
}
|
|
63
|
+
/*
|
|
64
|
+
returns only the published peer info
|
|
65
|
+
{
|
|
66
|
+
<peer1 host>: {
|
|
67
|
+
<dial1>: [<match1>, <match2>, ..],
|
|
68
|
+
<dial2>: [<match1>, <match2>, ..],
|
|
69
|
+
},
|
|
70
|
+
<peer2 host>: {
|
|
71
|
+
<dial1>: [<match1>, <match2>, ..],
|
|
72
|
+
<dial2>: [<match1>, <match2>, ..],
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
*/
|
|
49
76
|
published() {
|
|
50
77
|
let info = this.info()
|
|
51
78
|
console.log("published info", info)
|
|
@@ -55,14 +82,16 @@ class Router {
|
|
|
55
82
|
pub[host] = {}
|
|
56
83
|
for(let dial in routes) {
|
|
57
84
|
let matches = routes[dial]
|
|
85
|
+
// current host => the single source of truth
|
|
58
86
|
if (dial.startsWith(this.kernel.peer.host)) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
let
|
|
64
|
-
let
|
|
65
|
-
|
|
87
|
+
pub[host][dial] = matches
|
|
88
|
+
// let exposed_matches = matches.filter((m) => {
|
|
89
|
+
// return m.endsWith(`${this.kernel.peer.name}.localhost`)
|
|
90
|
+
// })
|
|
91
|
+
// let port = dial.split(":")[1]
|
|
92
|
+
// let exposed_port = this.port_mapping[`${port}`]
|
|
93
|
+
// let exposed_dial = `${this.kernel.peer.host}:${exposed_port}` // exposed_dial :- 192.168...
|
|
94
|
+
// pub[host][exposed_dial] = exposed_matches
|
|
66
95
|
} else {
|
|
67
96
|
pub[host][dial] = matches
|
|
68
97
|
}
|