Skip to content
This repository has been archived by the owner on Apr 3, 2021. It is now read-only.

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
eycorsican committed Mar 17, 2019
1 parent a3814ce commit 61ca15b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
6 changes: 6 additions & 0 deletions proxy/shadowsocks/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ func (h *tcpHandler) Connect(conn core.TCPConn, target net.Addr) error {
log.Fatalf("unexpected nil target")
}

// Connect the relay server.
rc, err := net.Dial("tcp", h.server)
if err != nil {
return errors.New(fmt.Sprintf("dial remote server failed: %v", err))
}
rc = h.cipher.StreamConn(rc)

// Replace with a domain name if target address IP is a fake IP.
host, port, err := net.SplitHostPort(target.String())
if err != nil {
log.Errorf("error when split host port %v", err)
Expand All @@ -77,15 +79,19 @@ func (h *tcpHandler) Connect(conn core.TCPConn, target net.Addr) error {
}
dest := fmt.Sprintf("%s:%s", targetHost, port)

// Write target address.
tgt := sssocks.ParseAddr(dest)
_, err = rc.Write(tgt)
if err != nil {
return fmt.Errorf("send target address failed: %v", err)
}

h.Lock()
h.conns[conn] = rc
h.Unlock()

go h.fetchInput(conn, rc)

log.Infof("new proxy connection for target: %s:%s", target.Network(), dest)
return nil
}
Expand Down
1 change: 1 addition & 0 deletions proxy/shadowsocks/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func (h *udpHandler) DidReceiveTo(conn core.UDPConn, data []byte, addr net.Addr)
}

if ok1 {
// Replace with a domain name if target address IP is a fake IP.
host, port, err := net.SplitHostPort(addr.String())
if err != nil {
log.Errorf("error when split host port %v", err)
Expand Down
6 changes: 5 additions & 1 deletion proxy/socks/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func (h *tcpHandler) Connect(conn core.TCPConn, target net.Addr) error {
if err != nil {
return err
}

// Replace with a domain name if target address IP is a fake IP.
host, port, err := net.SplitHostPort(target.String())
if err != nil {
log.Errorf("error when split host port %v", err)
Expand All @@ -77,7 +79,9 @@ func (h *tcpHandler) Connect(conn core.TCPConn, target net.Addr) error {
}
}
}
c, err := dialer.Dial(target.Network(), fmt.Sprintf("%s:%s", targetHost, port))
dest := fmt.Sprintf("%s:%s", targetHost, port)

c, err := dialer.Dial(target.Network(), dest)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion proxy/socks/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func (h *udpHandler) Connect(conn core.UDPConn, target net.Addr) error {
return h.connectInternal(conn, "")
}

// Replace with a domain name if target address IP is a fake IP.
host, port, err := net.SplitHostPort(target.String())
if err != nil {
log.Errorf("error when split host port %v", err)
Expand All @@ -122,7 +123,9 @@ func (h *udpHandler) Connect(conn core.UDPConn, target net.Addr) error {
}
}
}
return h.connectInternal(conn, fmt.Sprintf("%s:%s", targetHost, port))
dest := fmt.Sprintf("%s:%s", targetHost, port)

return h.connectInternal(conn, dest)
}

func (h *udpHandler) connectInternal(conn core.UDPConn, dest string) error {
Expand Down Expand Up @@ -238,6 +241,7 @@ func (h *udpHandler) DidReceiveTo(conn core.UDPConn, data []byte, addr net.Addr)
}

if ok1 && ok2 {
// Replace with a domain name if target address IP is a fake IP.
host, port, err := net.SplitHostPort(addr.String())
if err != nil {
log.Errorf("error when split host port %v", err)
Expand Down

0 comments on commit 61ca15b

Please sign in to comment.