Chore: merge branch 'with-tun' into plus-pro

This commit is contained in:
yaling888
2022-05-07 04:17:03 +08:00
6 changed files with 78 additions and 56 deletions

View File

@@ -39,8 +39,8 @@ var (
// default timeout for UDP session
udpTimeout = 60 * time.Second
// MitmOutbound mitm proxy adapter
MitmOutbound C.ProxyAdapter
// mitmOutbound mitm proxy adapter
mitmOutbound C.ProxyAdapter
)
func init() {
@@ -97,6 +97,11 @@ func SetMode(m TunnelMode) {
mode = m
}
// SetMitmOutbound set the MITM outbound
func SetMitmOutbound(outbound C.ProxyAdapter) {
mitmOutbound = outbound
}
// Rewrites return all rewrites
func Rewrites() C.RewriteRule {
return rewrites
@@ -307,9 +312,11 @@ func handleTCPConn(connCtx C.ConnContext) {
ctx, cancel := context.WithTimeout(context.Background(), C.DefaultTCPTimeout)
defer cancel()
if MitmOutbound != nil && metadata.Type != C.MITM {
if remoteConn, err1 := MitmOutbound.DialContext(ctx, metadata); err1 == nil {
if mitmOutbound != nil && metadata.Type != C.MITM {
if remoteConn, err1 := mitmOutbound.DialContext(ctx, metadata); err1 == nil {
remoteConn = statistic.NewSniffing(remoteConn, metadata, nil)
defer func(remoteConn C.Conn) {
_ = remoteConn.Close()
}(remoteConn)
@@ -334,7 +341,11 @@ func handleTCPConn(connCtx C.ConnContext) {
}
return
}
remoteConn = statistic.NewTCPTracker(remoteConn, statistic.DefaultManager, metadata, rule)
if remoteConn.Chains().Last() != "REJECT" {
remoteConn = statistic.NewTCPTracker(remoteConn, statistic.DefaultManager, metadata, rule)
}
defer func(remoteConn C.Conn) {
_ = remoteConn.Close()
}(remoteConn)