diff --git a/internal/constant/constant.go b/internal/constant/constant.go index a801f60ad..8c6d5629a 100644 --- a/internal/constant/constant.go +++ b/internal/constant/constant.go @@ -3,7 +3,7 @@ package constant import "time" const ( - Version = "1.0.4" + Version = "1.0.5" MaxMWSSStreamCnt = 10 DialTimeOut = 3 * time.Second diff --git a/internal/lb/lb.go b/internal/lb/lb.go index 735e7b5b1..a79b95aae 100644 --- a/internal/lb/lb.go +++ b/internal/lb/lb.go @@ -96,8 +96,3 @@ func (lp *LBNodes) PickMin() *LBNode { func (lp *LBNodes) DeferPick(node *LBNode) { lp.IncrUserCnt(node, -1) } - -func (lp *LBNodes) OnError(node *LBNode) { - // NOTE 遇到错误的时候降低这个节点的权重 - lp.IncrUserCnt(node, 100) -} diff --git a/internal/transporter/mwss.go b/internal/transporter/mwss.go index 3b64032d9..225adbdcc 100644 --- a/internal/transporter/mwss.go +++ b/internal/transporter/mwss.go @@ -30,7 +30,6 @@ func (s *Mwss) HandleTCPConn(c *net.TCPConn) error { wsc, err := s.mtp.Dial(node.Remote + "/mwss/") if err != nil { - s.raw.TCPNodes.OnError(node) return err } defer wsc.Close() diff --git a/internal/transporter/raw.go b/internal/transporter/raw.go index dcb7d6972..b2fbc9237 100644 --- a/internal/transporter/raw.go +++ b/internal/transporter/raw.go @@ -41,7 +41,6 @@ func (raw *Raw) HandleUDPConn(uaddr *net.UDPAddr, local *net.UDPConn) { rc, err := net.Dial("udp", node.Remote) if err != nil { logger.Info(err) - raw.UDPNodes.OnError(node) return } defer func() { @@ -99,7 +98,6 @@ func (raw *Raw) HandleTCPConn(c *net.TCPConn) error { rc, err := net.Dial("tcp", node.Remote) if err != nil { - raw.TCPNodes.OnError(node) return err } logger.Infof("[raw] HandleTCPConn from %s to %s", c.LocalAddr().String(), node.Remote) @@ -122,7 +120,6 @@ func (raw *Raw) HandleWsRequset(w http.ResponseWriter, req *http.Request) { rc, err := net.Dial("tcp", node.Remote) if err != nil { logger.Infof("dial error: %s", err) - raw.TCPNodes.OnError(node) return } defer rc.Close() @@ -147,7 +144,6 @@ func (raw *Raw) HandleWssRequset(w http.ResponseWriter, req *http.Request) { rc, err := net.Dial("tcp", node.Remote) if err != nil { logger.Infof("dial error: %s", err) - raw.TCPNodes.OnError(node) return } defer rc.Close() @@ -168,7 +164,6 @@ func (raw *Raw) HandleMWssRequset(c net.Conn) { rc, err := net.Dial("tcp", node.Remote) if err != nil { logger.Infof("dial error: %s", err) - raw.TCPNodes.OnError(node) return } defer rc.Close() diff --git a/internal/transporter/ws.go b/internal/transporter/ws.go index 521062ce2..910050796 100644 --- a/internal/transporter/ws.go +++ b/internal/transporter/ws.go @@ -31,7 +31,6 @@ func (s *Ws) HandleTCPConn(c *net.TCPConn) error { wsc, _, _, err := ws.Dial(context.TODO(), node.Remote+"/ws/") if err != nil { - s.raw.TCPNodes.OnError(node) return err } defer wsc.Close() diff --git a/internal/web/server.go b/internal/web/server.go index edd085b6e..47b282fc2 100644 --- a/internal/web/server.go +++ b/internal/web/server.go @@ -50,23 +50,7 @@ func registerMetrics(cfg *config.Config) { go pg.Run() } -func StartWebServer(port, token string, cfg *config.Config) { - time.Sleep(time.Second) - addr := "0.0.0.0:" + port - logger.Infof("[web] Start Web Server at http://%s/", addr) - r := mux.NewRouter() - AttachProfiler(r) - registerMetrics(cfg) - r.Handle("/", http.HandlerFunc(Welcome)) - r.Handle("/metrics/", promhttp.Handler()) - if token != "" { - logger.Fatal(http.ListenAndServe(addr, SimpleTokenAuthMiddleware(token, r))) - } else { - logger.Fatal(http.ListenAndServe(addr, r)) - } -} - -func SimpleTokenAuthMiddleware(token string, h http.Handler) http.Handler { +func simpleTokenAuthMiddleware(token string, h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if t := r.URL.Query().Get("token"); t != token { msg := fmt.Sprintf("[web] unauthorsied from %s", r.RemoteAddr) @@ -83,3 +67,19 @@ func SimpleTokenAuthMiddleware(token string, h http.Handler) http.Handler { h.ServeHTTP(w, r) }) } + +func StartWebServer(port, token string, cfg *config.Config) { + time.Sleep(time.Second) + addr := "0.0.0.0:" + port + logger.Infof("[web] Start Web Server at http://%s/", addr) + r := mux.NewRouter() + AttachProfiler(r) + registerMetrics(cfg) + r.Handle("/", http.HandlerFunc(Welcome)) + r.Handle("/metrics/", promhttp.Handler()) + if token != "" { + logger.Fatal(http.ListenAndServe(addr, simpleTokenAuthMiddleware(token, r))) + } else { + logger.Fatal(http.ListenAndServe(addr, r)) + } +}