fix: add config and logger, cleanup

This commit is contained in:
sajadMRjl
2026-01-28 03:07:06 +03:30
parent 5b5b992754
commit 476aa90968
9 changed files with 228 additions and 118 deletions

View File

@@ -1,95 +1,90 @@
package main
import (
"fmt"
"log/slog"
"os"
"sync"
"time"
"find-me-internet/internal/config"
"find-me-internet/internal/filter"
"find-me-internet/internal/logger"
"find-me-internet/internal/parser"
"find-me-internet/internal/tester"
)
const (
SingBoxPath = "./bin/sing-box" // Make sure this exists!
TestTarget = "http://cp.cloudflare.com"
MaxWorkers = 10
)
func main() {
// 0. Setup
// Check if binary exists
if _, err := os.Stat(SingBoxPath); os.IsNotExist(err) {
fmt.Printf("Error: sing-box binary not found at %s\n", SingBoxPath)
return
// 1. Initialization
cfg := config.Load()
logger.Setup(cfg.LogLevel)
// Verify Sing-box binary
if _, err := os.Stat(cfg.SingBoxPath); os.IsNotExist(err) {
slog.Error("Sing-box binary not found", "path", cfg.SingBoxPath)
os.Exit(1)
}
// Mock Input Data (Replace with file reading logic later)
slog.Info("Starting Proxy Scanner", "workers", cfg.Workers, "level", cfg.LogLevel)
// Mock Data (Replace with File Reader later)
rawLinks := []string{
"vless://4525c260-df3c-4f62-b8f1-f4f5f305694b@66.81.247.155:443?encryption=none&security=tls&sni=yyzsuabw9e3qd5ud7ihi5dxm96oglnsvr83cjojnm1efncfhr9ucordq.zjde5.de5.net&fp=chrome&insecure=0&allowInsecure=0&type=ws&host=yyzsuabw9e3qd5ud7ihi5dxm96oglnsvr83cjojnm1efncfhr9ucordq.zjde5.de5.net&path=%2F%3Fed#%DA%86%D9%86%D9%84%20%D8%AA%D9%84%DA%AF%D8%B1%D8%A7%D9%85%20%3A%20%40CroSs_Guildd%F0%9F%92%8A",
"vless://efdb2890-6dd7-4e65-8984-f0b1d3ae4e01@here-we-go-again.embeddedonline.org:443?encryption=none&security=tls&sni=here-we-go-again.embeddedonline.org&fp=chrome&alpn=http%2F1.1&insecure=0&allowInsecure=0&type=ws&host=here-we-go-again.embeddedonline.org&path=%2FJ1jTS0GMxqS0Atmd5x#here-we-go-again.embeddedonline.org%20tls%20WS%20direct%20vless",
// Add more links here...
}
fmt.Printf("Loaded %d links. Starting scan...\n", len(rawLinks))
// 2. Setup Pipelines
netFilter := filter.NewPipeline(cfg.TcpTimeout)
boxRunner := tester.NewRunner(cfg.SingBoxPath, cfg.TestURL, cfg.TestTimeout)
// Pipelines
netFilter := filter.NewPipeline(2 * time.Second)
boxRunner := tester.NewRunner(SingBoxPath, TestTarget, 5*time.Second)
// Concurrency Controls
// 3. Concurrency Control
var wg sync.WaitGroup
semaphore := make(chan struct{}, MaxWorkers) // Limit active Sing-box instances
// Results
successCount := 0
var mu sync.Mutex
semaphore := make(chan struct{}, cfg.Workers) // Limits concurrent Sing-box instances
startTotal := time.Now()
validCount := 0
// 4. Processing Loop
for _, link := range rawLinks {
wg.Add(1)
go func(raw string) {
defer wg.Done()
// --- STAGE 1: PARSE ---
// Step A: Parse
proxy, err := parser.ParseLink(raw)
if err != nil {
// fmt.Printf("Invalid Link: %v\n", err)
slog.Debug("Parse failed", "err", err)
return
}
// --- STAGE 2: CHEAP FILTER ---
// Check TCP and TLS Handshake first
// Step B: Cheap Filter (TCP/TLS)
if !netFilter.Check(proxy) {
// fmt.Printf("[DEAD] %s:%d\n", proxy.Address, proxy.Port)
// Failed cheap checks, discard silently or debug
return
}
// --- STAGE 3: EXPENSIVE TEST ---
semaphore <- struct{}{} // Acquire worker slot
// Step C: Expensive Test (Sing-box)
semaphore <- struct{}{} // Acquire lock
err = boxRunner.Test(proxy)
<-semaphore // Release worker slot
<-semaphore // Release lock
if err != nil {
fmt.Printf("[FAIL] %s (%v)\n", proxy.SNI, err)
slog.Debug("Test failed", "proxy", proxy.Address, "err", err)
return
}
// --- SUCCESS ---
mu.Lock()
successCount++
mu.Unlock()
fmt.Printf("✅ [OK] %s | Latency: %dms | Type: %s\n",
proxy.Address, proxy.Latency.Milliseconds(), proxy.Type)
// Success!
validCount++
slog.Info("Valid Proxy Found",
"addr", proxy.Address,
"latency", proxy.Latency.Milliseconds(),
"type", proxy.Type,
)
}(link)
}
wg.Wait()
fmt.Printf("\n--- Scan Complete in %s ---\n", time.Since(startTotal))
fmt.Printf("Valid Proxies Found: %d\n", successCount)
slog.Info("Scan Complete", "duration", time.Since(startTotal), "valid", validCount)
}