Browse Source

Merge branch 'master' into set-var-in-go-build

Kslr 5 years ago
parent
commit
fd1eae75ea

+ 16 - 0
common/cmdarg/cmdarg.go

@@ -0,0 +1,16 @@
+package cmdarg
+
+import "strings"
+
+// Arg is used by flag to accept multiple argument.
+type Arg []string
+
+func (c *Arg) String() string {
+	return strings.Join([]string(*c), " ")
+}
+
+// Set is the method flag package calls
+func (c *Arg) Set(value string) error {
+	*c = append(*c, value)
+	return nil
+}

+ 9 - 0
common/log/logger.go

@@ -119,6 +119,15 @@ func CreateStdoutLogWriter() WriterCreator {
 	}
 }
 
+// CreateStderrLogWriter returns a LogWriterCreator that creates LogWriter for stderr.
+func CreateStderrLogWriter() WriterCreator {
+	return func() Writer {
+		return &consoleLogWriter{
+			logger: log.New(os.Stderr, "", log.Ldate|log.Ltime),
+		}
+	}
+}
+
 // CreateFileLogWriter returns a LogWriterCreator that creates LogWriter for the given file.
 func CreateFileLogWriter(path string) (WriterCreator, error) {
 	file, err := os.OpenFile(path, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)

+ 5 - 0
common/platform/ctlcmd/ctlcmd.go

@@ -40,5 +40,10 @@ func Run(args []string, input io.Reader) (buf.MultiBuffer, error) {
 		return nil, newError(msg).Base(err)
 	}
 
+	// log stderr, info message
+	if !errBuffer.IsEmpty() {
+		newError("v2ctl > \n", errBuffer.MultiBuffer.String()).AtInfo().WriteToLog()
+	}
+
 	return outBuffer.MultiBuffer, nil
 }

+ 24 - 8
config.go

@@ -9,6 +9,8 @@ import (
 	"github.com/golang/protobuf/proto"
 	"v2ray.com/core/common"
 	"v2ray.com/core/common/buf"
+	"v2ray.com/core/common/cmdarg"
+	"v2ray.com/core/main/confloader"
 )
 
 // ConfigFormat is a configurable format of V2Ray config file.
@@ -19,7 +21,7 @@ type ConfigFormat struct {
 }
 
 // ConfigLoader is a utility to load V2Ray config from external source.
-type ConfigLoader func(input io.Reader) (*Config, error)
+type ConfigLoader func(input interface{}) (*Config, error)
 
 var (
 	configLoaderByName = make(map[string]*ConfigFormat)
@@ -54,7 +56,10 @@ func getExtension(filename string) string {
 }
 
 // LoadConfig loads config with given format from given source.
-func LoadConfig(formatName string, filename string, input io.Reader) (*Config, error) {
+// input accepts 2 different types:
+// * []string slice of multiple filename/url(s) to open to read
+// * io.Reader that reads a config content (the original way)
+func LoadConfig(formatName string, filename string, input interface{}) (*Config, error) {
 	ext := getExtension(filename)
 	if len(ext) > 0 {
 		if f, found := configLoaderByExt[ext]; found {
@@ -69,12 +74,8 @@ func LoadConfig(formatName string, filename string, input io.Reader) (*Config, e
 	return nil, newError("Unable to load config in ", formatName).AtWarning()
 }
 
-func loadProtobufConfig(input io.Reader) (*Config, error) {
+func loadProtobufConfig(data []byte) (*Config, error) {
 	config := new(Config)
-	data, err := buf.ReadAllToBytes(input)
-	if err != nil {
-		return nil, err
-	}
 	if err := proto.Unmarshal(data, config); err != nil {
 		return nil, err
 	}
@@ -85,6 +86,21 @@ func init() {
 	common.Must(RegisterConfigLoader(&ConfigFormat{
 		Name:      "Protobuf",
 		Extension: []string{"pb"},
-		Loader:    loadProtobufConfig,
+		Loader: func(input interface{}) (*Config, error) {
+			switch v := input.(type) {
+			case cmdarg.Arg:
+				r, err := confloader.LoadConfig(v[0])
+				common.Must(err)
+				data, err := buf.ReadAllToBytes(r)
+				common.Must(err)
+				return loadProtobufConfig(data)
+			case io.Reader:
+				data, err := buf.ReadAllToBytes(v)
+				common.Must(err)
+				return loadProtobufConfig(data)
+			default:
+				return nil, newError("unknow type")
+			}
+		},
 	}))
 }

+ 1 - 1
core.go

@@ -19,7 +19,7 @@ import (
 )
 
 var (
-	version  = "4.21.3"
+	version  = "4.22.0"
 	build    = "Custom"
 	codename = "V2Fly, a community-driven edition of V2Ray."
 	intro    = "A unified platform for anti-censorship."

+ 0 - 48
infra/conf/command/command.go

@@ -1,48 +0,0 @@
-package command
-
-//go:generate errorgen
-
-import (
-	"os"
-
-	"github.com/golang/protobuf/proto"
-	"v2ray.com/core/common"
-	"v2ray.com/core/infra/conf/serial"
-	"v2ray.com/core/infra/control"
-)
-
-type ConfigCommand struct{}
-
-func (c *ConfigCommand) Name() string {
-	return "config"
-}
-
-func (c *ConfigCommand) Description() control.Description {
-	return control.Description{
-		Short: "Convert config among different formats.",
-		Usage: []string{
-			"v2ctl config",
-		},
-	}
-}
-
-func (c *ConfigCommand) Execute(args []string) error {
-	pbConfig, err := serial.LoadJSONConfig(os.Stdin)
-	if err != nil {
-		return newError("failed to parse json config").Base(err)
-	}
-
-	bytesConfig, err := proto.Marshal(pbConfig)
-	if err != nil {
-		return newError("failed to marshal proto config").Base(err)
-	}
-
-	if _, err := os.Stdout.Write(bytesConfig); err != nil {
-		return newError("failed to write proto config").Base(err)
-	}
-	return nil
-}
-
-func init() {
-	common.Must(control.RegisterCommand(&ConfigCommand{}))
-}

+ 12 - 1
infra/conf/serial/loader.go

@@ -38,7 +38,9 @@ func findOffset(b []byte, o int) *offset {
 	return &offset{line: line, char: char}
 }
 
-func LoadJSONConfig(reader io.Reader) (*core.Config, error) {
+// DecodeJSONConfig reads from reader and decode the config into *conf.Config
+// syntax error could be detected.
+func DecodeJSONConfig(reader io.Reader) (*conf.Config, error) {
 	jsonConfig := &conf.Config{}
 
 	jsonContent := bytes.NewBuffer(make([]byte, 0, 10240))
@@ -62,6 +64,15 @@ func LoadJSONConfig(reader io.Reader) (*core.Config, error) {
 		return nil, newError("failed to read config file").Base(err)
 	}
 
+	return jsonConfig, nil
+}
+
+func LoadJSONConfig(reader io.Reader) (*core.Config, error) {
+	jsonConfig, err := DecodeJSONConfig(reader)
+	if err != nil {
+		return nil, err
+	}
+
 	pbConfig, err := jsonConfig.Build()
 	if err != nil {
 		return nil, newError("failed to parse json config").Base(err)

+ 88 - 0
infra/conf/v2ray.go

@@ -304,6 +304,94 @@ type Config struct {
 	Reverse         *ReverseConfig         `json:"reverse"`
 }
 
+func (c *Config) findInboundTag(tag string) int {
+	found := -1
+	for idx, ib := range c.InboundConfigs {
+		if ib.Tag == tag {
+			found = idx
+			break
+		}
+	}
+	return found
+}
+
+func (c *Config) findOutboundTag(tag string) int {
+	found := -1
+	for idx, ob := range c.OutboundConfigs {
+		if ob.Tag == tag {
+			found = idx
+			break
+		}
+	}
+	return found
+}
+
+// Override method accepts another Config overrides the current attribute
+func (c *Config) Override(o *Config, fn string) {
+
+	// only process the non-deprecated members
+
+	if o.LogConfig != nil {
+		c.LogConfig = o.LogConfig
+	}
+	if o.RouterConfig != nil {
+		c.RouterConfig = o.RouterConfig
+	}
+	if o.DNSConfig != nil {
+		c.DNSConfig = o.DNSConfig
+	}
+	if o.Transport != nil {
+		c.Transport = o.Transport
+	}
+	if o.Policy != nil {
+		c.Policy = o.Policy
+	}
+	if o.Api != nil {
+		c.Api = o.Api
+	}
+	if o.Stats != nil {
+		c.Stats = o.Stats
+	}
+	if o.Reverse != nil {
+		c.Reverse = o.Reverse
+	}
+
+	// update the Inbound in slice if the only one in overide config has same tag
+	if len(o.InboundConfigs) > 0 {
+		if len(c.InboundConfigs) > 0 && len(o.InboundConfigs) == 1 {
+			if idx := c.findInboundTag(o.InboundConfigs[0].Tag); idx > -1 {
+				c.InboundConfigs[idx] = o.InboundConfigs[0]
+				newError("<", fn, "> updated inbound with tag: ", o.InboundConfigs[0].Tag).AtInfo().WriteToLog()
+			} else {
+				c.InboundConfigs = append(c.InboundConfigs, o.InboundConfigs[0])
+				newError("<", fn, "> appended inbound with tag: ", o.InboundConfigs[0].Tag).AtInfo().WriteToLog()
+			}
+		} else {
+			c.InboundConfigs = o.InboundConfigs
+		}
+	}
+
+	// update the Outbound in slice if the only one in overide config has same tag
+	if len(o.OutboundConfigs) > 0 {
+		if len(c.OutboundConfigs) > 0 && len(o.OutboundConfigs) == 1 {
+			if idx := c.findOutboundTag(o.OutboundConfigs[0].Tag); idx > -1 {
+				c.OutboundConfigs[idx] = o.OutboundConfigs[0]
+				newError("<", fn, "> updated outbound with tag: ", o.OutboundConfigs[0].Tag).AtInfo().WriteToLog()
+			} else {
+				if strings.Contains(strings.ToLower(fn), "tail") {
+					c.OutboundConfigs = append(c.OutboundConfigs, o.OutboundConfigs[0])
+					newError("<", fn, "> appended outbound with tag: ", o.OutboundConfigs[0].Tag).AtInfo().WriteToLog()
+				} else {
+					c.OutboundConfigs = append(o.OutboundConfigs, c.OutboundConfigs...)
+					newError("<", fn, "> prepended outbound with tag: ", o.OutboundConfigs[0].Tag).AtInfo().WriteToLog()
+				}
+			}
+		} else {
+			c.OutboundConfigs = o.OutboundConfigs
+		}
+	}
+}
+
 func applyTransportConfig(s *StreamConfig, t *TransportConfig) {
 	if s.TCPSettings == nil {
 		s.TCPSettings = t.TCPConfig

+ 78 - 0
infra/conf/v2ray_test.go

@@ -6,6 +6,7 @@ import (
 	"testing"
 
 	"github.com/golang/protobuf/proto"
+	"github.com/google/go-cmp/cmp"
 	"v2ray.com/core"
 	"v2ray.com/core/app/dispatcher"
 	"v2ray.com/core/app/log"
@@ -369,3 +370,80 @@ func TestMuxConfig_Build(t *testing.T) {
 		})
 	}
 }
+
+func TestConfig_Override(t *testing.T) {
+	tests := []struct {
+		name string
+		orig *Config
+		over *Config
+		fn   string
+		want *Config
+	}{
+		{"combine/empty",
+			&Config{},
+			&Config{
+				LogConfig:    &LogConfig{},
+				RouterConfig: &RouterConfig{},
+				DNSConfig:    &DnsConfig{},
+				Transport:    &TransportConfig{},
+				Policy:       &PolicyConfig{},
+				Api:          &ApiConfig{},
+				Stats:        &StatsConfig{},
+				Reverse:      &ReverseConfig{},
+			},
+			"",
+			&Config{
+				LogConfig:    &LogConfig{},
+				RouterConfig: &RouterConfig{},
+				DNSConfig:    &DnsConfig{},
+				Transport:    &TransportConfig{},
+				Policy:       &PolicyConfig{},
+				Api:          &ApiConfig{},
+				Stats:        &StatsConfig{},
+				Reverse:      &ReverseConfig{},
+			},
+		},
+		{"combine/newattr",
+			&Config{InboundConfigs: []InboundDetourConfig{InboundDetourConfig{Tag: "old"}}},
+			&Config{LogConfig: &LogConfig{}}, "",
+			&Config{LogConfig: &LogConfig{}, InboundConfigs: []InboundDetourConfig{InboundDetourConfig{Tag: "old"}}}},
+		{"replace/inbounds",
+			&Config{InboundConfigs: []InboundDetourConfig{InboundDetourConfig{Tag: "pos0"}, InboundDetourConfig{Protocol: "vmess", Tag: "pos1"}}},
+			&Config{InboundConfigs: []InboundDetourConfig{InboundDetourConfig{Tag: "pos1", Protocol: "kcp"}}},
+			"",
+			&Config{InboundConfigs: []InboundDetourConfig{InboundDetourConfig{Tag: "pos0"}, InboundDetourConfig{Tag: "pos1", Protocol: "kcp"}}}},
+		{"replace/inbounds-replaceall",
+			&Config{InboundConfigs: []InboundDetourConfig{InboundDetourConfig{Tag: "pos0"}, InboundDetourConfig{Protocol: "vmess", Tag: "pos1"}}},
+			&Config{InboundConfigs: []InboundDetourConfig{InboundDetourConfig{Tag: "pos1", Protocol: "kcp"}, InboundDetourConfig{Tag: "pos2", Protocol: "kcp"}}},
+			"",
+			&Config{InboundConfigs: []InboundDetourConfig{InboundDetourConfig{Tag: "pos1", Protocol: "kcp"}, InboundDetourConfig{Tag: "pos2", Protocol: "kcp"}}}},
+		{"replace/notag-append",
+			&Config{InboundConfigs: []InboundDetourConfig{InboundDetourConfig{}, InboundDetourConfig{Protocol: "vmess"}}},
+			&Config{InboundConfigs: []InboundDetourConfig{InboundDetourConfig{Tag: "pos1", Protocol: "kcp"}}},
+			"",
+			&Config{InboundConfigs: []InboundDetourConfig{InboundDetourConfig{}, InboundDetourConfig{Protocol: "vmess"}, InboundDetourConfig{Tag: "pos1", Protocol: "kcp"}}}},
+		{"replace/outbounds",
+			&Config{OutboundConfigs: []OutboundDetourConfig{OutboundDetourConfig{Tag: "pos0"}, OutboundDetourConfig{Protocol: "vmess", Tag: "pos1"}}},
+			&Config{OutboundConfigs: []OutboundDetourConfig{OutboundDetourConfig{Tag: "pos1", Protocol: "kcp"}}},
+			"",
+			&Config{OutboundConfigs: []OutboundDetourConfig{OutboundDetourConfig{Tag: "pos0"}, OutboundDetourConfig{Tag: "pos1", Protocol: "kcp"}}}},
+		{"replace/outbounds-prepend",
+			&Config{OutboundConfigs: []OutboundDetourConfig{OutboundDetourConfig{Tag: "pos0"}, OutboundDetourConfig{Protocol: "vmess", Tag: "pos1"}}},
+			&Config{OutboundConfigs: []OutboundDetourConfig{OutboundDetourConfig{Tag: "pos1", Protocol: "kcp"}, OutboundDetourConfig{Tag: "pos2", Protocol: "kcp"}}},
+			"config.json",
+			&Config{OutboundConfigs: []OutboundDetourConfig{OutboundDetourConfig{Tag: "pos1", Protocol: "kcp"}, OutboundDetourConfig{Tag: "pos2", Protocol: "kcp"}}}},
+		{"replace/outbounds-append",
+			&Config{OutboundConfigs: []OutboundDetourConfig{OutboundDetourConfig{Tag: "pos0"}, OutboundDetourConfig{Protocol: "vmess", Tag: "pos1"}}},
+			&Config{OutboundConfigs: []OutboundDetourConfig{OutboundDetourConfig{Tag: "pos2", Protocol: "kcp"}}},
+			"config_tail.json",
+			&Config{OutboundConfigs: []OutboundDetourConfig{OutboundDetourConfig{Tag: "pos0"}, OutboundDetourConfig{Protocol: "vmess", Tag: "pos1"}, OutboundDetourConfig{Tag: "pos2", Protocol: "kcp"}}}},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			tt.orig.Override(tt.over, tt.fn)
+			if r := cmp.Diff(tt.orig, tt.want); r != "" {
+				t.Error(r)
+			}
+		})
+	}
+}

+ 86 - 0
infra/control/config.go

@@ -0,0 +1,86 @@
+package control
+
+import (
+	"bytes"
+	"io"
+	"io/ioutil"
+	"os"
+	"strings"
+
+	"github.com/golang/protobuf/proto"
+	"v2ray.com/core/common"
+	"v2ray.com/core/infra/conf"
+	"v2ray.com/core/infra/conf/serial"
+)
+
+// ConfigCommand is the json to pb convert struct
+type ConfigCommand struct{}
+
+// Name for cmd usage
+func (c *ConfigCommand) Name() string {
+	return "config"
+}
+
+// Description for help usage
+func (c *ConfigCommand) Description() Description {
+	return Description{
+		Short: "merge multiple json config",
+		Usage: []string{"v2ctl config config.json c1.json c2.json <url>.json"},
+	}
+}
+
+// Execute real work here.
+func (c *ConfigCommand) Execute(args []string) error {
+	if len(args) < 1 {
+		return newError("empty config list")
+	}
+
+	conf := &conf.Config{}
+	for _, arg := range args {
+		newError("Reading config: ", arg).AtInfo().WriteToLog()
+		r, err := c.LoadArg(arg)
+		common.Must(err)
+		c, err := serial.DecodeJSONConfig(r)
+		common.Must(err)
+		conf.Override(c, arg)
+	}
+
+	pbConfig, err := conf.Build()
+	if err != nil {
+		return err
+	}
+
+	bytesConfig, err := proto.Marshal(pbConfig)
+	if err != nil {
+		return newError("failed to marshal proto config").Base(err)
+	}
+
+	if _, err := os.Stdout.Write(bytesConfig); err != nil {
+		return newError("failed to write proto config").Base(err)
+	}
+
+	return nil
+}
+
+// LoadArg loads one arg, maybe an remote url, or local file path
+func (c *ConfigCommand) LoadArg(arg string) (out io.Reader, err error) {
+
+	var data []byte
+	if strings.HasPrefix(arg, "http://") || strings.HasPrefix(arg, "https://") {
+		data, err = FetchHTTPContent(arg)
+	} else if arg == "stdin:" {
+		data, err = ioutil.ReadAll(os.Stdin)
+	} else {
+		data, err = ioutil.ReadFile(arg)
+	}
+
+	if err != nil {
+		return
+	}
+	out = bytes.NewBuffer(data)
+	return
+}
+
+func init() {
+	common.Must(RegisterCommand(&ConfigCommand{}))
+}

+ 25 - 16
infra/control/fetch.go

@@ -5,6 +5,7 @@ import (
 	"net/url"
 	"os"
 	"strings"
+	"time"
 
 	"v2ray.com/core/common"
 	"v2ray.com/core/common/buf"
@@ -23,46 +24,54 @@ func (c *FetchCommand) Description() Description {
 	}
 }
 
-func (c *FetchCommand) isValidScheme(scheme string) bool {
-	scheme = strings.ToLower(scheme)
-	return scheme == "http" || scheme == "https"
-}
-
 func (c *FetchCommand) Execute(args []string) error {
 	if len(args) < 1 {
 		return newError("empty url")
 	}
-	target := args[0]
+	content, err := FetchHTTPContent(args[0])
+	if err != nil {
+		return newError("failed to read HTTP response").Base(err)
+	}
+
+	os.Stdout.Write(content)
+	return nil
+}
+
+// FetchHTTPContent dials https for remote content
+func FetchHTTPContent(target string) ([]byte, error) {
+
 	parsedTarget, err := url.Parse(target)
 	if err != nil {
-		return newError("invalid URL: ", target).Base(err)
+		return nil, newError("invalid URL: ", target).Base(err)
 	}
-	if !c.isValidScheme(parsedTarget.Scheme) {
-		return newError("invalid scheme: ", parsedTarget.Scheme)
+
+	if s := strings.ToLower(parsedTarget.Scheme); s != "http" && s != "https" {
+		return nil, newError("invalid scheme: ", parsedTarget.Scheme)
 	}
 
-	client := &http.Client{}
+	client := &http.Client{
+		Timeout: 30 * time.Second,
+	}
 	resp, err := client.Do(&http.Request{
 		Method: "GET",
 		URL:    parsedTarget,
 		Close:  true,
 	})
 	if err != nil {
-		return newError("failed to dial to ", target).Base(err)
+		return nil, newError("failed to dial to ", target).Base(err)
 	}
+	defer resp.Body.Close()
 
 	if resp.StatusCode != 200 {
-		return newError("unexpected HTTP status code: ", resp.StatusCode)
+		return nil, newError("unexpected HTTP status code: ", resp.StatusCode)
 	}
 
 	content, err := buf.ReadAllToBytes(resp.Body)
 	if err != nil {
-		return newError("failed to read HTTP response").Base(err)
+		return nil, newError("failed to read HTTP response").Base(err)
 	}
 
-	os.Stdout.Write(content)
-
-	return nil
+	return content, nil
 }
 
 func init() {

+ 4 - 1
infra/control/main/main.go

@@ -5,7 +5,8 @@ import (
 	"fmt"
 	"os"
 
-	_ "v2ray.com/core/infra/conf/command"
+	commlog "v2ray.com/core/common/log"
+	// _ "v2ray.com/core/infra/conf/command"
 	"v2ray.com/core/infra/control"
 )
 
@@ -17,6 +18,8 @@ func getCommandName() string {
 }
 
 func main() {
+	// let the v2ctl prints log at stderr
+	commlog.RegisterHandler(commlog.NewLogger(commlog.CreateStderrLogWriter()))
 	name := getCommandName()
 	cmd := control.GetCommand(name)
 	if cmd == nil {

+ 17 - 2
main/confloader/confloader.go

@@ -5,15 +5,30 @@ import (
 	"os"
 )
 
-type configFileLoader func(string) (io.ReadCloser, error)
+type configFileLoader func(string) (io.Reader, error)
+type extconfigLoader func([]string) (io.Reader, error)
 
 var (
 	EffectiveConfigFileLoader configFileLoader
+	EffectiveExtConfigLoader  extconfigLoader
 )
 
-func LoadConfig(file string) (io.ReadCloser, error) {
+// LoadConfig reads from a path/url/stdin
+// actual work is in external module
+func LoadConfig(file string) (io.Reader, error) {
 	if EffectiveConfigFileLoader == nil {
+		newError("external config module not loaded, reading from stdin").AtInfo().WriteToLog()
 		return os.Stdin, nil
 	}
 	return EffectiveConfigFileLoader(file)
 }
+
+// LoadExtConfig calls v2ctl to handle multiple config
+// the actual work also in external module
+func LoadExtConfig(files []string) (io.Reader, error) {
+	if EffectiveExtConfigLoader == nil {
+		return nil, newError("external config module not loaded").AtError()
+	}
+
+	return EffectiveExtConfigLoader(files)
+}

+ 9 - 0
main/confloader/errors.generated.go

@@ -0,0 +1,9 @@
+package confloader
+
+import "v2ray.com/core/common/errors"
+
+type errPathObjHolder struct{}
+
+func newError(values ...interface{}) *errors.Error {
+	return errors.New(values...).WithPathObj(errPathObjHolder{})
+}

+ 60 - 22
main/confloader/external/external.go

@@ -1,48 +1,86 @@
 package external
 
+//go:generate errorgen
+
 import (
+	"bytes"
 	"io"
+	"io/ioutil"
+	"net/http"
+	"net/url"
 	"os"
 	"strings"
+	"time"
 
 	"v2ray.com/core/common/buf"
 	"v2ray.com/core/common/platform/ctlcmd"
 	"v2ray.com/core/main/confloader"
 )
 
-//go:generate errorgen
+func ConfigLoader(arg string) (out io.Reader, err error) {
+
+	var data []byte
+	if strings.HasPrefix(arg, "http://") || strings.HasPrefix(arg, "https://") {
+		data, err = FetchHTTPContent(arg)
+	} else if arg == "stdin:" {
+		data, err = ioutil.ReadAll(os.Stdin)
+	} else {
+		data, err = ioutil.ReadFile(arg)
+	}
+
+	if err != nil {
+		return
+	}
+	out = bytes.NewBuffer(data)
+	return
+}
+
+func FetchHTTPContent(target string) ([]byte, error) {
 
-func loadConfigFile(configFile string) (io.ReadCloser, error) {
-	if configFile == "stdin:" {
-		return os.Stdin, nil
+	parsedTarget, err := url.Parse(target)
+	if err != nil {
+		return nil, newError("invalid URL: ", target).Base(err)
+	}
+
+	if s := strings.ToLower(parsedTarget.Scheme); s != "http" && s != "https" {
+		return nil, newError("invalid scheme: ", parsedTarget.Scheme)
+	}
+
+	client := &http.Client{
+		Timeout: 30 * time.Second,
 	}
+	resp, err := client.Do(&http.Request{
+		Method: "GET",
+		URL:    parsedTarget,
+		Close:  true,
+	})
+	if err != nil {
+		return nil, newError("failed to dial to ", target).Base(err)
+	}
+	defer resp.Body.Close()
 
-	if strings.HasPrefix(configFile, "http://") || strings.HasPrefix(configFile, "https://") {
-		content, err := ctlcmd.Run([]string{"fetch", configFile}, nil)
-		if err != nil {
-			return nil, err
-		}
-		return &buf.MultiBufferContainer{
-			MultiBuffer: content,
-		}, nil
+	if resp.StatusCode != 200 {
+		return nil, newError("unexpected HTTP status code: ", resp.StatusCode)
 	}
 
-	fixedFile := os.ExpandEnv(configFile)
-	file, err := os.Open(fixedFile)
+	content, err := buf.ReadAllToBytes(resp.Body)
 	if err != nil {
-		return nil, newError("config file not readable").Base(err)
+		return nil, newError("failed to read HTTP response").Base(err)
 	}
-	defer file.Close()
 
-	content, err := buf.ReadFrom(file)
+	return content, nil
+}
+
+func ExtConfigLoader(files []string) (io.Reader, error) {
+	buf, err := ctlcmd.Run(append([]string{"config"}, files...), os.Stdin)
 	if err != nil {
-		return nil, newError("failed to load config file: ", fixedFile).Base(err).AtWarning()
+		return nil, err
 	}
-	return &buf.MultiBufferContainer{
-		MultiBuffer: content,
-	}, nil
+
+	return strings.NewReader(buf.String()), nil
 }
 
 func init() {
-	confloader.EffectiveConfigFileLoader = loadConfigFile
+	confloader.EffectiveConfigFileLoader = ConfigLoader
+	confloader.EffectiveExtConfigLoader = ExtConfigLoader
 }

+ 15 - 9
main/json/config_json.go

@@ -7,22 +7,28 @@ import (
 
 	"v2ray.com/core"
 	"v2ray.com/core/common"
-	"v2ray.com/core/common/buf"
-	"v2ray.com/core/common/platform/ctlcmd"
+	"v2ray.com/core/common/cmdarg"
+	"v2ray.com/core/infra/conf/serial"
+	"v2ray.com/core/main/confloader"
 )
 
 func init() {
 	common.Must(core.RegisterConfigLoader(&core.ConfigFormat{
 		Name:      "JSON",
 		Extension: []string{"json"},
-		Loader: func(input io.Reader) (*core.Config, error) {
-			jsonContent, err := ctlcmd.Run([]string{"config"}, input)
-			if err != nil {
-				return nil, newError("failed to execute v2ctl to convert config file.").Base(err).AtWarning()
+		Loader: func(input interface{}) (*core.Config, error) {
+			switch v := input.(type) {
+			case cmdarg.Arg:
+				r, err := confloader.LoadExtConfig(v)
+				if err != nil {
+					return nil, newError("failed to execute v2ctl to convert config file.").Base(err).AtWarning()
+				}
+				return core.LoadConfig("protobuf", "", r)
+			case io.Reader:
+				return serial.LoadJSONConfig(v)
+			default:
+				return nil, newError("unknow type")
 			}
-			return core.LoadConfig("protobuf", "", &buf.MultiBufferContainer{
-				MultiBuffer: jsonContent,
-			})
 		},
 	}))
 }

+ 1 - 1
infra/conf/command/errors.generated.go → main/jsonem/errors.generated.go

@@ -1,4 +1,4 @@
-package command
+package jsonem
 
 import "v2ray.com/core/common/errors"
 

+ 24 - 1
main/jsonem/jsonem.go

@@ -1,15 +1,38 @@
 package jsonem
 
 import (
+	"io"
+
 	"v2ray.com/core"
 	"v2ray.com/core/common"
+	"v2ray.com/core/common/cmdarg"
+	"v2ray.com/core/infra/conf"
 	"v2ray.com/core/infra/conf/serial"
+	"v2ray.com/core/main/confloader"
 )
 
 func init() {
 	common.Must(core.RegisterConfigLoader(&core.ConfigFormat{
 		Name:      "JSON",
 		Extension: []string{"json"},
-		Loader:    serial.LoadJSONConfig,
+		Loader: func(input interface{}) (*core.Config, error) {
+			switch v := input.(type) {
+			case cmdarg.Arg:
+				cf := &conf.Config{}
+				for _, arg := range v {
+					newError("Reading config: ", arg).AtInfo().WriteToLog()
+					r, err := confloader.LoadConfig(arg)
+					common.Must(err)
+					c, err := serial.DecodeJSONConfig(r)
+					common.Must(err)
+					cf.Override(c, arg)
+				}
+				return cf.Build()
+			case io.Reader:
+				return serial.LoadJSONConfig(v)
+			default:
+				return nil, newError("unknow type")
+			}
+		},
 	}))
 }

+ 21 - 17
main/main.go

@@ -13,16 +13,17 @@ import (
 	"syscall"
 
 	"v2ray.com/core"
+	"v2ray.com/core/common/cmdarg"
 	"v2ray.com/core/common/platform"
-	"v2ray.com/core/main/confloader"
 	_ "v2ray.com/core/main/distro/all"
 )
 
 var (
-	configFile = flag.String("config", "", "Config file for V2Ray.")
-	version    = flag.Bool("version", false, "Show current version of V2Ray.")
-	test       = flag.Bool("test", false, "Test config file only, without launching V2Ray server.")
-	format     = flag.String("format", "json", "Format of input file.")
+	configFiles cmdarg.Arg // "Config file for V2Ray.", the option is customed type, parse in main
+	version     = flag.Bool("version", false, "Show current version of V2Ray.")
+	test        = flag.Bool("test", false, "Test config file only, without launching V2Ray server.")
+	format      = flag.String("format", "json", "Format of input file.")
+	errNoConfig = newError("no valid config")
 )
 
 func fileExists(file string) bool {
@@ -30,23 +31,23 @@ func fileExists(file string) bool {
 	return err == nil && !info.IsDir()
 }
 
-func getConfigFilePath() string {
-	if len(*configFile) > 0 {
-		return *configFile
+func getConfigFilePath() (cmdarg.Arg, error) {
+	if len(configFiles) > 0 {
+		return configFiles, nil
 	}
 
 	if workingDir, err := os.Getwd(); err == nil {
 		configFile := filepath.Join(workingDir, "config.json")
 		if fileExists(configFile) {
-			return configFile
+			return cmdarg.Arg{configFile}, nil
 		}
 	}
 
 	if configFile := platform.GetConfigurationPath(); fileExists(configFile) {
-		return configFile
+		return cmdarg.Arg{configFile}, nil
 	}
 
-	return ""
+	return cmdarg.Arg{"stdin:"}, nil
 }
 
 func GetConfigFormat() string {
@@ -59,16 +60,14 @@ func GetConfigFormat() string {
 }
 
 func startV2Ray() (core.Server, error) {
-	configFile := getConfigFilePath()
-	configInput, err := confloader.LoadConfig(configFile)
+	configFiles, err := getConfigFilePath()
 	if err != nil {
-		return nil, newError("failed to load config: ", configFile).Base(err)
+		return nil, err
 	}
-	defer configInput.Close()
 
-	config, err := core.LoadConfig(GetConfigFormat(), configFile, configInput)
+	config, err := core.LoadConfig(GetConfigFormat(), configFiles[0], configFiles)
 	if err != nil {
-		return nil, newError("failed to read config file: ", configFile).Base(err)
+		return nil, newError("failed to read config files: [", configFiles.String(), "]").Base(err)
 	}
 
 	server, err := core.New(config)
@@ -87,6 +86,8 @@ func printVersion() {
 }
 
 func main() {
+	flag.Var(&configFiles, "config", "Config file for V2Ray. Multiple assign is accepted (only json). Latter ones overrides the former ones.")
+	flag.Var(&configFiles, "c", "short alias of -config")
 	flag.Parse()
 
 	printVersion()
@@ -99,6 +100,9 @@ func main() {
 	if err != nil {
 		fmt.Println(err.Error())
 		// Configuration error. Exit with a special value to prevent systemd from restarting.
+		if err == errNoConfig {
+			flag.PrintDefaults()
+		}
 		os.Exit(23)
 	}
 

+ 15 - 0
main/targets.bzl

@@ -67,3 +67,18 @@ def gen_targets(matrix):
         name = bin_name + "_sig",
         base = ":" + bin_name,
       )
+
+      bin_name = "v2ray_" + os + "_" + arch + "_armv6"
+      foreign_go_binary(
+        name = bin_name,
+        pkg = pkg,
+        output = output+"_armv6",
+        os = os,
+        arch = arch,
+        arm = "6",
+      )
+
+      gpg_sign(
+        name = bin_name + "_sig",
+        base = ":" + bin_name,
+      )

+ 276 - 265
release/BUILD

@@ -1,337 +1,348 @@
-package(default_visibility=["//visibility:public"])
+package(default_visibility = ["//visibility:public"])
 
 load("//infra/bazel:zip.bzl", "pkg_zip")
 load("//release:mapping.bzl", "gen_mappings")
 
 filegroup(
-  name = "config_json",
-  srcs = ["config/config.json", "config/vpoint_socks_vmess.json", "config/vpoint_vmess_freedom.json"],
+    name = "config_json",
+    srcs = [
+        "config/config.json",
+        "config/vpoint_socks_vmess.json",
+        "config/vpoint_vmess_freedom.json",
+    ],
 )
 
 filegroup(
-  name = "systemd",
-  srcs = ["config/systemd/v2ray.service", "config/systemv/v2ray"],
+    name = "systemd",
+    srcs = [
+        "config/systemd/v2ray.service",
+        "config/systemv/v2ray",
+    ],
 )
 
 filegroup(
-  name = "doc",
-  srcs = glob(["doc/*.md"]),
+    name = "doc",
+    srcs = glob(["doc/*.md"]),
 )
 
 filegroup(
-  name = "geodata",
-  srcs = ["config/geoip.dat", "config/geosite.dat"],
+    name = "geodata",
+    srcs = [
+        "config/geoip.dat",
+        "config/geosite.dat",
+    ],
 )
 
 pkg_zip(
-  name = "v2ray_darwin_amd64_package",
-  srcs = [
-    "//main:v2ray_darwin_amd64",
-    "//main:v2ray_darwin_amd64_sig",
-    "//infra/control/main:v2ctl_darwin_amd64",
-    "//infra/control/main:v2ctl_darwin_amd64_sig",
-    ":config_json",
-    ":doc",
-    ":geodata",
-  ],
-  out = "v2ray-macos.zip",
-  mappings = gen_mappings("darwin", "amd64"),
+    name = "v2ray_darwin_amd64_package",
+    srcs = [
+        ":config_json",
+        ":doc",
+        ":geodata",
+        "//infra/control/main:v2ctl_darwin_amd64",
+        "//infra/control/main:v2ctl_darwin_amd64_sig",
+        "//main:v2ray_darwin_amd64",
+        "//main:v2ray_darwin_amd64_sig",
+    ],
+    out = "v2ray-macos.zip",
+    mappings = gen_mappings("darwin", "amd64"),
 )
 
 pkg_zip(
-  name = "v2ray_windows_amd64_package",
-  srcs = [
-    "//main:v2ray_windows_amd64",
-    "//main:v2ray_windows_amd64_sig",
-    "//main:v2ray_windows_amd64_nowindow",
-    "//main:v2ray_windows_amd64_nowindow_sig",
-    "//infra/control/main:v2ctl_windows_amd64",
-    "//infra/control/main:v2ctl_windows_amd64_sig",
-    ":config_json",
-    ":doc",
-    ":geodata",
-  ],
-  out = "v2ray-windows-64.zip",
-  mappings = gen_mappings("windows", "amd64"),
+    name = "v2ray_windows_amd64_package",
+    srcs = [
+        ":config_json",
+        ":doc",
+        ":geodata",
+        "//infra/control/main:v2ctl_windows_amd64",
+        "//infra/control/main:v2ctl_windows_amd64_sig",
+        "//main:v2ray_windows_amd64",
+        "//main:v2ray_windows_amd64_nowindow",
+        "//main:v2ray_windows_amd64_nowindow_sig",
+        "//main:v2ray_windows_amd64_sig",
+    ],
+    out = "v2ray-windows-64.zip",
+    mappings = gen_mappings("windows", "amd64"),
 )
 
 pkg_zip(
-  name = "v2ray_windows_x86_package",
-  srcs = [
-    "//main:v2ray_windows_386",
-    "//main:v2ray_windows_386_sig",
-    "//main:v2ray_windows_386_nowindow",
-    "//main:v2ray_windows_386_nowindow_sig",
-    "//infra/control/main:v2ctl_windows_386",
-    "//infra/control/main:v2ctl_windows_386_sig",
-    ":config_json",
-    ":doc",
-    ":geodata",
-  ],
-  out = "v2ray-windows-32.zip",
-  mappings = gen_mappings("windows", "386"),
+    name = "v2ray_windows_x86_package",
+    srcs = [
+        ":config_json",
+        ":doc",
+        ":geodata",
+        "//infra/control/main:v2ctl_windows_386",
+        "//infra/control/main:v2ctl_windows_386_sig",
+        "//main:v2ray_windows_386",
+        "//main:v2ray_windows_386_nowindow",
+        "//main:v2ray_windows_386_nowindow_sig",
+        "//main:v2ray_windows_386_sig",
+    ],
+    out = "v2ray-windows-32.zip",
+    mappings = gen_mappings("windows", "386"),
 )
 
 pkg_zip(
-  name = "v2ray_freebsd_amd64_package",
-  srcs = [
-    "//main:v2ray_freebsd_amd64",
-    "//main:v2ray_freebsd_amd64_sig",
-    "//infra/control/main:v2ctl_freebsd_amd64",
-    "//infra/control/main:v2ctl_freebsd_amd64_sig",
-    ":config_json",
-    ":doc",
-    ":geodata",
-  ],
-  out = "v2ray-freebsd-64.zip",
-  mappings = gen_mappings("freebsd", "amd64"),
+    name = "v2ray_freebsd_amd64_package",
+    srcs = [
+        ":config_json",
+        ":doc",
+        ":geodata",
+        "//infra/control/main:v2ctl_freebsd_amd64",
+        "//infra/control/main:v2ctl_freebsd_amd64_sig",
+        "//main:v2ray_freebsd_amd64",
+        "//main:v2ray_freebsd_amd64_sig",
+    ],
+    out = "v2ray-freebsd-64.zip",
+    mappings = gen_mappings("freebsd", "amd64"),
 )
 
 pkg_zip(
-  name = "v2ray_freebsd_x86_package",
-  srcs = [
-    "//main:v2ray_freebsd_386",
-    "//main:v2ray_freebsd_386_sig",
-    "//infra/control/main:v2ctl_freebsd_386",
-    "//infra/control/main:v2ctl_freebsd_386_sig",
-    ":config_json",
-    ":doc",
-    ":geodata",
-  ],
-  out = "v2ray-freebsd-32.zip",
-  mappings = gen_mappings("freebsd", "386"),
+    name = "v2ray_freebsd_x86_package",
+    srcs = [
+        ":config_json",
+        ":doc",
+        ":geodata",
+        "//infra/control/main:v2ctl_freebsd_386",
+        "//infra/control/main:v2ctl_freebsd_386_sig",
+        "//main:v2ray_freebsd_386",
+        "//main:v2ray_freebsd_386_sig",
+    ],
+    out = "v2ray-freebsd-32.zip",
+    mappings = gen_mappings("freebsd", "386"),
 )
 
 pkg_zip(
-  name = "v2ray_openbsd_amd64_package",
-  srcs = [
-    "//main:v2ray_openbsd_amd64",
-    "//main:v2ray_openbsd_amd64_sig",
-    "//infra/control/main:v2ctl_openbsd_amd64",
-    "//infra/control/main:v2ctl_openbsd_amd64_sig",
-    ":config_json",
-    ":doc",
-    ":geodata",
-  ],
-  out = "v2ray-openbsd-64.zip",
-  mappings = gen_mappings("openbsd", "amd64"),
+    name = "v2ray_openbsd_amd64_package",
+    srcs = [
+        ":config_json",
+        ":doc",
+        ":geodata",
+        "//infra/control/main:v2ctl_openbsd_amd64",
+        "//infra/control/main:v2ctl_openbsd_amd64_sig",
+        "//main:v2ray_openbsd_amd64",
+        "//main:v2ray_openbsd_amd64_sig",
+    ],
+    out = "v2ray-openbsd-64.zip",
+    mappings = gen_mappings("openbsd", "amd64"),
 )
 
 pkg_zip(
-  name = "v2ray_openbsd_x86_package",
-  srcs = [
-    "//main:v2ray_openbsd_386",
-    "//main:v2ray_openbsd_386_sig",
-    "//infra/control/main:v2ctl_openbsd_386",
-    "//infra/control/main:v2ctl_openbsd_386_sig",
-    ":config_json",
-    ":doc",
-    ":geodata",
-  ],
-  out = "v2ray-openbsd-32.zip",
-  mappings = gen_mappings("openbsd", "386"),
+    name = "v2ray_openbsd_x86_package",
+    srcs = [
+        ":config_json",
+        ":doc",
+        ":geodata",
+        "//infra/control/main:v2ctl_openbsd_386",
+        "//infra/control/main:v2ctl_openbsd_386_sig",
+        "//main:v2ray_openbsd_386",
+        "//main:v2ray_openbsd_386_sig",
+    ],
+    out = "v2ray-openbsd-32.zip",
+    mappings = gen_mappings("openbsd", "386"),
 )
 
 pkg_zip(
-  name = "v2ray_dragonfly_amd64_package",
-  srcs = [
-    "//main:v2ray_dragonfly_amd64",
-    "//main:v2ray_dragonfly_amd64_sig",
-    "//infra/control/main:v2ctl_dragonfly_amd64",
-    "//infra/control/main:v2ctl_dragonfly_amd64_sig",
-    ":config_json",
-    ":doc",
-    ":geodata",
-  ],
-  out = "v2ray-dragonfly-64.zip",
-  mappings = gen_mappings("dragonfly", "amd64"),
+    name = "v2ray_dragonfly_amd64_package",
+    srcs = [
+        ":config_json",
+        ":doc",
+        ":geodata",
+        "//infra/control/main:v2ctl_dragonfly_amd64",
+        "//infra/control/main:v2ctl_dragonfly_amd64_sig",
+        "//main:v2ray_dragonfly_amd64",
+        "//main:v2ray_dragonfly_amd64_sig",
+    ],
+    out = "v2ray-dragonfly-64.zip",
+    mappings = gen_mappings("dragonfly", "amd64"),
 )
 
 pkg_zip(
-  name = "v2ray_linux_amd64_package",
-  srcs = [
-    "//main:v2ray_linux_amd64",
-    "//main:v2ray_linux_amd64_sig",
-    "//infra/control/main:v2ctl_linux_amd64",
-    "//infra/control/main:v2ctl_linux_amd64_sig",
-    ":config_json",
-    ":systemd",
-    ":doc",
-    ":geodata",
-  ],
-  out = "v2ray-linux-64.zip",
-  mappings = gen_mappings("linux", "amd64"),
+    name = "v2ray_linux_amd64_package",
+    srcs = [
+        ":config_json",
+        ":doc",
+        ":geodata",
+        ":systemd",
+        "//infra/control/main:v2ctl_linux_amd64",
+        "//infra/control/main:v2ctl_linux_amd64_sig",
+        "//main:v2ray_linux_amd64",
+        "//main:v2ray_linux_amd64_sig",
+    ],
+    out = "v2ray-linux-64.zip",
+    mappings = gen_mappings("linux", "amd64"),
 )
 
 pkg_zip(
-  name = "v2ray_linux_x86_package",
-  srcs = [
-    "//main:v2ray_linux_386",
-    "//main:v2ray_linux_386_sig",
-    "//infra/control/main:v2ctl_linux_386",
-    "//infra/control/main:v2ctl_linux_386_sig",
-    ":config_json",
-    ":systemd",
-    ":doc",
-    ":geodata",
-  ],
-  out = "v2ray-linux-32.zip",
-  mappings = gen_mappings("linux", "386"),
+    name = "v2ray_linux_x86_package",
+    srcs = [
+        ":config_json",
+        ":doc",
+        ":geodata",
+        ":systemd",
+        "//infra/control/main:v2ctl_linux_386",
+        "//infra/control/main:v2ctl_linux_386_sig",
+        "//main:v2ray_linux_386",
+        "//main:v2ray_linux_386_sig",
+    ],
+    out = "v2ray-linux-32.zip",
+    mappings = gen_mappings("linux", "386"),
 )
 
 pkg_zip(
-  name = "v2ray_linux_arm_package",
-  srcs = [
-    "//main:v2ray_linux_arm",
-    "//main:v2ray_linux_arm_sig",
-    "//main:v2ray_linux_arm_armv7",
-    "//main:v2ray_linux_arm_armv7_sig",
-    "//infra/control/main:v2ctl_linux_arm",
-    "//infra/control/main:v2ctl_linux_arm_sig",
-    "//infra/control/main:v2ctl_linux_arm_armv7",
-    "//infra/control/main:v2ctl_linux_arm_armv7_sig",
-    ":config_json",
-    ":systemd",
-    ":doc",
-    ":geodata",
-  ],
-  out = "v2ray-linux-arm.zip",
-  mappings = gen_mappings("linux", "arm"),
+    name = "v2ray_linux_arm_package",
+    srcs = [
+        ":config_json",
+        ":doc",
+        ":geodata",
+        ":systemd",
+        "//infra/control/main:v2ctl_linux_arm",
+        "//infra/control/main:v2ctl_linux_arm_armv7",
+        "//infra/control/main:v2ctl_linux_arm_armv7_sig",
+        "//infra/control/main:v2ctl_linux_arm_sig",
+        "//main:v2ray_linux_arm",
+        "//main:v2ray_linux_arm_armv6",
+        "//main:v2ray_linux_arm_armv6_sig",
+        "//main:v2ray_linux_arm_armv7",
+        "//main:v2ray_linux_arm_armv7_sig",
+        "//main:v2ray_linux_arm_sig",
+    ],
+    out = "v2ray-linux-arm.zip",
+    mappings = gen_mappings("linux", "arm"),
 )
 
 pkg_zip(
-  name = "v2ray_linux_arm64_package",
-  srcs = [
-    "//main:v2ray_linux_arm64",
-    "//main:v2ray_linux_arm64_sig",
-    "//infra/control/main:v2ctl_linux_arm64",
-    "//infra/control/main:v2ctl_linux_arm64_sig",
-    ":config_json",
-    ":systemd",
-    ":doc",
-    ":geodata",
-  ],
-  out = "v2ray-linux-arm64.zip",
-  mappings = gen_mappings("linux", "arm64"),
+    name = "v2ray_linux_arm64_package",
+    srcs = [
+        ":config_json",
+        ":doc",
+        ":geodata",
+        ":systemd",
+        "//infra/control/main:v2ctl_linux_arm64",
+        "//infra/control/main:v2ctl_linux_arm64_sig",
+        "//main:v2ray_linux_arm64",
+        "//main:v2ray_linux_arm64_sig",
+    ],
+    out = "v2ray-linux-arm64.zip",
+    mappings = gen_mappings("linux", "arm64"),
 )
 
 pkg_zip(
-  name = "v2ray_linux_mips_package",
-  srcs = [
-    "//main:v2ray_linux_mips",
-    "//main:v2ray_linux_mips_sig",
-    "//main:v2ray_linux_mips_softfloat",
-    "//main:v2ray_linux_mips_softfloat_sig",
-    "//infra/control/main:v2ctl_linux_mips",
-    "//infra/control/main:v2ctl_linux_mips_sig",
-    "//infra/control/main:v2ctl_linux_mips_softfloat",
-    "//infra/control/main:v2ctl_linux_mips_softfloat_sig",
-    ":config_json",
-    ":systemd",
-    ":doc",
-    ":geodata",
-  ],
-  out = "v2ray-linux-mips.zip",
-  mappings = gen_mappings("linux", "mips"),
+    name = "v2ray_linux_mips_package",
+    srcs = [
+        ":config_json",
+        ":doc",
+        ":geodata",
+        ":systemd",
+        "//infra/control/main:v2ctl_linux_mips",
+        "//infra/control/main:v2ctl_linux_mips_sig",
+        "//infra/control/main:v2ctl_linux_mips_softfloat",
+        "//infra/control/main:v2ctl_linux_mips_softfloat_sig",
+        "//main:v2ray_linux_mips",
+        "//main:v2ray_linux_mips_sig",
+        "//main:v2ray_linux_mips_softfloat",
+        "//main:v2ray_linux_mips_softfloat_sig",
+    ],
+    out = "v2ray-linux-mips.zip",
+    mappings = gen_mappings("linux", "mips"),
 )
 
 pkg_zip(
-  name = "v2ray_linux_mipsle_package",
-  srcs = [
-    "//main:v2ray_linux_mipsle",
-    "//main:v2ray_linux_mipsle_sig",
-    "//main:v2ray_linux_mipsle_softfloat",
-    "//main:v2ray_linux_mipsle_softfloat_sig",
-    "//infra/control/main:v2ctl_linux_mipsle",
-    "//infra/control/main:v2ctl_linux_mipsle_sig",
-    "//infra/control/main:v2ctl_linux_mipsle_softfloat",
-    "//infra/control/main:v2ctl_linux_mipsle_softfloat_sig",
-    ":config_json",
-    ":systemd",
-    ":doc",
-    ":geodata",
-  ],
-  out = "v2ray-linux-mipsle.zip",
-  mappings = gen_mappings("linux", "mipsle"),
+    name = "v2ray_linux_mipsle_package",
+    srcs = [
+        ":config_json",
+        ":doc",
+        ":geodata",
+        ":systemd",
+        "//infra/control/main:v2ctl_linux_mipsle",
+        "//infra/control/main:v2ctl_linux_mipsle_sig",
+        "//infra/control/main:v2ctl_linux_mipsle_softfloat",
+        "//infra/control/main:v2ctl_linux_mipsle_softfloat_sig",
+        "//main:v2ray_linux_mipsle",
+        "//main:v2ray_linux_mipsle_sig",
+        "//main:v2ray_linux_mipsle_softfloat",
+        "//main:v2ray_linux_mipsle_softfloat_sig",
+    ],
+    out = "v2ray-linux-mipsle.zip",
+    mappings = gen_mappings("linux", "mipsle"),
 )
 
-
 pkg_zip(
-  name = "v2ray_linux_mips64_package",
-  srcs = [
-    "//main:v2ray_linux_mips64",
-    "//main:v2ray_linux_mips64_sig",
-    "//infra/control/main:v2ctl_linux_mips64",
-    "//infra/control/main:v2ctl_linux_mips64_sig",
-    ":config_json",
-    ":systemd",
-    ":doc",
-    ":geodata",
-  ],
-  out = "v2ray-linux-mips64.zip",
-  mappings = gen_mappings("linux", "mips64"),
+    name = "v2ray_linux_mips64_package",
+    srcs = [
+        ":config_json",
+        ":doc",
+        ":geodata",
+        ":systemd",
+        "//infra/control/main:v2ctl_linux_mips64",
+        "//infra/control/main:v2ctl_linux_mips64_sig",
+        "//main:v2ray_linux_mips64",
+        "//main:v2ray_linux_mips64_sig",
+    ],
+    out = "v2ray-linux-mips64.zip",
+    mappings = gen_mappings("linux", "mips64"),
 )
 
 pkg_zip(
-  name = "v2ray_linux_mips64le_package",
-  srcs = [
-    "//main:v2ray_linux_mips64le",
-    "//main:v2ray_linux_mips64le_sig",
-    "//infra/control/main:v2ctl_linux_mips64le",
-    "//infra/control/main:v2ctl_linux_mips64le_sig",
-    ":config_json",
-    ":systemd",
-    ":doc",
-    ":geodata",
-  ],
-  out = "v2ray-linux-mips64le.zip",
-  mappings = gen_mappings("linux", "mips64le"),
+    name = "v2ray_linux_mips64le_package",
+    srcs = [
+        ":config_json",
+        ":doc",
+        ":geodata",
+        ":systemd",
+        "//infra/control/main:v2ctl_linux_mips64le",
+        "//infra/control/main:v2ctl_linux_mips64le_sig",
+        "//main:v2ray_linux_mips64le",
+        "//main:v2ray_linux_mips64le_sig",
+    ],
+    out = "v2ray-linux-mips64le.zip",
+    mappings = gen_mappings("linux", "mips64le"),
 )
 
 pkg_zip(
-  name = "v2ray_linux_s390x_package",
-  srcs = [
-    "//main:v2ray_linux_s390x",
-    "//main:v2ray_linux_s390x_sig",
-    "//infra/control/main:v2ctl_linux_s390x",
-    "//infra/control/main:v2ctl_linux_s390x_sig",
-    ":config_json",
-    ":systemd",
-    ":doc",
-    ":geodata",
-  ],
-  out = "v2ray-linux-s390x.zip",
-  mappings = gen_mappings("linux", "s390x"),
+    name = "v2ray_linux_s390x_package",
+    srcs = [
+        ":config_json",
+        ":doc",
+        ":geodata",
+        ":systemd",
+        "//infra/control/main:v2ctl_linux_s390x",
+        "//infra/control/main:v2ctl_linux_s390x_sig",
+        "//main:v2ray_linux_s390x",
+        "//main:v2ray_linux_s390x_sig",
+    ],
+    out = "v2ray-linux-s390x.zip",
+    mappings = gen_mappings("linux", "s390x"),
 )
 
 pkg_zip(
-  name = "v2ray_linux_ppc64_package",
-  srcs = [
-    "//main:v2ray_linux_ppc64",
-    "//main:v2ray_linux_ppc64_sig",
-    "//infra/control/main:v2ctl_linux_ppc64",
-    "//infra/control/main:v2ctl_linux_ppc64_sig",
-    ":config_json",
-    ":systemd",
-    ":doc",
-    ":geodata",
-  ],
-  out = "v2ray-linux-ppc64.zip",
-  mappings = gen_mappings("linux", "ppc64"),
+    name = "v2ray_linux_ppc64_package",
+    srcs = [
+        ":config_json",
+        ":doc",
+        ":geodata",
+        ":systemd",
+        "//infra/control/main:v2ctl_linux_ppc64",
+        "//infra/control/main:v2ctl_linux_ppc64_sig",
+        "//main:v2ray_linux_ppc64",
+        "//main:v2ray_linux_ppc64_sig",
+    ],
+    out = "v2ray-linux-ppc64.zip",
+    mappings = gen_mappings("linux", "ppc64"),
 )
 
 pkg_zip(
-  name = "v2ray_linux_ppc64le_package",
-  srcs = [
-    "//main:v2ray_linux_ppc64le",
-    "//main:v2ray_linux_ppc64le_sig",
-    "//infra/control/main:v2ctl_linux_ppc64le",
-    "//infra/control/main:v2ctl_linux_ppc64le_sig",
-    ":config_json",
-    ":systemd",
-    ":doc",
-    ":geodata",
-  ],
-  out = "v2ray-linux-ppc64le.zip",
-  mappings = gen_mappings("linux", "ppc64le"),
+    name = "v2ray_linux_ppc64le_package",
+    srcs = [
+        ":config_json",
+        ":doc",
+        ":geodata",
+        ":systemd",
+        "//infra/control/main:v2ctl_linux_ppc64le",
+        "//infra/control/main:v2ctl_linux_ppc64le_sig",
+        "//main:v2ray_linux_ppc64le",
+        "//main:v2ray_linux_ppc64le_sig",
+    ],
+    out = "v2ray-linux-ppc64le.zip",
+    mappings = gen_mappings("linux", "ppc64le"),
 )

+ 0 - 47
release/make-release.sh

@@ -1,47 +0,0 @@
-#!/bin/bash
-
-VER=$1
-PROJECT=$2
-
-DOTCNT=$(echo $VER | grep -o "\." | wc -l)
-if [ "$DOTCNT" -gt 1 ]; then
-  PRE="true"
-else
-  PRE="false"
-  VER="${VER}.0"
-fi
-
-if [ -z "$PROJECT" ]; then
-  echo "Project not specified. Exiting..."
-  exit 0
-fi
-
-echo Creating a new release: $VER
-
-IFS="." read -a PARTS <<< "$VER"
-MAJOR=${PARTS[0]}
-MINOR=${PARTS[1]}
-MINOR=$((MINOR+1))
-VERN=${MAJOR}.${MINOR}
-
-pushd $GOPATH/src/v2ray.com/core
-echo "Adding a new tag: " "v$VER"
-git tag -s -a "v$VER" -m "Version ${VER}"
-sed -i '' "s/\(version *= *\"\).*\(\"\)/\1$VERN\2/g" core.go
-echo "Committing core.go (may not necessary)"
-git commit core.go -S -m "Update version"
-echo "Pushing changes"
-git push --follow-tags
-popd
-
-echo "Launching build machine."
-DIR="$(dirname "$0")"
-RAND="$(openssl rand -hex 5)"
-gcloud compute instances create "v2raycore-${RAND}" \
-    --machine-type=n1-standard-2 \
-    --metadata=release_tag=v${VER},prerelease=${PRE} \
-    --metadata-from-file=startup-script=${DIR}/release-ci.sh \
-    --zone=europe-west4-c \
-    --project ${PROJECT} \
-    --scopes "https://www.googleapis.com/auth/compute,https://www.googleapis.com/auth/devstorage.read_write" \
-