UNPKG

@tgsnake/core

Version:

Pure Telegram MTProto library for nodejs

39 lines (38 loc) 1.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TCPPaddedIntermediate = void 0; const platform_node_js_1 = require("../../platform.node.js"); const tcp_js_1 = require("./tcp.js"); class TCPPaddedIntermediate extends tcp_js_1.TCP { constructor() { super(); } async connect(ip, port, proxy, dcId) { await super.connect(ip, port, proxy, dcId); await super.send(platform_node_js_1.Buffer.concat([ platform_node_js_1.Buffer.from('dd', 'hex'), platform_node_js_1.Buffer.from('dd', 'hex'), platform_node_js_1.Buffer.from('dd', 'hex'), platform_node_js_1.Buffer.from('dd', 'hex'), ])); } async send(data) { data = platform_node_js_1.Buffer.concat([ data, platform_node_js_1.Buffer.alloc(platform_node_js_1.Buffer.byteLength(data) % 4), ]); const allocLength = platform_node_js_1.Buffer.alloc(4); allocLength.writeInt32LE(platform_node_js_1.Buffer.byteLength(data), 0); await super.send(platform_node_js_1.Buffer.concat([allocLength, data])); } async recv(_length = 0) { const length = await super.recv(4); if (!length) return; const data = await super.recv(length.readInt32LE(0)); if (!data) return; return data.subarray(0, platform_node_js_1.Buffer.byteLength(data) - (platform_node_js_1.Buffer.byteLength(data) % 4)); } } exports.TCPPaddedIntermediate = TCPPaddedIntermediate;