pinokiod 3.8.25 → 3.8.27

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
@@ -32,6 +32,7 @@ const Store = require('./store')
32
32
  const Proto = require('./prototype')
33
33
  const Caddy = require("./caddy")
34
34
  const Procs = require('./procs')
35
+ const Peer = require('./peer')
35
36
  const VARS = {
36
37
  pip: {
37
38
  install: {
@@ -86,6 +87,8 @@ class Kernel {
86
87
  this.kv = new KV(this)
87
88
  this.cloudflare = new Cloudflare()
88
89
  this.shellpath = shellPath.sync()
90
+
91
+ this.peer = new Peer()
89
92
  }
90
93
  /*
91
94
  kernel.env() => return the system environment
package/kernel/peer.js ADDED
@@ -0,0 +1,45 @@
1
+ const dgram = require('dgram');
2
+
3
+ class PeerDiscovery {
4
+ constructor(port = 41234, message = 'ping', interval = 1000) {
5
+ this.port = port;
6
+ this.message = Buffer.from(message);
7
+ this.interval = interval;
8
+ this.socket = dgram.createSocket('udp4');
9
+ this.peers = new Set();
10
+ this.start();
11
+ }
12
+
13
+ start() {
14
+ // Listen for incoming pings
15
+ this.socket.on('message', (msg, rinfo) => {
16
+ const ip = rinfo.address;
17
+ if (msg.toString() === this.message.toString() && this._isLocalLAN(ip)) {
18
+ if (!this.peers.has(ip)) {
19
+ this.peers.add(ip);
20
+ console.log(`Discovered peer: ${ip}`);
21
+ }
22
+ }
23
+ });
24
+
25
+ // Enable broadcast
26
+ this.socket.bind(this.port, () => {
27
+ this.socket.setBroadcast(true);
28
+
29
+ // Send broadcast pings every interval
30
+ setInterval(() => {
31
+ this.socket.send(this.message, 0, this.message.length, this.port, '255.255.255.255');
32
+ }, this.interval);
33
+ });
34
+ }
35
+
36
+ get() {
37
+ return Array.from(this.peers);
38
+ }
39
+
40
+ _isLocalLAN(ip) {
41
+ return ip.startsWith('192.168.');
42
+ }
43
+ }
44
+
45
+ module.exports = PeerDiscovery;
package/kernel/procs.js CHANGED
@@ -70,7 +70,7 @@ class Procs {
70
70
  const map = {};
71
71
  lines.forEach(line => {
72
72
  if (isWin) {
73
- const [name, , , , pid] = line.split('","').map(s => s.replace(/(^"|"$)/g, ''));
73
+ const [name, pid] = line.split('","').map(s => s.replace(/(^"|"$)/g, ''));
74
74
  map[pid] = name;
75
75
  } else {
76
76
  const [pid, ...nameParts] = line.trim().split(/\s+/);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "3.8.25",
3
+ "version": "3.8.27",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/server/index.js CHANGED
@@ -2668,6 +2668,8 @@ class Server {
2668
2668
  })
2669
2669
  await this.kernel.caddy.update()
2670
2670
 
2671
+ let peers = this.kernel.peer.get()
2672
+
2671
2673
  let live_proxies = this.kernel.api.proxies["/proxy"]
2672
2674
  if (!live_proxies) live_proxies = []
2673
2675
  let proxies = []
@@ -2745,6 +2747,7 @@ class Server {
2745
2747
  }
2746
2748
  }
2747
2749
  res.render("proxy", {
2750
+ peers,
2748
2751
  list,
2749
2752
  agent: this.agent,
2750
2753
  theme: this.theme,
@@ -161,7 +161,7 @@ body.dark .browser-options-row {
161
161
  }
162
162
  .container {
163
163
  display: grid;
164
- grid-template-columns: repeat(3, 1fr);
164
+ grid-template-columns: repeat(4, 1fr);
165
165
  }
166
166
  .dark .container-row {
167
167
  background: rgba(255, 255, 255, 0.04);
@@ -210,6 +210,14 @@ body.dark .browser-options-row {
210
210
  <div class='header-label'><i class='fa-solid fa-wifi'></i> Local Sharing</div>
211
211
  <div class='desc'>Serve Pinokio, installed apps, and even external apps to any device on the same network.</div>
212
212
  <div class='container'>
213
+ <div class='container-row'>
214
+ <div class='header-label-sub'><i class="fa-solid fa-microchip"></i> Peers</div>
215
+ <% peers.forEach((item) => { %>
216
+ <a target="_blank" href="http://<%=item%>" class='line align-top'>
217
+ <h3 class='table-grid'><%=item%></h3>
218
+ </a>
219
+ <% }) %>
220
+ </div>
213
221
  <div class='container-row'>
214
222
  <div class='header-label-sub'><i class="fa-solid fa-microchip"></i> Apps</div>
215
223
  <div class='line align-top'>