mihomo/tunnel/connection.go

30 lines
753 B
Go
Raw Normal View History

package tunnel
import (
"io"
"github.com/Dreamacro/clash/adapters/local"
C "github.com/Dreamacro/clash/constant"
)
func (t *Tunnel) handleHTTP(request *adapters.HttpAdapter, proxy C.ProxyAdapter) {
2018-08-11 22:51:30 +08:00
conn := newTrafficTrack(proxy.Conn(), t.traffic)
2018-08-11 22:51:30 +08:00
// Before we unwrap src and/or dst, copy any buffered data.
if wc, ok := request.Conn().(*adapters.PeekedConn); ok && len(wc.Peeked) > 0 {
if _, err := conn.Write(wc.Peeked); err != nil {
return
}
2018-08-11 22:51:30 +08:00
wc.Peeked = nil
}
go io.Copy(request.Conn(), conn)
io.Copy(conn, request.Conn())
}
func (t *Tunnel) handleSOCKS(request *adapters.SocksAdapter, proxy C.ProxyAdapter) {
conn := newTrafficTrack(proxy.Conn(), t.traffic)
go io.Copy(request.Conn(), conn)
io.Copy(conn, request.Conn())
}