From 20c998795438b1375b0ea1bb38a1651cde1ff0ef Mon Sep 17 00:00:00 2001 From: purpose233 Date: Sun, 19 May 2019 17:59:38 +0800 Subject: [PATCH] refactor: change the file structure to npm style --- README.md | 4 ++-- src/client.js => bin/client | 11 +++++++---- src/server.js => bin/server | 12 +++++++----- {src => lib}/common/config.js | 0 {src => lib}/common/constant.js | 0 {src => lib}/common/log.js | 0 {src => lib}/common/socket.js | 0 {src => lib}/tcpClient.js | 0 {src => lib}/tcpServer.js | 0 {src => lib}/tunnelServer.js | 0 {src => lib}/udpClient.js | 0 {src => lib}/udpServer.js | 0 package.json | 10 ++++++---- 13 files changed, 22 insertions(+), 15 deletions(-) rename src/client.js => bin/client (64%) rename src/server.js => bin/server (65%) rename {src => lib}/common/config.js (100%) rename {src => lib}/common/constant.js (100%) rename {src => lib}/common/log.js (100%) rename {src => lib}/common/socket.js (100%) rename {src => lib}/tcpClient.js (100%) rename {src => lib}/tcpServer.js (100%) rename {src => lib}/tunnelServer.js (100%) rename {src => lib}/udpClient.js (100%) rename {src => lib}/udpServer.js (100%) diff --git a/README.md b/README.md index 696152f..aa1ef62 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ npm install ## Usage Server side: ``` -node ./src/server.js -c +node ./src/server -c ``` A demo of server config file is shown as follow: ```json @@ -37,7 +37,7 @@ A demo of server config file is shown as follow: Client side: ``` -node ./src/client.js -c +node ./src/client -c ``` A demo of client config file is shown as follow: ```json diff --git a/src/client.js b/bin/client similarity index 64% rename from src/client.js rename to bin/client index 0db3067..72d2d72 100644 --- a/src/client.js +++ b/bin/client @@ -1,8 +1,10 @@ +#!/usr/bin/env node + const program = require('commander'); -const {logConfigError} = require('./common/log'); -const {parseClientConfig} = require('./common/config'); -const {createTcpController} = require('./tcpClient'); -const {createUdpController} = require('./udpClient'); +const {logConfigError} = require('../lib/common/log'); +const {parseClientConfig} = require('../lib/common/config'); +const {createTcpController} = require('../lib/tcpClient'); +const {createUdpController} = require('../lib/udpClient'); program .version('0.0.1') @@ -11,6 +13,7 @@ program const filePath = program.config; const udpTimeout = 10; +const udpBindPortThreshold = 10000; const parseResult = parseClientConfig(filePath); if (typeof parseResult !== 'object') { diff --git a/src/server.js b/bin/server similarity index 65% rename from src/server.js rename to bin/server index 471225f..afadb02 100644 --- a/src/server.js +++ b/bin/server @@ -1,10 +1,12 @@ +#!/usr/bin/env node + const program = require('commander'); const EventEmitter = require('events').EventEmitter; -const {parseServerConfig} = require('./common/config'); -const {logConfigError} = require('./common/log'); -const {createTunnelServer} = require('./tunnelServer'); -const {createTcpProxies} = require('./tcpServer'); -const {createUdpProxies} = require('./udpServer'); +const {parseServerConfig} = require('../lib/common/config'); +const {logConfigError} = require('../lib/common/log'); +const {createTunnelServer} = require('../lib/tunnelServer'); +const {createTcpProxies} = require('../lib/tcpServer'); +const {createUdpProxies} = require('../lib/udpServer'); program .version('0.0.1') diff --git a/src/common/config.js b/lib/common/config.js similarity index 100% rename from src/common/config.js rename to lib/common/config.js diff --git a/src/common/constant.js b/lib/common/constant.js similarity index 100% rename from src/common/constant.js rename to lib/common/constant.js diff --git a/src/common/log.js b/lib/common/log.js similarity index 100% rename from src/common/log.js rename to lib/common/log.js diff --git a/src/common/socket.js b/lib/common/socket.js similarity index 100% rename from src/common/socket.js rename to lib/common/socket.js diff --git a/src/tcpClient.js b/lib/tcpClient.js similarity index 100% rename from src/tcpClient.js rename to lib/tcpClient.js diff --git a/src/tcpServer.js b/lib/tcpServer.js similarity index 100% rename from src/tcpServer.js rename to lib/tcpServer.js diff --git a/src/tunnelServer.js b/lib/tunnelServer.js similarity index 100% rename from src/tunnelServer.js rename to lib/tunnelServer.js diff --git a/src/udpClient.js b/lib/udpClient.js similarity index 100% rename from src/udpClient.js rename to lib/udpClient.js diff --git a/src/udpServer.js b/lib/udpServer.js similarity index 100% rename from src/udpServer.js rename to lib/udpServer.js diff --git a/package.json b/package.json index 3c1fef5..43f26c5 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,16 @@ { "name": "socket-traversal", - "version": "1.0.0", - "description": "", + "version": "0.0.1", + "description": "A tool for UDP/TCP internal network penetration.", "main": "index.js", "directories": { "test": "test" }, - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "bin": { + "st-client": "bin/client", + "st-server": "bin/server" }, + "scripts": {}, "repository": { "type": "git", "url": "git+https://github.com/purpose233/socket-traversal.git"