regions? regions!

canary
Marcus 2021-03-20 10:42:04 -04:00
parent b0265b7ca7
commit 541eb7847a
1 changed files with 31 additions and 11 deletions

View File

@ -1,3 +1,6 @@
// #region === [ private lib functions ] ===
class STPPacket { class STPPacket {
cmd = 'NOOP'; cmd = 'NOOP';
data = {}; data = {};
@ -12,15 +15,6 @@ class STPPacket {
} }
} }
class KeyExchangePacket extends STPPacket {
constructor(key, type = 'pkcs8-pem') {
super();
this.cmd = 'KEY';
this.data.key = key;
this.meta.type = type;
}
}
function basicPacket(commandName) { function basicPacket(commandName) {
return class extends STPPacket { return class extends STPPacket {
constructor() { constructor() {
@ -30,6 +24,19 @@ function basicPacket(commandName) {
} }
} }
// #endregion
// #region === [ exotic packet classes ] ===
class KeyExchangePacket extends STPPacket {
constructor(key, type = 'pkcs8-pem') {
super();
this.cmd = 'KEY';
this.data.key = key;
this.meta.type = type;
}
}
class ClientsPacket extends STPPacket { class ClientsPacket extends STPPacket {
constructor(clients) { constructor(clients) {
super(); super();
@ -38,9 +45,17 @@ class ClientsPacket extends STPPacket {
} }
} }
// #endregion
// #region === [ ordinary packet classes ] ===
const AckPacket = basicPacket('ACK'); const AckPacket = basicPacket('ACK');
const GetClientsPacket = basicPacket('QNODES'); const GetClientsPacket = basicPacket('QNODES');
// #endregion
// #region === [ public lib functions ] ===
function reconstructPacket(packet) { function reconstructPacket(packet) {
if(packet.startsWith('\02')) if(packet.startsWith('\02'))
@ -62,7 +77,10 @@ function reconstructPacket(packet) {
} }
// module.exports.STPPacket = STPPacket; // #endregion
// #region === [ exports ] ===
module.exports.KeyExchangePacket = KeyExchangePacket; module.exports.KeyExchangePacket = KeyExchangePacket;
module.exports.ClientsPacket = ClientsPacket; module.exports.ClientsPacket = ClientsPacket;
@ -70,3 +88,5 @@ module.exports.AckPacket = AckPacket;
module.exports.GetClientsPacket = GetClientsPacket; module.exports.GetClientsPacket = GetClientsPacket;
module.exports.reconstructPacket = reconstructPacket; module.exports.reconstructPacket = reconstructPacket;
// #endregion