@ying-tunnel/cli 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # @ying-tunnel/cli
2
+
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 1.0.0 released
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @ying-tunnel/lib@1.0.0
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ ## ying-tunnel 客户端连接程序
2
+
3
+ ### 安装
4
+
5
+ ```bash
6
+ npm i @ying-tunnel/cli -g
7
+ ```
8
+
9
+ ### 使用示例
10
+
11
+ ```bash
12
+ ying-tunnel <要连接的服务ip或域名> <要连接的服务端口> <对应的token配置>
13
+ ```
14
+
15
+ ```bash
16
+ ying-tunnel 127.0.0.1 4948 OxFhMdko9XkAJM37l8RC2
17
+ ```
package/bin/index.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require("../dist/main.js");
package/dist/main.js ADDED
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const cac_1 = __importDefault(require("cac"));
7
+ const lib_1 = require("@ying-tunnel/lib");
8
+ const cli = (0, cac_1.default)();
9
+ cli.command("<host> <port> <token>", "link to tcp socket.").action(init);
10
+ cli.help();
11
+ cli.parse();
12
+ function init(host, port, token) {
13
+ const proxyClient = new lib_1.ProxyClient();
14
+ const tunnelClient = new lib_1.TunnelClient({ host, port: Number(port), token });
15
+ tunnelClient.on("message", (unpackData) => {
16
+ switch (unpackData.header.type) {
17
+ case lib_1.TunnelPackageType.TCPRequestStart:
18
+ const host = unpackData.header.localHost.split(":");
19
+ proxyClient.start(host[0], Number(host[1]), unpackData.header.sign);
20
+ break;
21
+ case lib_1.TunnelPackageType.TCPRequestStream:
22
+ proxyClient.stream(unpackData.header.sign, unpackData.bodyBuffer);
23
+ break;
24
+ case lib_1.TunnelPackageType.TCPRequestClose:
25
+ proxyClient.destroy(unpackData.header.sign);
26
+ break;
27
+ }
28
+ });
29
+ proxyClient.on("data", (sign, chunk) => {
30
+ console.log(`proxyClient: 请求${sign}数据`, chunk.length);
31
+ tunnelClient.sendMessage(lib_1.TunnelPackage.pack({
32
+ type: lib_1.TunnelPackageType.TCPResponseStream,
33
+ sign,
34
+ }, chunk));
35
+ });
36
+ proxyClient.on("close", (sign) => {
37
+ console.log(`proxyClient: 请求${sign}关闭`);
38
+ tunnelClient.sendMessage(lib_1.TunnelPackage.pack({
39
+ type: lib_1.TunnelPackageType.TCPResponseClose,
40
+ sign,
41
+ }));
42
+ });
43
+ }
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@ying-tunnel/cli",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "keywords": [],
6
+ "author": "",
7
+ "license": "ISC",
8
+ "bin": {
9
+ "ying-tunnel": "./bin/index.js"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "nodemonConfig": {
15
+ "watch": [
16
+ "src"
17
+ ],
18
+ "ext": "ts",
19
+ "exec": "ts-node src/main.ts 127.0.0.1 4948 OxFhMdko9XkAJM37l8RC2"
20
+ },
21
+ "dependencies": {
22
+ "cac": "^6.7.14",
23
+ "@ying-tunnel/lib": "^1.0.0"
24
+ },
25
+ "scripts": {
26
+ "dev": "nodemon",
27
+ "build": "tsc"
28
+ }
29
+ }