fix: failed latency test if plugin is needed

This commit is contained in:
mzz2017 committed 2021-09-15 00:39:30 +08:00
1 parent 0b3beb7f98
commit 958cbee014
8 files changed
+39 -10

No files matched your search

+1 -1
View File
@@ -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
}
}
+14 -4
View File
@@ -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
+9 -3
View File
@@ -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
}
@@ -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
+1 -1
View File
@@ -12,7 +12,7 @@ import (
type Server interface {
// ListenAndServe sets up a listener and serve on it
ListenAndServe() error
ListenAddr() string
Close() error
}
+4
View File
@@ -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)
+4
View File
@@ -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)
+2 -1
View File
@@ -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
}