Skip to content

Commit

Permalink
support trojan+ws
Browse files Browse the repository at this point in the history
  • Loading branch information
xxf098 committed Nov 18, 2022
1 parent a4b1a36 commit 4dc0460
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
34 changes: 28 additions & 6 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,18 +711,35 @@ func createTrojanOutboundDetourConfig(profile *Vmess) conf.OutboundDetourConfig
})
outboundsSettingsMsg := json.RawMessage(outboundsSettings)
transportProtocol := conf.TransportProtocol("tcp")
trojanOutboundDetourConfig := conf.OutboundDetourConfig{
Protocol: "trojan",
Tag: "proxy",
Settings: &outboundsSettingsMsg,
StreamSetting: &conf.StreamConfig{
streamSetting := &conf.StreamConfig{
Security: "tls",
Network: &transportProtocol,
TLSSettings: &conf.TLSConfig{
Insecure: config.SkipCertVerify,
ServerName: config.SNI,
},
}
if config.Net == "ws" {
transportProtocol := conf.TransportProtocol(config.Net)
streamSetting = &conf.StreamConfig{
Security: "tls",
Network: &transportProtocol,
TLSSettings: &conf.TLSConfig{
Insecure: config.SkipCertVerify,
ServerName: config.SNI,
},
},
WSSettings: &conf.WebSocketConfig{Path: config.Path},
}
if len(config.Host) < 1 {
config.Host = config.SNI
}
streamSetting.WSSettings.Headers = map[string]string{"Host": config.Host}
}
trojanOutboundDetourConfig := conf.OutboundDetourConfig{
Protocol: "trojan",
Tag: "proxy",
Settings: &outboundsSettingsMsg,
StreamSetting: streamSetting,
}
return trojanOutboundDetourConfig
}
Expand Down Expand Up @@ -1136,3 +1153,8 @@ func profile2Option(profile *Vmess) (interface{}, error) {
}
return nil, newError("not support protocol")
}

type latencyResult struct {
elapsed int64
err error
}
17 changes: 16 additions & 1 deletion features/trojan.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,32 @@ type Trojan struct {
Password string
SNI string
SkipCertVerify bool
Net string
Path string // ws path
Host string // ws host / http host
VmessOptions
}

func NewTrojan(Add string, Port int, Password string, SNI string, SkipCertVerify bool, opt []byte) *Trojan {
func NewTrojan(
Add string,
Port int,
Password string,
SNI string,
SkipCertVerify bool,
Net string,
Path string,
Host string,
opt []byte) *Trojan {
options := NewVmessOptions(opt)
return &Trojan{
Add: Add,
Port: Port,
Password: Password,
SNI: SNI,
SkipCertVerify: SkipCertVerify,
Net: Net,
Path: Path,
Host: Host,
VmessOptions: options,
}
}
4 changes: 2 additions & 2 deletions tun2socks.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ type Vmess features.Vmess
type Vless features.Vless
type Shadowsocks features.Shadowsocks

func NewTrojan(Add string, Port int, Password string, SNI string, SkipCertVerify bool, opt []byte) *Trojan {
t := Trojan(*features.NewTrojan(Add, Port, Password, SNI, SkipCertVerify, opt))
func NewTrojan(Add string, Port int, Password string, SNI string, SkipCertVerify bool, Net string, Path string, Host string, opt []byte) *Trojan {
t := Trojan(*features.NewTrojan(Add, Port, Password, SNI, SkipCertVerify, Net, Path, Host, opt))
return &t
}

Expand Down

0 comments on commit 4dc0460

Please sign in to comment.