From 3926463c5980574b891cd16787995c3a6b390f0f Mon Sep 17 00:00:00 2001 From: pocketW <104479902+pocketW@users.noreply.github.com> Date: Sun, 18 Dec 2022 12:11:55 +1100 Subject: [PATCH] feat: add shadowsocks2022 support for v2raysocks --- api/v2raysocks/v2raysocks.go | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/api/v2raysocks/v2raysocks.go b/api/v2raysocks/v2raysocks.go index 3366274..83b1d2f 100644 --- a/api/v2raysocks/v2raysocks.go +++ b/api/v2raysocks/v2raysocks.go @@ -14,6 +14,8 @@ import ( "github.com/bitly/go-simplejson" "github.com/go-resty/resty/v2" + "github.com/sagernet/sing-shadowsocks/shadowaead_2022" + C "github.com/sagernet/sing/common" "github.com/XrayR-project/XrayR/api" ) @@ -325,21 +327,28 @@ func (c *APIClient) ParseTrojanNodeResponse(nodeInfoResponse *simplejson.Json) ( return nodeinfo, nil } -// ParseSSNodeResponse parse the response for the given nodeinfor format +// ParseSSNodeResponse parse the response for the given nodeinfo format func (c *APIClient) ParseSSNodeResponse(nodeInfoResponse *simplejson.Json) (*api.NodeInfo, error) { - var method string + var method, serverPsk string tmpInboundInfo := nodeInfoResponse.Get("inbounds").MustArray() marshalByte, _ := json.Marshal(tmpInboundInfo[0].(map[string]interface{})) inboundInfo, _ := simplejson.NewJson(marshalByte) port := uint32(inboundInfo.Get("port").MustUint64()) - userInfo, err := c.GetUserList() - if err != nil { - return nil, err - } - if len(*userInfo) > 0 { - method = (*userInfo)[0].Method + method = inboundInfo.Get("settings").Get("method").MustString() + // Shadowsocks 2022 + if C.Contains(shadowaead_2022.List, method) { + serverPsk = inboundInfo.Get("settings").Get("password").MustString() + } else { + userInfo, err := c.GetUserList() + if err != nil { + return nil, err + } + if len(*userInfo) > 0 { + method = (*userInfo)[0].Method + } } + // Create GeneralNodeInfo nodeinfo := &api.NodeInfo{ NodeType: c.NodeType, @@ -347,6 +356,7 @@ func (c *APIClient) ParseSSNodeResponse(nodeInfoResponse *simplejson.Json) (*api Port: port, TransportProtocol: "tcp", CypherMethod: method, + ServerKey: serverPsk, } return nodeinfo, nil