core.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Package core provides an entry point to use Xray core functionalities.
  2. //
  3. // Xray makes it possible to accept incoming network connections with certain
  4. // protocol, process the data, and send them through another connection with
  5. // the same or a difference protocol on demand.
  6. //
  7. // It may be configured to work with multiple protocols at the same time, and
  8. // uses the internal router to tunnel through different inbound and outbound
  9. // connections.
  10. package core
  11. import (
  12. "fmt"
  13. "runtime"
  14. "runtime/debug"
  15. "github.com/xtls/xray-core/common/serial"
  16. )
  17. var (
  18. Version_x byte = 26
  19. Version_y byte = 2
  20. Version_z byte = 6
  21. )
  22. var (
  23. build = "Custom"
  24. codename = "Xray, Penetrates Everything."
  25. intro = "A unified platform for anti-censorship."
  26. )
  27. func init() {
  28. // Manually injected
  29. if build != "Custom" {
  30. return
  31. }
  32. info, ok := debug.ReadBuildInfo()
  33. if !ok {
  34. return
  35. }
  36. var isDirty bool
  37. var foundBuild bool
  38. for _, setting := range info.Settings {
  39. switch setting.Key {
  40. case "vcs.revision":
  41. if len(setting.Value) < 7 {
  42. return
  43. }
  44. build = setting.Value[:7]
  45. foundBuild = true
  46. case "vcs.modified":
  47. isDirty = setting.Value == "true"
  48. }
  49. }
  50. if isDirty && foundBuild {
  51. build += "-dirty"
  52. }
  53. }
  54. // Version returns Xray's version as a string, in the form of "x.y.z" where x, y and z are numbers.
  55. // ".z" part may be omitted in regular releases.
  56. func Version() string {
  57. return fmt.Sprintf("%v.%v.%v", Version_x, Version_y, Version_z)
  58. }
  59. // VersionStatement returns a list of strings representing the full version info.
  60. func VersionStatement() []string {
  61. return []string{
  62. serial.Concat("Xray ", Version(), " (", codename, ") ", build, " (", runtime.Version(), " ", runtime.GOOS, "/", runtime.GOARCH, ")"),
  63. intro,
  64. }
  65. }