From c1f91567ad53f2d4c53646bbc7a8400ea2a5eb22 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Wed, 12 Oct 2016 16:46:02 +0200 Subject: [PATCH] refactor shell --- shell/point/config.go => config.go | 2 +- shell/point/config_json.go => config_json.go | 2 +- shell/point/config_json_test.go => config_json_test.go | 4 ++-- shell/point/inbound_detour.go => inbound_detour.go | 2 +- .../inbound_detour_always.go => inbound_detour_always.go | 2 +- .../inbound_detour_dynamic.go => inbound_detour_dynamic.go | 2 +- {shell/point/main => main}/main.go | 7 +++---- {shell/point/main => main}/main_test.go | 0 testing/scenarios/server_env.go | 2 +- tools/build/go.go | 2 +- shell/point/point.go => v2ray.go | 6 +----- 11 files changed, 13 insertions(+), 18 deletions(-) rename shell/point/config.go => config.go (99%) rename shell/point/config_json.go => config_json.go (99%) rename shell/point/config_json_test.go => config_json_test.go (97%) rename shell/point/inbound_detour.go => inbound_detour.go (91%) rename shell/point/inbound_detour_always.go => inbound_detour_always.go (99%) rename shell/point/inbound_detour_dynamic.go => inbound_detour_dynamic.go (99%) rename {shell/point/main => main}/main.go (94%) rename {shell/point/main => main}/main_test.go (100%) rename shell/point/point.go => v2ray.go (95%) diff --git a/shell/point/config.go b/config.go similarity index 99% rename from shell/point/config.go rename to config.go index 8adb17da..5f15a1b3 100644 --- a/shell/point/config.go +++ b/config.go @@ -1,4 +1,4 @@ -package point +package core import ( "io" diff --git a/shell/point/config_json.go b/config_json.go similarity index 99% rename from shell/point/config_json.go rename to config_json.go index f0f0a88f..23327bd3 100644 --- a/shell/point/config_json.go +++ b/config_json.go @@ -1,6 +1,6 @@ // +build json -package point +package core import ( "encoding/json" diff --git a/shell/point/config_json_test.go b/config_json_test.go similarity index 97% rename from shell/point/config_json_test.go rename to config_json_test.go index e4086a76..bd4518c9 100644 --- a/shell/point/config_json_test.go +++ b/config_json_test.go @@ -1,6 +1,6 @@ // +build json -package point_test +package core_test import ( "encoding/json" @@ -9,7 +9,7 @@ import ( "path/filepath" "testing" - . "v2ray.com/core/shell/point" + . "v2ray.com/core" "v2ray.com/core/testing/assert" ) diff --git a/shell/point/inbound_detour.go b/inbound_detour.go similarity index 91% rename from shell/point/inbound_detour.go rename to inbound_detour.go index 81179c31..9d5642f4 100644 --- a/shell/point/inbound_detour.go +++ b/inbound_detour.go @@ -1,4 +1,4 @@ -package point +package core import ( "v2ray.com/core/proxy" diff --git a/shell/point/inbound_detour_always.go b/inbound_detour_always.go similarity index 99% rename from shell/point/inbound_detour_always.go rename to inbound_detour_always.go index 0181c10c..90866fc8 100644 --- a/shell/point/inbound_detour_always.go +++ b/inbound_detour_always.go @@ -1,4 +1,4 @@ -package point +package core import ( "v2ray.com/core/app" diff --git a/shell/point/inbound_detour_dynamic.go b/inbound_detour_dynamic.go similarity index 99% rename from shell/point/inbound_detour_dynamic.go rename to inbound_detour_dynamic.go index 7ab6d3b1..0a64559d 100644 --- a/shell/point/inbound_detour_dynamic.go +++ b/inbound_detour_dynamic.go @@ -1,4 +1,4 @@ -package point +package core import ( "sync" diff --git a/shell/point/main/main.go b/main/main.go similarity index 94% rename from shell/point/main/main.go rename to main/main.go index 35eefaae..dbb27199 100644 --- a/shell/point/main/main.go +++ b/main/main.go @@ -11,7 +11,6 @@ import ( "v2ray.com/core" "v2ray.com/core/common/log" - "v2ray.com/core/shell/point" // The following are necessary as they register handlers in their init functions. _ "v2ray.com/core/proxy/blackhole" @@ -49,7 +48,7 @@ func init() { flag.StringVar(&configFile, "config", defaultConfigFile, "Config file for this Point server.") } -func startV2Ray() *point.Point { +func startV2Ray() *core.Point { if len(configFile) == 0 { log.Error("Config file is not set.") return nil @@ -67,13 +66,13 @@ func startV2Ray() *point.Point { defer file.Close() configInput = file } - config, err := point.LoadConfig(configInput) + config, err := core.LoadConfig(configInput) if err != nil { log.Error("Failed to read config file (", configFile, "): ", configFile, err) return nil } - vPoint, err := point.NewPoint(config) + vPoint, err := core.NewPoint(config) if err != nil { log.Error("Failed to create Point server: ", err) return nil diff --git a/shell/point/main/main_test.go b/main/main_test.go similarity index 100% rename from shell/point/main/main_test.go rename to main/main_test.go diff --git a/testing/scenarios/server_env.go b/testing/scenarios/server_env.go index 8c8c1fdf..31e0f476 100644 --- a/testing/scenarios/server_env.go +++ b/testing/scenarios/server_env.go @@ -33,7 +33,7 @@ func GetTestBinaryPath() string { } func GetSourcePath() string { - return filepath.Join("v2ray.com", "core", "shell", "point", "main") + return filepath.Join("v2ray.com", "core", "main") } func TestFile(filename string) string { diff --git a/tools/build/go.go b/tools/build/go.go index 150e6f96..67221a78 100644 --- a/tools/build/go.go +++ b/tools/build/go.go @@ -14,7 +14,7 @@ func buildV2Ray(targetFile string, version string, goOS GoOS, goArch GoArch) err today := fmt.Sprintf("%04d%02d%02d", year, int(month), day) ldFlags = ldFlags + " -X v2ray.com/core.version=" + version + " -X v2ray.com/core.build=" + today } - cmd := exec.Command("go", "build", "-tags", "json", "-o", targetFile, "-compiler", "gc", "-ldflags", ldFlags, "v2ray.com/core/shell/point/main") + cmd := exec.Command("go", "build", "-tags", "json", "-o", targetFile, "-compiler", "gc", "-ldflags", ldFlags, "v2ray.com/core/main") cmd.Env = append(cmd.Env, "GOOS="+string(goOS), "GOARCH="+string(goArch)) cmd.Env = append(cmd.Env, os.Environ()...) output, err := cmd.CombinedOutput() diff --git a/shell/point/point.go b/v2ray.go similarity index 95% rename from shell/point/point.go rename to v2ray.go index b09e498b..47528acc 100644 --- a/shell/point/point.go +++ b/v2ray.go @@ -1,8 +1,4 @@ -// Package point is a shell of V2Ray to run on various of systems. -// Point server is a full functionality proxying system. It consists of an inbound and an outbound -// connection, as well as any number of inbound and outbound detours. It provides a way internally -// to route network packets. -package point +package core import ( "v2ray.com/core/app"