Skip to content

Commit

Permalink
v5: Remove v2ctl & wv2ray (rebased from 7c1ab06)
Browse files Browse the repository at this point in the history
  • Loading branch information
qjebbs authored and xiaokangwang committed Sep 4, 2021
1 parent 557b0c3 commit b05a469
Show file tree
Hide file tree
Showing 139 changed files with 100 additions and 773 deletions.
10 changes: 0 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
3 changes: 0 additions & 3 deletions app/commander/commander.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly

package commander

//go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen
Expand Down
3 changes: 0 additions & 3 deletions app/commander/outbound.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly

package commander

import (
Expand Down
3 changes: 0 additions & 3 deletions app/commander/service.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly

package commander

import (
Expand Down
3 changes: 0 additions & 3 deletions app/dispatcher/default.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly

package dispatcher

//go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen
Expand Down
3 changes: 0 additions & 3 deletions app/dispatcher/dispatcher.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly

package dispatcher

//go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen
3 changes: 0 additions & 3 deletions app/dispatcher/sniffer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly

package dispatcher

import (
Expand Down
3 changes: 0 additions & 3 deletions app/dispatcher/stats.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly

package dispatcher

import (
Expand Down
5 changes: 1 addition & 4 deletions app/dns/dnscommon.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly

package dns

import (
Expand Down Expand Up @@ -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[:]))
Expand Down
3 changes: 0 additions & 3 deletions app/dns/dnscommon_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly

package dns

import (
Expand Down
3 changes: 0 additions & 3 deletions app/dns/hosts.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly

package dns

import (
Expand Down
7 changes: 2 additions & 5 deletions app/dns/nameserver.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly

package dns

import (
Expand Down Expand Up @@ -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 {
Expand All @@ -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),
})
Expand Down
46 changes: 20 additions & 26 deletions app/dns/nameserver_doh.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly

package dns

import (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
61 changes: 27 additions & 34 deletions app/dns/nameserver_udp.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly

package dns

import (
Expand Down Expand Up @@ -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
Expand All @@ -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()),
}
Expand Down Expand Up @@ -85,15 +82,14 @@ 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
}
}

if len(s.ips) == 0 {
s.ips = make(map[string]*record)
s.ips = make(map[string]record)
}

for id, req := range s.requests {
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {
Expand All @@ -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) {
Expand All @@ -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)
}
}

Expand All @@ -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
Expand Down
3 changes: 0 additions & 3 deletions app/log/command/command.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly

package command

//go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen
Expand Down
3 changes: 0 additions & 3 deletions app/log/log.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build !confonly
// +build !confonly

package log

//go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen
Expand Down
Loading

0 comments on commit b05a469

Please sign in to comment.