Browse Source

Chore: use mirror.Tunnel

pull/133/head
xjasonlyu 3 years ago
parent
commit
ccf53dcb88
  1. 3
      engine/engine.go
  2. 18
      engine/mirror/tunnel.go
  3. 18
      engine/tunnel.go

3
engine/engine.go

@ -7,6 +7,7 @@ import (
"github.com/xjasonlyu/tun2socks/v2/component/dialer"
"github.com/xjasonlyu/tun2socks/v2/core"
"github.com/xjasonlyu/tun2socks/v2/core/device"
"github.com/xjasonlyu/tun2socks/v2/engine/mirror"
"github.com/xjasonlyu/tun2socks/v2/log"
"github.com/xjasonlyu/tun2socks/v2/proxy"
"github.com/xjasonlyu/tun2socks/v2/restapi"
@ -156,7 +157,7 @@ func netstack(k *Key) (err error) {
if _defaultStack, err = core.CreateStack(&core.Config{
LinkEndpoint: _defaultDevice,
TransportHandler: &fakeTunnel{},
TransportHandler: &mirror.Tunnel{},
ErrorFunc: func(err tcpip.Error) {
log.Warnf("[STACK] %s", err)
},

18
engine/mirror/tunnel.go

@ -0,0 +1,18 @@
package mirror
import (
"github.com/xjasonlyu/tun2socks/v2/core/adapter"
"github.com/xjasonlyu/tun2socks/v2/tunnel"
)
var _ adapter.TransportHandler = (*Tunnel)(nil)
type Tunnel struct{}
func (*Tunnel) HandleTCP(conn adapter.TCPConn) {
tunnel.TCPIn() <- conn
}
func (*Tunnel) HandleUDP(conn adapter.UDPConn) {
tunnel.UDPIn() <- conn
}

18
engine/tunnel.go

@ -1,18 +0,0 @@
package engine
import (
"github.com/xjasonlyu/tun2socks/v2/core/adapter"
"github.com/xjasonlyu/tun2socks/v2/tunnel"
)
var _ adapter.TransportHandler = (*fakeTunnel)(nil)
type fakeTunnel struct{}
func (*fakeTunnel) HandleTCP(conn adapter.TCPConn) {
tunnel.TCPIn() <- conn
}
func (*fakeTunnel) HandleUDP(conn adapter.UDPConn) {
tunnel.UDPIn() <- conn
}
Loading…
Cancel
Save