mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-04-16 20:45:50 +00:00
1. **Fixed XPadding Placement Dropdown**: - Added the missing `cookie` and `query` options to `xPaddingPlacement` (`stream_xhttp.html`). - *Why:* Previously, users wanting `cookie` obfuscation were forced to use the `header` placement string. This caused Xray-core to blindly intercept the entire monolithic HTTP Cookie header, failing internal padding-length validations and causing the inbound to silently drop the connection. 2. **Fixed Uplink Data Placement Validation**: - Replaced the unsupported `query` option with `cookie` in `uplinkDataPlacement`. - *Why:* Xray-core's `transport_internet.go` explicitly forbids `query` as an uplink placement option. Selecting it from the UI previously sent a payload that would cause Xray-core to instantly throw an `unsupported uplink data placement: query` panic. Adding `cookie` perfectly aligns the UI with Xray-core restrictions. ### Related Issues - Resolves #3992
67 lines
1.7 KiB
Go
67 lines
1.7 KiB
Go
package router
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/xtls/xray-core/app/observatory"
|
|
"github.com/xtls/xray-core/common"
|
|
"github.com/xtls/xray-core/common/dice"
|
|
"github.com/xtls/xray-core/core"
|
|
"github.com/xtls/xray-core/features/extension"
|
|
)
|
|
|
|
// RandomStrategy represents a random balancing strategy
|
|
type RandomStrategy struct {
|
|
FallbackTag string
|
|
|
|
ctx context.Context
|
|
observatory extension.Observatory
|
|
}
|
|
|
|
func (s *RandomStrategy) InjectContext(ctx context.Context) {
|
|
s.ctx = ctx
|
|
if len(s.FallbackTag) > 0 {
|
|
common.Must(core.RequireFeatures(s.ctx, func(observatory extension.Observatory) error {
|
|
s.observatory = observatory
|
|
return nil
|
|
}))
|
|
}
|
|
}
|
|
|
|
func (s *RandomStrategy) GetPrincipleTarget(strings []string) []string {
|
|
return strings
|
|
}
|
|
|
|
func (s *RandomStrategy) PickOutbound(candidates []string) string {
|
|
if s.observatory != nil {
|
|
observeReport, err := s.observatory.GetObservation(s.ctx)
|
|
if err == nil {
|
|
aliveTags := make([]string, 0)
|
|
if result, ok := observeReport.(*observatory.ObservationResult); ok {
|
|
status := result.Status
|
|
statusMap := make(map[string]*observatory.OutboundStatus)
|
|
for _, outboundStatus := range status {
|
|
statusMap[outboundStatus.OutboundTag] = outboundStatus
|
|
}
|
|
for _, candidate := range candidates {
|
|
if outboundStatus, found := statusMap[candidate]; found {
|
|
if outboundStatus.Alive {
|
|
aliveTags = append(aliveTags, candidate)
|
|
}
|
|
} else {
|
|
// unfound candidate is considered alive
|
|
aliveTags = append(aliveTags, candidate)
|
|
}
|
|
}
|
|
candidates = aliveTags
|
|
}
|
|
}
|
|
}
|
|
|
|
count := len(candidates)
|
|
if count == 0 {
|
|
// goes to fallbackTag
|
|
return ""
|
|
}
|
|
return candidates[dice.Roll(count)]
|
|
}
|