cleanup punchpkt

This commit is contained in:
DavidVentura
2024-01-31 16:13:20 +01:00
parent c12c432e71
commit 33e7aeaacc
2 changed files with 3 additions and 21 deletions
+1 -11
View File
@@ -1,9 +1,7 @@
import { RemoteInfo } from "node:dgram";
import { Commands, CommandsByValue, ControlCommands } from "./datatypes.js";
import { XqBytesDec } from "./func_replacements.js";
import { hexdump } from "./hexdump.js";
import { parse_PunchPkt, create_P2pRdy, SendListWifi, SendUsrChk, DevSerial } from "./impl.js";
import { create_P2pRdy, SendListWifi, SendUsrChk, DevSerial } from "./impl.js";
import { Session } from "./session.js";
import { u16_swap, u32_swap } from "./utils.js";
@@ -36,19 +34,11 @@ export const handle_P2PRdy = (session: Session, _: DataView) => {
export const makePunchPkt = (dev: DevSerial): DataView => {
const len = dev.prefix.length + dev.suffix.length + 8;
const outbuf = new DataView(new Uint8Array(0x14).buffer); // 8 = serial u64
console.log(len, dev.prefix.length, dev.serialU64, dev.suffix.length);
console.log(dev.prefix, dev.serialU64, dev.suffix);
outbuf.add(0).writeString(dev.prefix);
outbuf.add(4).writeU64(dev.serialU64);
outbuf.add(8 + dev.prefix.length).writeString(dev.suffix);
return create_P2pRdy(outbuf);
};
export const handle_PunchPkt = (session: Session, dv: DataView, rinfo: RemoteInfo) => {
const dev = parse_PunchPkt(dv);
session.eventEmitter.emit("connect", dev.devId, rinfo);
console.log("connect????");
session.send(makePunchPkt(dev));
};
export const createResponseForControlCommand = (session: Session, dv: DataView): DataView[] => {
const start_type = dv.add(8).readU16(); // 0xa11 on control; data starts here on DATA pkt