config.go 1.9 KB

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