*Change the communication protocol to require a rpc text "command" before attempting to read as a second listener

This commit is contained in:
Derrick Hammer 2022-07-22 19:58:28 -04:00
parent 76a3010ae6
commit dc5996957e
1 changed files with 11 additions and 1 deletions

View File

@ -246,7 +246,17 @@ export async function start() {
(await getDHT("server")).on("connection", (socket: any) => { (await getDHT("server")).on("connection", (socket: any) => {
socket.rawStream._ondestroy = () => false; socket.rawStream._ondestroy = () => false;
socket.on("data", async (data: any) => {
let isRpc = false;
socket.once("data", async (data: any) => {
if (data === "rpc") {
isRpc = true;
}
});
socket.once("data", async (data: any) => {
if (!isRpc) {
return;
}
let request: RPCRequest; let request: RPCRequest;
try { try {
request = unpack(data) as RPCRequest; request = unpack(data) as RPCRequest;