Chore: throw more detail dial error

This commit is contained in:
gVisor bot 2019-12-05 17:51:21 +08:00
parent 76d93ab450
commit 85285bd1ea
4 changed files with 13 additions and 13 deletions

View file

@ -45,7 +45,7 @@ func (h *Http) DialContext(ctx context.Context, metadata *C.Metadata) (C.Conn, e
} }
if err != nil { if err != nil {
return nil, fmt.Errorf("%s connect error", h.addr) return nil, fmt.Errorf("%s connect error: %w", h.addr, err)
} }
tcpKeepAlive(c) tcpKeepAlive(c)
if err := h.shakeHand(metadata, c); err != nil { if err := h.shakeHand(metadata, c); err != nil {

View file

@ -61,7 +61,7 @@ type v2rayObfsOption struct {
func (ss *ShadowSocks) DialContext(ctx context.Context, metadata *C.Metadata) (C.Conn, error) { func (ss *ShadowSocks) DialContext(ctx context.Context, metadata *C.Metadata) (C.Conn, error) {
c, err := dialContext(ctx, "tcp", ss.server) c, err := dialContext(ctx, "tcp", ss.server)
if err != nil { if err != nil {
return nil, fmt.Errorf("%s connect error: %s", ss.server, err.Error()) return nil, fmt.Errorf("%s connect error: %w", ss.server, err)
} }
tcpKeepAlive(c) tcpKeepAlive(c)
switch ss.obfsMode { switch ss.obfsMode {
@ -74,7 +74,7 @@ func (ss *ShadowSocks) DialContext(ctx context.Context, metadata *C.Metadata) (C
var err error var err error
c, err = v2rayObfs.NewV2rayObfs(c, ss.v2rayOption) c, err = v2rayObfs.NewV2rayObfs(c, ss.v2rayOption)
if err != nil { if err != nil {
return nil, fmt.Errorf("%s connect error: %s", ss.server, err.Error()) return nil, fmt.Errorf("%s connect error: %w", ss.server, err)
} }
} }
c = ss.cipher.StreamConn(c) c = ss.cipher.StreamConn(c)
@ -95,7 +95,7 @@ func (ss *ShadowSocks) DialUDP(metadata *C.Metadata) (C.PacketConn, net.Addr, er
targetAddr := socks5.ParseAddr(metadata.RemoteAddress()) targetAddr := socks5.ParseAddr(metadata.RemoteAddress())
if targetAddr == nil { if targetAddr == nil {
return nil, nil, fmt.Errorf("parse address error: %v:%v", metadata.String(), metadata.DstPort) return nil, nil, fmt.Errorf("parse address %s error: %s", metadata.String(), metadata.DstPort)
} }
pc = ss.cipher.PacketConn(pc) pc = ss.cipher.PacketConn(pc)
@ -114,7 +114,7 @@ func NewShadowSocks(option ShadowSocksOption) (*ShadowSocks, error) {
password := option.Password password := option.Password
ciph, err := core.PickCipher(cipher, nil, password) ciph, err := core.PickCipher(cipher, nil, password)
if err != nil { if err != nil {
return nil, fmt.Errorf("ss %s initialize error: %s", server, err.Error()) return nil, fmt.Errorf("ss %s initialize error: %w", server, err)
} }
var v2rayOption *v2rayObfs.Option var v2rayOption *v2rayObfs.Option
@ -136,7 +136,7 @@ func NewShadowSocks(option ShadowSocksOption) (*ShadowSocks, error) {
if option.Plugin == "obfs" { if option.Plugin == "obfs" {
opts := simpleObfsOption{Host: "bing.com"} opts := simpleObfsOption{Host: "bing.com"}
if err := decoder.Decode(option.PluginOpts, &opts); err != nil { if err := decoder.Decode(option.PluginOpts, &opts); err != nil {
return nil, fmt.Errorf("ss %s initialize obfs error: %s", server, err.Error()) return nil, fmt.Errorf("ss %s initialize obfs error: %w", server, err)
} }
if opts.Mode != "tls" && opts.Mode != "http" { if opts.Mode != "tls" && opts.Mode != "http" {
@ -147,7 +147,7 @@ func NewShadowSocks(option ShadowSocksOption) (*ShadowSocks, error) {
} else if option.Plugin == "v2ray-plugin" { } else if option.Plugin == "v2ray-plugin" {
opts := v2rayObfsOption{Host: "bing.com", Mux: true} opts := v2rayObfsOption{Host: "bing.com", Mux: true}
if err := decoder.Decode(option.PluginOpts, &opts); err != nil { if err := decoder.Decode(option.PluginOpts, &opts); err != nil {
return nil, fmt.Errorf("ss %s initialize v2ray-plugin error: %s", server, err.Error()) return nil, fmt.Errorf("ss %s initialize v2ray-plugin error: %w", server, err)
} }
if opts.Mode != "websocket" { if opts.Mode != "websocket" {

View file

@ -30,7 +30,7 @@ type SnellOption struct {
func (s *Snell) DialContext(ctx context.Context, metadata *C.Metadata) (C.Conn, error) { func (s *Snell) DialContext(ctx context.Context, metadata *C.Metadata) (C.Conn, error) {
c, err := dialContext(ctx, "tcp", s.server) c, err := dialContext(ctx, "tcp", s.server)
if err != nil { if err != nil {
return nil, fmt.Errorf("%s connect error: %s", s.server, err.Error()) return nil, fmt.Errorf("%s connect error: %w", s.server, err)
} }
tcpKeepAlive(c) tcpKeepAlive(c)
switch s.obfsOption.Mode { switch s.obfsOption.Mode {
@ -53,7 +53,7 @@ func NewSnell(option SnellOption) (*Snell, error) {
decoder := structure.NewDecoder(structure.Option{TagName: "obfs", WeaklyTypedInput: true}) decoder := structure.NewDecoder(structure.Option{TagName: "obfs", WeaklyTypedInput: true})
obfsOption := &simpleObfsOption{Host: "bing.com"} obfsOption := &simpleObfsOption{Host: "bing.com"}
if err := decoder.Decode(option.ObfsOpts, obfsOption); err != nil { if err := decoder.Decode(option.ObfsOpts, obfsOption); err != nil {
return nil, fmt.Errorf("snell %s initialize obfs error: %s", server, err.Error()) return nil, fmt.Errorf("snell %s initialize obfs error: %w", server, err)
} }
if obfsOption.Mode != "tls" && obfsOption.Mode != "http" { if obfsOption.Mode != "tls" && obfsOption.Mode != "http" {

View file

@ -44,7 +44,7 @@ func (ss *Socks5) DialContext(ctx context.Context, metadata *C.Metadata) (C.Conn
} }
if err != nil { if err != nil {
return nil, fmt.Errorf("%s connect error", ss.addr) return nil, fmt.Errorf("%s connect error: %w", ss.addr, err)
} }
tcpKeepAlive(c) tcpKeepAlive(c)
var user *socks5.User var user *socks5.User
@ -65,7 +65,7 @@ func (ss *Socks5) DialUDP(metadata *C.Metadata) (_ C.PacketConn, _ net.Addr, err
defer cancel() defer cancel()
c, err := dialContext(ctx, "tcp", ss.addr) c, err := dialContext(ctx, "tcp", ss.addr)
if err != nil { if err != nil {
err = fmt.Errorf("%s connect error", ss.addr) err = fmt.Errorf("%s connect error: %w", ss.addr, err)
return return
} }
@ -92,7 +92,7 @@ func (ss *Socks5) DialUDP(metadata *C.Metadata) (_ C.PacketConn, _ net.Addr, err
bindAddr, err := socks5.ClientHandshake(c, serializesSocksAddr(metadata), socks5.CmdUDPAssociate, user) bindAddr, err := socks5.ClientHandshake(c, serializesSocksAddr(metadata), socks5.CmdUDPAssociate, user)
if err != nil { if err != nil {
err = fmt.Errorf("%v client hanshake error", err) err = fmt.Errorf("client hanshake error: %w", err)
return return
} }
@ -103,7 +103,7 @@ func (ss *Socks5) DialUDP(metadata *C.Metadata) (_ C.PacketConn, _ net.Addr, err
targetAddr := socks5.ParseAddr(metadata.RemoteAddress()) targetAddr := socks5.ParseAddr(metadata.RemoteAddress())
if targetAddr == nil { if targetAddr == nil {
return nil, nil, fmt.Errorf("parse address error: %v:%v", metadata.String(), metadata.DstPort) return nil, nil, fmt.Errorf("parse address %s error: %s", metadata.String(), metadata.DstPort)
} }
pc, err := net.ListenPacket("udp", "") pc, err := net.ListenPacket("udp", "")