mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-18 14:50:45 +08:00
add go-tun2socks code
This commit is contained in:
26
proxy/echo/tcp.go
Normal file
26
proxy/echo/tcp.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package echo
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
|
||||
"github.com/xjasonlyu/tun2socks/core"
|
||||
)
|
||||
|
||||
// An echo proxy, do nothing but echo back data to the sender, the handler was
|
||||
// created for testing purposes, it may causes issues when more than one clients
|
||||
// are connecting the handler simultaneously.
|
||||
type tcpHandler struct{}
|
||||
|
||||
func NewTCPHandler() core.TCPConnHandler {
|
||||
return &tcpHandler{}
|
||||
}
|
||||
|
||||
func (h *tcpHandler) echoBack(conn net.Conn) {
|
||||
io.Copy(conn, conn)
|
||||
}
|
||||
|
||||
func (h *tcpHandler) Handle(conn net.Conn, target *net.TCPAddr) error {
|
||||
go h.echoBack(conn)
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user