Skip to content

Commit c4581ad

Browse files
authored
Xray core1.8.20 & support splitHTTP (#661)
* upgrade xray core 1.8.20 * support splitHTTP
1 parent 127318c commit c4581ad

File tree

12 files changed

+130
-114
lines changed

12 files changed

+130
-114
lines changed

api/newV2board/model.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,19 @@ type v2ray struct {
3131
Network string `json:"network"`
3232
NetworkSettings struct {
3333
Path string `json:"path"`
34+
Host string `json:"host"`
3435
Headers *json.RawMessage `json:"headers"`
3536
ServiceName string `json:"serviceName"`
3637
Header *json.RawMessage `json:"header"`
3738
} `json:"networkSettings"`
3839
VlessNetworkSettings struct {
3940
Path string `json:"path"`
41+
Host string `json:"host"`
4042
Headers *json.RawMessage `json:"headers"`
4143
ServiceName string `json:"serviceName"`
4244
Header *json.RawMessage `json:"header"`
4345
} `json:"network_settings"`
44-
VlessFlow string `json:"flow"`
46+
VlessFlow string `json:"flow"`
4547
VlessTlsSettings struct {
4648
ServerPort string `json:"server_port"`
4749
Dest string `json:"dest"`

api/newV2board/v2board.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,18 @@ func (c *APIClient) parseV2rayNodeResponse(s *serverConfig) (*api.NodeInfo, erro
413413
header = httpHeader
414414
}
415415
}
416+
case "httpupgrade", "splithttp":
417+
if s.NetworkSettings.Headers != nil {
418+
if httpHeaders, err := s.NetworkSettings.Headers.MarshalJSON(); err != nil {
419+
return nil, err
420+
} else {
421+
b, _ := simplejson.NewJson(httpHeaders)
422+
host = b.Get("Host").MustString()
423+
}
424+
}
425+
if s.NetworkSettings.Host != "" {
426+
host = s.NetworkSettings.Host
427+
}
416428
}
417429

418430
switch s.Tls {

app/mydispatcher/default.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/xtls/xray-core/common"
1313
"github.com/xtls/xray-core/common/buf"
14+
"github.com/xtls/xray-core/common/errors"
1415
"github.com/xtls/xray-core/common/log"
1516
"github.com/xtls/xray-core/common/net"
1617
"github.com/xtls/xray-core/common/protocol"
@@ -169,7 +170,7 @@ func (d *DefaultDispatcher) getLink(ctx context.Context, network net.Network, sn
169170
// Speed Limit and Device Limit
170171
bucket, ok, reject := d.Limiter.GetUserBucket(sessionInbound.Tag, user.Email, sessionInbound.Source.Address.IP().String())
171172
if reject {
172-
newError("Devices reach the limit: ", user.Email).AtWarning().WriteToLog()
173+
errors.LogWarning(ctx, "Devices reach the limit: ", user.Email)
173174
common.Close(outboundLink.Writer)
174175
common.Close(inboundLink.Writer)
175176
common.Interrupt(outboundLink.Reader)
@@ -217,12 +218,12 @@ func (d *DefaultDispatcher) shouldOverride(ctx context.Context, result SniffResu
217218
protocolString = resComp.ProtocolForDomainResult()
218219
}
219220
for _, p := range request.OverrideDestinationForProtocol {
220-
if strings.HasPrefix(protocolString, p) {
221+
if strings.HasPrefix(protocolString, p) || strings.HasPrefix(p, protocolString) {
221222
return true
222223
}
223224
if fkr0, ok := d.fdns.(dns.FakeDNSEngineRev0); ok && protocolString != "bittorrent" && p == "fakedns" &&
224225
destination.Address.Family().IsIP() && fkr0.IsIPInIPPool(destination.Address) {
225-
newError("Using sniffer ", protocolString, " since the fake DNS missed").WriteToLog(session.ExportIDToError(ctx))
226+
errors.LogInfo(ctx, "Using sniffer ", protocolString, " since the fake DNS missed")
226227
return true
227228
}
228229
if resultSubset, ok := result.(SnifferIsProtoSubsetOf); ok {
@@ -273,7 +274,7 @@ func (d *DefaultDispatcher) Dispatch(ctx context.Context, destination net.Destin
273274
}
274275
if err == nil && d.shouldOverride(ctx, result, sniffingRequest, destination) {
275276
domain := result.Domain()
276-
newError("sniffed domain: ", domain).WriteToLog(session.ExportIDToError(ctx))
277+
errors.LogInfo(ctx, "sniffed domain: ", domain)
277278
destination.Address = net.ParseAddress(domain)
278279
if sniffingRequest.RouteOnly && result.Protocol() != "fakedns" {
279280
ob.RouteTarget = destination
@@ -320,7 +321,7 @@ func (d *DefaultDispatcher) DispatchLink(ctx context.Context, destination net.De
320321
}
321322
if err == nil && d.shouldOverride(ctx, result, sniffingRequest, destination) {
322323
domain := result.Domain()
323-
newError("sniffed domain: ", domain).WriteToLog(session.ExportIDToError(ctx))
324+
errors.LogInfo(ctx, "sniffed domain: ", domain)
324325
destination.Address = net.ParseAddress(domain)
325326
if sniffingRequest.RouteOnly && result.Protocol() != "fakedns" {
326327
ob.RouteTarget = destination
@@ -404,7 +405,7 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport.
404405
// Whether the inbound connection contains a user
405406
if sessionInbound.User != nil {
406407
if d.RuleManager.Detect(sessionInbound.Tag, destination.String(), sessionInbound.User.Email) {
407-
newError(fmt.Sprintf("User %s access %s reject by rule", sessionInbound.User.Email, destination.String())).AtError().WriteToLog()
408+
errors.LogError(ctx, fmt.Sprintf("User %s access %s reject by rule", sessionInbound.User.Email, destination.String()))
408409
newError("destination is reject by rule")
409410
common.Close(link.Writer)
410411
common.Interrupt(link.Reader)
@@ -419,10 +420,10 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport.
419420
ctx = session.SetForcedOutboundTagToContext(ctx, "")
420421
if h := d.ohm.GetHandler(forcedOutboundTag); h != nil {
421422
isPickRoute = 1
422-
newError("taking platform initialized detour [", forcedOutboundTag, "] for [", destination, "]").WriteToLog(session.ExportIDToError(ctx))
423+
errors.LogInfo(ctx, "taking platform initialized detour [", forcedOutboundTag, "] for [", destination, "]")
423424
handler = h
424425
} else {
425-
newError("non existing tag for platform initialized detour: ", forcedOutboundTag).AtError().WriteToLog(session.ExportIDToError(ctx))
426+
errors.LogError(ctx, "non existing tag for platform initialized detour: ", forcedOutboundTag)
426427
common.Close(link.Writer)
427428
common.Interrupt(link.Reader)
428429
return
@@ -432,13 +433,13 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport.
432433
outTag := route.GetOutboundTag()
433434
if h := d.ohm.GetHandler(outTag); h != nil {
434435
isPickRoute = 2
435-
newError("taking detour [", outTag, "] for [", destination, "]").WriteToLog(session.ExportIDToError(ctx))
436+
errors.LogInfo(ctx, "taking detour [", outTag, "] for [", destination, "]")
436437
handler = h
437438
} else {
438-
newError("non existing outTag: ", outTag).AtWarning().WriteToLog(session.ExportIDToError(ctx))
439+
errors.LogWarning(ctx, "non existing outTag: ", outTag)
439440
}
440441
} else {
441-
newError("default route for ", destination).WriteToLog(session.ExportIDToError(ctx))
442+
errors.LogInfo(ctx, "default route for ", destination)
442443
}
443444
}
444445

@@ -452,7 +453,7 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport.
452453
}
453454

454455
if handler == nil {
455-
newError("default outbound handler not exist").WriteToLog(session.ExportIDToError(ctx))
456+
errors.LogInfo(ctx, "default outbound handler not exist")
456457
common.Close(link.Writer)
457458
common.Interrupt(link.Reader)
458459
return

app/mydispatcher/fakednssniffer.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"strings"
66

77
"github.com/xtls/xray-core/common"
8+
"github.com/xtls/xray-core/common/errors"
89
"github.com/xtls/xray-core/common/net"
910
"github.com/xtls/xray-core/common/session"
1011
"github.com/xtls/xray-core/core"
@@ -32,7 +33,7 @@ func newFakeDNSSniffer(ctx context.Context) (protocolSnifferWithMetadata, error)
3233
if Target.Network == net.Network_TCP || Target.Network == net.Network_UDP {
3334
domainFromFakeDNS := fakeDNSEngine.GetDomainFromFakeDNS(Target.Address)
3435
if domainFromFakeDNS != "" {
35-
newError("fake dns got domain: ", domainFromFakeDNS, " for ip: ", Target.Address.String()).WriteToLog(session.ExportIDToError(ctx))
36+
errors.LogInfo(ctx, "fake dns got domain: ", domainFromFakeDNS, " for ip: ", ob.Target.Address.String())
3637
return &fakeDNSSniffResult{domainName: domainFromFakeDNS}, nil
3738
}
3839
}
@@ -109,10 +110,10 @@ func newFakeDNSThenOthers(ctx context.Context, fakeDNSSniffer protocolSnifferWit
109110
}
110111
return nil, common.ErrNoClue
111112
}
112-
newError("ip address not in fake dns range, return as is").AtDebug().WriteToLog()
113+
errors.LogDebug(ctx, "ip address not in fake dns range, return as is")
113114
return nil, common.ErrNoClue
114115
}
115-
newError("fake dns sniffer did not set address in range option, assume false.").AtWarning().WriteToLog()
116+
errors.LogWarning(ctx, "fake dns sniffer did not set address in range option, assume false.")
116117
return nil, common.ErrNoClue
117118
},
118119
metadataSniffer: false,

common/limiter/errors.go

Lines changed: 0 additions & 7 deletions
This file was deleted.

common/limiter/limiter.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
redisStore "github.com/eko/gocache/store/redis/v4"
1717
goCache "github.com/patrickmn/go-cache"
1818
"github.com/redis/go-redis/v9"
19+
"github.com/xtls/xray-core/common/errors"
1920
"golang.org/x/time/rate"
2021

2122
"github.com/XrayR-project/XrayR/api"
@@ -218,7 +219,7 @@ func (l *Limiter) GetUserBucket(tag string, email string, ip string) (limiter *r
218219
return nil, false, false
219220
}
220221
} else {
221-
newError("Get Inbound Limiter information failed").AtDebug().WriteToLog()
222+
errors.LogDebug(context.Background(), "Get Inbound Limiter information failed")
222223
return nil, false, false
223224
}
224225
}
@@ -238,7 +239,7 @@ func globalLimit(inboundInfo *InboundInfo, email string, uid int, ip string, dev
238239
// If the email is a new device
239240
go pushIP(inboundInfo, uniqueKey, &map[string]int{ip: uid})
240241
} else {
241-
newError("cache service").Base(err).AtError().WriteToLog()
242+
errors.LogErrorInner(context.Background(), err, "cache service")
242243
}
243244
return false
244245
}
@@ -264,7 +265,7 @@ func pushIP(inboundInfo *InboundInfo, uniqueKey string, ipMap *map[string]int) {
264265
defer cancel()
265266

266267
if err := inboundInfo.GlobalLimit.globalOnlineIP.Set(ctx, uniqueKey, ipMap); err != nil {
267-
newError("cache service").Base(err).AtError().WriteToLog()
268+
errors.LogErrorInner(context.Background(), err, "cache service")
268269
}
269270
}
270271

common/rule/errors.go

Lines changed: 0 additions & 7 deletions
This file was deleted.

common/rule/rule.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
package rule
33

44
import (
5+
"context"
56
"fmt"
67
"reflect"
78
"strconv"
89
"strings"
910
"sync"
1011

1112
mapset "github.com/deckarep/golang-set"
13+
"github.com/xtls/xray-core/common/errors"
1214

1315
"github.com/XrayR-project/XrayR/api"
1416
)
@@ -65,7 +67,7 @@ func (r *Manager) Detect(tag string, destination string, email string) (reject b
6567
l := strings.Split(email, "|")
6668
uid, err := strconv.Atoi(l[len(l)-1])
6769
if err != nil {
68-
newError(fmt.Sprintf("Record illegal behavior failed! Cannot find user's uid: %s", email)).AtDebug().WriteToLog()
70+
errors.LogDebug(context.Background(), fmt.Sprintf("Record illegal behavior failed! Cannot find user's uid: %s", email))
6971
return reject
7072
}
7173
newSet := mapset.NewSetWith(api.DetectResult{UID: uid, RuleID: hitRuleID})

0 commit comments

Comments
 (0)