Skip to content

Commit 765bcef

Browse files
committed
ref: Remove unused code
1 parent 499ec82 commit 765bcef

File tree

2 files changed

+1
-124
lines changed

2 files changed

+1
-124
lines changed

pkg/v2rayprobe/litespeedtest/web/profile.go

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"bufio"
1010
"bytes"
1111
"context"
12-
"encoding/base64"
1312
"encoding/json"
1413
"errors"
1514
"fmt"
@@ -463,6 +462,7 @@ func (p *ProfileTest) TestAll(ctx context.Context, trafficChan chan<- int64) (ch
463462
return nodeChan, nil
464463
}
465464

465+
// Deprecated: use testAllBatch instead
466466
func (p *ProfileTest) testAll(ctx context.Context) (render.Nodes, error) {
467467
linksCount := len(p.Links)
468468
if linksCount < 1 {
@@ -858,59 +858,6 @@ func FormatDuration(duration time.Duration) string {
858858
return fmt.Sprintf("%dm %ds", m, s)
859859
}
860860

861-
func png2base64(path string) (string, error) {
862-
bytes, err := ioutil.ReadFile(path)
863-
if err != nil {
864-
return "", err
865-
}
866-
return "data:image/png;base64," + base64.StdEncoding.EncodeToString(bytes), nil
867-
}
868-
869861
func isYamlFile(filePath string) bool {
870862
return strings.HasSuffix(filePath, ".yaml") || strings.HasSuffix(filePath, ".yml")
871863
}
872-
873-
// api
874-
func PeekClash(input string, n int) ([]string, error) {
875-
scanner := bufio.NewScanner(strings.NewReader(input))
876-
proxiesStart := false
877-
data := []byte{}
878-
linkCount := 0
879-
for scanner.Scan() {
880-
b := scanner.Bytes()
881-
trimLine := strings.TrimSpace(string(b))
882-
if trimLine == "proxy-groups:" || trimLine == "rules:" || trimLine == "Proxy Group:" {
883-
break
884-
}
885-
if proxiesStart {
886-
if _, err := config.ParseBaseProxy(trimLine); err != nil {
887-
continue
888-
}
889-
if strings.HasPrefix(trimLine, "-") {
890-
if linkCount >= n {
891-
break
892-
}
893-
linkCount += 1
894-
}
895-
data = append(data, b...)
896-
data = append(data, byte('\n'))
897-
continue
898-
}
899-
if !proxiesStart && (trimLine == "proxies:" || trimLine == "Proxy:") {
900-
proxiesStart = true
901-
b = []byte("proxies:")
902-
}
903-
data = append(data, b...)
904-
data = append(data, byte('\n'))
905-
}
906-
// fmt.Println(string(data))
907-
links, err := parseClashByte(data)
908-
if err != nil || len(links) < 1 {
909-
return []string{}, err
910-
}
911-
endIndex := n
912-
if endIndex > len(links) {
913-
endIndex = len(links)
914-
}
915-
return links[:endIndex], nil
916-
}

pkg/v2rayprobe/litespeedtest/web/server.go

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -13,83 +13,14 @@ import (
1313
"net/http"
1414
"net/url"
1515
"os"
16-
"strconv"
1716
"strings"
1817
"time"
1918

2019
"ConfigProbe/pkg/v2rayprobe/litespeedtest/config"
2120
"ConfigProbe/pkg/v2rayprobe/litespeedtest/utils"
2221
"ConfigProbe/pkg/v2rayprobe/litespeedtest/web/render"
23-
"github.com/gorilla/websocket"
2422
)
2523

26-
var upgrader = websocket.Upgrader{}
27-
28-
func ServeFile(port int) error {
29-
http.HandleFunc("/test", updateTest)
30-
http.HandleFunc("/getSubscriptionLink", getSubscriptionLink)
31-
http.HandleFunc("/getSubscription", getSubscription)
32-
log.Printf("Start server at http://127.0.0.1:%d\n", port)
33-
if ipAddr, err := localIP(); err == nil {
34-
log.Printf("Start server at http://%s", net.JoinHostPort(ipAddr.String(), strconv.Itoa(port)))
35-
}
36-
err := http.ListenAndServe(fmt.Sprintf(":%d", port), nil)
37-
return err
38-
}
39-
40-
func updateTest(w http.ResponseWriter, r *http.Request) {
41-
c, err := upgrader.Upgrade(w, r, nil)
42-
if err != nil {
43-
log.Print("upgrade:", err)
44-
return
45-
}
46-
defer c.Close()
47-
ctx, cancel := context.WithCancel(context.Background())
48-
defer cancel()
49-
for {
50-
mt, message, err := c.ReadMessage()
51-
if err != nil {
52-
log.Println("read:", err)
53-
break
54-
}
55-
// log.Printf("recv: %s", message)
56-
links, options, err := parseMessage(message)
57-
if err != nil {
58-
msg := `{"info": "error", "reason": "invalidsub"}`
59-
c.WriteMessage(mt, []byte(msg))
60-
continue
61-
}
62-
if options.Unique {
63-
uniqueLinks := []string{}
64-
uniqueMap := map[string]struct{}{}
65-
for _, link := range links {
66-
cfg, err := config.Link2Config(link)
67-
if err != nil {
68-
continue
69-
}
70-
key := fmt.Sprintf("%s%d%s%s%s", cfg.Server, cfg.Port, cfg.Password, cfg.Protocol, cfg.SNI)
71-
if _, ok := uniqueMap[key]; !ok {
72-
uniqueLinks = append(uniqueLinks, link)
73-
uniqueMap[key] = struct{}{}
74-
}
75-
}
76-
links = uniqueLinks
77-
}
78-
p := ProfileTest{
79-
Writer: c,
80-
MessageType: mt,
81-
Links: links,
82-
Options: options,
83-
}
84-
go p.testAll(ctx)
85-
// err = c.WriteMessage(mt, getMsgByte(0, "gotspeed"))
86-
// if err != nil {
87-
// log.Println("write:", err)
88-
// break
89-
// }
90-
}
91-
}
92-
9324
func readConfig(configPath string) (*ProfileTestOptions, error) {
9425
data, err := os.ReadFile(configPath)
9526
if err != nil {
@@ -200,7 +131,6 @@ type TestResult struct {
200131
Nodes render.Nodes `json:"nodes"`
201132
}
202133

203-
204134
func isPrivateIP(ip net.IP) bool {
205135
var privateIPBlocks []*net.IPNet
206136
for _, cidr := range []string{

0 commit comments

Comments
 (0)