mirror of
https://github.com/cedar2025/hysteria.git
synced 2025-08-11 20:01:49 +00:00
.github
cmd
docs
pkg
acl
auth
congestion
core
faketcp
http
obfs
relay
socks5
tproxy
transport
tun
server.go
server_stub.go
tcp.go
udp.go
utils
.gitignore
ACL.md
ACL.zh.md
CHANGELOG.md
Docker.md
Docker.zh.md
Dockerfile
LICENSE.md
README.md
README.zh.md
docker-compose.yaml
go.mod
go.sum
43 lines
1015 B
Go
43 lines
1015 B
Go
// +build cgo
|
|
|
|
package tun
|
|
|
|
import (
|
|
tun2socks "github.com/eycorsican/go-tun2socks/core"
|
|
"github.com/tobyxdd/hysteria/pkg/utils"
|
|
"net"
|
|
)
|
|
|
|
func (s *Server) Handle(conn net.Conn, target *net.TCPAddr) error {
|
|
if s.RequestFunc != nil {
|
|
s.RequestFunc(conn.LocalAddr(), target.String())
|
|
}
|
|
var closeErr error
|
|
defer func() {
|
|
if s.ErrorFunc != nil && closeErr != nil {
|
|
s.ErrorFunc(conn.LocalAddr(), target.String(), closeErr)
|
|
}
|
|
}()
|
|
rc, err := s.HyClient.DialTCP(target.String())
|
|
if err != nil {
|
|
closeErr = err
|
|
return err
|
|
}
|
|
go s.relayTCP(conn, rc)
|
|
return nil
|
|
}
|
|
|
|
func (s *Server) relayTCP(clientConn, relayConn net.Conn) {
|
|
closeErr := utils.PipePairWithTimeout(relayConn, clientConn, s.Timeout)
|
|
if s.ErrorFunc != nil {
|
|
s.ErrorFunc(clientConn.LocalAddr(), relayConn.RemoteAddr().String(), closeErr)
|
|
}
|
|
relayConn.Close()
|
|
clientConn.Close()
|
|
if closeErr != nil && closeErr.Error() == "deadline exceeded" {
|
|
if clientConn, ok := clientConn.(tun2socks.TCPConn); ok {
|
|
clientConn.Abort()
|
|
}
|
|
}
|
|
}
|