mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-05-17 17:48:40 +00:00
Return additional ProxySettings, SenderSettings and ReceiverSettings strucutres.
This commit is contained in:
parent
229a4b3fe1
commit
1f014eb655
9 changed files with 102 additions and 9 deletions
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/xtls/xray-core/common/errors"
|
"github.com/xtls/xray-core/common/errors"
|
||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
"github.com/xtls/xray-core/common/net/cnc"
|
"github.com/xtls/xray-core/common/net/cnc"
|
||||||
|
"github.com/xtls/xray-core/common/serial"
|
||||||
"github.com/xtls/xray-core/common/signal/done"
|
"github.com/xtls/xray-core/common/signal/done"
|
||||||
"github.com/xtls/xray-core/transport"
|
"github.com/xtls/xray-core/transport"
|
||||||
)
|
)
|
||||||
|
@ -108,3 +109,13 @@ func (co *Outbound) Close() error {
|
||||||
co.closed = true
|
co.closed = true
|
||||||
return co.listener.Close()
|
return co.listener.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SenderSettings implements outbound.Handler.
|
||||||
|
func (co *Outbound) SenderSettings() *serial.TypedMessage {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProxySettings implements outbound.Handler.
|
||||||
|
func (co *Outbound) ProxySettings() *serial.TypedMessage {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/xtls/xray-core/common/errors"
|
"github.com/xtls/xray-core/common/errors"
|
||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
"github.com/xtls/xray-core/common/net/cnc"
|
"github.com/xtls/xray-core/common/net/cnc"
|
||||||
|
"github.com/xtls/xray-core/common/serial"
|
||||||
"github.com/xtls/xray-core/common/signal/done"
|
"github.com/xtls/xray-core/common/signal/done"
|
||||||
"github.com/xtls/xray-core/transport"
|
"github.com/xtls/xray-core/transport"
|
||||||
)
|
)
|
||||||
|
@ -108,3 +109,13 @@ func (co *Outbound) Close() error {
|
||||||
co.closed = true
|
co.closed = true
|
||||||
return co.listener.Close()
|
return co.listener.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SenderSettings implements outbound.Handler.
|
||||||
|
func (co *Outbound) SenderSettings() *serial.TypedMessage {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProxySettings implements outbound.Handler.
|
||||||
|
func (co *Outbound) ProxySettings() *serial.TypedMessage {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -104,7 +104,9 @@ func (s *handlerServer) ListInbounds(ctx context.Context, request *ListInboundsR
|
||||||
response := &ListInboundsResponse{}
|
response := &ListInboundsResponse{}
|
||||||
for _, handler := range handlers {
|
for _, handler := range handlers {
|
||||||
response.Inbounds = append(response.Inbounds, &core.InboundHandlerConfig{
|
response.Inbounds = append(response.Inbounds, &core.InboundHandlerConfig{
|
||||||
Tag: handler.Tag(),
|
Tag: handler.Tag(),
|
||||||
|
ReceiverSettings: handler.ReceiverSettings(),
|
||||||
|
ProxySettings: handler.ProxySettings(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return response, nil
|
return response, nil
|
||||||
|
@ -180,7 +182,9 @@ func (s *handlerServer) ListOutbounds(ctx context.Context, request *ListOutbound
|
||||||
response := &ListOutboundsResponse{}
|
response := &ListOutboundsResponse{}
|
||||||
for _, handler := range handlers {
|
for _, handler := range handlers {
|
||||||
response.Outbounds = append(response.Outbounds, &core.OutboundHandlerConfig{
|
response.Outbounds = append(response.Outbounds, &core.OutboundHandlerConfig{
|
||||||
Tag: handler.Tag(),
|
Tag: handler.Tag(),
|
||||||
|
SenderSettings: handler.SenderSettings(),
|
||||||
|
ProxySettings: handler.ProxySettings(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return response, nil
|
return response, nil
|
||||||
|
|
|
@ -9,11 +9,13 @@ import (
|
||||||
"github.com/xtls/xray-core/common/errors"
|
"github.com/xtls/xray-core/common/errors"
|
||||||
"github.com/xtls/xray-core/common/mux"
|
"github.com/xtls/xray-core/common/mux"
|
||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
|
"github.com/xtls/xray-core/common/serial"
|
||||||
"github.com/xtls/xray-core/core"
|
"github.com/xtls/xray-core/core"
|
||||||
"github.com/xtls/xray-core/features/policy"
|
"github.com/xtls/xray-core/features/policy"
|
||||||
"github.com/xtls/xray-core/features/stats"
|
"github.com/xtls/xray-core/features/stats"
|
||||||
"github.com/xtls/xray-core/proxy"
|
"github.com/xtls/xray-core/proxy"
|
||||||
"github.com/xtls/xray-core/transport/internet"
|
"github.com/xtls/xray-core/transport/internet"
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getStatCounter(v *core.Instance, tag string) (stats.Counter, stats.Counter) {
|
func getStatCounter(v *core.Instance, tag string) (stats.Counter, stats.Counter) {
|
||||||
|
@ -42,10 +44,12 @@ func getStatCounter(v *core.Instance, tag string) (stats.Counter, stats.Counter)
|
||||||
}
|
}
|
||||||
|
|
||||||
type AlwaysOnInboundHandler struct {
|
type AlwaysOnInboundHandler struct {
|
||||||
proxy proxy.Inbound
|
proxyConfig interface{}
|
||||||
workers []worker
|
receiverConfig *proxyman.ReceiverConfig
|
||||||
mux *mux.Server
|
proxy proxy.Inbound
|
||||||
tag string
|
workers []worker
|
||||||
|
mux *mux.Server
|
||||||
|
tag string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAlwaysOnInboundHandler(ctx context.Context, tag string, receiverConfig *proxyman.ReceiverConfig, proxyConfig interface{}) (*AlwaysOnInboundHandler, error) {
|
func NewAlwaysOnInboundHandler(ctx context.Context, tag string, receiverConfig *proxyman.ReceiverConfig, proxyConfig interface{}) (*AlwaysOnInboundHandler, error) {
|
||||||
|
@ -59,9 +63,11 @@ func NewAlwaysOnInboundHandler(ctx context.Context, tag string, receiverConfig *
|
||||||
}
|
}
|
||||||
|
|
||||||
h := &AlwaysOnInboundHandler{
|
h := &AlwaysOnInboundHandler{
|
||||||
proxy: p,
|
receiverConfig: receiverConfig,
|
||||||
mux: mux.NewServer(ctx),
|
proxyConfig: proxyConfig,
|
||||||
tag: tag,
|
proxy: p,
|
||||||
|
mux: mux.NewServer(ctx),
|
||||||
|
tag: tag,
|
||||||
}
|
}
|
||||||
|
|
||||||
uplinkCounter, downlinkCounter := getStatCounter(core.MustFromContext(ctx), tag)
|
uplinkCounter, downlinkCounter := getStatCounter(core.MustFromContext(ctx), tag)
|
||||||
|
@ -187,3 +193,16 @@ func (h *AlwaysOnInboundHandler) Tag() string {
|
||||||
func (h *AlwaysOnInboundHandler) GetInbound() proxy.Inbound {
|
func (h *AlwaysOnInboundHandler) GetInbound() proxy.Inbound {
|
||||||
return h.proxy
|
return h.proxy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReceiverSettings implements inbound.Handler.
|
||||||
|
func (h *AlwaysOnInboundHandler) ReceiverSettings() *serial.TypedMessage {
|
||||||
|
return serial.ToTypedMessage(h.receiverConfig)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProxySettings implements inbound.Handler.
|
||||||
|
func (h *AlwaysOnInboundHandler) ProxySettings() *serial.TypedMessage {
|
||||||
|
if v, ok := h.proxyConfig.(proto.Message); ok {
|
||||||
|
return serial.ToTypedMessage(v)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -10,10 +10,12 @@ import (
|
||||||
"github.com/xtls/xray-core/common/errors"
|
"github.com/xtls/xray-core/common/errors"
|
||||||
"github.com/xtls/xray-core/common/mux"
|
"github.com/xtls/xray-core/common/mux"
|
||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
|
"github.com/xtls/xray-core/common/serial"
|
||||||
"github.com/xtls/xray-core/common/task"
|
"github.com/xtls/xray-core/common/task"
|
||||||
"github.com/xtls/xray-core/core"
|
"github.com/xtls/xray-core/core"
|
||||||
"github.com/xtls/xray-core/proxy"
|
"github.com/xtls/xray-core/proxy"
|
||||||
"github.com/xtls/xray-core/transport/internet"
|
"github.com/xtls/xray-core/transport/internet"
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DynamicInboundHandler struct {
|
type DynamicInboundHandler struct {
|
||||||
|
@ -205,3 +207,16 @@ func (h *DynamicInboundHandler) GetRandomInboundProxy() (interface{}, net.Port,
|
||||||
func (h *DynamicInboundHandler) Tag() string {
|
func (h *DynamicInboundHandler) Tag() string {
|
||||||
return h.tag
|
return h.tag
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReceiverSettings implements inbound.Handler.
|
||||||
|
func (h *DynamicInboundHandler) ReceiverSettings() *serial.TypedMessage {
|
||||||
|
return serial.ToTypedMessage(h.receiverConfig)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProxySettings implements inbound.Handler.
|
||||||
|
func (h *DynamicInboundHandler) ProxySettings() *serial.TypedMessage {
|
||||||
|
if v, ok := h.proxyConfig.(proto.Message); ok {
|
||||||
|
return serial.ToTypedMessage(v)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import (
|
||||||
"github.com/xtls/xray-core/common/mux"
|
"github.com/xtls/xray-core/common/mux"
|
||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
"github.com/xtls/xray-core/common/net/cnc"
|
"github.com/xtls/xray-core/common/net/cnc"
|
||||||
|
"github.com/xtls/xray-core/common/serial"
|
||||||
"github.com/xtls/xray-core/common/session"
|
"github.com/xtls/xray-core/common/session"
|
||||||
"github.com/xtls/xray-core/core"
|
"github.com/xtls/xray-core/core"
|
||||||
"github.com/xtls/xray-core/features/outbound"
|
"github.com/xtls/xray-core/features/outbound"
|
||||||
|
@ -27,6 +28,7 @@ import (
|
||||||
"github.com/xtls/xray-core/transport/internet/stat"
|
"github.com/xtls/xray-core/transport/internet/stat"
|
||||||
"github.com/xtls/xray-core/transport/internet/tls"
|
"github.com/xtls/xray-core/transport/internet/tls"
|
||||||
"github.com/xtls/xray-core/transport/pipe"
|
"github.com/xtls/xray-core/transport/pipe"
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getStatCounter(v *core.Instance, tag string) (stats.Counter, stats.Counter) {
|
func getStatCounter(v *core.Instance, tag string) (stats.Counter, stats.Counter) {
|
||||||
|
@ -59,6 +61,7 @@ type Handler struct {
|
||||||
tag string
|
tag string
|
||||||
senderSettings *proxyman.SenderConfig
|
senderSettings *proxyman.SenderConfig
|
||||||
streamSettings *internet.MemoryStreamConfig
|
streamSettings *internet.MemoryStreamConfig
|
||||||
|
proxyConfig proto.Message
|
||||||
proxy proxy.Outbound
|
proxy proxy.Outbound
|
||||||
outboundManager outbound.Manager
|
outboundManager outbound.Manager
|
||||||
mux *mux.ClientManager
|
mux *mux.ClientManager
|
||||||
|
@ -101,6 +104,7 @@ func NewHandler(ctx context.Context, config *core.OutboundHandlerConfig) (outbou
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
h.proxyConfig = proxyConfig
|
||||||
|
|
||||||
rawProxyHandler, err := common.CreateObject(ctx, proxyConfig)
|
rawProxyHandler, err := common.CreateObject(ctx, proxyConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -349,6 +353,16 @@ func (h *Handler) Close() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SenderSettings implements outbound.Handler.
|
||||||
|
func (h *Handler) SenderSettings() *serial.TypedMessage {
|
||||||
|
return serial.ToTypedMessage(h.senderSettings)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProxySettings implements outbound.Handler.
|
||||||
|
func (h *Handler) ProxySettings() *serial.TypedMessage {
|
||||||
|
return serial.ToTypedMessage(h.proxyConfig)
|
||||||
|
}
|
||||||
|
|
||||||
func ParseRandomIP(addr net.Address, prefix string) net.Address {
|
func ParseRandomIP(addr net.Address, prefix string) net.Address {
|
||||||
|
|
||||||
_, ipnet, _ := gonet.ParseCIDR(addr.IP().String() + "/" + prefix)
|
_, ipnet, _ := gonet.ParseCIDR(addr.IP().String() + "/" + prefix)
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/xtls/xray-core/common/errors"
|
"github.com/xtls/xray-core/common/errors"
|
||||||
"github.com/xtls/xray-core/common/mux"
|
"github.com/xtls/xray-core/common/mux"
|
||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
|
"github.com/xtls/xray-core/common/serial"
|
||||||
"github.com/xtls/xray-core/common/session"
|
"github.com/xtls/xray-core/common/session"
|
||||||
"github.com/xtls/xray-core/common/task"
|
"github.com/xtls/xray-core/common/task"
|
||||||
"github.com/xtls/xray-core/features/outbound"
|
"github.com/xtls/xray-core/features/outbound"
|
||||||
|
@ -111,6 +112,16 @@ func (o *Outbound) Close() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SenderSettings implements outbound.Handler.
|
||||||
|
func (o *Outbound) SenderSettings() *serial.TypedMessage {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProxySettings implements outbound.Handler.
|
||||||
|
func (o *Outbound) ProxySettings() *serial.TypedMessage {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type StaticMuxPicker struct {
|
type StaticMuxPicker struct {
|
||||||
access sync.Mutex
|
access sync.Mutex
|
||||||
workers []*PortalWorker
|
workers []*PortalWorker
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common"
|
"github.com/xtls/xray-core/common"
|
||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
|
"github.com/xtls/xray-core/common/serial"
|
||||||
"github.com/xtls/xray-core/features"
|
"github.com/xtls/xray-core/features"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -15,6 +16,10 @@ type Handler interface {
|
||||||
common.Runnable
|
common.Runnable
|
||||||
// The tag of this handler.
|
// The tag of this handler.
|
||||||
Tag() string
|
Tag() string
|
||||||
|
// Returns the active receiver settings.
|
||||||
|
ReceiverSettings() *serial.TypedMessage
|
||||||
|
// Returns the active proxy settings.
|
||||||
|
ProxySettings() *serial.TypedMessage
|
||||||
|
|
||||||
// Deprecated: Do not use in new code.
|
// Deprecated: Do not use in new code.
|
||||||
GetRandomInboundProxy() (interface{}, net.Port, int)
|
GetRandomInboundProxy() (interface{}, net.Port, int)
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common"
|
"github.com/xtls/xray-core/common"
|
||||||
|
"github.com/xtls/xray-core/common/serial"
|
||||||
"github.com/xtls/xray-core/features"
|
"github.com/xtls/xray-core/features"
|
||||||
"github.com/xtls/xray-core/transport"
|
"github.com/xtls/xray-core/transport"
|
||||||
)
|
)
|
||||||
|
@ -15,6 +16,8 @@ type Handler interface {
|
||||||
common.Runnable
|
common.Runnable
|
||||||
Tag() string
|
Tag() string
|
||||||
Dispatch(ctx context.Context, link *transport.Link)
|
Dispatch(ctx context.Context, link *transport.Link)
|
||||||
|
SenderSettings() *serial.TypedMessage
|
||||||
|
ProxySettings() *serial.TypedMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
type HandlerSelector interface {
|
type HandlerSelector interface {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue