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 { Commands, CommandsByValue, ControlCommands } from "./datatypes.js";
import { XqBytesDec } from "./func_replacements.js"; import { XqBytesDec } from "./func_replacements.js";
import { hexdump } from "./hexdump.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 { Session } from "./session.js";
import { u16_swap, u32_swap } from "./utils.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 => { export const makePunchPkt = (dev: DevSerial): DataView => {
const len = dev.prefix.length + dev.suffix.length + 8; const len = dev.prefix.length + dev.suffix.length + 8;
const outbuf = new DataView(new Uint8Array(0x14).buffer); // 8 = serial u64 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(0).writeString(dev.prefix);
outbuf.add(4).writeU64(dev.serialU64); outbuf.add(4).writeU64(dev.serialU64);
outbuf.add(8 + dev.prefix.length).writeString(dev.suffix); outbuf.add(8 + dev.prefix.length).writeString(dev.suffix);
return create_P2pRdy(outbuf); 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[] => { export const createResponseForControlCommand = (session: Session, dv: DataView): DataView[] => {
const start_type = dv.add(8).readU16(); // 0xa11 on control; data starts here on DATA pkt const start_type = dv.add(8).readU16(); // 0xa11 on control; data starts here on DATA pkt
+2 -10
View File
@@ -1,15 +1,7 @@
import { createSocket, RemoteInfo } from "node:dgram"; import { createSocket, RemoteInfo } from "node:dgram";
import { create_P2pAlive, DevSerial } from "./impl.js"; import { create_P2pAlive, DevSerial } from "./impl.js";
import { Commands, CommandsByValue } from "./datatypes.js"; import { Commands, CommandsByValue } from "./datatypes.js";
import { import { handle_P2PAlive, handle_P2PRdy, handle_Drw, notImpl, noop, makePunchPkt } from "./handlers.js";
handle_P2PAlive,
handle_PunchPkt,
handle_P2PRdy,
handle_Drw,
notImpl,
noop,
makePunchPkt,
} from "./handlers.js";
import { hexdump } from "./hexdump.js"; import { hexdump } from "./hexdump.js";
import EventEmitter from "node:events"; import EventEmitter from "node:events";
import { SendVideoResolution, SendStartVideo, SendWifiDetails } from "./impl.js"; import { SendVideoResolution, SendStartVideo, SendWifiDetails } from "./impl.js";
@@ -127,7 +119,7 @@ const startVideoStream = (s: Session) => {
}; };
export const Handlers: Record<keyof typeof Commands, PacketHandler> = { export const Handlers: Record<keyof typeof Commands, PacketHandler> = {
PunchPkt: handle_PunchPkt, PunchPkt: notImpl,
P2PAlive: handle_P2PAlive, P2PAlive: handle_P2PAlive,
P2pRdy: handle_P2PRdy, P2pRdy: handle_P2PRdy,
DrwAck: noop, DrwAck: noop,