Skip to content

Commit

Permalink
Added Quic network protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
lilendian0x00 committed Apr 26, 2024
1 parent bea2c39 commit bea7c60
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
13 changes: 13 additions & 0 deletions xray/protocols.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ type Vless struct {
Address string `json:"add"` // HOST:PORT
Encryption string `json:"encryption"`
Flow string `json:"flow"`
QuicSecurity string `json:"quicSecurity"`
Key string `json:"key"` // Quic key
Security string `json:"security"` // reality or tls
PublicKey string `json:"pbk"`
ShortIds string `json:"sid"` // Mandatory, the shortId list available to the client, which can be used to distinguish different clients
Expand Down Expand Up @@ -89,6 +91,8 @@ type Trojan struct {
Password string // Password
Address string `json:"add"` // HOST:PORT
Flow string `json:"flow"`
QuicSecurity string `json:"quicSecurity"`
Key string `json:"key"` // Quic key
Security string `json:"security"` // tls
HeaderType string `json:"headerType"` // TCP HTTP Obfuscation
Host string `json:"host"` // HTTP, WS
Expand All @@ -105,6 +109,15 @@ type Trojan struct {
OrigLink string `json:"-"` // Original link
}

type Wireguard struct {
Remark string
PublicKey string `json:"publickey"`
SecretKey string `json:"secretkey"`
Endpoint string
LocalAddress string `json:"address"` // Local address IPv4/IPv6 seperated by commas
Mtu int32 `json:"mtu"`
}

type Socks struct {
Remark string
Address string // HOST:PORT
Expand Down
12 changes: 12 additions & 0 deletions xray/trojan.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,18 @@ func (t *Trojan) BuildOutboundDetourConfig(allowInsecure bool) (*conf.OutboundDe

t.Flow = ""
break
case "quic":
tp := "none"
if t.HeaderType != "" {
tp = t.HeaderType
}
fmt.Println(t.HeaderType)
s.QUICSettings = &conf.QUICConfig{
Header: json.RawMessage([]byte(fmt.Sprintf(`{ "type": "%s" }`, tp))),
Security: t.QuicSecurity,
Key: t.Key,
}
break
}

if t.Security == "tls" {
Expand Down
12 changes: 12 additions & 0 deletions xray/vless.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,18 @@ func (v *Vless) BuildOutboundDetourConfig(allowInsecure bool) (*conf.OutboundDet
}
v.Flow = ""
break
case "quic":
t := "none"
if v.HeaderType != "" {
t = v.HeaderType
}
fmt.Println(v.HeaderType)
s.QUICSettings = &conf.QUICConfig{
Header: json.RawMessage([]byte(fmt.Sprintf(`{ "type": "%s" }`, t))),
Security: v.QuicSecurity,
Key: v.Key,
}
break
}

if v.Security == "tls" {
Expand Down
14 changes: 11 additions & 3 deletions xray/vmess.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ func method1(v *Vmess, link string) error {
if err != nil {
return err
}

if err = json.Unmarshal(decoded, v); err != nil {
return err
}

fmt.Println(string(decoded))
return nil
}

Expand Down Expand Up @@ -275,6 +272,17 @@ func (v *Vmess) BuildOutboundDetourConfig(allowInsecure bool) (*conf.OutboundDet
IdleTimeout: 60,
ServiceName: v.Path,
}
case "quic":
t := "none"
if v.Type != "" {
t = v.Type
}
s.QUICSettings = &conf.QUICConfig{
Header: json.RawMessage([]byte(fmt.Sprintf(`{ "type": "%s" }`, t))),
Security: v.Host,
Key: v.Path,
}
break
}

if v.TLS == "tls" {
Expand Down
2 changes: 2 additions & 0 deletions xray/xray.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ func ParseXrayConfig(configLink string) (Protocol, error) {
protocol = &Trojan{}
} else if strings.HasPrefix(configLink, "socks://") {
protocol = &Socks{}
} else if strings.HasPrefix(configLink, "wireguard://") {
protocol = &Wireguard{}
} else {
return protocol, errors.New("Invalid protocol type! ")
}
Expand Down

0 comments on commit bea7c60

Please sign in to comment.