mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 01:27:03 -05:00
Fix dependency cycle caused by core import in internet package
This commit is contained in:
parent
dd51d32250
commit
5f3851df39
@ -23,6 +23,8 @@ import (
|
||||
_ "github.com/v2fly/v2ray-core/v4/app/router"
|
||||
_ "github.com/v2fly/v2ray-core/v4/app/stats"
|
||||
|
||||
_ "github.com/v2fly/v2ray-core/v4/transport/internet/tagged/taggedimpl"
|
||||
|
||||
// Inbound and outbound proxies.
|
||||
_ "github.com/v2fly/v2ray-core/v4/proxy/blackhole"
|
||||
_ "github.com/v2fly/v2ray-core/v4/proxy/dns"
|
||||
|
@ -2,8 +2,7 @@ package internet
|
||||
|
||||
import (
|
||||
"context"
|
||||
core "github.com/v2fly/v2ray-core/v4"
|
||||
"github.com/v2fly/v2ray-core/v4/features/routing"
|
||||
"github.com/v2fly/v2ray-core/v4/transport/internet/tagged"
|
||||
|
||||
"github.com/v2fly/v2ray-core/v4/common/net"
|
||||
"github.com/v2fly/v2ray-core/v4/common/session"
|
||||
@ -79,28 +78,8 @@ func DialSystem(ctx context.Context, dest net.Destination, sockopt *SocketConfig
|
||||
}
|
||||
|
||||
func DialTaggedOutbound(ctx context.Context, dest net.Destination, tag string) (net.Conn, error) {
|
||||
var dispatcher routing.Dispatcher
|
||||
if err := core.RequireFeatures(ctx, func(dispatcherInstance routing.Dispatcher) {
|
||||
dispatcher = dispatcherInstance
|
||||
}); err != nil {
|
||||
return nil, newError("Required Feature dispatcher not resolved").Base(err)
|
||||
if tagged.Dialer == nil {
|
||||
return nil, newError("tagged dial not enabled")
|
||||
}
|
||||
|
||||
content := new(session.Content)
|
||||
content.SkipDNSResolve = true
|
||||
session.SetForcedOutboundTagToContext(ctx, tag)
|
||||
|
||||
ctx = session.ContextWithContent(ctx, content)
|
||||
|
||||
r, err := dispatcher.Dispatch(ctx, dest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var readerOpt net.ConnectionOption
|
||||
if dest.Network == net.Network_TCP {
|
||||
readerOpt = net.ConnectionOutputMulti(r.Reader)
|
||||
} else {
|
||||
readerOpt = net.ConnectionOutputMultiUDP(r.Reader)
|
||||
}
|
||||
return net.NewConnection(net.ConnectionInputMulti(r.Writer), readerOpt), nil
|
||||
return tagged.Dialer(ctx, dest, tag)
|
||||
}
|
||||
|
10
transport/internet/tagged/tagged.go
Normal file
10
transport/internet/tagged/tagged.go
Normal file
@ -0,0 +1,10 @@
|
||||
package tagged
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/v2fly/v2ray-core/v4/common/net"
|
||||
)
|
||||
|
||||
type DialFunc func(ctx context.Context, dest net.Destination, tag string) (net.Conn, error)
|
||||
|
||||
var Dialer DialFunc
|
41
transport/internet/tagged/taggedimpl/impl.go
Normal file
41
transport/internet/tagged/taggedimpl/impl.go
Normal file
@ -0,0 +1,41 @@
|
||||
package taggedimpl
|
||||
|
||||
import (
|
||||
"context"
|
||||
core "github.com/v2fly/v2ray-core/v4"
|
||||
"github.com/v2fly/v2ray-core/v4/common/net"
|
||||
"github.com/v2fly/v2ray-core/v4/common/session"
|
||||
"github.com/v2fly/v2ray-core/v4/features/routing"
|
||||
"github.com/v2fly/v2ray-core/v4/transport/internet/tagged"
|
||||
)
|
||||
|
||||
func DialTaggedOutbound(ctx context.Context, dest net.Destination, tag string) (net.Conn, error) {
|
||||
var dispatcher routing.Dispatcher
|
||||
if err := core.RequireFeatures(ctx, func(dispatcherInstance routing.Dispatcher) {
|
||||
dispatcher = dispatcherInstance
|
||||
}); err != nil {
|
||||
return nil, newError("Required Feature dispatcher not resolved").Base(err)
|
||||
}
|
||||
|
||||
content := new(session.Content)
|
||||
content.SkipDNSResolve = true
|
||||
session.SetForcedOutboundTagToContext(ctx, tag)
|
||||
|
||||
ctx = session.ContextWithContent(ctx, content)
|
||||
|
||||
r, err := dispatcher.Dispatch(ctx, dest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var readerOpt net.ConnectionOption
|
||||
if dest.Network == net.Network_TCP {
|
||||
readerOpt = net.ConnectionOutputMulti(r.Reader)
|
||||
} else {
|
||||
readerOpt = net.ConnectionOutputMultiUDP(r.Reader)
|
||||
}
|
||||
return net.NewConnection(net.ConnectionInputMulti(r.Writer), readerOpt), nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
tagged.Dialer = DialTaggedOutbound
|
||||
}
|
3
transport/internet/tagged/taggedimpl/taggedimpl.go
Normal file
3
transport/internet/tagged/taggedimpl/taggedimpl.go
Normal file
@ -0,0 +1,3 @@
|
||||
package taggedimpl
|
||||
|
||||
//go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen
|
Loading…
Reference in New Issue
Block a user