mirror of
https://github.com/cmz0228/hysteria-dev.git
synced 2025-06-16 09:19:51 +00:00

fix: #306, #394, #185, #161 break changes: we won't create or maintain the interface now, so it is user's duty to create the tun interface, for example, with command like ip tuntap add dev hytun mode tun (or maybe we can use songgao/water to keep this behavior unchanged). correspondingly, the "address", "gateway", "mask", "dns", "persist" options in the "tun" config have been removed. in addition, please note xjasonlyu/tun2socks is licensed under GPLv3 and hysteria is licensed under MIT, I don't ensure is it legal to use it as a go mod, but there are too many requests related on it so whatever...
45 lines
880 B
Go
45 lines
880 B
Go
package tun
|
|
|
|
import (
|
|
"github.com/tobyxdd/hysteria/pkg/utils"
|
|
"github.com/xjasonlyu/tun2socks/v2/core/adapter"
|
|
"net"
|
|
)
|
|
|
|
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)
|
|
}
|