v5: Remove v2ctl & wv2ray (#488)

* remove v2ctl, wv2ray
* remove v2ctl, wv2ray build scripts
* remove infra/control/main
* remove !confonly flag
* remove ctlcmd package
* remove Confgi.Override func
* move commands package into main
This commit is contained in:
Jebbs 2020-12-04 22:32:55 +08:00 committed by GitHub
parent 9367e9b1f2
commit 7c1ab06206
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
145 changed files with 28 additions and 497 deletions

View File

@ -102,16 +102,6 @@ jobs:
run: |
mkdir -p build_assets
go build -v -o build_assets/v2ray -trimpath -ldflags "-s -w -buildid=" ./main
go build -v -o build_assets/v2ctl -trimpath -ldflags "-s -w -buildid=" -tags confonly ./infra/control/main
- name: Build Windows wv2ray
if: matrix.goos == 'windows'
run: |
echo "::warning ::wv2ray.exe will be removed in v5"
go build -v -o build_assets/wv2ray.exe -trimpath -ldflags "-s -w -H windowsgui -buildid=" ./main
cd ./build_assets || exit 1
mv v2ray v2ray.exe
mv v2ctl v2ctl.exe
- name: Prepare package
run: cp -v ./release/config/*.* ./build_assets

View File

@ -1,5 +1,3 @@
// +build !confonly
package commander
//go:generate go run v2ray.com/core/common/errors/errorgen

View File

@ -1,5 +1,3 @@
// +build !confonly
package commander
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package commander
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package dispatcher
//go:generate go run v2ray.com/core/common/errors/errorgen

View File

@ -1,5 +1,3 @@
// +build !confonly
package dispatcher
//go:generate go run v2ray.com/core/common/errors/errorgen

View File

@ -1,5 +1,3 @@
// +build !confonly
package dispatcher
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package dispatcher
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package dns
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package dns
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package dns
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package dns
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package dns
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package dns
//go:generate go run v2ray.com/core/common/errors/errorgen

View File

@ -1,5 +1,3 @@
// +build !confonly
package dns
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package command
//go:generate go run v2ray.com/core/common/errors/errorgen

View File

@ -1,5 +1,3 @@
// +build !confonly
package log
//go:generate go run v2ray.com/core/common/errors/errorgen

View File

@ -1,5 +1,3 @@
// +build !confonly
package log
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package command
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package reverse
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package reverse
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package reverse
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package reverse
//go:generate go run v2ray.com/core/common/errors/errorgen

View File

@ -1,5 +1,3 @@
// +build !confonly
package router
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package command
//go:generate go run v2ray.com/core/common/errors/errorgen

View File

@ -1,5 +1,3 @@
// +build !confonly
package router
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package router
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package router
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package router
//go:generate go run v2ray.com/core/common/errors/errorgen

View File

@ -1,5 +1,3 @@
// +build !confonly
package stats
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package command
//go:generate go run v2ray.com/core/common/errors/errorgen

View File

@ -1,5 +1,3 @@
// +build !confonly
package stats
import "sync/atomic"

View File

@ -1,5 +1,3 @@
// +build !confonly
package stats
//go:generate go run v2ray.com/core/common/errors/errorgen

View File

@ -1,5 +1,3 @@
// +build !confonly
package net
import (

View File

@ -1,9 +0,0 @@
// +build !windows
package ctlcmd
import "syscall"
func getSysProcAttr() *syscall.SysProcAttr {
return nil
}

View File

@ -1,11 +0,0 @@
// +build windows
package ctlcmd
import "syscall"
func getSysProcAttr() *syscall.SysProcAttr {
return &syscall.SysProcAttr{
HideWindow: true,
}
}

View File

@ -1,50 +0,0 @@
package ctlcmd
import (
"io"
"os"
"os/exec"
"strings"
"v2ray.com/core/common/buf"
"v2ray.com/core/common/platform"
)
//go:generate go run v2ray.com/core/common/errors/errorgen
func Run(args []string, input io.Reader) (buf.MultiBuffer, error) {
v2ctl := platform.GetToolLocation("v2ctl")
if _, err := os.Stat(v2ctl); err != nil {
return nil, newError("v2ctl doesn't exist").Base(err)
}
var errBuffer buf.MultiBufferContainer
var outBuffer buf.MultiBufferContainer
cmd := exec.Command(v2ctl, args...)
cmd.Stderr = &errBuffer
cmd.Stdout = &outBuffer
cmd.SysProcAttr = getSysProcAttr()
if input != nil {
cmd.Stdin = input
}
if err := cmd.Start(); err != nil {
return nil, newError("failed to start v2ctl").Base(err)
}
if err := cmd.Wait(); err != nil {
msg := "failed to execute v2ctl"
if errBuffer.Len() > 0 {
msg += ": \n" + strings.TrimSpace(errBuffer.MultiBuffer.String())
}
return nil, newError(msg).Base(err)
}
// log stderr, info message
if !errBuffer.IsEmpty() {
newError("<v2ctl message> \n", strings.TrimSpace(errBuffer.MultiBuffer.String())).AtInfo().WriteToLog()
}
return outBuffer.MultiBuffer, nil
}

View File

@ -1,9 +0,0 @@
package ctlcmd
import "v2ray.com/core/common/errors"
type errPathObjHolder struct{}
func newError(values ...interface{}) *errors.Error {
return errors.New(values...).WithPathObj(errPathObjHolder{})
}

View File

@ -1,5 +1,3 @@
// +build !confonly
package core
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package core
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package core
import (

View File

@ -2,8 +2,6 @@ package conf
import (
"encoding/json"
"log"
"os"
"strings"
"v2ray.com/core"
@ -35,8 +33,6 @@ var (
"trojan": func() interface{} { return new(TrojanClientConfig) },
"dns": func() interface{} { return new(DNSOutboundConfig) },
}, "protocol", "settings")
ctllog = log.New(os.Stderr, "v2ctl> ", 0)
)
func toProtocolList(s []string) ([]proxyman.KnownProtocols, error) {
@ -368,86 +364,6 @@ func (c *Config) findOutboundTag(tag string) int {
return found
}
// Override method accepts another Config overrides the current attribute
func (c *Config) Override(o *Config, fn string) {
// only process the non-deprecated members
if o.LogConfig != nil {
c.LogConfig = o.LogConfig
}
if o.RouterConfig != nil {
c.RouterConfig = o.RouterConfig
}
if o.DNSConfig != nil {
c.DNSConfig = o.DNSConfig
}
if o.Transport != nil {
c.Transport = o.Transport
}
if o.Policy != nil {
c.Policy = o.Policy
}
if o.API != nil {
c.API = o.API
}
if o.Stats != nil {
c.Stats = o.Stats
}
if o.Reverse != nil {
c.Reverse = o.Reverse
}
// deprecated attrs... keep them for now
if o.InboundConfig != nil {
c.InboundConfig = o.InboundConfig
}
if o.OutboundConfig != nil {
c.OutboundConfig = o.OutboundConfig
}
if o.InboundDetours != nil {
c.InboundDetours = o.InboundDetours
}
if o.OutboundDetours != nil {
c.OutboundDetours = o.OutboundDetours
}
// deprecated attrs
// update the Inbound in slice if the only one in overide config has same tag
if len(o.InboundConfigs) > 0 {
if len(c.InboundConfigs) > 0 && len(o.InboundConfigs) == 1 {
if idx := c.findInboundTag(o.InboundConfigs[0].Tag); idx > -1 {
c.InboundConfigs[idx] = o.InboundConfigs[0]
ctllog.Println("[", fn, "] updated inbound with tag: ", o.InboundConfigs[0].Tag)
} else {
c.InboundConfigs = append(c.InboundConfigs, o.InboundConfigs[0])
ctllog.Println("[", fn, "] appended inbound with tag: ", o.InboundConfigs[0].Tag)
}
} else {
c.InboundConfigs = o.InboundConfigs
}
}
// update the Outbound in slice if the only one in overide config has same tag
if len(o.OutboundConfigs) > 0 {
if len(c.OutboundConfigs) > 0 && len(o.OutboundConfigs) == 1 {
if idx := c.findOutboundTag(o.OutboundConfigs[0].Tag); idx > -1 {
c.OutboundConfigs[idx] = o.OutboundConfigs[0]
ctllog.Println("[", fn, "] updated outbound with tag: ", o.OutboundConfigs[0].Tag)
} else {
if strings.Contains(strings.ToLower(fn), "tail") {
c.OutboundConfigs = append(c.OutboundConfigs, o.OutboundConfigs[0])
ctllog.Println("[", fn, "] appended outbound with tag: ", o.OutboundConfigs[0].Tag)
} else {
c.OutboundConfigs = append(o.OutboundConfigs, c.OutboundConfigs...)
ctllog.Println("[", fn, "] prepended outbound with tag: ", o.OutboundConfigs[0].Tag)
}
}
} else {
c.OutboundConfigs = o.OutboundConfigs
}
}
}
func applyTransportConfig(s *StreamConfig, t *TransportConfig) {
if s.TCPSettings == nil {
s.TCPSettings = t.TCPConfig

View File

@ -6,7 +6,6 @@ import (
"testing"
"github.com/golang/protobuf/proto"
"github.com/google/go-cmp/cmp"
"v2ray.com/core"
"v2ray.com/core/app/dispatcher"
"v2ray.com/core/app/log"
@ -370,80 +369,3 @@ func TestMuxConfig_Build(t *testing.T) {
})
}
}
func TestConfig_Override(t *testing.T) {
tests := []struct {
name string
orig *Config
over *Config
fn string
want *Config
}{
{"combine/empty",
&Config{},
&Config{
LogConfig: &LogConfig{},
RouterConfig: &RouterConfig{},
DNSConfig: &DNSConfig{},
Transport: &TransportConfig{},
Policy: &PolicyConfig{},
API: &APIConfig{},
Stats: &StatsConfig{},
Reverse: &ReverseConfig{},
},
"",
&Config{
LogConfig: &LogConfig{},
RouterConfig: &RouterConfig{},
DNSConfig: &DNSConfig{},
Transport: &TransportConfig{},
Policy: &PolicyConfig{},
API: &APIConfig{},
Stats: &StatsConfig{},
Reverse: &ReverseConfig{},
},
},
{"combine/newattr",
&Config{InboundConfigs: []InboundDetourConfig{{Tag: "old"}}},
&Config{LogConfig: &LogConfig{}}, "",
&Config{LogConfig: &LogConfig{}, InboundConfigs: []InboundDetourConfig{{Tag: "old"}}}},
{"replace/inbounds",
&Config{InboundConfigs: []InboundDetourConfig{{Tag: "pos0"}, {Protocol: "vmess", Tag: "pos1"}}},
&Config{InboundConfigs: []InboundDetourConfig{{Tag: "pos1", Protocol: "kcp"}}},
"",
&Config{InboundConfigs: []InboundDetourConfig{{Tag: "pos0"}, {Tag: "pos1", Protocol: "kcp"}}}},
{"replace/inbounds-replaceall",
&Config{InboundConfigs: []InboundDetourConfig{{Tag: "pos0"}, {Protocol: "vmess", Tag: "pos1"}}},
&Config{InboundConfigs: []InboundDetourConfig{{Tag: "pos1", Protocol: "kcp"}, {Tag: "pos2", Protocol: "kcp"}}},
"",
&Config{InboundConfigs: []InboundDetourConfig{{Tag: "pos1", Protocol: "kcp"}, {Tag: "pos2", Protocol: "kcp"}}}},
{"replace/notag-append",
&Config{InboundConfigs: []InboundDetourConfig{{}, {Protocol: "vmess"}}},
&Config{InboundConfigs: []InboundDetourConfig{{Tag: "pos1", Protocol: "kcp"}}},
"",
&Config{InboundConfigs: []InboundDetourConfig{{}, {Protocol: "vmess"}, {Tag: "pos1", Protocol: "kcp"}}}},
{"replace/outbounds",
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos0"}, {Protocol: "vmess", Tag: "pos1"}}},
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos1", Protocol: "kcp"}}},
"",
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos0"}, {Tag: "pos1", Protocol: "kcp"}}}},
{"replace/outbounds-prepend",
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos0"}, {Protocol: "vmess", Tag: "pos1"}}},
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos1", Protocol: "kcp"}, {Tag: "pos2", Protocol: "kcp"}}},
"config.json",
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos1", Protocol: "kcp"}, {Tag: "pos2", Protocol: "kcp"}}}},
{"replace/outbounds-append",
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos0"}, {Protocol: "vmess", Tag: "pos1"}}},
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos2", Protocol: "kcp"}}},
"config_tail.json",
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos0"}, {Protocol: "vmess", Tag: "pos1"}, {Tag: "pos2", Protocol: "kcp"}}}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.orig.Override(tt.over, tt.fn)
if r := cmp.Diff(tt.orig, tt.want); r != "" {
t.Error(r)
}
})
}
}

View File

@ -1,11 +0,0 @@
package main
import (
_ "v2ray.com/core/commands/all"
"v2ray.com/core/commands/base"
)
func main() {
base.RootCommand.Long = "A tool set for V2Ray."
base.Execute()
}

View File

@ -1,7 +1,7 @@
package api
import (
"v2ray.com/core/commands/base"
"v2ray.com/core/main/commands/base"
)
// CmdAPI calls an API in an V2Ray process

View File

@ -4,10 +4,10 @@ import (
"fmt"
handlerService "v2ray.com/core/app/proxyman/command"
"v2ray.com/core/commands/base"
"v2ray.com/core/common/cmdarg"
"v2ray.com/core/infra/conf"
"v2ray.com/core/infra/conf/serial"
"v2ray.com/core/main/commands/base"
)
var cmdAddInbounds = &base.Command{

View File

@ -4,9 +4,9 @@ import (
"fmt"
handlerService "v2ray.com/core/app/proxyman/command"
"v2ray.com/core/commands/base"
"v2ray.com/core/common/cmdarg"
"v2ray.com/core/infra/conf/serial"
"v2ray.com/core/main/commands/base"
)
var cmdRemoveInbounds = &base.Command{

View File

@ -2,7 +2,7 @@ package api
import (
logService "v2ray.com/core/app/log/command"
"v2ray.com/core/commands/base"
"v2ray.com/core/main/commands/base"
)
var cmdRestartLogger = &base.Command{

View File

@ -4,10 +4,10 @@ import (
"fmt"
handlerService "v2ray.com/core/app/proxyman/command"
"v2ray.com/core/commands/base"
"v2ray.com/core/common/cmdarg"
"v2ray.com/core/infra/conf"
"v2ray.com/core/infra/conf/serial"
"v2ray.com/core/main/commands/base"
)
var cmdAddOutbounds = &base.Command{

View File

@ -4,9 +4,9 @@ import (
"fmt"
handlerService "v2ray.com/core/app/proxyman/command"
"v2ray.com/core/commands/base"
"v2ray.com/core/common/cmdarg"
"v2ray.com/core/infra/conf/serial"
"v2ray.com/core/main/commands/base"
)
var cmdRemoveOutbounds = &base.Command{

View File

@ -8,7 +8,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"
"v2ray.com/core/commands/base"
"v2ray.com/core/main/commands/base"
)
type serviceHandler func(ctx context.Context, conn *grpc.ClientConn, cmd *base.Command, args []string) string

View File

@ -2,7 +2,7 @@ package api
import (
statsService "v2ray.com/core/app/stats/command"
"v2ray.com/core/commands/base"
"v2ray.com/core/main/commands/base"
)
var cmdGetStats = &base.Command{

View File

@ -2,7 +2,7 @@ package api
import (
statsService "v2ray.com/core/app/stats/command"
"v2ray.com/core/commands/base"
"v2ray.com/core/main/commands/base"
)
var cmdQueryStats = &base.Command{

View File

@ -2,7 +2,7 @@ package api
import (
statsService "v2ray.com/core/app/stats/command"
"v2ray.com/core/commands/base"
"v2ray.com/core/main/commands/base"
)
var cmdSysStats = &base.Command{

View File

@ -1,9 +1,9 @@
package all
import (
"v2ray.com/core/commands/all/api"
"v2ray.com/core/commands/all/tls"
"v2ray.com/core/commands/base"
"v2ray.com/core/main/commands/all/api"
"v2ray.com/core/main/commands/all/tls"
"v2ray.com/core/main/commands/base"
)
// go:generate go run v2ray.com/core/common/errors/errorgen

View File

@ -8,8 +8,8 @@ import (
"google.golang.org/protobuf/proto"
"gopkg.in/yaml.v2"
"v2ray.com/core/commands/base"
"v2ray.com/core/infra/conf/serial"
"v2ray.com/core/main/commands/base"
)
var cmdConvert = &base.Command{

View File

@ -6,10 +6,10 @@ import (
"path/filepath"
"strings"
"v2ray.com/core/commands/base"
"v2ray.com/core/common/cmdarg"
"v2ray.com/core/infra/conf/json"
"v2ray.com/core/infra/conf/merge"
"v2ray.com/core/main/commands/base"
)
func mergeConvertToMap(files []string, format string) map[string]interface{} {

View File

@ -1,7 +1,7 @@
package all
import (
"v2ray.com/core/commands/base"
"v2ray.com/core/main/commands/base"
)
var docFormat = &base.Command{

View File

@ -7,9 +7,9 @@ import (
"encoding/base64"
"fmt"
"v2ray.com/core/commands/base"
"v2ray.com/core/common"
"v2ray.com/core/common/platform"
"v2ray.com/core/main/commands/base"
)
var cmdLove = &base.Command{

View File

@ -1,7 +1,7 @@
package all
import (
"v2ray.com/core/commands/base"
"v2ray.com/core/main/commands/base"
)
var docMerge = &base.Command{

View File

@ -8,10 +8,10 @@ import (
"strings"
"time"
"v2ray.com/core/commands/base"
"v2ray.com/core/common"
"v2ray.com/core/common/protocol/tls/cert"
"v2ray.com/core/common/task"
"v2ray.com/core/main/commands/base"
)
// cmdCert is the tls cert command

View File

@ -6,7 +6,7 @@ import (
"fmt"
"net"
"v2ray.com/core/commands/base"
"v2ray.com/core/main/commands/base"
)
// cmdPing is the tls ping command

View File

@ -1,7 +1,7 @@
package tls
import (
"v2ray.com/core/commands/base"
"v2ray.com/core/main/commands/base"
)
// CmdTLS holds all tls sub commands

View File

@ -3,8 +3,8 @@ package all
import (
"fmt"
"v2ray.com/core/commands/base"
"v2ray.com/core/common/uuid"
"v2ray.com/core/main/commands/base"
)
var cmdUUID = &base.Command{

View File

@ -4,7 +4,7 @@ import (
"os"
"github.com/v2fly/VSign/signerVerify"
"v2ray.com/core/commands/base"
"v2ray.com/core/main/commands/base"
)
var cmdVerify = &base.Command{

View File

@ -11,9 +11,9 @@ import (
"syscall"
"v2ray.com/core"
"v2ray.com/core/commands/base"
"v2ray.com/core/common/cmdarg"
"v2ray.com/core/common/platform"
"v2ray.com/core/main/commands/base"
)
// CmdRun runs V2Ray with config

View File

@ -5,7 +5,7 @@ import (
"log"
"v2ray.com/core"
"v2ray.com/core/commands/base"
"v2ray.com/core/main/commands/base"
)
// CmdTest tests config files

View File

@ -4,7 +4,7 @@ import (
"fmt"
"v2ray.com/core"
"v2ray.com/core/commands/base"
"v2ray.com/core/main/commands/base"
)
// CmdVersion prints V2Ray Versions

View File

@ -62,5 +62,5 @@ import (
_ "v2ray.com/core/main/yaml"
// commands
_ "v2ray.com/core/commands/all"
_ "v2ray.com/core/main/commands/all"
)

View File

@ -1,8 +1,8 @@
package main
import (
"v2ray.com/core/commands/base"
"v2ray.com/core/main/commands"
"v2ray.com/core/main/commands/base"
_ "v2ray.com/core/main/distro/all"
)

View File

@ -1,5 +1,3 @@
// +build !confonly
// Package blackhole is an outbound handler that blocks all connections.
package blackhole

View File

@ -1,5 +1,3 @@
// +build !confonly
package dns
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package dokodemo
//go:generate go run v2ray.com/core/common/errors/errorgen

View File

@ -1,5 +1,3 @@
// +build !confonly
package freedom
//go:generate go run v2ray.com/core/common/errors/errorgen

View File

@ -1,5 +1,3 @@
// +build !confonly
package http
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package http
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package shadowsocks
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package shadowsocks
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package shadowsocks
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package socks
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package socks
import "v2ray.com/core/common/protocol"

View File

@ -1,5 +1,3 @@
// +build !confonly
package socks
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package socks
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package trojan
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package trojan
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package trojan
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package vless
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package encoding
import (

View File

@ -1,5 +1,3 @@
// +build !confonly
package encoding
//go:generate go run v2ray.com/core/common/errors/errorgen

View File

@ -1,3 +1 @@
// +build !confonly
package inbound

View File

@ -1,5 +1,3 @@
// +build !confonly
package inbound
//go:generate go run v2ray.com/core/common/errors/errorgen

View File

@ -1,3 +1 @@
// +build !confonly
package outbound

View File

@ -1,5 +1,3 @@
// +build !confonly
package outbound
//go:generate go run v2ray.com/core/common/errors/errorgen

View File

@ -1,5 +1,3 @@
// +build !confonly
package vless
import (

Some files were not shown because too many files have changed in this diff Show More