pinokiod 3.8.59 → 3.8.61

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.
@@ -7,6 +7,7 @@ const LocalhostPortRouter = require('./localhost_port_router')
7
7
  const PeerHomeRouter = require('./peer_home_router')
8
8
  const PeerVariableRouter = require('./peer_variable_router')
9
9
  const PeerPortRouter = require('./peer_port_router')
10
+ const PeerPeerRouter = require('./peer_peer_router')
10
11
  class Router {
11
12
  constructor(kernel) {
12
13
  this.kernel = kernel
@@ -16,12 +17,12 @@ class Router {
16
17
  this.peer_home_router = new PeerHomeRouter(this)
17
18
  this.peer_variable_router = new PeerVariableRouter(this)
18
19
  this.peer_port_router = new PeerPortRouter(this)
20
+ this.peer_peer_router = new PeerPeerRouter(this)
19
21
  this.default_prefix = "pinokio"
20
22
  this.default_suffix = "localhost"
21
23
  this.default_match = this.default_prefix + "." + this.default_suffix
22
24
  this.default_port = "42000"
23
25
  this.default_host = "127.0.0.1"
24
- this.config
25
26
  }
26
27
  async add({ host, match, dial }) {
27
28
  if (!this._mapping[host]) {
@@ -45,6 +46,25 @@ class Router {
45
46
  }
46
47
  return mapping
47
48
  }
49
+ published() {
50
+ let info = this.info()
51
+ let pub = {}
52
+ for(let host in info) {
53
+ let routes = info[host]
54
+ pub[host] = {}
55
+ for(let dial in routes) {
56
+ let matches = routes[dial]
57
+ let exposed_matches = matches.filter((m) => {
58
+ return m.endsWith(`${this.kernel.peer.name}.localhost`)
59
+ })
60
+ let port = dial.split(":")[1]
61
+ let exposed_port = this.port_mapping[`${port}`]
62
+ let exposed_dial = `${this.kernel.peer.host}:${exposed_port}` // exposed_dial :- 192.168...
63
+ pub[host][exposed_dial] = exposed_matches
64
+ }
65
+ }
66
+ return pub
67
+ }
48
68
  async fill() {
49
69
  const jsonString = JSON.stringify(this.config)
50
70
  // find all PORT_PLACEHOLDER patterns
@@ -52,6 +72,8 @@ class Router {
52
72
  console.log("matches", matches)
53
73
 
54
74
  // iterate through them and see if the port already exists
75
+ let count = matches ? new Set(matches).size : 0
76
+ /*
55
77
  let count = 0
56
78
  if (matches) {
57
79
  for(let match of matches) {
@@ -64,6 +86,7 @@ class Router {
64
86
  }
65
87
  }
66
88
  }
89
+ */
67
90
 
68
91
  console.log("count", count)
69
92
 
@@ -116,15 +139,20 @@ class Router {
116
139
  console.log(">3", { peers })
117
140
  for(let host in peers) {
118
141
  let peer = peers[host]
119
- this.peer_home_router.handle(peer)
120
- this.peer_variable_router.handle(peer)
121
- this.peer_port_router.handle(peer)
142
+ if (peer.host === this.kernel.peer.host) {
143
+ this.peer_home_router.handle(peer)
144
+ this.peer_variable_router.handle(peer)
145
+ this.peer_port_router.handle(peer)
146
+ } else {
147
+ this.peer_peer_router.handle(peer)
148
+ }
122
149
  }
123
150
  // replace :PORT_PLACEHOLDER with available ports
151
+ console.log("CONFIG BEFORE", JSON.stringify(this.config, null, 2))
124
152
 
125
153
  await this.fill()
126
154
 
127
- console.log("CONFIG", JSON.stringify(this.config, null, 2))
155
+ console.log("CONFIG AFTER", JSON.stringify(this.config, null, 2))
128
156
 
129
157
 
130
158
  let response = await axios.post('http://127.0.0.1:2019/load', this.config, {
@@ -0,0 +1,27 @@
1
+ const Common = require('./common')
2
+ class PeerPeerRouter {
3
+ constructor(router) {
4
+ this.router = router
5
+ this.common = new Common(router)
6
+ }
7
+ handle(peer) {
8
+ let routes = peer.router[peer.host]
9
+ for(let dial in routes) {
10
+ let matches = routes[dial]
11
+ let exposed_matches = matches.filter((m) => {
12
+ return m.endsWith(`${peer.name}.localhost`)
13
+ })
14
+ let port = dial.split(":")[1]
15
+ let exposed_dial = `${peer.host}:${port}` // exposed_dial :- 192.168...
16
+ for(let match of exposed_matches) {
17
+ console.log("common.handle", { match, exposed_dial, host: peer.host })
18
+ this.common.handle({
19
+ match,
20
+ dial: exposed_dial,
21
+ host: peer.host
22
+ })
23
+ }
24
+ }
25
+ }
26
+ }
27
+ module.exports = PeerPeerRouter
@@ -8,7 +8,7 @@ class PeerVariableRouter extends Processor {
8
8
  this.connector = new Connector(router)
9
9
  }
10
10
  handle(peer) {
11
- console.log("PeerVariableRouter", peer)
11
+ console.log("PeerVariableRouter", JSON.stringify(peer, null, 2))
12
12
  for(let script_path in peer.memory.local) {
13
13
  let local_variables = peer.memory.local[script_path]
14
14
  for(let key in local_variables) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "3.8.59",
3
+ "version": "3.8.61",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/server/index.js CHANGED
@@ -3264,7 +3264,8 @@ class Server {
3264
3264
  platform: this.kernel.platform,
3265
3265
  name: this.kernel.peer.name,
3266
3266
  host: this.kernel.peer.host,
3267
- router: this.kernel.router.info(),
3267
+ //router: this.kernel.router.info(),
3268
+ router: this.kernel.router.published(),
3268
3269
  memory: this.kernel.memory
3269
3270
  })
3270
3271
  }))