diff --git a/service/common/cmds/command.go b/service/common/cmds/command.go index 02572ad4..6df2fc17 100644 --- a/service/common/cmds/command.go +++ b/service/common/cmds/command.go @@ -23,8 +23,8 @@ func ExecCommands(commands string, stopWhenError bool) error { out, err := exec.Command("sh", "-c", line).CombinedOutput() if err != nil { e = fmt.Errorf("ExecCommands: %v %v: %w", line, string(out), err) - log.Trace("%v", e) if stopWhenError { + log.Trace("%v", e) return e } } diff --git a/service/core/v2ray/process.go b/service/core/v2ray/process.go index b338a904..700bbbd1 100644 --- a/service/core/v2ray/process.go +++ b/service/core/v2ray/process.go @@ -69,18 +69,28 @@ func NewProcess(tmpl *Template) (process *Process, err error) { } } }() + // ports to check + portList := []string{strconv.Itoa(tmpl.ApiPort)} + for _, plu := range tmpl.Plugins { + _, port, err := net.SplitHostPort(plu.ListenAddr()) + if err != nil { + return nil, err + } + portList = append(portList, port) + } startTime := time.Now() - for { - conn, err := net.Dial("tcp", net.JoinHostPort("127.0.0.1", strconv.Itoa(tmpl.ApiPort))) + for i := 0; i < len(portList); { + conn, err := net.Dial("tcp", net.JoinHostPort("127.0.0.1", portList[i])) if err == nil { conn.Close() - break + i++ + continue } if time.Since(startTime) > 15*time.Second { return nil, fmt.Errorf("v2ray-core does not start normally, check the log for more information") } - time.Sleep(1000 * time.Millisecond) + time.Sleep(500 * time.Millisecond) } process.proc = proc return process, nil diff --git a/service/core/v2ray/v2rayTmpl.go b/service/core/v2ray/v2rayTmpl.go index a2fcdfd8..b40c2bf6 100644 --- a/service/core/v2ray/v2rayTmpl.go +++ b/service/core/v2ray/v2rayTmpl.go @@ -30,6 +30,7 @@ import ( "sort" "strconv" "strings" + "sync" "time" ) @@ -70,11 +71,16 @@ func (t *Template) Close() error { } func (t *Template) ServePlugins() error { + var wg sync.WaitGroup var err error for _, p := range t.Plugins { - if e := p.ListenAndServe(); err == nil && e != nil { - err = e - } + wg.Add(1) + go func(p plugin.Server) { + if e := p.ListenAndServe(); e != nil { + err = e + } + wg.Done() + }(p) } return err } diff --git a/service/pkg/plugin/pingtunnel/pingtunnel.go b/service/pkg/plugin/pingtunnel/pingtunnel.go index f8fe531e..d5497089 100644 --- a/service/pkg/plugin/pingtunnel/pingtunnel.go +++ b/service/pkg/plugin/pingtunnel/pingtunnel.go @@ -76,6 +76,10 @@ func (tunnel *PingTunnel) ListenAndServe() error { return tunnel.ListenAndServeTCP() } +func (tunnel *PingTunnel) ListenAddr() string { + return tunnel.listenAddress +} + // ListenAndServeTCP listen and serve on tcp port. func (tunnel *PingTunnel) ListenAndServeTCP() error { listen := tunnel.listenAddress diff --git a/service/pkg/plugin/server.go b/service/pkg/plugin/server.go index dd39e6d9..a28f4c29 100644 --- a/service/pkg/plugin/server.go +++ b/service/pkg/plugin/server.go @@ -12,7 +12,7 @@ import ( type Server interface { // ListenAndServe sets up a listener and serve on it ListenAndServe() error - + ListenAddr() string Close() error } diff --git a/service/pkg/plugin/socks5/socks5.go b/service/pkg/plugin/socks5/socks5.go index f2698677..970ebece 100644 --- a/service/pkg/plugin/socks5/socks5.go +++ b/service/pkg/plugin/socks5/socks5.go @@ -83,6 +83,10 @@ func (s *Socks5) ListenAndServe() error { return s.ListenAndServeTCP() } +func (s *Socks5) ListenAddr() string { + return s.addr +} + // ListenAndServeTCP listen and serve on tcp port. func (s *Socks5) ListenAndServeTCP() error { l, err := net.Listen("tcp", s.addr) diff --git a/service/pkg/plugin/tcp/tcp.go b/service/pkg/plugin/tcp/tcp.go index 3406168f..aea69824 100644 --- a/service/pkg/plugin/tcp/tcp.go +++ b/service/pkg/plugin/tcp/tcp.go @@ -59,6 +59,10 @@ func (s *Tcp) ListenAndServe() error { return s.ListenAndServeTCP() } +func (s *Tcp) ListenAddr() string { + return s.listenAddr +} + // ListenAndServeTCP listen and serve on tcp port. func (s *Tcp) ListenAndServeTCP() error { l, err := net.Listen("tcp", s.listenAddr) diff --git a/service/pkg/plugin/tls/tls.go b/service/pkg/plugin/tls/tls.go index 5a2af4e0..de2b0e24 100644 --- a/service/pkg/plugin/tls/tls.go +++ b/service/pkg/plugin/tls/tls.go @@ -48,7 +48,8 @@ func NewTls(s string, d plugin.Dialer) (*Tls, error) { } // skipVerify - if query.Get("skipVerify") == "true" || query.Get("skipVerify") == "1" { + if query.Get("allowInsecure") == "true" || query.Get("allowInsecure") == "1" || + query.Get("skipVerify") == "true" || query.Get("skipVerify") == "1" { t.skipVerify = true }