1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 09:36:34 -05:00

v5: Remove v2ctl & wv2ray (rebased from 7c1ab06206)

This commit is contained in:
Jebbs 2020-12-04 22:32:55 +08:00 committed by Shelikhoo
parent 557b0c3353
commit b05a469488
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316
139 changed files with 100 additions and 773 deletions

View File

@ -109,16 +109,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: Download geo files
run: |

View File

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

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package commander
import (

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package commander
import (

View File

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

View File

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

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package dispatcher
import (

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package dispatcher
import (

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package dns
import (
@ -214,7 +211,7 @@ L:
case dnsmessage.TypeAAAA:
ans, err := parser.AAAAResource()
if err != nil {
newError("failed to parse AAAA record for domain: ", ah.Name).Base(err).WriteToLog()
newError("failed to parse A record for domain: ", ah.Name).Base(err).WriteToLog()
break L
}
ipRecord.IP = append(ipRecord.IP, net.IPAddress(ans.AAAA[:]))

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package dns
import (

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package dns
import (

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package dns
import (
@ -71,7 +68,7 @@ func NewServer(dest net.Destination, dispatcher routing.Dispatcher) (Server, err
}
// NewClient creates a DNS client managing a name server with client IP, domain rules and expected IPs.
func NewClient(ctx context.Context, ns *NameServer, clientIP net.IP, container router.GeoIPMatcherContainer, matcherInfos *[]*DomainMatcherInfo, updateDomainRule func(strmatcher.Matcher, int, []*DomainMatcherInfo) error) (*Client, error) {
func NewClient(ctx context.Context, ns *NameServer, clientIP net.IP, container router.GeoIPMatcherContainer, matcherInfos *[]DomainMatcherInfo, updateDomainRule func(strmatcher.Matcher, int, []DomainMatcherInfo) error) (*Client, error) {
client := &Client{}
err := core.RequireFeatures(ctx, func(dispatcher routing.Dispatcher) error {
@ -93,7 +90,7 @@ func NewClient(ctx context.Context, ns *NameServer, clientIP net.IP, container r
// https://github.com/v2fly/v2ray-core/issues/529
// https://github.com/v2fly/v2ray-core/issues/719
for i := 0; i < len(localTLDsAndDotlessDomains); i++ {
*matcherInfos = append(*matcherInfos, &DomainMatcherInfo{
*matcherInfos = append(*matcherInfos, DomainMatcherInfo{
clientIdx: uint16(0),
domainRuleIdx: uint16(0),
})

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package dns
import (
@ -33,7 +30,7 @@ import (
// thus most of the DOH implementation is copied from udpns.go
type DoHNameServer struct {
sync.RWMutex
ips map[string]*record
ips map[string]record
pub *pubsub.Service
cleanup *task.Periodic
reqID uint32
@ -113,7 +110,7 @@ func NewDoHLocalNameServer(url *url.URL) *DoHNameServer {
func baseDOHNameServer(url *url.URL, prefix string) *DoHNameServer {
s := &DoHNameServer{
ips: make(map[string]*record),
ips: make(map[string]record),
pub: pubsub.NewService(),
name: prefix + "//" + url.Host,
dohURL: url.String(),
@ -157,7 +154,7 @@ func (s *DoHNameServer) Cleanup() error {
}
if len(s.ips) == 0 {
s.ips = make(map[string]*record)
s.ips = make(map[string]record)
}
return nil
@ -167,10 +164,7 @@ func (s *DoHNameServer) updateIP(req *dnsRequest, ipRec *IPRecord) {
elapsed := time.Since(req.start)
s.Lock()
rec, found := s.ips[req.domain]
if !found {
rec = &record{}
}
rec := s.ips[req.domain]
updated := false
switch req.reqType {
@ -180,7 +174,7 @@ func (s *DoHNameServer) updateIP(req *dnsRequest, ipRec *IPRecord) {
updated = true
}
case dnsmessage.TypeAAAA:
addr := make([]net.Address, 0, len(ipRec.IP))
addr := make([]net.Address, 0)
for _, ip := range ipRec.IP {
if len(ip.IP()) == net.IPv6len {
addr = append(addr, ip)
@ -299,30 +293,30 @@ func (s *DoHNameServer) findIPsForDomain(domain string, option dns_feature.IPOpt
return nil, errRecordNotFound
}
var err4 error
var err6 error
var ips []net.Address
var ip6 []net.Address
if option.IPv4Enable {
ips, err4 = record.A.getIPs()
var lastErr error
if option.IPv6Enable && record.AAAA != nil && record.AAAA.RCode == dnsmessage.RCodeSuccess {
aaaa, err := record.AAAA.getIPs()
if err != nil {
lastErr = err
}
ips = append(ips, aaaa...)
}
if option.IPv6Enable {
ip6, err6 = record.AAAA.getIPs()
ips = append(ips, ip6...)
if option.IPv4Enable && record.A != nil && record.A.RCode == dnsmessage.RCodeSuccess {
a, err := record.A.getIPs()
if err != nil {
lastErr = err
}
ips = append(ips, a...)
}
if len(ips) > 0 {
return toNetIP(ips)
}
if err4 != nil {
return nil, err4
}
if err6 != nil {
return nil, err6
if lastErr != nil {
return nil, lastErr
}
if (option.IPv4Enable && record.A != nil) || (option.IPv6Enable && record.AAAA != nil) {

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package dns
import (
@ -29,9 +26,9 @@ import (
type ClassicNameServer struct {
sync.RWMutex
name string
address *net.Destination
ips map[string]*record
requests map[uint16]*dnsRequest
address net.Destination
ips map[string]record
requests map[uint16]dnsRequest
pub *pubsub.Service
udpServer *udp.Dispatcher
cleanup *task.Periodic
@ -46,9 +43,9 @@ func NewClassicNameServer(address net.Destination, dispatcher routing.Dispatcher
}
s := &ClassicNameServer{
address: &address,
ips: make(map[string]*record),
requests: make(map[uint16]*dnsRequest),
address: address,
ips: make(map[string]record),
requests: make(map[uint16]dnsRequest),
pub: pubsub.NewService(),
name: strings.ToUpper(address.String()),
}
@ -85,7 +82,6 @@ func (s *ClassicNameServer) Cleanup() error {
}
if record.A == nil && record.AAAA == nil {
newError(s.name, " cleanup ", domain).AtDebug().WriteToLog()
delete(s.ips, domain)
} else {
s.ips[domain] = record
@ -93,7 +89,7 @@ func (s *ClassicNameServer) Cleanup() error {
}
if len(s.ips) == 0 {
s.ips = make(map[string]*record)
s.ips = make(map[string]record)
}
for id, req := range s.requests {
@ -103,7 +99,7 @@ func (s *ClassicNameServer) Cleanup() error {
}
if len(s.requests) == 0 {
s.requests = make(map[uint16]*dnsRequest)
s.requests = make(map[uint16]dnsRequest)
}
return nil
@ -141,17 +137,15 @@ func (s *ClassicNameServer) HandleResponse(ctx context.Context, packet *udp_prot
elapsed := time.Since(req.start)
newError(s.name, " got answer: ", req.domain, " ", req.reqType, " -> ", ipRec.IP, " ", elapsed).AtInfo().WriteToLog()
if len(req.domain) > 0 && (rec.A != nil || rec.AAAA != nil) {
s.updateIP(req.domain, &rec)
s.updateIP(req.domain, rec)
}
}
func (s *ClassicNameServer) updateIP(domain string, newRec *record) {
func (s *ClassicNameServer) updateIP(domain string, newRec record) {
s.Lock()
rec, found := s.ips[domain]
if !found {
rec = &record{}
}
newError(s.name, " updating IP records for domain:", domain).AtDebug().WriteToLog()
rec := s.ips[domain]
updated := false
if isNewer(rec.A, newRec.A) {
@ -164,7 +158,6 @@ func (s *ClassicNameServer) updateIP(domain string, newRec *record) {
}
if updated {
newError(s.name, " updating IP records for domain:", domain).AtDebug().WriteToLog()
s.ips[domain] = rec
}
if newRec.A != nil {
@ -187,7 +180,7 @@ func (s *ClassicNameServer) addPendingRequest(req *dnsRequest) {
id := req.msg.ID
req.expire = time.Now().Add(time.Second * 8)
s.requests[id] = req
s.requests[id] = *req
}
func (s *ClassicNameServer) sendQuery(ctx context.Context, domain string, clientIP net.IP, option dns_feature.IPOption) {
@ -205,7 +198,7 @@ func (s *ClassicNameServer) sendQuery(ctx context.Context, domain string, client
udpCtx = session.ContextWithContent(udpCtx, &session.Content{
Protocol: "dns",
})
s.udpServer.Dispatch(udpCtx, *s.address, b)
s.udpServer.Dispatch(udpCtx, s.address, b)
}
}
@ -218,30 +211,30 @@ func (s *ClassicNameServer) findIPsForDomain(domain string, option dns_feature.I
return nil, errRecordNotFound
}
var err4 error
var err6 error
var ips []net.Address
var ip6 []net.Address
var lastErr error
if option.IPv4Enable {
ips, err4 = record.A.getIPs()
a, err := record.A.getIPs()
if err != nil {
lastErr = err
}
ips = append(ips, a...)
}
if option.IPv6Enable {
ip6, err6 = record.AAAA.getIPs()
ips = append(ips, ip6...)
aaaa, err := record.AAAA.getIPs()
if err != nil {
lastErr = err
}
ips = append(ips, aaaa...)
}
if len(ips) > 0 {
return toNetIP(ips)
}
if err4 != nil {
return nil, err4
}
if err6 != nil {
return nil, err6
if lastErr != nil {
return nil, lastErr
}
return nil, dns_feature.ErrEmptyResponse

View File

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

View File

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

View File

@ -1,11 +1,6 @@
//go:build !confonly
// +build !confonly
package log
import (
"sync"
"github.com/v2fly/v2ray-core/v4/common"
"github.com/v2fly/v2ray-core/v4/common/log"
)
@ -18,24 +13,16 @@ type HandlerCreator func(LogType, HandlerCreatorOptions) (log.Handler, error)
var handlerCreatorMap = make(map[LogType]HandlerCreator)
var handlerCreatorMapLock = &sync.RWMutex{}
func RegisterHandlerCreator(logType LogType, f HandlerCreator) error {
if f == nil {
return newError("nil HandlerCreator")
}
handlerCreatorMapLock.Lock()
defer handlerCreatorMapLock.Unlock()
handlerCreatorMap[logType] = f
return nil
}
func createHandler(logType LogType, options HandlerCreatorOptions) (log.Handler, error) {
handlerCreatorMapLock.RLock()
defer handlerCreatorMapLock.RUnlock()
creator, found := handlerCreatorMap[logType]
if !found {
return nil, newError("unable to create log handler for ", logType)

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package command
import (

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package reverse
import (

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package reverse
import (

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package reverse
import (
@ -155,7 +152,7 @@ func (p *StaticMuxPicker) PickAvailable() (*mux.ClientWorker, error) {
return nil, newError("empty worker list")
}
minIdx := -1
var minIdx = -1
var minConn uint32 = 9999
for i, w := range p.workers {
if w.draining {

View File

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

View File

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

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package router
import (

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package router
import (
@ -62,7 +59,7 @@ func (m *GeoIPMatcher) Init(cidrs []*CIDR) error {
m.ip6 = make([]ipv6, 0, ip6Count)
m.prefix6 = make([]uint8, 0, ip6Count)
for _, cidr := range cidrList {
for _, cidr := range cidrs {
ip := cidr.Ip
prefix := uint8(cidr.Prefix)
switch len(ip) {

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package router
import (

View File

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

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package stats
import (

View File

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

View File

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

View File

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

View File

@ -1,43 +0,0 @@
package all
import (
"flag"
"fmt"
"io/ioutil"
"github.com/v2fly/v2ray-core/v4/commands/base"
v2tls "github.com/v2fly/v2ray-core/v4/transport/internet/tls"
)
type CertificateChainHashCommand struct{}
func (c CertificateChainHashCommand) Name() string {
return "certChainHash"
}
func (c CertificateChainHashCommand) Description() base.Command {
return base.Command{
Short: "Calculate TLS certificates hash.",
UsageLine: "v2ctl certChainHash --cert <cert.pem Calculate TLS certificate chain hash.",
}
}
func (c CertificateChainHashCommand) Execute(args []string) error {
fs := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
cert := fs.String("cert", "fullchain.pem", "The file path of the certificates chain")
if err := fs.Parse(args); err != nil {
return err
}
certContent, err := ioutil.ReadFile(*cert)
if err != nil {
return err
}
certChainHashB64 := v2tls.CalculatePEMCertChainSHA256Hash(certContent)
fmt.Println(certChainHashB64)
return nil
}
func init() {
// Do not release tool before v5's refactor
// common.Must(RegisterCommand(&CertificateChainHashCommand{}))
}

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package net
import (

View File

@ -1,12 +0,0 @@
//go:build windows
// +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"
"github.com/v2fly/v2ray-core/v4/common/buf"
"github.com/v2fly/v2ray-core/v4/common/platform"
)
//go:generate go run github.com/v2fly/v2ray-core/v4/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 "github.com/v2fly/v2ray-core/v4/common/errors"
type errPathObjHolder struct{}
func newError(values ...interface{}) *errors.Error {
return errors.New(values...).WithPathObj(errPathObjHolder{})
}

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package core
import (

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package core
import (

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package core
import (

View File

@ -2,8 +2,6 @@ package conf
import (
"encoding/json"
"log"
"os"
"strings"
core "github.com/v2fly/v2ray-core/v4"
@ -37,8 +35,6 @@ var (
"dns": func() interface{} { return new(DNSOutboundConfig) },
"loopback": func() interface{} { return new(LoopbackConfig) },
}, "protocol", "settings")
ctllog = log.New(os.Stderr, "v2ctl> ", 0)
)
func toProtocolList(s []string) ([]proxyman.KnownProtocols, error) {
@ -381,98 +377,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
}
if o.FakeDNS != nil {
c.FakeDNS = o.FakeDNS
}
if o.BrowserForwarder != nil {
c.BrowserForwarder = o.BrowserForwarder
}
if o.Observatory != nil {
c.Observatory = o.Observatory
}
// 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"
core "github.com/v2fly/v2ray-core/v4"
"github.com/v2fly/v2ray-core/v4/app/dispatcher"
@ -371,95 +370,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 (
_ "github.com/v2fly/v2ray-core/v4/commands/all"
"github.com/v2fly/v2ray-core/v4/commands/base"
)
func main() {
base.RootCommand.Long = "A tool set for V2Ray."
base.Execute()
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@ import (
"strings"
"time"
"github.com/v2fly/v2ray-core/v4/commands/base"
"github.com/v2fly/v2ray-core/v4/main/commands/base"
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"
)

View File

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

View File

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

View File

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

View File

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

View File

@ -7,8 +7,8 @@ import (
"os"
"strings"
"github.com/v2fly/v2ray-core/v4/commands/base"
"github.com/v2fly/v2ray-core/v4/infra/conf/serial"
"github.com/v2fly/v2ray-core/v4/main/commands/base"
"gopkg.in/yaml.v2"
)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,7 +7,7 @@ import (
"fmt"
"net"
"github.com/v2fly/v2ray-core/v4/commands/base"
"github.com/v2fly/v2ray-core/v4/main/commands/base"
v2tls "github.com/v2fly/v2ray-core/v4/transport/internet/tls"
)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -80,5 +80,5 @@ import (
_ "github.com/v2fly/v2ray-core/v4/main/yaml"
// commands
_ "github.com/v2fly/v2ray-core/v4/commands/all"
_ "github.com/v2fly/v2ray-core/v4/main/commands/all"
)

View File

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

View File

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

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package dns
import (

View File

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

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package freedom
//go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen
@ -67,7 +64,7 @@ func (h *Handler) resolveIP(ctx context.Context, domain string, localAddr net.Ad
newError("DNS client doesn't implement ClientWithIPOption")
}
lookupFunc := h.dns.LookupIP
var lookupFunc = h.dns.LookupIP
if h.config.DomainStrategy == Config_USE_IP4 || (localAddr != nil && localAddr.Family().IsIPv4()) {
if lookupIPv4, ok := h.dns.(dns.IPv4Lookup); ok {
lookupFunc = lookupIPv4.LookupIPv4

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package http
import (

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package http
import (

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package shadowsocks
import (

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package shadowsocks
import (
@ -40,6 +37,7 @@ func ReadTCPSession(user *protocol.MemoryUser, reader io.Reader) (*protocol.Requ
behaviorSeed := crc32.ChecksumIEEE(hashkdf.Sum(nil))
drainer, err := drain.NewBehaviorSeedLimitedDrainer(int64(behaviorSeed), 16+38, 3266, 64)
if err != nil {
return nil, nil, newError("failed to initialize drainer").Base(err)
}
@ -140,6 +138,7 @@ func ReadTCPResponse(user *protocol.MemoryUser, reader io.Reader) (buf.Reader, e
behaviorSeed := crc32.ChecksumIEEE(hashkdf.Sum(nil))
drainer, err := drain.NewBehaviorSeedLimitedDrainer(int64(behaviorSeed), 16+38, 3266, 64)
if err != nil {
return nil, newError("failed to initialize drainer").Base(err)
}

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package shadowsocks
import (

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package socks
import (

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package socks
import "github.com/v2fly/v2ray-core/v4/common/protocol"

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package socks
import (

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package socks
import (

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package trojan
import (

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package trojan
import (

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package trojan
import (

View File

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

View File

@ -1,4 +1 @@
//go:build !confonly
// +build !confonly
package inbound

View File

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

View File

@ -1,4 +1 @@
//go:build !confonly
// +build !confonly
package outbound

View File

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

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package vless
import (

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package inbound
// GetDefaultValue returns default settings of DefaultConfig.

View File

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

View File

@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly
package outbound
import (

View File

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

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