2022-01-18 21:09:36 +08:00
|
|
|
package inner
|
|
|
|
|
|
|
|
import (
|
2023-05-01 21:27:55 +08:00
|
|
|
"errors"
|
|
|
|
"net"
|
|
|
|
|
2022-01-18 21:09:36 +08:00
|
|
|
"github.com/Dreamacro/clash/adapter/inbound"
|
|
|
|
C "github.com/Dreamacro/clash/constant"
|
|
|
|
)
|
|
|
|
|
|
|
|
var tcpIn chan<- C.ConnContext
|
|
|
|
|
|
|
|
func New(in chan<- C.ConnContext) {
|
|
|
|
tcpIn = in
|
|
|
|
}
|
|
|
|
|
2023-05-01 21:27:55 +08:00
|
|
|
func HandleTcp(address string) (conn net.Conn, err error) {
|
|
|
|
if tcpIn == nil {
|
|
|
|
return nil, errors.New("tcp uninitialized")
|
|
|
|
}
|
|
|
|
// executor Parsed
|
2022-01-18 21:09:36 +08:00
|
|
|
conn1, conn2 := net.Pipe()
|
2023-05-01 21:27:55 +08:00
|
|
|
context := inbound.NewInner(conn2, address)
|
2022-01-18 21:09:36 +08:00
|
|
|
tcpIn <- context
|
2023-05-01 21:27:55 +08:00
|
|
|
return conn1, nil
|
2022-01-18 21:09:36 +08:00
|
|
|
}
|