refactor a bit more
This commit is contained in:
+2
-29
@@ -1,33 +1,5 @@
|
|||||||
import { swap_endianness_u32, swap_endianness_u16, u16_swap } from "./utils.js";
|
import { swap_endianness_u32, swap_endianness_u16, u16_swap } from "./utils.js";
|
||||||
export const Commands = {
|
import { Commands, CommandsByValue } from "./datatypes.js";
|
||||||
Close: 0xf1f0,
|
|
||||||
LanSearchExt: 0xf132,
|
|
||||||
LanSearch: 0xf130,
|
|
||||||
P2PAlive: 0xf1e0,
|
|
||||||
P2PAliveAck: 0xf1e1,
|
|
||||||
Hello: 0xf100,
|
|
||||||
P2pRdy: 0xf142,
|
|
||||||
P2pReq: 0xf120,
|
|
||||||
LstReq: 0xf167,
|
|
||||||
DrwAck: 0xf1d1,
|
|
||||||
Drw: 0xf1d0,
|
|
||||||
|
|
||||||
// From CSession_CtrlPkt_Proc, incomplete
|
|
||||||
PunchTo: 0xf140,
|
|
||||||
PunchPkt: 0xf141,
|
|
||||||
HelloAck: 0xf101,
|
|
||||||
RlyTo: 0xf102,
|
|
||||||
DevLgnAck: 0xf111,
|
|
||||||
P2PReqAck: 0xf121,
|
|
||||||
ListenReqAck: 0xf169,
|
|
||||||
RlyHelloAck: 0xf170, // always
|
|
||||||
RlyHelloAck2: 0xf171, // if len >1??
|
|
||||||
};
|
|
||||||
|
|
||||||
export const CommandsByValue = Object.keys(Commands).reduce((acc, cur) => {
|
|
||||||
acc[Commands[cur]] = cur;
|
|
||||||
return acc;
|
|
||||||
}, {});
|
|
||||||
|
|
||||||
const writeCommand2 = (command, buf) => {
|
const writeCommand2 = (command, buf) => {
|
||||||
buf.writeByteArray([(command & 0xff00) >> 8, command & 0xff]);
|
buf.writeByteArray([(command & 0xff00) >> 8, command & 0xff]);
|
||||||
@@ -37,6 +9,7 @@ const writeCommand4 = (command, buf) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const XqBytesDec = (inoutbuf, buflen, rotate) => {
|
export const XqBytesDec = (inoutbuf, buflen, rotate) => {
|
||||||
|
// only rotation is different
|
||||||
let new_buf = new Uint8Array(buflen);
|
let new_buf = new Uint8Array(buflen);
|
||||||
new_buf.fill(0x1);
|
new_buf.fill(0x1);
|
||||||
for (let i = 0; i < buflen; i++) {
|
for (let i = 0; i < buflen; i++) {
|
||||||
|
|||||||
+1
-6
@@ -1,5 +1,5 @@
|
|||||||
import { sock } from "./server.js";
|
import { sock } from "./server.js";
|
||||||
import { Commands, CommandsByValue } from "./func_replacements.js";
|
import { ControlCommands, Commands, CommandsByValue } from "./datatypes.js";
|
||||||
import { createWriteStream } from "node:fs";
|
import { createWriteStream } from "node:fs";
|
||||||
import { SendUsrAck, SendUsrChk, create_P2pRdy } from "./impl.js";
|
import { SendUsrAck, SendUsrChk, create_P2pRdy } from "./impl.js";
|
||||||
|
|
||||||
@@ -97,11 +97,6 @@ const deal_with_data = (dv: DataView) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const ControlCommands = {
|
|
||||||
ConnectUser: 0x2010,
|
|
||||||
ConnectUserAck: 0x2011,
|
|
||||||
};
|
|
||||||
|
|
||||||
const makeDrwAck = (dv: DataView): DataView => {
|
const makeDrwAck = (dv: DataView): DataView => {
|
||||||
const pkt_id = dv.add(6).readU16();
|
const pkt_id = dv.add(6).readU16();
|
||||||
const m_stream = dv.add(5).readU8(); // data = 1, control = 0
|
const m_stream = dv.add(5).readU8(); // data = 1, control = 0
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import "./shim.ts";
|
import "./shim.ts";
|
||||||
|
|
||||||
import { Commands, XqBytesEnc } from "./func_replacements.js";
|
import { XqBytesEnc } from "./func_replacements.js";
|
||||||
|
import { Commands } from "./datatypes.js";
|
||||||
import { u16_swap } from "./utils.js";
|
import { u16_swap } from "./utils.js";
|
||||||
|
|
||||||
const str2byte = (s: string): number[] => {
|
const str2byte = (s: string): number[] => {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import dgram from "node:dgram";
|
import dgram from "node:dgram";
|
||||||
import { create_LanSearch, Commands, CommandsByValue } from "./func_replacements.js";
|
import { create_LanSearch } from "./func_replacements.js";
|
||||||
|
import { Commands, CommandsByValue } from "./datatypes.js";
|
||||||
import { handle_P2PAlive, handle_PunchPkt, handle_P2PRdy, handle_Drw, notImpl, noop } from "./handlers.js";
|
import { handle_P2PAlive, handle_PunchPkt, handle_P2PRdy, handle_Drw, notImpl, noop } from "./handlers.js";
|
||||||
import { hexdump } from "./hexdump.js";
|
import { hexdump } from "./hexdump.js";
|
||||||
|
|
||||||
@@ -54,7 +55,6 @@ const MakeSock = (cb: msgCb, connCb: connCb, options?: opt): sock => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const Handlers: Record<keyof typeof Commands, (sock: sock, dv: DataView) => void> = {
|
const Handlers: Record<keyof typeof Commands, (sock: sock, dv: DataView) => void> = {
|
||||||
// FIXME: keys are 'any' bc import?
|
|
||||||
PunchPkt: handle_PunchPkt,
|
PunchPkt: handle_PunchPkt,
|
||||||
|
|
||||||
Close: notImpl,
|
Close: notImpl,
|
||||||
|
|||||||
Reference in New Issue
Block a user