Skip to content

Commit

Permalink
new: make 0 as default ip for warp if not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com committed Jan 26, 2024
1 parent 2626ecb commit 854054f
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 15 deletions.
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var examples = map[string][]string{
"warp://key@host:1234/#WARPkey",
"warp://engage.cloudflareclient.com:2408#WARPnoKey",
"warp://[email protected]:2408/?ifp=5-10#WARPparam",
"warp://auto/#WARP_auto",
},
}

Expand Down
2 changes: 1 addition & 1 deletion ray2sing/beepass.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func BeepassSingbox(beepassUrl string) (*T.Outbound, error) {
ShadowsocksOptions: T.ShadowsocksOutboundOptions{
ServerOptions: T.ServerOptions{
Server: decoded.Server,
ServerPort: toInt16(decoded.ServerPort),
ServerPort: toInt16(decoded.ServerPort, 443),
},
Method: decoded.Method,
Password: decoded.Password,
Expand Down
4 changes: 2 additions & 2 deletions ray2sing/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,12 @@ func toInt(s string) int {
return i
}

func toInt16(s string) uint16 {
func toInt16(s string, defaultPort uint16) uint16 {
val, err := strconv.ParseInt(s, 10, 17)
if err != nil {
// fmoption.Printf("err %v", err)
// handle the error appropriately; here we return 0
return 443
return defaultPort
}
return uint16(val)
}
Expand Down
2 changes: 1 addition & 1 deletion ray2sing/hysteria.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func HysteriaSingbox(hysteriaURL string) (*T.Outbound, error) {
u, err := ParseUrl(hysteriaURL)
u, err := ParseUrl(hysteriaURL, 443)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion ray2sing/hysteria2.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

func Hysteria2Singbox(hysteria2Url string) (*T.Outbound, error) {
u, err := ParseUrl(hysteria2Url)
u, err := ParseUrl(hysteria2Url, 443)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion ray2sing/shadowsocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func parseShadowsocks(configStr string) (map[string]string, error) {
}

func ShadowsocksSingbox(shadowsocksUrl string) (*T.Outbound, error) {
u, err := ParseUrl(shadowsocksUrl)
u, err := ParseUrl(shadowsocksUrl, 443)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion ray2sing/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func SSHSingbox(sshURL string) (*T.Outbound, error) {
u, err := ParseUrl(sshURL)
u, err := ParseUrl(sshURL, 22)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion ray2sing/trojan.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

func TrojanSingbox(trojanURL string) (*T.Outbound, error) {
u, err := ParseUrl(trojanURL)
u, err := ParseUrl(trojanURL, 443)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion ray2sing/tuic.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func TuicSingbox(tuicUrl string) (*T.Outbound, error) {
u, err := ParseUrl(tuicUrl)
u, err := ParseUrl(tuicUrl, 443)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions ray2sing/url_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ func (u UrlSchema) GetRelayOptions() (*T.TurnRelayOptions, error) {
}

// parseHysteria2 parses a given URL and returns a HysteriaURLData struct.
func ParseUrl(inputURL string) (*UrlSchema, error) {
func ParseUrl(inputURL string, defaultPort uint16) (*UrlSchema, error) {
parsedURL, err := url.Parse(inputURL)
if err != nil {
return nil, err
}

port := toInt16(parsedURL.Port())
port := toInt16(parsedURL.Port(), defaultPort)

data := &UrlSchema{
Scheme: parsedURL.Scheme,
Expand Down
2 changes: 1 addition & 1 deletion ray2sing/vless.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

func VlessSingbox(vlessURL string) (*T.Outbound, error) {
u, err := ParseUrl(vlessURL)
u, err := ParseUrl(vlessURL, 443)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion ray2sing/vmess.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func VmessSingbox(vmessURL string) (*T.Outbound, error) {
return nil, err
}

port := toInt16(decoded["port"])
port := toInt16(decoded["port"], 443)
transportOptions, err := getTransportOptions(decoded)
if err != nil {
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion ray2sing/warp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
)

func WarpSingbox(url string) (*T.Outbound, error) {
u, err := ParseUrl(url)
u, err := ParseUrl(url, 0)
if err != nil {
return nil, err
}

out := &T.Outbound{
Type: "custom",
Tag: u.Name,
Expand Down
3 changes: 2 additions & 1 deletion ray2sing/wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func WiregaurdSingbox(url string) (*T.Outbound, error) {
u, err := ParseUrl(url)
u, err := ParseUrl(url, 0)
if err != nil {
return nil, err
}
Expand All @@ -22,6 +22,7 @@ func WiregaurdSingbox(url string) (*T.Outbound, error) {
PrivateKey: u.Params["pk"],
PeerPublicKey: u.Params["peer_pk"],
PreSharedKey: u.Params["pre_shared_key"],
FakePackets: u.Params["ifp"],
},
}

Expand Down

0 comments on commit 854054f

Please sign in to comment.