func main() { flag.Parse() core.PrintVersion() if *version { return } switch *logLevel { case "debug": log.SetLogLevel(log.DebugLevel) case "info": log.SetLogLevel(log.InfoLevel) case "warning": log.SetLogLevel(log.WarningLevel) case "error": log.SetLogLevel(log.ErrorLevel) default: fmt.Println("Unknown log level: " + *logLevel) return } if len(configFile) == 0 { log.Error("Config file is not set.") return } config, err := point.LoadConfig(configFile) if err != nil { log.Error("Failed to read config file (", configFile, "): ", configFile, err) return } if config.LogConfig != nil && len(config.LogConfig.AccessLog) > 0 { log.InitAccessLogger(config.LogConfig.AccessLog) } vPoint, err := point.NewPoint(config) if err != nil { log.Error("Failed to create Point server: ", err) return } if *test { fmt.Println("Configuration OK.") return } err = vPoint.Start() if err != nil { log.Error("Error starting Point server: ", err) return } osSignals := make(chan os.Signal, 1) signal.Notify(osSignals, os.Interrupt, os.Kill) <-osSignals vPoint.Close() }
func main() { flag.Parse() if *version { fmt.Printf("V2Ray %s (%s) %s", core.Version(), core.Codename, core.Build()) fmt.Println() fmt.Println(core.Intro) return } switch *logLevel { case "debug": log.SetLogLevel(log.DebugLevel) case "info": log.SetLogLevel(log.InfoLevel) case "warning": log.SetLogLevel(log.WarningLevel) case "error": log.SetLogLevel(log.ErrorLevel) default: fmt.Println("Unknown log level: " + *logLevel) return } if configFile == nil || len(*configFile) == 0 { log.Error("Config file is not set.") return } config, err := jsonconf.LoadConfig(*configFile) if err != nil { log.Error("Failed to read config file (%s): %v", *configFile, err) return } if config.LogConfig() != nil && len(config.LogConfig().AccessLog()) > 0 { log.InitAccessLogger(config.LogConfig().AccessLog()) } vPoint, err := core.NewPoint(config) if err != nil { log.Error("Failed to create Point server: %v", err) return } err = vPoint.Start() if err != nil { log.Error("Error starting Point server: %v", err) return } finish := make(chan bool) <-finish }
func main() { flag.Parse() core.PrintVersion() if *version { return } switch *logLevel { case "debug": log.SetLogLevel(log.DebugLevel) case "info": log.SetLogLevel(log.InfoLevel) case "warning": log.SetLogLevel(log.WarningLevel) case "error": log.SetLogLevel(log.ErrorLevel) default: fmt.Println("Unknown log level: " + *logLevel) return } if len(configFile) == 0 { log.Error("Config file is not set.") return } config, err := point.LoadConfig(configFile) if err != nil { log.Error("Failed to read config file (", configFile, "): ", configFile, err) return } vPoint, err := point.NewPoint(config) if err != nil { log.Error("Failed to create Point server: ", err) return } if *test { fmt.Println("Configuration OK.") return } err = vPoint.Start() if err != nil { log.Error("Error starting Point server: ", err) return } finish := make(chan bool) <-finish }
func startV2Ray() *point.Point { switch *logLevel { case "debug": log.SetLogLevel(log.DebugLevel) case "info": log.SetLogLevel(log.InfoLevel) case "warning": log.SetLogLevel(log.WarningLevel) case "error": log.SetLogLevel(log.ErrorLevel) default: fmt.Println("Unknown log level: " + *logLevel) return nil } if len(configFile) == 0 { log.Error("Config file is not set.") return nil } config, err := point.LoadConfig(configFile) if err != nil { log.Error("Failed to read config file (", configFile, "): ", configFile, err) return nil } if config.LogConfig != nil && len(config.LogConfig.AccessLog) > 0 { log.InitAccessLogger(config.LogConfig.AccessLog) } vPoint, err := point.NewPoint(config) if err != nil { log.Error("Failed to create Point server: ", err) return nil } if *test { fmt.Println("Configuration OK.") return nil } err = vPoint.Start() if err != nil { log.Error("Error starting Point server: ", err) return nil } return vPoint }
func main() { flag.Parse() if *version { fmt.Printf("V2Ray version %s (%s): %s", core.Version, core.Codename, core.Intro) fmt.Println() return } switch *logLevel { case "debug": log.SetLogLevel(log.DebugLevel) case "info": log.SetLogLevel(log.InfoLevel) case "warning": log.SetLogLevel(log.WarningLevel) case "error": log.SetLogLevel(log.ErrorLevel) } if configFile == nil || len(*configFile) == 0 { panic(log.Error("Config file is not set.")) } config, err := jsonconf.LoadConfig(*configFile) if err != nil { panic(log.Error("Failed to read config file (%s): %v", *configFile, err)) } vPoint, err := core.NewPoint(config) if err != nil { panic(log.Error("Failed to create Point server: %v", err)) } err = vPoint.Start() if err != nil { log.Error("Error starting Point server: %v", err) } finish := make(chan bool) <-finish }
// NewPoint returns a new Point server based on given configuration. // The server is not started at this point. func NewPoint(pConfig *Config) (*Point, error) { var vpoint = new(Point) vpoint.port = pConfig.Port if pConfig.LogConfig != nil { logConfig := pConfig.LogConfig if len(logConfig.AccessLog) > 0 { err := log.InitAccessLogger(logConfig.AccessLog) if err != nil { return nil, err } } if len(logConfig.ErrorLog) > 0 { err := log.InitErrorLogger(logConfig.ErrorLog) if err != nil { return nil, err } } log.SetLogLevel(logConfig.LogLevel) } vpoint.space = controller.New() vpoint.space.Bind(vpoint) ichConfig := pConfig.InboundConfig.Settings ich, err := proxyrepo.CreateInboundConnectionHandler(pConfig.InboundConfig.Protocol, vpoint.space.ForContext("vpoint-default-inbound"), ichConfig) if err != nil { log.Error("Failed to create inbound connection handler: ", err) return nil, err } vpoint.ich = ich ochConfig := pConfig.OutboundConfig.Settings och, err := proxyrepo.CreateOutboundConnectionHandler(pConfig.OutboundConfig.Protocol, vpoint.space.ForContext("vpoint-default-outbound"), ochConfig) if err != nil { log.Error("Failed to create outbound connection handler: ", err) return nil, err } vpoint.och = och vpoint.taggedIdh = make(map[string]InboundDetourHandler) detours := pConfig.InboundDetours if len(detours) > 0 { vpoint.idh = make([]InboundDetourHandler, len(detours)) for idx, detourConfig := range detours { allocConfig := detourConfig.Allocation var detourHandler InboundDetourHandler switch allocConfig.Strategy { case AllocationStrategyAlways: dh, err := NewInboundDetourHandlerAlways(vpoint.space.ForContext(detourConfig.Tag), detourConfig) if err != nil { log.Error("Point: Failed to create detour handler: ", err) return nil, BadConfiguration } detourHandler = dh default: log.Error("Point: Unknown allocation strategy: ", allocConfig.Strategy) return nil, BadConfiguration } vpoint.idh[idx] = detourHandler if len(detourConfig.Tag) > 0 { vpoint.taggedIdh[detourConfig.Tag] = detourHandler } } } outboundDetours := pConfig.OutboundDetours if len(outboundDetours) > 0 { vpoint.odh = make(map[string]proxy.OutboundConnectionHandler) for _, detourConfig := range outboundDetours { detourHandler, err := proxyrepo.CreateOutboundConnectionHandler(detourConfig.Protocol, vpoint.space.ForContext(detourConfig.Tag), detourConfig.Settings) if err != nil { log.Error("Failed to create detour outbound connection handler: ", err) return nil, err } vpoint.odh[detourConfig.Tag] = detourHandler } } routerConfig := pConfig.RouterConfig if routerConfig != nil { r, err := router.CreateRouter(routerConfig.Strategy, routerConfig.Settings) if err != nil { log.Error("Failed to create router: ", err) return nil, BadConfiguration } vpoint.router = r } return vpoint, nil }
// NewPoint returns a new Point server based on given configuration. // The server is not started at this point. func NewPoint(pConfig *Config) (*Point, error) { var vpoint = new(Point) vpoint.port = pConfig.Port if pConfig.LogConfig != nil { logConfig := pConfig.LogConfig if len(logConfig.AccessLog) > 0 { err := log.InitAccessLogger(logConfig.AccessLog) if err != nil { return nil, err } } if len(logConfig.ErrorLog) > 0 { err := log.InitErrorLogger(logConfig.ErrorLog) if err != nil { return nil, err } } log.SetLogLevel(logConfig.LogLevel) } vpoint.space = controller.New() vpoint.space.Bind(vpoint) ichConfig := pConfig.InboundConfig.Settings ich, err := proxyrepo.CreateInboundConnectionHandler(pConfig.InboundConfig.Protocol, vpoint.space.ForContext("vpoint-default-inbound"), ichConfig) if err != nil { log.Error("Failed to create inbound connection handler: ", err) return nil, err } vpoint.ich = ich ochConfig := pConfig.OutboundConfig.Settings och, err := proxyrepo.CreateOutboundConnectionHandler(pConfig.OutboundConfig.Protocol, vpoint.space.ForContext("vpoint-default-outbound"), ochConfig) if err != nil { log.Error("Failed to create outbound connection handler: ", err) return nil, err } vpoint.och = och detours := pConfig.InboundDetours if len(detours) > 0 { vpoint.idh = make([]*InboundDetourHandler, len(detours)) for idx, detourConfig := range detours { detourHandler := &InboundDetourHandler{ space: vpoint.space.ForContext(detourConfig.Tag), config: detourConfig, } err := detourHandler.Initialize() if err != nil { return nil, err } vpoint.idh[idx] = detourHandler } } outboundDetours := pConfig.OutboundDetours if len(outboundDetours) > 0 { vpoint.odh = make(map[string]proxy.OutboundConnectionHandler) for _, detourConfig := range outboundDetours { detourHandler, err := proxyrepo.CreateOutboundConnectionHandler(detourConfig.Protocol, vpoint.space.ForContext(detourConfig.Tag), detourConfig.Settings) if err != nil { log.Error("Failed to create detour outbound connection handler: ", err) return nil, err } vpoint.odh[detourConfig.Tag] = detourHandler } } routerConfig := pConfig.RouterConfig if routerConfig != nil { r, err := router.CreateRouter(routerConfig.Strategy, routerConfig.Settings) if err != nil { log.Error("Failed to create router: ", err) return nil, BadConfiguration } vpoint.router = r } return vpoint, nil }
// NewPoint returns a new Point server based on given configuration. // The server is not started at this point. func NewPoint(pConfig PointConfig) (*Point, error) { var vpoint = new(Point) vpoint.port = pConfig.Port() if pConfig.LogConfig() != nil { logConfig := pConfig.LogConfig() if len(logConfig.AccessLog()) > 0 { err := log.InitAccessLogger(logConfig.AccessLog()) if err != nil { return nil, err } } if len(logConfig.ErrorLog()) > 0 { err := log.InitErrorLogger(logConfig.ErrorLog()) if err != nil { return nil, err } } log.SetLogLevel(logConfig.LogLevel()) } vpoint.space = controller.New() vpoint.space.Bind(vpoint) ichFactory := connhandler.GetInboundConnectionHandlerFactory(pConfig.InboundConfig().Protocol()) if ichFactory == nil { log.Error("Unknown inbound connection handler factory %s", pConfig.InboundConfig().Protocol()) return nil, BadConfiguration } ichConfig := pConfig.InboundConfig().Settings() ich, err := ichFactory.Create(vpoint.space.ForContext("vpoint-default-inbound"), ichConfig) if err != nil { log.Error("Failed to create inbound connection handler: %v", err) return nil, err } vpoint.ich = ich ochFactory := connhandler.GetOutboundConnectionHandlerFactory(pConfig.OutboundConfig().Protocol()) if ochFactory == nil { log.Error("Unknown outbound connection handler factory %s", pConfig.OutboundConfig().Protocol()) return nil, BadConfiguration } ochConfig := pConfig.OutboundConfig().Settings() och, err := ochFactory.Create(vpoint.space.ForContext("vpoint-default-outbound"), ochConfig) if err != nil { log.Error("Failed to create outbound connection handler: %v", err) return nil, err } vpoint.och = och detours := pConfig.InboundDetours() if len(detours) > 0 { vpoint.idh = make([]*InboundDetourHandler, len(detours)) for idx, detourConfig := range detours { detourHandler := &InboundDetourHandler{ space: vpoint.space.ForContext(detourConfig.Tag()), config: detourConfig, } err := detourHandler.Initialize() if err != nil { return nil, err } vpoint.idh[idx] = detourHandler } } outboundDetours := pConfig.OutboundDetours() if len(outboundDetours) > 0 { vpoint.odh = make(map[string]connhandler.OutboundConnectionHandler) for _, detourConfig := range outboundDetours { detourFactory := connhandler.GetOutboundConnectionHandlerFactory(detourConfig.Protocol()) if detourFactory == nil { log.Error("Unknown detour outbound connection handler factory %s", detourConfig.Protocol()) return nil, BadConfiguration } detourHandler, err := detourFactory.Create(vpoint.space.ForContext(detourConfig.Tag()), detourConfig.Settings()) if err != nil { log.Error("Failed to create detour outbound connection handler: %v", err) return nil, err } vpoint.odh[detourConfig.Tag()] = detourHandler } } routerConfig := pConfig.RouterConfig() if routerConfig != nil { r, err := router.CreateRouter(routerConfig.Strategy(), routerConfig.Settings()) if err != nil { log.Error("Failed to create router: %v", err) return nil, BadConfiguration } vpoint.router = r } return vpoint, nil }