Skip to content

Commit

Permalink
changelog
Browse files Browse the repository at this point in the history
worker state
cleanup in progress
client destroy
  • Loading branch information
tomekmarchi committed Nov 7, 2023
1 parent 5d0c865 commit 4309416
Show file tree
Hide file tree
Showing 16 changed files with 345 additions and 624 deletions.
20 changes: 19 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,29 @@
|[Sentivate](https://sentivate.com) - [Twitter](https://twitter.com/sentivate)|
---

## [v3.0.0](https://github.com/universalweb/Network/compare/v1.3.3...v3.0.0)
## [v3.0.1](https://github.com/universalweb/Network/compare/v3.0.1...v3.0.1)

---
---

## [v3.0.1](https://github.com/universalweb/Network/compare/v1.3.3...v3.0.1) - 2023-11-07

---
---

### Commits

- Initial Multithreading support [`348e18a`](https://github.com/universalweb/Network/commit/348e18a5b8664be996f4d7c0c0bffc427a5c3074)
- Security fixes [`e9bd907`](https://github.com/universalweb/Network/commit/e9bd90792d6e4cb46b7f86b5b813c4f1bb7f566c)
- Hex Based Ids [`cf212dc`](https://github.com/universalweb/Network/commit/cf212dc8abe436b606388b113dd4c11db3302dea)
- New Math Algo for chunking [`16eb39d`](https://github.com/universalweb/Network/commit/16eb39d0a8a38f0b8e59c1b55281bcdc0fd1670a)
- Chunking math changes [`f266b4a`](https://github.com/universalweb/Network/commit/f266b4aff382d2d42ede20510d18a1fd093ec7a2)
- smart ids in progress [`a0c35ac`](https://github.com/universalweb/Network/commit/a0c35ac67364071310942017158b55d2b66954f1)
- Demo 99% Restored [`15787ad`](https://github.com/universalweb/Network/commit/15787ad109172abee7e2bc5797a8fdc745a45b11)
- certificate changes [`7397a14`](https://github.com/universalweb/Network/commit/7397a14cf9345208c61dce45a1ebb66b469e5d75)
- DO NOT RUN DEMO [`9c8bdb1`](https://github.com/universalweb/Network/commit/9c8bdb11558d5ee0b34f6a21275cf4dd39d63bdd)
- Version change to v3 [`19ca7d0`](https://github.com/universalweb/Network/commit/19ca7d079a84e93ae50e230fe1fe2f98e76eb2c9)

## v1.3.3 - 2023-10-14

---
Expand Down
898 changes: 284 additions & 614 deletions package-lock.json

Large diffs are not rendered by default.

Binary file modified profiles/default-Ephemeral.cert
Binary file not shown.
Binary file modified profiles/default-EphemeralPublic.cert
Binary file not shown.
Binary file modified profiles/default-Master.cert
Binary file not shown.
Binary file modified profiles/default-MasterPublic.cert
Binary file not shown.
Binary file modified profiles/default-Profile.cert
Binary file not shown.
Binary file modified services/universal.web-Ephemeral.cert
Binary file not shown.
Binary file modified services/universal.web-EphemeralPublic.cert
Binary file not shown.
Binary file modified services/universal.web-Master.cert
Binary file not shown.
Binary file modified services/universal.web-MasterPublic.cert
Binary file not shown.
Binary file modified services/universal.web-Profile.cert
Binary file not shown.
1 change: 1 addition & 0 deletions udsp/server/clients/destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export async function destroy(client, reason, server) {
}
await server.clientEvent('destroy', client);
server.clients.delete(client.connectionIdString);
server.updateWorkerState();
// Clear all client data
client.ip = null;
client.port = null;
Expand Down
35 changes: 27 additions & 8 deletions udsp/server/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
import cluster from 'node:cluster';
import { construct, hasValue } from '@universalweb/acid';
import { assign, construct, hasValue } from '@universalweb/acid';
import { getCoreCount } from '#utilities/hardware/cpu';
import { Server } from './init.js';
import { decode } from '#utilities/serialize';
import { onPacket } from './onPacket.js';
const numCPUs = getCoreCount();
function workerReady(worker) {
worker.ready = true;
worker.process.send('registered');
console.log('worker is READY:', worker.id);
}
function workerOnMessage(workers, worker, msg) {
const decodedMessage = decode(msg);
const [eventName, data] = decodedMessage;
console.log('Worker Message Received', eventName, data);
switch (eventName) {
case 'state':
assign(worker.state, data);
console.log('Worker State Update', worker.state);
break;
default:
break;
}
}
export async function server(config, ...args) {
if (config.scale) {
const {
Expand All @@ -31,26 +49,27 @@ export async function server(config, ...args) {
config.isPrimary = true;
config.workerId = String(0);
const masterLoadBalancer = await new Server(config, ...args);
const workers = new Map();
const workers = [];
masterLoadBalancer.workers = workers;
for (let index = 0; index < coreCount; index++) {
const worker = cluster.fork();
workers.set(worker.id, worker);
worker.state = {};
worker.port = port + worker.id;
workers[worker.id] = worker;
worker.on('message', (msg) => {
if (msg === 'ready') {
workers.set(worker.id, worker);
worker.port = port + worker.id;
worker.process.send('registered');
console.log('worker is registered:', worker.id);
workerReady(worker);
return;
}
workerOnMessage(workers, worker, msg);
});
}
cluster.on('online', (worker) => {
console.log('worker is online:', worker.id);
});
cluster.on('exit', (worker, code, signal) => {
console.log('worker is dead:', worker.isDead(), code);
workers.delete(worker.id, worker);
workers[worker.id] = null;
});
// console.log(cluster.settings);
return masterLoadBalancer;
Expand Down
12 changes: 11 additions & 1 deletion udsp/server/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class Server extends UDSP {
if (key) {
console.log(`Loadbalancer has a new client ${idString}`);
}
const worker = this.workers.get(1);
const worker = this.workers[1];
const passMessage = encode([packet, connection]);
if (worker && passMessage) {
worker.process.send(passMessage);
Expand Down Expand Up @@ -229,6 +229,16 @@ export class Server extends UDSP {
foundEvent(this, client);
}
}
updateWorkerState() {
this.clientCount = this.clients.size;
this.syncWorkerState();
}
syncWorkerState() {
const { clientCount } = this;
process.send(encode(['state', {
clientCount
}]));
}
on = on;
listen = listen;
onError = onError;
Expand Down
3 changes: 3 additions & 0 deletions udsp/server/onPacket.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export async function onPacket(packet, connection) {
return console.trace('Failed to create client', idString);
}
config.destination = client;
if (this.isWorker) {
this.updateWorkerState(client);
}
}
if (!client) {
// Send error message back to origin or not
Expand Down

0 comments on commit 4309416

Please sign in to comment.