Skip to content

Commit

Permalink
vless: fixed a bug in fallback processing
Browse files Browse the repository at this point in the history
  • Loading branch information
nadoo committed Oct 15, 2020
1 parent d510ea4 commit 13babd9
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 29 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ require (
github.com/xtaci/kcp-go/v5 v5.6.1
golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee
golang.org/x/net v0.0.0-20201010224723-4f7140c49acb // indirect
golang.org/x/sys v0.0.0-20201014080544-cc95f250f6bc // indirect
golang.org/x/tools v0.0.0-20201013201025-64a9e34f3752 // indirect
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211 // indirect
golang.org/x/tools v0.0.0-20201014231627-1610a49f37af // indirect
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect
)

Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ golang.org/x/sys v0.0.0-20200808120158-1030fc2bf1d9/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200916030750-2334cc1a136f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201014080544-cc95f250f6bc h1:HVFDs9bKvTxP6bh1Rj9MCSo+UmafQtI8ZWDPVwVk9g4=
golang.org/x/sys v0.0.0-20201014080544-cc95f250f6bc/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211 h1:9UQO31fZ+0aKQOFldThf7BKPMJTiBfWycGh/u3UoO88=
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand All @@ -177,8 +177,8 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20200425043458-8463f397d07c h1:iHhCR0b26amDCiiO+kBguKZom9aMF+NrFxh9zeKR/XU=
golang.org/x/tools v0.0.0-20200425043458-8463f397d07c/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20200808161706-5bf02b21f123/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20201013201025-64a9e34f3752 h1:2ntEwh02rqo2jSsrYmp4yKHHjh0CbXP3ZtSUetSB+q8=
golang.org/x/tools v0.0.0-20201013201025-64a9e34f3752/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU=
golang.org/x/tools v0.0.0-20201014231627-1610a49f37af h1:VIUWFyOgzG3c0t9KYop5Ybp4m56LupfOnFYX7Ipnz+I=
golang.org/x/tools v0.0.0-20201014231627-1610a49f37af/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
Expand Down
7 changes: 1 addition & 6 deletions proxy/trojan/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ func (s *Trojan) dial(network, addr string) (net.Conn, error) {
// DialUDP connects to the given address via the proxy.
func (s *Trojan) DialUDP(network, addr string) (net.PacketConn, net.Addr, error) {
c, err := s.dial("udp", addr)
if err != nil {
return nil, nil, err
}

pkc := NewPktConn(c, socks.ParseAddr(addr))
// TODO: check the addr in return value
return pkc, nil, nil
return NewPktConn(c, socks.ParseAddr(addr)), nil, err
}
2 changes: 1 addition & 1 deletion proxy/trojan/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (s *Trojan) Serve(c net.Conn) {

cmd, target, err := s.readHeader(io.TeeReader(c, headBuf))
if err != nil {
log.F("[trojan] verify header from %s error: %v", c.RemoteAddr(), err)
// log.F("[trojan] verify header from %s error: %v", c.RemoteAddr(), err)
if s.fallback != "" {
s.serveFallback(c, s.fallback, headBuf)
}
Expand Down
20 changes: 8 additions & 12 deletions proxy/vless/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,23 @@ func (s *VLess) Addr() string {

// Dial connects to the address addr on the network net via the proxy.
func (s *VLess) Dial(network, addr string) (net.Conn, error) {
return s.dial(network, addr)
}

func (s *VLess) dial(network, addr string) (net.Conn, error) {
rc, err := s.dialer.Dial("tcp", s.addr)
if err != nil {
log.F("[vless]: dial to %s error: %s", s.addr, err)
return nil, err
}
return NewClientConn(rc, s.uuid, network, addr)
}

// DialUDP connects to the given address via the proxy.
func (s *VLess) DialUDP(network, addr string) (net.PacketConn, net.Addr, error) {
rc, err := s.dialer.Dial("tcp", s.addr)
if err != nil {
log.F("[vless]: dial to %s error: %s", s.addr, err)
return nil, nil, err
}

c, err := NewClientConn(rc, s.uuid, network, addr)
if err != nil {
return nil, nil, err
}

return NewPktConn(c), nil, nil
c, err := s.dial("udp", addr)
// TODO: check the addr in return value
return NewPktConn(c), nil, err
}

// ClientConn is a vless client connection.
Expand Down
12 changes: 8 additions & 4 deletions proxy/vless/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ func (s *VLess) Serve(c net.Conn) {
headBuf := pool.GetWriteBuffer()
defer pool.PutWriteBuffer(headBuf)

c = NewServerConn(c)

cmd, target, err := s.readHeader(io.TeeReader(c, headBuf))
if err != nil {
log.F("[vless] verify header from %s error: %v", c.RemoteAddr(), err)
// log.F("[vless] verify header from %s error: %v", c.RemoteAddr(), err)
if s.fallback != "" {
s.serveFallback(c, s.fallback, headBuf)
}
return
}

c = NewServerConn(c)

network := "tcp"
dialer := s.proxy.NextDialer(target)

Expand Down Expand Up @@ -232,7 +232,11 @@ func (c *ServerConn) Write(b []byte) (int, error) {
c.sent = true

n, err := c.Conn.Write(buf.Bytes())
return n - 2, err
if n > 2 {
return n - 2, err
}

return 0, err
}

return c.Conn.Write(b)
Expand Down

0 comments on commit 13babd9

Please sign in to comment.