mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-29 16:58:34 +00:00
Add observatory / latestPing balancing strategy
Co-authored-by: Shelikhoo <xiaokangwang@outlook.com>
This commit is contained in:
parent
77d0419aca
commit
5c366db847
21 changed files with 1127 additions and 31 deletions
11
transport/internet/tagged/tagged.go
Normal file
11
transport/internet/tagged/tagged.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
package tagged
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
)
|
||||
|
||||
type DialFunc func(ctx context.Context, dest net.Destination, tag string) (net.Conn, error)
|
||||
|
||||
var Dialer DialFunc
|
9
transport/internet/tagged/taggedimpl/errors.generated.go
Normal file
9
transport/internet/tagged/taggedimpl/errors.generated.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
package taggedimpl
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
46
transport/internet/tagged/taggedimpl/impl.go
Normal file
46
transport/internet/tagged/taggedimpl/impl.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
package taggedimpl
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/xtls/xray-core/common/net/cnc"
|
||||
"github.com/xtls/xray-core/core"
|
||||
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/session"
|
||||
"github.com/xtls/xray-core/features/routing"
|
||||
"github.com/xtls/xray-core/transport/internet/tagged"
|
||||
)
|
||||
|
||||
func DialTaggedOutbound(ctx context.Context, dest net.Destination, tag string) (net.Conn, error) {
|
||||
var dispatcher routing.Dispatcher
|
||||
if core.FromContext(ctx) == nil {
|
||||
return nil, newError("Instance context variable is not in context, dial denied. ")
|
||||
}
|
||||
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
|
||||
|
||||
ctx = session.ContextWithContent(ctx, content)
|
||||
ctx = session.SetForcedOutboundTagToContext(ctx, tag)
|
||||
|
||||
r, err := dispatcher.Dispatch(ctx, dest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var readerOpt cnc.ConnectionOption
|
||||
if dest.Network == net.Network_TCP {
|
||||
readerOpt = cnc.ConnectionOutputMulti(r.Reader)
|
||||
} else {
|
||||
readerOpt = cnc.ConnectionOutputMultiUDP(r.Reader)
|
||||
}
|
||||
return cnc.NewConnection(cnc.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/xtls/xray-core/common/errors/errorgen
|
Loading…
Add table
Add a link
Reference in a new issue