diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0f41b5ad6..d242e4b32 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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: | diff --git a/app/commander/commander.go b/app/commander/commander.go index 75d60bf54..569822138 100644 --- a/app/commander/commander.go +++ b/app/commander/commander.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package commander //go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen diff --git a/app/commander/outbound.go b/app/commander/outbound.go index 866d2eac8..638640843 100644 --- a/app/commander/outbound.go +++ b/app/commander/outbound.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package commander import ( diff --git a/app/commander/service.go b/app/commander/service.go index 0cb0a68b5..b34b0a229 100644 --- a/app/commander/service.go +++ b/app/commander/service.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package commander import ( diff --git a/app/dispatcher/default.go b/app/dispatcher/default.go index 5ea8d5bdb..a0bea4cb3 100644 --- a/app/dispatcher/default.go +++ b/app/dispatcher/default.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package dispatcher //go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen diff --git a/app/dispatcher/dispatcher.go b/app/dispatcher/dispatcher.go index 4151a017a..4404aee9b 100644 --- a/app/dispatcher/dispatcher.go +++ b/app/dispatcher/dispatcher.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package dispatcher //go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen diff --git a/app/dispatcher/sniffer.go b/app/dispatcher/sniffer.go index ead159b9d..101e1e46c 100644 --- a/app/dispatcher/sniffer.go +++ b/app/dispatcher/sniffer.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package dispatcher import ( diff --git a/app/dispatcher/stats.go b/app/dispatcher/stats.go index 0a33feba6..33ad54560 100644 --- a/app/dispatcher/stats.go +++ b/app/dispatcher/stats.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package dispatcher import ( diff --git a/app/dns/dnscommon.go b/app/dns/dnscommon.go index 0624a4db0..94200f829 100644 --- a/app/dns/dnscommon.go +++ b/app/dns/dnscommon.go @@ -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[:])) diff --git a/app/dns/dnscommon_test.go b/app/dns/dnscommon_test.go index 21d6ad060..1e195b74a 100644 --- a/app/dns/dnscommon_test.go +++ b/app/dns/dnscommon_test.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package dns import ( diff --git a/app/dns/hosts.go b/app/dns/hosts.go index 0dfc87700..357c7a753 100644 --- a/app/dns/hosts.go +++ b/app/dns/hosts.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package dns import ( diff --git a/app/dns/nameserver.go b/app/dns/nameserver.go index b2adea091..25c8fb951 100644 --- a/app/dns/nameserver.go +++ b/app/dns/nameserver.go @@ -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), }) diff --git a/app/dns/nameserver_doh.go b/app/dns/nameserver_doh.go index ec86884a1..e24f69180 100644 --- a/app/dns/nameserver_doh.go +++ b/app/dns/nameserver_doh.go @@ -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) { diff --git a/app/dns/nameserver_udp.go b/app/dns/nameserver_udp.go index 70c8beab4..3aa4976c1 100644 --- a/app/dns/nameserver_udp.go +++ b/app/dns/nameserver_udp.go @@ -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 diff --git a/app/log/command/command.go b/app/log/command/command.go index 0e7f1b42d..5672fb98c 100644 --- a/app/log/command/command.go +++ b/app/log/command/command.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package command //go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen diff --git a/app/log/log.go b/app/log/log.go index f472a01b4..256feb7fa 100644 --- a/app/log/log.go +++ b/app/log/log.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package log //go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen diff --git a/app/log/log_creator.go b/app/log/log_creator.go index 3fbc5cd46..f8930d6dc 100644 --- a/app/log/log_creator.go +++ b/app/log/log_creator.go @@ -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) diff --git a/app/proxyman/command/command.go b/app/proxyman/command/command.go index cc6d44028..9c590ac51 100644 --- a/app/proxyman/command/command.go +++ b/app/proxyman/command/command.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package command import ( diff --git a/app/reverse/bridge.go b/app/reverse/bridge.go index ba3d06e58..c38bf5af0 100644 --- a/app/reverse/bridge.go +++ b/app/reverse/bridge.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package reverse import ( diff --git a/app/reverse/config.go b/app/reverse/config.go index 28ab2568a..8d6124d78 100644 --- a/app/reverse/config.go +++ b/app/reverse/config.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package reverse import ( diff --git a/app/reverse/portal.go b/app/reverse/portal.go index a32d550cf..5e4236779 100644 --- a/app/reverse/portal.go +++ b/app/reverse/portal.go @@ -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 { diff --git a/app/reverse/reverse.go b/app/reverse/reverse.go index 5dd3e557a..e9c23e33d 100644 --- a/app/reverse/reverse.go +++ b/app/reverse/reverse.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package reverse //go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen diff --git a/app/router/command/command.go b/app/router/command/command.go index ef007bd1d..883e7151b 100644 --- a/app/router/command/command.go +++ b/app/router/command/command.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package command //go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen diff --git a/app/router/condition.go b/app/router/condition.go index 62199807c..859374649 100644 --- a/app/router/condition.go +++ b/app/router/condition.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package router import ( diff --git a/app/router/condition_geoip.go b/app/router/condition_geoip.go index 3392c6ced..bb4964bd7 100644 --- a/app/router/condition_geoip.go +++ b/app/router/condition_geoip.go @@ -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) { diff --git a/app/router/config.go b/app/router/config.go index b083e2fbf..29b2096fe 100644 --- a/app/router/config.go +++ b/app/router/config.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package router import ( diff --git a/app/router/router.go b/app/router/router.go index 2ae3b09f1..0583562ea 100644 --- a/app/router/router.go +++ b/app/router/router.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package router //go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen diff --git a/app/stats/channel.go b/app/stats/channel.go index d12cbcad4..10e4490f7 100644 --- a/app/stats/channel.go +++ b/app/stats/channel.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package stats import ( diff --git a/app/stats/command/command.go b/app/stats/command/command.go index d1e94729a..fc922d91d 100644 --- a/app/stats/command/command.go +++ b/app/stats/command/command.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package command //go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen diff --git a/app/stats/counter.go b/app/stats/counter.go index a6606a9eb..f8373ee78 100644 --- a/app/stats/counter.go +++ b/app/stats/counter.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package stats import "sync/atomic" diff --git a/app/stats/stats.go b/app/stats/stats.go index 26eb6ef68..85ad12318 100644 --- a/app/stats/stats.go +++ b/app/stats/stats.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package stats //go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen diff --git a/commands/all/certchainhash.go b/commands/all/certchainhash.go deleted file mode 100644 index 77939755f..000000000 --- a/commands/all/certchainhash.go +++ /dev/null @@ -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 0 { - msg += ": \n" + strings.TrimSpace(errBuffer.MultiBuffer.String()) - } - return nil, newError(msg).Base(err) - } - - // log stderr, info message - if !errBuffer.IsEmpty() { - newError(" \n", strings.TrimSpace(errBuffer.MultiBuffer.String())).AtInfo().WriteToLog() - } - - return outBuffer.MultiBuffer, nil -} diff --git a/common/platform/ctlcmd/errors.generated.go b/common/platform/ctlcmd/errors.generated.go deleted file mode 100644 index e75e7efcb..000000000 --- a/common/platform/ctlcmd/errors.generated.go +++ /dev/null @@ -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{}) -} diff --git a/config.go b/config.go index 75d19dfce..5aa825944 100644 --- a/config.go +++ b/config.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package core import ( diff --git a/context.go b/context.go index 95c6831a7..f5b00a8c6 100644 --- a/context.go +++ b/context.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package core import ( diff --git a/functions.go b/functions.go index f47aa3edd..88deeaa50 100644 --- a/functions.go +++ b/functions.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package core import ( diff --git a/infra/conf/v2ray.go b/infra/conf/v2ray.go index 72a03bcde..2708aed04 100644 --- a/infra/conf/v2ray.go +++ b/infra/conf/v2ray.go @@ -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 diff --git a/infra/conf/v2ray_test.go b/infra/conf/v2ray_test.go index ce358cfeb..b53465258 100644 --- a/infra/conf/v2ray_test.go +++ b/infra/conf/v2ray_test.go @@ -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) - } - }) - } -} diff --git a/infra/control/main/main.go b/infra/control/main/main.go deleted file mode 100644 index 3b7f4a4ed..000000000 --- a/infra/control/main/main.go +++ /dev/null @@ -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() -} diff --git a/commands/all/api/api.go b/main/commands/all/api/api.go similarity index 88% rename from commands/all/api/api.go rename to main/commands/all/api/api.go index b5ab1c7d4..cd10148bf 100644 --- a/commands/all/api/api.go +++ b/main/commands/all/api/api.go @@ -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 diff --git a/commands/all/api/inbounds_add.go b/main/commands/all/api/inbounds_add.go similarity index 97% rename from commands/all/api/inbounds_add.go rename to main/commands/all/api/inbounds_add.go index 05f5ae11f..6284260ab 100644 --- a/commands/all/api/inbounds_add.go +++ b/main/commands/all/api/inbounds_add.go @@ -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{ diff --git a/commands/all/api/inbounds_remove.go b/main/commands/all/api/inbounds_remove.go similarity index 97% rename from commands/all/api/inbounds_remove.go rename to main/commands/all/api/inbounds_remove.go index 376e6d57a..9fe08d51f 100644 --- a/commands/all/api/inbounds_remove.go +++ b/main/commands/all/api/inbounds_remove.go @@ -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{ diff --git a/commands/all/api/logger_restart.go b/main/commands/all/api/logger_restart.go similarity index 94% rename from commands/all/api/logger_restart.go rename to main/commands/all/api/logger_restart.go index cebdd8254..6a97af095 100644 --- a/commands/all/api/logger_restart.go +++ b/main/commands/all/api/logger_restart.go @@ -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{ diff --git a/commands/all/api/outbounds_add.go b/main/commands/all/api/outbounds_add.go similarity index 97% rename from commands/all/api/outbounds_add.go rename to main/commands/all/api/outbounds_add.go index 6d658f914..17da414ca 100644 --- a/commands/all/api/outbounds_add.go +++ b/main/commands/all/api/outbounds_add.go @@ -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{ diff --git a/commands/all/api/outbounds_remove.go b/main/commands/all/api/outbounds_remove.go similarity index 97% rename from commands/all/api/outbounds_remove.go rename to main/commands/all/api/outbounds_remove.go index ab8eea05e..b95d73787 100644 --- a/commands/all/api/outbounds_remove.go +++ b/main/commands/all/api/outbounds_remove.go @@ -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{ diff --git a/commands/all/api/shared.go b/main/commands/all/api/shared.go similarity index 95% rename from commands/all/api/shared.go rename to main/commands/all/api/shared.go index 5baadff03..8a723b601 100644 --- a/commands/all/api/shared.go +++ b/main/commands/all/api/shared.go @@ -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" ) diff --git a/commands/all/api/stats_get.go b/main/commands/all/api/stats_get.go similarity index 95% rename from commands/all/api/stats_get.go rename to main/commands/all/api/stats_get.go index 22c96de84..48aef9edd 100644 --- a/commands/all/api/stats_get.go +++ b/main/commands/all/api/stats_get.go @@ -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{ diff --git a/commands/all/api/stats_query.go b/main/commands/all/api/stats_query.go similarity index 95% rename from commands/all/api/stats_query.go rename to main/commands/all/api/stats_query.go index ef7056a64..6ee9912c7 100644 --- a/commands/all/api/stats_query.go +++ b/main/commands/all/api/stats_query.go @@ -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{ diff --git a/commands/all/api/stats_sys.go b/main/commands/all/api/stats_sys.go similarity index 93% rename from commands/all/api/stats_sys.go rename to main/commands/all/api/stats_sys.go index 58ef1382e..39f328dc2 100644 --- a/commands/all/api/stats_sys.go +++ b/main/commands/all/api/stats_sys.go @@ -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{ diff --git a/commands/all/commands.go b/main/commands/all/commands.go similarity index 63% rename from commands/all/commands.go rename to main/commands/all/commands.go index 218875456..321557736 100644 --- a/commands/all/commands.go +++ b/main/commands/all/commands.go @@ -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 diff --git a/commands/all/convert.go b/main/commands/all/convert.go similarity index 98% rename from commands/all/convert.go rename to main/commands/all/convert.go index 4c16d925e..d1a4eace0 100644 --- a/commands/all/convert.go +++ b/main/commands/all/convert.go @@ -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" ) diff --git a/commands/all/convert_confs.go b/main/commands/all/convert_confs.go similarity index 98% rename from commands/all/convert_confs.go rename to main/commands/all/convert_confs.go index 8584c9948..be7307ccd 100644 --- a/commands/all/convert_confs.go +++ b/main/commands/all/convert_confs.go @@ -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{} { diff --git a/commands/all/errors.generated.go b/main/commands/all/errors.generated.go similarity index 100% rename from commands/all/errors.generated.go rename to main/commands/all/errors.generated.go diff --git a/commands/all/format_doc.go b/main/commands/all/format_doc.go similarity index 96% rename from commands/all/format_doc.go rename to main/commands/all/format_doc.go index 70bc7c1dd..43441b5ef 100644 --- a/commands/all/format_doc.go +++ b/main/commands/all/format_doc.go @@ -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{ diff --git a/commands/all/love.go b/main/commands/all/love.go similarity index 97% rename from commands/all/love.go rename to main/commands/all/love.go index a7d24b9e3..90a211d42 100644 --- a/commands/all/love.go +++ b/main/commands/all/love.go @@ -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{ diff --git a/commands/all/merge_doc.go b/main/commands/all/merge_doc.go similarity index 97% rename from commands/all/merge_doc.go rename to main/commands/all/merge_doc.go index 4ada22921..ce4c028be 100644 --- a/commands/all/merge_doc.go +++ b/main/commands/all/merge_doc.go @@ -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{ diff --git a/commands/all/tls/cert.go b/main/commands/all/tls/cert.go similarity index 98% rename from commands/all/tls/cert.go rename to main/commands/all/tls/cert.go index ae19a07c8..be7b2b1f0 100644 --- a/commands/all/tls/cert.go +++ b/main/commands/all/tls/cert.go @@ -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 diff --git a/commands/all/tls/ping.go b/main/commands/all/tls/ping.go similarity index 98% rename from commands/all/tls/ping.go rename to main/commands/all/tls/ping.go index ac190cf4d..47c070d1a 100644 --- a/commands/all/tls/ping.go +++ b/main/commands/all/tls/ping.go @@ -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" ) diff --git a/commands/all/tls/tls.go b/main/commands/all/tls/tls.go similarity index 83% rename from commands/all/tls/tls.go rename to main/commands/all/tls/tls.go index 4df0e79f3..8b09e01c5 100644 --- a/commands/all/tls/tls.go +++ b/main/commands/all/tls/tls.go @@ -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 diff --git a/commands/all/uuid.go b/main/commands/all/uuid.go similarity index 85% rename from commands/all/uuid.go rename to main/commands/all/uuid.go index 2caaf0e79..2bf528433 100644 --- a/commands/all/uuid.go +++ b/main/commands/all/uuid.go @@ -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{ diff --git a/commands/all/verify.go b/main/commands/all/verify.go similarity index 95% rename from commands/all/verify.go rename to main/commands/all/verify.go index 696f797df..19db86340 100644 --- a/commands/all/verify.go +++ b/main/commands/all/verify.go @@ -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{ diff --git a/commands/base/command.go b/main/commands/base/command.go similarity index 100% rename from commands/base/command.go rename to main/commands/base/command.go diff --git a/commands/base/env.go b/main/commands/base/env.go similarity index 100% rename from commands/base/env.go rename to main/commands/base/env.go diff --git a/commands/base/execute.go b/main/commands/base/execute.go similarity index 100% rename from commands/base/execute.go rename to main/commands/base/execute.go diff --git a/commands/base/help.go b/main/commands/base/help.go similarity index 100% rename from commands/base/help.go rename to main/commands/base/help.go diff --git a/commands/base/root.go b/main/commands/base/root.go similarity index 100% rename from commands/base/root.go rename to main/commands/base/root.go diff --git a/main/commands/run.go b/main/commands/run.go index 080b38f8e..05be55abe 100644 --- a/main/commands/run.go +++ b/main/commands/run.go @@ -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 diff --git a/main/commands/test.go b/main/commands/test.go index 39b55b06e..75388f0d6 100644 --- a/main/commands/test.go +++ b/main/commands/test.go @@ -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 diff --git a/main/commands/version.go b/main/commands/version.go index 1cd17a59e..627ffe0d6 100644 --- a/main/commands/version.go +++ b/main/commands/version.go @@ -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 diff --git a/main/distro/all/all.go b/main/distro/all/all.go index a8ded332a..15fd76e69 100644 --- a/main/distro/all/all.go +++ b/main/distro/all/all.go @@ -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" ) diff --git a/main/main.go b/main/main.go index df5f37f3a..2b33ebede 100644 --- a/main/main.go +++ b/main/main.go @@ -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" ) diff --git a/proxy/blackhole/blackhole.go b/proxy/blackhole/blackhole.go index 2186ac850..3d4c112ae 100644 --- a/proxy/blackhole/blackhole.go +++ b/proxy/blackhole/blackhole.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - // Package blackhole is an outbound handler that blocks all connections. package blackhole diff --git a/proxy/dns/dns.go b/proxy/dns/dns.go index a323dca9c..16f9e73f7 100644 --- a/proxy/dns/dns.go +++ b/proxy/dns/dns.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package dns import ( diff --git a/proxy/dokodemo/dokodemo.go b/proxy/dokodemo/dokodemo.go index bd61af4bd..cb0fead15 100644 --- a/proxy/dokodemo/dokodemo.go +++ b/proxy/dokodemo/dokodemo.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package dokodemo //go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen diff --git a/proxy/freedom/freedom.go b/proxy/freedom/freedom.go index 7232ce2ff..2d0acfe78 100644 --- a/proxy/freedom/freedom.go +++ b/proxy/freedom/freedom.go @@ -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 diff --git a/proxy/http/client.go b/proxy/http/client.go index 09180addf..1fdd862b9 100644 --- a/proxy/http/client.go +++ b/proxy/http/client.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package http import ( diff --git a/proxy/http/server.go b/proxy/http/server.go index 34e69deab..eb4316c11 100644 --- a/proxy/http/server.go +++ b/proxy/http/server.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package http import ( diff --git a/proxy/shadowsocks/client.go b/proxy/shadowsocks/client.go index 0a3aad407..80d619af7 100644 --- a/proxy/shadowsocks/client.go +++ b/proxy/shadowsocks/client.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package shadowsocks import ( diff --git a/proxy/shadowsocks/protocol.go b/proxy/shadowsocks/protocol.go index 68301ebb7..f806442f9 100644 --- a/proxy/shadowsocks/protocol.go +++ b/proxy/shadowsocks/protocol.go @@ -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) } diff --git a/proxy/shadowsocks/server.go b/proxy/shadowsocks/server.go index 49132ef95..16c938b61 100644 --- a/proxy/shadowsocks/server.go +++ b/proxy/shadowsocks/server.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package shadowsocks import ( diff --git a/proxy/socks/client.go b/proxy/socks/client.go index 00308d481..a9b1f459c 100644 --- a/proxy/socks/client.go +++ b/proxy/socks/client.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package socks import ( diff --git a/proxy/socks/config.go b/proxy/socks/config.go index c723f9aeb..30f51e756 100644 --- a/proxy/socks/config.go +++ b/proxy/socks/config.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package socks import "github.com/v2fly/v2ray-core/v4/common/protocol" diff --git a/proxy/socks/protocol.go b/proxy/socks/protocol.go index a0e942a7f..04cabb9a6 100644 --- a/proxy/socks/protocol.go +++ b/proxy/socks/protocol.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package socks import ( diff --git a/proxy/socks/server.go b/proxy/socks/server.go index ab9dc6235..033dc5d9b 100644 --- a/proxy/socks/server.go +++ b/proxy/socks/server.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package socks import ( diff --git a/proxy/trojan/client.go b/proxy/trojan/client.go index bf23c5cec..c6246e34d 100644 --- a/proxy/trojan/client.go +++ b/proxy/trojan/client.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package trojan import ( diff --git a/proxy/trojan/server.go b/proxy/trojan/server.go index 9c25beb0a..ca61aaa80 100644 --- a/proxy/trojan/server.go +++ b/proxy/trojan/server.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package trojan import ( diff --git a/proxy/trojan/validator.go b/proxy/trojan/validator.go index 7eefeec0d..ad11980c3 100644 --- a/proxy/trojan/validator.go +++ b/proxy/trojan/validator.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package trojan import ( diff --git a/proxy/vless/encoding/encoding.go b/proxy/vless/encoding/encoding.go index 7ec515bbb..7c4ad36df 100644 --- a/proxy/vless/encoding/encoding.go +++ b/proxy/vless/encoding/encoding.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package encoding //go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen diff --git a/proxy/vless/inbound/config.go b/proxy/vless/inbound/config.go index 56e21fd17..71c65bf69 100644 --- a/proxy/vless/inbound/config.go +++ b/proxy/vless/inbound/config.go @@ -1,4 +1 @@ -//go:build !confonly -// +build !confonly - package inbound diff --git a/proxy/vless/inbound/inbound.go b/proxy/vless/inbound/inbound.go index a1cd081f7..ce0dcd8a0 100644 --- a/proxy/vless/inbound/inbound.go +++ b/proxy/vless/inbound/inbound.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package inbound //go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen diff --git a/proxy/vless/outbound/config.go b/proxy/vless/outbound/config.go index 0e6dbf53d..a1e73e066 100644 --- a/proxy/vless/outbound/config.go +++ b/proxy/vless/outbound/config.go @@ -1,4 +1 @@ -//go:build !confonly -// +build !confonly - package outbound diff --git a/proxy/vless/outbound/outbound.go b/proxy/vless/outbound/outbound.go index 7f8bc06d2..a9b6ac52b 100644 --- a/proxy/vless/outbound/outbound.go +++ b/proxy/vless/outbound/outbound.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package outbound //go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen diff --git a/proxy/vless/validator.go b/proxy/vless/validator.go index 3ea1383e1..7e8c29af5 100644 --- a/proxy/vless/validator.go +++ b/proxy/vless/validator.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package vless import ( diff --git a/proxy/vmess/inbound/config.go b/proxy/vmess/inbound/config.go index 62153ed18..e4c5fbb3c 100644 --- a/proxy/vmess/inbound/config.go +++ b/proxy/vmess/inbound/config.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package inbound // GetDefaultValue returns default settings of DefaultConfig. diff --git a/proxy/vmess/inbound/inbound.go b/proxy/vmess/inbound/inbound.go index 70eaa2575..efcab6845 100644 --- a/proxy/vmess/inbound/inbound.go +++ b/proxy/vmess/inbound/inbound.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package inbound //go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen diff --git a/proxy/vmess/outbound/command.go b/proxy/vmess/outbound/command.go index dfff8a0c9..a990a97ee 100644 --- a/proxy/vmess/outbound/command.go +++ b/proxy/vmess/outbound/command.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package outbound import ( diff --git a/proxy/vmess/outbound/outbound.go b/proxy/vmess/outbound/outbound.go index e3b9daf96..c172d9dce 100644 --- a/proxy/vmess/outbound/outbound.go +++ b/proxy/vmess/outbound/outbound.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package outbound //go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen diff --git a/proxy/vmess/validator.go b/proxy/vmess/validator.go index 2b91f9e6f..934a41226 100644 --- a/proxy/vmess/validator.go +++ b/proxy/vmess/validator.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package vmess import ( diff --git a/release/user-package.sh b/release/user-package.sh index 7d544f507..ea9f01542 100755 --- a/release/user-package.sh +++ b/release/user-package.sh @@ -37,12 +37,6 @@ build_v2() { echo ">>> Compile v2ray ..." env CGO_ENABLED=0 go build -o "$TMP"/v2ray"${EXESUFFIX}" -ldflags "$LDFLAGS" ./main - if [[ $GOOS == "windows" ]]; then - env CGO_ENABLED=0 go build -o "$TMP"/wv2ray"${EXESUFFIX}" -ldflags "-H windowsgui $LDFLAGS" ./main - fi - - echo ">>> Compile v2ctl ..." - env CGO_ENABLED=0 go build -o "$TMP"/v2ctl"${EXESUFFIX}" -tags confonly -ldflags "$LDFLAGS" ./infra/control/main } build_dat() { diff --git a/transport/internet/domainsocket/config.go b/transport/internet/domainsocket/config.go index f9555e0c4..3fce8f283 100644 --- a/transport/internet/domainsocket/config.go +++ b/transport/internet/domainsocket/config.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package domainsocket import ( diff --git a/transport/internet/domainsocket/dial.go b/transport/internet/domainsocket/dial.go index 3de624483..314772352 100644 --- a/transport/internet/domainsocket/dial.go +++ b/transport/internet/domainsocket/dial.go @@ -1,5 +1,5 @@ -//go:build !windows && !wasm && !confonly -// +build !windows,!wasm,!confonly +// +build !windows +// +build !wasm package domainsocket diff --git a/transport/internet/domainsocket/listener.go b/transport/internet/domainsocket/listener.go index d4988f49a..e46864de4 100644 --- a/transport/internet/domainsocket/listener.go +++ b/transport/internet/domainsocket/listener.go @@ -1,5 +1,5 @@ -//go:build !windows && !wasm && !confonly -// +build !windows,!wasm,!confonly +// +build !windows +// +build !wasm package domainsocket diff --git a/transport/internet/http/config.go b/transport/internet/http/config.go index 7dc261350..b9ac37d13 100644 --- a/transport/internet/http/config.go +++ b/transport/internet/http/config.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package http import ( diff --git a/transport/internet/http/dialer.go b/transport/internet/http/dialer.go index faf811b29..f31bf9b41 100644 --- a/transport/internet/http/dialer.go +++ b/transport/internet/http/dialer.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package http import ( @@ -10,9 +7,10 @@ import ( "net/url" "sync" + core "github.com/v2fly/v2ray-core/v4" + "golang.org/x/net/http2" - core "github.com/v2fly/v2ray-core/v4" "github.com/v2fly/v2ray-core/v4/common" "github.com/v2fly/v2ray-core/v4/common/buf" "github.com/v2fly/v2ray-core/v4/common/net" @@ -26,24 +24,16 @@ var ( globalDialerAccess sync.Mutex ) -type dialerCanceller func() - -func getHTTPClient(ctx context.Context, dest net.Destination, tlsSettings *tls.Config) (*http.Client, dialerCanceller) { +func getHTTPClient(ctx context.Context, dest net.Destination, tlsSettings *tls.Config) *http.Client { globalDialerAccess.Lock() defer globalDialerAccess.Unlock() - canceller := func() { - globalDialerAccess.Lock() - defer globalDialerAccess.Unlock() - delete(globalDialerMap, dest) - } - if globalDialerMap == nil { globalDialerMap = make(map[net.Destination]*http.Client) } if client, found := globalDialerMap[dest]; found { - return client, canceller + return client } transport := &http2.Transport{ @@ -90,7 +80,7 @@ func getHTTPClient(ctx context.Context, dest net.Destination, tlsSettings *tls.C } globalDialerMap[dest] = client - return client, canceller + return client } // Dial dials a new TCP connection to the given destination. @@ -100,7 +90,7 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me if tlsConfig == nil { return nil, newError("TLS must be enabled for http transport.").AtWarning() } - client, canceller := getHTTPClient(ctx, dest, tlsConfig) + client := getHTTPClient(ctx, dest, tlsConfig) opts := pipe.OptionsFromContext(ctx) preader, pwriter := pipe.New(opts...) @@ -138,7 +128,6 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me response, err := client.Do(request) // nolint: bodyclose if err != nil { - canceller() return nil, newError("failed to dial to ", dest).Base(err).AtWarning() } if response.StatusCode != 200 { diff --git a/transport/internet/http/hub.go b/transport/internet/http/hub.go index 16a40a98c..8f3bab437 100644 --- a/transport/internet/http/hub.go +++ b/transport/internet/http/hub.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package http import ( diff --git a/transport/internet/kcp/config.go b/transport/internet/kcp/config.go index 9e4c3768c..35c89ed77 100644 --- a/transport/internet/kcp/config.go +++ b/transport/internet/kcp/config.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package kcp import ( diff --git a/transport/internet/kcp/connection.go b/transport/internet/kcp/connection.go index 27dcd555d..fd050745a 100644 --- a/transport/internet/kcp/connection.go +++ b/transport/internet/kcp/connection.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package kcp import ( diff --git a/transport/internet/kcp/crypt.go b/transport/internet/kcp/crypt.go index 5379c1884..ae4b24b83 100644 --- a/transport/internet/kcp/crypt.go +++ b/transport/internet/kcp/crypt.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package kcp import ( diff --git a/transport/internet/kcp/dialer.go b/transport/internet/kcp/dialer.go index df42b6904..ab14b8e57 100644 --- a/transport/internet/kcp/dialer.go +++ b/transport/internet/kcp/dialer.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package kcp import ( diff --git a/transport/internet/kcp/io.go b/transport/internet/kcp/io.go index 25d6f1359..11712e348 100644 --- a/transport/internet/kcp/io.go +++ b/transport/internet/kcp/io.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package kcp import ( diff --git a/transport/internet/kcp/listener.go b/transport/internet/kcp/listener.go index 7ce942fed..965664cd8 100644 --- a/transport/internet/kcp/listener.go +++ b/transport/internet/kcp/listener.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package kcp import ( diff --git a/transport/internet/kcp/output.go b/transport/internet/kcp/output.go index 4a8d36c84..dbfb5b3d4 100644 --- a/transport/internet/kcp/output.go +++ b/transport/internet/kcp/output.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package kcp import ( diff --git a/transport/internet/kcp/receiving.go b/transport/internet/kcp/receiving.go index ee3edae83..4779f5790 100644 --- a/transport/internet/kcp/receiving.go +++ b/transport/internet/kcp/receiving.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package kcp import ( diff --git a/transport/internet/kcp/segment.go b/transport/internet/kcp/segment.go index edf33e8f3..847351e50 100644 --- a/transport/internet/kcp/segment.go +++ b/transport/internet/kcp/segment.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package kcp import ( diff --git a/transport/internet/kcp/sending.go b/transport/internet/kcp/sending.go index 47f359f56..1533adbe3 100644 --- a/transport/internet/kcp/sending.go +++ b/transport/internet/kcp/sending.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package kcp import ( diff --git a/transport/internet/quic/config.go b/transport/internet/quic/config.go index 7578284cd..b8c936510 100644 --- a/transport/internet/quic/config.go +++ b/transport/internet/quic/config.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package quic import ( diff --git a/transport/internet/quic/conn.go b/transport/internet/quic/conn.go index b6b5bfacf..9a768776d 100644 --- a/transport/internet/quic/conn.go +++ b/transport/internet/quic/conn.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package quic import ( diff --git a/transport/internet/quic/dialer.go b/transport/internet/quic/dialer.go index fd901f319..df20d1fe6 100644 --- a/transport/internet/quic/dialer.go +++ b/transport/internet/quic/dialer.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package quic import ( diff --git a/transport/internet/quic/hub.go b/transport/internet/quic/hub.go index 088166991..0a67fedab 100644 --- a/transport/internet/quic/hub.go +++ b/transport/internet/quic/hub.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package quic import ( diff --git a/transport/internet/quic/pool.go b/transport/internet/quic/pool.go index 5af56b8b1..683dbc172 100644 --- a/transport/internet/quic/pool.go +++ b/transport/internet/quic/pool.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package quic import ( diff --git a/transport/internet/quic/quic.go b/transport/internet/quic/quic.go index 4898ce0cd..e49124ddc 100644 --- a/transport/internet/quic/quic.go +++ b/transport/internet/quic/quic.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package quic import ( diff --git a/transport/internet/tcp/config.go b/transport/internet/tcp/config.go index ec14e3d1a..929a1bbf5 100644 --- a/transport/internet/tcp/config.go +++ b/transport/internet/tcp/config.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package tcp import ( diff --git a/transport/internet/tcp/dialer.go b/transport/internet/tcp/dialer.go index d01356d80..1a421c350 100644 --- a/transport/internet/tcp/dialer.go +++ b/transport/internet/tcp/dialer.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package tcp import ( diff --git a/transport/internet/tcp/hub.go b/transport/internet/tcp/hub.go index 6e46e1bb8..f88b3b0d9 100644 --- a/transport/internet/tcp/hub.go +++ b/transport/internet/tcp/hub.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package tcp import ( diff --git a/transport/internet/tcp/sockopt_freebsd.go b/transport/internet/tcp/sockopt_freebsd.go index 663b638ca..69c1e9f1f 100644 --- a/transport/internet/tcp/sockopt_freebsd.go +++ b/transport/internet/tcp/sockopt_freebsd.go @@ -1,5 +1,4 @@ -//go:build freebsd && !confonly -// +build freebsd,!confonly +// +build freebsd package tcp diff --git a/transport/internet/tcp/sockopt_linux.go b/transport/internet/tcp/sockopt_linux.go index b7be95dc7..b2ad856ee 100644 --- a/transport/internet/tcp/sockopt_linux.go +++ b/transport/internet/tcp/sockopt_linux.go @@ -1,5 +1,4 @@ -//go:build linux && !confonly -// +build linux,!confonly +// +build linux package tcp diff --git a/transport/internet/tcp/sockopt_other.go b/transport/internet/tcp/sockopt_other.go index 52418c953..28edcb6e7 100644 --- a/transport/internet/tcp/sockopt_other.go +++ b/transport/internet/tcp/sockopt_other.go @@ -1,5 +1,4 @@ -//go:build !linux && !freebsd && !confonly -// +build !linux,!freebsd,!confonly +// +build !linux,!freebsd package tcp diff --git a/transport/internet/tls/config.go b/transport/internet/tls/config.go index 640acac56..68eec8dd1 100644 --- a/transport/internet/tls/config.go +++ b/transport/internet/tls/config.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package tls import ( @@ -36,32 +33,6 @@ func ParseCertificate(c *cert.Certificate) *Certificate { func (c *Config) loadSelfCertPool() (*x509.CertPool, error) { root := x509.NewCertPool() for _, cert := range c.Certificate { - /* Do not treat client certificate authority as a peer certificate authority. - This is designed to prevent a client certificate with a permissive key usage from being used to attacker server. - In next release, the certificate usage will be enforced strictly. - Only a certificate with AUTHORITY_VERIFY usage will be accepted. - */ - if cert.Usage == Certificate_AUTHORITY_VERIFY_CLIENT { - continue - } - if !root.AppendCertsFromPEM(cert.Certificate) { - return nil, newError("failed to append cert").AtWarning() - } - } - return root, nil -} - -func (c *Config) loadSelfCertPoolClientCA() (*x509.CertPool, error) { - root := x509.NewCertPool() - for _, cert := range c.Certificate { - /* Do not treat client certificate authority as a peer certificate authority. - This is designed to prevent a client certificate with a permissive key usage from being used to attacker server. - In next release, the certificate usage will be enforced strictly. - Only a certificate with AUTHORITY_VERIFY usage will be accepted. - */ - if cert.Usage != Certificate_AUTHORITY_VERIFY_CLIENT { - continue - } if !root.AppendCertsFromPEM(cert.Certificate) { return nil, newError("failed to append cert").AtWarning() } @@ -228,11 +199,6 @@ func (c *Config) GetTLSConfig(opts ...Option) *tls.Config { newError("failed to load system root certificate").AtError().Base(err).WriteToLog() } - clientRoot, err := c.loadSelfCertPoolClientCA() - if err != nil { - newError("failed to load client root certificate").AtError().Base(err).WriteToLog() - } - if c == nil { return &tls.Config{ ClientSessionCache: globalSessionCache, @@ -242,6 +208,7 @@ func (c *Config) GetTLSConfig(opts ...Option) *tls.Config { SessionTicketsDisabled: true, } } + config := &tls.Config{ ClientSessionCache: globalSessionCache, RootCAs: root, @@ -249,15 +216,12 @@ func (c *Config) GetTLSConfig(opts ...Option) *tls.Config { NextProtos: c.NextProtocol, SessionTicketsDisabled: !c.EnableSessionResumption, VerifyPeerCertificate: c.verifyPeerCert, - ClientCAs: clientRoot, } for _, opt := range opts { opt(config) } - if c.VerifyClientCertificate { - config.ClientAuth = tls.RequireAndVerifyClientCert - } + config.Certificates = c.BuildCertificates() config.BuildNameToCertificate() diff --git a/transport/internet/tls/config_other.go b/transport/internet/tls/config_other.go index 166306c83..3a46792b6 100644 --- a/transport/internet/tls/config_other.go +++ b/transport/internet/tls/config_other.go @@ -1,5 +1,4 @@ -//go:build !windows && !confonly -// +build !windows,!confonly +// +build !windows package tls @@ -45,15 +44,6 @@ func (c *Config) getCertPool() (*x509.CertPool, error) { return nil, newError("system root").AtWarning().Base(err) } for _, cert := range c.Certificate { - /* Do not treat client certificate authority as a peer certificate authority. - This is designed to prevent a client certificate with a permissive key usage from being used to attacker server. - In next release, the certificate usage will be enforced strictly. - Only a certificate with AUTHORITY_VERIFY usage will be accepted. - */ - if cert.Usage == Certificate_AUTHORITY_VERIFY_CLIENT { - continue - } - if !pool.AppendCertsFromPEM(cert.Certificate) { return nil, newError("append cert to root").AtWarning().Base(err) } diff --git a/transport/internet/tls/config_windows.go b/transport/internet/tls/config_windows.go index 1d6bf04ec..94b247629 100644 --- a/transport/internet/tls/config_windows.go +++ b/transport/internet/tls/config_windows.go @@ -1,5 +1,4 @@ -//go:build windows && !confonly -// +build windows,!confonly +// +build windows package tls diff --git a/transport/internet/tls/tls.go b/transport/internet/tls/tls.go index 35aed72ec..db72d1bd7 100644 --- a/transport/internet/tls/tls.go +++ b/transport/internet/tls/tls.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package tls import ( diff --git a/transport/internet/websocket/config.go b/transport/internet/websocket/config.go index 558d9200f..5345b4684 100644 --- a/transport/internet/websocket/config.go +++ b/transport/internet/websocket/config.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package websocket import ( diff --git a/transport/internet/websocket/connection.go b/transport/internet/websocket/connection.go index 470a5b9ca..81d951b14 100644 --- a/transport/internet/websocket/connection.go +++ b/transport/internet/websocket/connection.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package websocket import ( diff --git a/transport/internet/websocket/dialer.go b/transport/internet/websocket/dialer.go index 76f1cffa5..7d5dd5dcf 100644 --- a/transport/internet/websocket/dialer.go +++ b/transport/internet/websocket/dialer.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package websocket import ( diff --git a/transport/internet/websocket/hub.go b/transport/internet/websocket/hub.go index 5a3ccd7d0..4e83f2360 100644 --- a/transport/internet/websocket/hub.go +++ b/transport/internet/websocket/hub.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package websocket import ( diff --git a/v2ray.go b/v2ray.go index 1ab60e849..ee4f211ed 100644 --- a/v2ray.go +++ b/v2ray.go @@ -1,6 +1,3 @@ -//go:build !confonly -// +build !confonly - package core import (