const net = require("net"); const { PomeloClient } = require("./lib/boot"); const { Stick, MaxBodyLen } = require("./lib/stick"); const { Message } = require("./Message"); const proxyList = require("./config/proxy.json"); console.log(proxyList); proxyList.forEach((config) => { proxy(config); }); function proxy(config) { console.log(config); const host = config.host; const port = config.port; const srcHost = config.srcHost; const srcPort = config.srcPort; const server = net.createServer((socket) => { console.log("listening " + host + ":" + port); const pomelo = new PomeloClient(); const stick = new Stick(1024); stick.setMaxBodyLen(MaxBodyLen["32K"]); const connectBuffer = []; let isReady = false; pomelo.init({ host: srcHost, port: srcPort, log: true }, () => { isReady = true; connectBuffer.forEach((data) => { stick.putData(data); }); }, (route, body)=>{ repPush(route, body); }); socket.on("connect", () => { console.log("connect"); }); socket.on("error", (error) => { console.log(error); }); socket.on("close", () => { console.log("close"); }); socket.on("drop", () => { console.log("drop"); }); socket.on("data", (data) => { if (isReady) { stick.putData(data); } else { connectBuffer.push(data); } }); stick.onBody((msgId, data) => { const msg = JSON.parse(data); console.log(msgId, msg); const account = "6516_2006_0xef59f6cc4d190a0ae576c46d4583e92b61174340"; switch (msgId) { case Message.TYPE_REQUEST: pomelo.request(msg.route, msg.params, (data) => { repRequest(msg.serial, data); }); break; case Message.TYPE_NOTIFY: pomelo.notify(data.toString(), { uid: account }); break; } }); const repRequest = (serial, data) => { data.serial = serial; socket.write(stick.makeData(Message.TYPE_RESPONSE, JSON.stringify(data))); }; const repPush = (route, data) => { socket.write(stick.makeData(Message.TYPE_PUSH, JSON.stringify(data))); }; }); server.listen(port, host); } // const testAccounts = [ // "6516_2006_0xef59f6cc4d190a0ae576c46d4583e92b61174340", // "6513_2006_FcZnmeGSoxGFQy1Zr6Lfr2o7dRoGcEYE", // "6513_2006_DAmSOj6LKh1jd45DlydwUm7g8iW4KjOv", // ]; // testAccounts.forEach((account) => { // const pomelo = new PomeloClient(); // pomelo.init( // { // host: "192.168.100.173", // port: 3999, // log: true, // }, // () => { // pomelo.request( // "gate.gateHandler.queryEntry", // { uid: account }, // (data) => { // console.log(data); // } // ); // } // ); // });