pinokiod 3.8.100 → 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 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
- await Promise.all([
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
- // await this.peer.refresh()
285
+ // 4. refresh peer info to reflect the updated router info
286
+ await this.peer.refresh()
286
287
 
288
+ // 4. tell peers to refresh
287
289
  if (notify_peers) {
288
- // broadcast to peers to refresh
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) {
@@ -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": ["*"],
@@ -91,8 +91,10 @@ class Router {
91
91
  // find all PORT_PLACEHOLDER patterns
92
92
  const matches = jsonString.match(/:PORT_PLACEHOLDER_[0-9.:]+/g)
93
93
 
94
+
94
95
  // iterate through them and see if the port already exists
95
96
  let count = matches ? new Set(matches).size : 0
97
+ console.log("fill matches", { matches, count })
96
98
  /*
97
99
  let count = 0
98
100
  if (matches) {
@@ -109,11 +111,13 @@ class Router {
109
111
  */
110
112
 
111
113
 
114
+
112
115
  let new_config
113
116
 
114
117
  if (count > 0) {
115
118
  let ports = await this.kernel.ports(count)
116
119
  let response = Util.fill_object(this.config, /PORT_PLACEHOLDER_.+/, ports, this.port_cache)
120
+ console.log("fill_object response", response)
117
121
  this.config = response.result
118
122
  let replaced_map = response.replaced_map
119
123
  for(let key in replaced_map) {
@@ -131,12 +135,66 @@ class Router {
131
135
 
132
136
  //let original_port = key.replace("PORT_PLACEHOLDER_", "")
133
137
  this.port_mapping[original_port] = replaced_map[key]
138
+ console.log("set port_mapping", { original_port, key, replaced_map })
134
139
  }
135
140
  this.port_cache = replaced_map
136
141
  }
137
142
 
138
143
  }
139
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
+
140
198
  async refresh() {
141
199
  console.log("router.refresh")
142
200
  console.time("router.refresh")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "3.8.100",
3
+ "version": "3.8.101",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
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) => {