github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/proxy/shadowsocks/simplified/config.go (about) 1 package simplified 2 3 import ( 4 "context" 5 "encoding/json" 6 7 "github.com/golang/protobuf/jsonpb" 8 9 "github.com/v2fly/v2ray-core/v5/common" 10 "github.com/v2fly/v2ray-core/v5/common/protocol" 11 "github.com/v2fly/v2ray-core/v5/common/serial" 12 "github.com/v2fly/v2ray-core/v5/proxy/shadowsocks" 13 ) 14 15 func (c *CipherTypeWrapper) UnmarshalJSONPB(unmarshaler *jsonpb.Unmarshaler, bytes []byte) error { 16 var method string 17 18 if err := json.Unmarshal(bytes, &method); err != nil { 19 return err 20 } 21 22 if c.Value = shadowsocks.CipherFromString(method); c.Value == shadowsocks.CipherType_UNKNOWN { 23 return newError("unknown cipher method: ", method) 24 } 25 26 return nil 27 } 28 29 func init() { 30 common.Must(common.RegisterConfig((*ServerConfig)(nil), func(ctx context.Context, config interface{}) (interface{}, error) { 31 simplifiedServer := config.(*ServerConfig) 32 fullServer := &shadowsocks.ServerConfig{ 33 User: &protocol.User{ 34 Account: serial.ToTypedMessage(&shadowsocks.Account{ 35 Password: simplifiedServer.Password, 36 CipherType: simplifiedServer.Method.Value, 37 }), 38 }, 39 Network: simplifiedServer.Networks.GetNetwork(), 40 PacketEncoding: simplifiedServer.PacketEncoding, 41 } 42 43 return common.CreateObject(ctx, fullServer) 44 })) 45 46 common.Must(common.RegisterConfig((*ClientConfig)(nil), func(ctx context.Context, config interface{}) (interface{}, error) { 47 simplifiedClient := config.(*ClientConfig) 48 fullClient := &shadowsocks.ClientConfig{ 49 Server: []*protocol.ServerEndpoint{ 50 { 51 Address: simplifiedClient.Address, 52 Port: simplifiedClient.Port, 53 User: []*protocol.User{ 54 { 55 Account: serial.ToTypedMessage(&shadowsocks.Account{ 56 Password: simplifiedClient.Password, 57 CipherType: simplifiedClient.Method.Value, 58 ExperimentReducedIvHeadEntropy: simplifiedClient.ExperimentReducedIvHeadEntropy, 59 }), 60 }, 61 }, 62 }, 63 }, 64 } 65 66 return common.CreateObject(ctx, fullClient) 67 })) 68 }