From e51591c7f701dcd80d9186cd9b56b3314b228cc7 Mon Sep 17 00:00:00 2001 From: yuzuki999 Date: Sun, 27 Aug 2023 13:20:31 +0800 Subject: [PATCH] fix NetworkSettings decode for sing --- core/sing/node.go | 50 ++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/core/sing/node.go b/core/sing/node.go index 8670c48..3a11675 100644 --- a/core/sing/node.go +++ b/core/sing/node.go @@ -86,33 +86,43 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio case "tcp": t.Type = "" case "ws": - network := WsNetworkConfig{} - err := json.Unmarshal(n.NetworkSettings, &network) - if err != nil { - return option.Inbound{}, fmt.Errorf("decode NetworkSettings error: %s", err) - } - var u *url.URL - u, err = url.Parse(network.Path) - if err != nil { - return option.Inbound{}, fmt.Errorf("parse path error: %s", err) - } - ed, _ := strconv.Atoi(u.Query().Get("ed")) - h := make(map[string]option.Listable[string], len(network.Headers)) - for k, v := range network.Headers { - h[k] = option.Listable[string]{ - v, + var ( + path string + ed int + headers map[string]option.Listable[string] + ) + if len(n.NetworkSettings) != 0 { + network := WsNetworkConfig{} + err := json.Unmarshal(n.NetworkSettings, &network) + if err != nil { + return option.Inbound{}, fmt.Errorf("decode NetworkSettings error: %s", err) + } + var u *url.URL + u, err = url.Parse(network.Path) + if err != nil { + return option.Inbound{}, fmt.Errorf("parse path error: %s", err) + } + path = u.Path + ed, _ = strconv.Atoi(u.Query().Get("ed")) + headers = make(map[string]option.Listable[string], len(network.Headers)) + for k, v := range network.Headers { + headers[k] = option.Listable[string]{ + v, + } } } t.WebsocketOptions = option.V2RayWebsocketOptions{ - Path: u.Path, + Path: path, EarlyDataHeaderName: "Sec-WebSocket-Protocol", MaxEarlyData: uint32(ed), - Headers: h, + Headers: headers, } case "grpc": - err := json.Unmarshal(n.NetworkSettings, &t.GRPCOptions) - if err != nil { - return option.Inbound{}, fmt.Errorf("decode NetworkSettings error: %s", err) + if len(n.NetworkSettings) != 0 { + err := json.Unmarshal(n.NetworkSettings, &t.GRPCOptions) + if err != nil { + return option.Inbound{}, fmt.Errorf("decode NetworkSettings error: %s", err) + } } } if info.Type == "vless" {