functions.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package core
  2. import (
  3. "context"
  4. "v2ray.com/core/common"
  5. "v2ray.com/core/common/buf"
  6. )
  7. // CreateObject creates a new object based on the given V2Ray instance and config. The V2Ray instance may be nil.
  8. func CreateObject(v *Instance, config interface{}) (interface{}, error) {
  9. ctx := context.Background()
  10. if v != nil {
  11. ctx = context.WithValue(ctx, v2rayKey, v)
  12. }
  13. return common.CreateObject(ctx, config)
  14. }
  15. // StartInstance starts a new V2Ray instance with given serialized config, and return a handle for shutting down the instance.
  16. func StartInstance(configFormat string, configBytes []byte) (common.Closable, error) {
  17. var mb buf.MultiBuffer
  18. common.Must2(mb.Write(configBytes))
  19. config, err := LoadConfig(configFormat, "", &mb)
  20. if err != nil {
  21. return nil, err
  22. }
  23. instance, err := New(config)
  24. if err != nil {
  25. return nil, err
  26. }
  27. if err := instance.Start(); err != nil {
  28. return nil, err
  29. }
  30. return instance, nil
  31. }
  32. func PrintDeprecatedFeatureWarning(feature string) {
  33. newError("You are using a deprecated feature: " + feature + ". Please update your config file with latest configuration format, or update your client software.").WriteToLog()
  34. }