mirror of
https://github.com/cedar2025/hysteria.git
synced 2025-08-02 07:26:55 +00:00
.github
cmd
docs
pkg
acl
congestion
core
http
pmtud
redirect
relay
sockopt
socks5
tproxy
transport
tun
server.go
tcp.go
udp.go
utils
.gitignore
CHANGELOG.md
Dockerfile
LICENSE.md
README.md
Taskfile.yaml
docker-compose.yaml
go.mod
go.sum
install_server.sh
49 lines
913 B
Go
49 lines
913 B
Go
//go:build gpl
|
|
// +build gpl
|
|
|
|
package tun
|
|
|
|
import (
|
|
"net"
|
|
|
|
"github.com/HyNetwork/hysteria/pkg/utils"
|
|
"github.com/xjasonlyu/tun2socks/v2/core/adapter"
|
|
)
|
|
|
|
func (s *Server) HandleTCP(localConn adapter.TCPConn) {
|
|
go s.handleTCPConn(localConn)
|
|
}
|
|
|
|
func (s *Server) handleTCPConn(localConn adapter.TCPConn) {
|
|
defer localConn.Close()
|
|
|
|
id := localConn.ID()
|
|
remoteAddr := net.TCPAddr{
|
|
IP: net.IP(id.LocalAddress),
|
|
Port: int(id.LocalPort),
|
|
}
|
|
localAddr := net.TCPAddr{
|
|
IP: net.IP(id.RemoteAddress),
|
|
Port: int(id.RemotePort),
|
|
}
|
|
|
|
if s.RequestFunc != nil {
|
|
s.RequestFunc(&localAddr, remoteAddr.String())
|
|
}
|
|
|
|
var err error
|
|
defer func() {
|
|
if s.ErrorFunc != nil && err != nil {
|
|
s.ErrorFunc(&localAddr, remoteAddr.String(), err)
|
|
}
|
|
}()
|
|
|
|
rc, err := s.HyClient.DialTCP(remoteAddr.String())
|
|
if err != nil {
|
|
return
|
|
}
|
|
defer rc.Close()
|
|
|
|
err = utils.PipePairWithTimeout(localConn, rc, s.Timeout)
|
|
}
|