Skip to content

Commit

Permalink
new: add xray fragment option
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com committed Jul 27, 2024
1 parent 783ece1 commit 8acc89f
Show file tree
Hide file tree
Showing 7 changed files with 309 additions and 9 deletions.
37 changes: 36 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,52 @@ require (
)

require (
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/cloudflare/circl v1.3.9 // indirect
github.com/dgryski/go-metro v0.0.0-20211217172704-adc40b04c140 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/pprof v0.0.0-20240528025155-186aa0362fba // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
github.com/miekg/dns v1.1.61 // indirect
github.com/onsi/ginkgo/v2 v2.19.0 // indirect
github.com/pires/go-proxyproto v0.7.0 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/quic-go v0.45.1 // indirect
github.com/refraction-networking/utls v1.6.7 // indirect
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 // indirect
github.com/sagernet/sing-dns v0.2.0 // indirect
github.com/sagernet/sing-shadowsocks v0.2.7 // indirect
github.com/seiflotfy/cuckoofilter v0.0.0-20240715131351-a2f2c23f1771 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e // indirect
github.com/vishvananda/netlink v1.2.1-beta.2.0.20230316163032-ced5aaba43e3 // indirect
github.com/vishvananda/netns v0.0.4 // indirect
github.com/xtls/reality v0.0.0-20240712055506-48f0b2d5ed6d // indirect
github.com/xtls/xray-core v1.8.21 // indirect
go.uber.org/mock v0.4.0 // indirect
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.22.0 // indirect
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
golang.zx2c4.com/wireguard v0.0.0-20231211153847-12269c276173 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gvisor.dev/gvisor v0.0.0-20231202080848-1f7806d17489 // indirect
lukechampine.com/blake3 v1.3.0 // indirect
)

replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.8.9-0.20240724225257-adf55aaf0721
replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.8.9-0.20240727194612-aeb0c78d6aa5
244 changes: 241 additions & 3 deletions go.sum

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions ray2sing/xraycommon.go → ray2sing/xray_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ray2sing

import (
E "github.com/sagernet/sing/common/exceptions"
"github.com/xtls/xray-core/infra/conf"

"strings"
)
Expand Down Expand Up @@ -202,3 +203,19 @@ func getStreamSettingsXray(decoded map[string]string) (map[string]any, error) {

return res, nil
}

func getXrayFragmentOptions(decoded map[string]string) *conf.Fragment {
trick := conf.Fragment{}
fragment := decoded["fragment"]
if fragment == "" {
return nil
}
splt := strings.Split(fragment, ",")
if len(splt) > 2 {
trick.Packets = splt[0]
trick.Length = splt[1]
trick.Interval = splt[2]
}

return &trick
}
11 changes: 9 additions & 2 deletions ray2sing/xraydirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@ func DirectXray(vlessURL string) (*T.Outbound, error) {
Type: "xray",
XrayOptions: T.XrayOutboundOptions{
// DialerOptions: getDialerOptions(decoded),
XrayOutboundJson: map[string]any{
"protocol": "freedom",
XrayOutboundJson: &map[string]any{
"protocol": "freedom",
"domainStrategy": "AsIs",
"settings": map[string]any{
"fragment": fragdata,
},
"streamSettings": map[string]any{
"sockopt": map[string]any{
"tcpNoDelay": true,
"tcpKeepAliveIdle": 100,
},
},
"tag": u.Name,
},
},
Expand Down
3 changes: 2 additions & 1 deletion ray2sing/xraytrojan.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ func TrojanXray(vlessURL string) (*T.Outbound, error) {
Type: "xray",
XrayOptions: T.XrayOutboundOptions{
// DialerOptions: getDialerOptions(decoded),
XrayOutboundJson: map[string]any{
Fragment: getXrayFragmentOptions(decoded),
XrayOutboundJson: &map[string]any{
"protocol": "trojan",

"settings": map[string]any{
Expand Down
3 changes: 2 additions & 1 deletion ray2sing/xrayvless.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ func VlessXray(vlessURL string) (*T.Outbound, error) {
Type: "xray",
XrayOptions: T.XrayOutboundOptions{
// DialerOptions: getDialerOptions(decoded),
XrayOutboundJson: map[string]any{
Fragment: getXrayFragmentOptions(decoded),
XrayOutboundJson: &map[string]any{

"protocol": "vless",
"settings": map[string]any{
Expand Down
3 changes: 2 additions & 1 deletion ray2sing/xrayvmess.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ func VmessXray(vlessURL string) (*T.Outbound, error) {
Type: "xray",
XrayOptions: T.XrayOutboundOptions{
// DialerOptions: getDialerOptions(decoded),
XrayOutboundJson: map[string]any{
Fragment:getXrayFragmentOptions(decoded),
XrayOutboundJson: &map[string]any{

"protocol": "vmess",
"settings": map[string]any{
Expand Down

0 comments on commit 8acc89f

Please sign in to comment.