Enhance MTProxy checker functionality by introducing a new -probe flag for selecting between fast and deep probing modes. Update README and Docker documentation to reflect this change, including details on timeout handling and exit codes for improved clarity.
Publish mtproxy_checker Docker image / test (push) Successful in 6s
Publish mtproxy_checker Docker image / build-and-push (push) Successful in 51s

This commit is contained in:
Denozordec
2026-04-11 13:48:02 +07:00
parent 6f2dbcbca3
commit 935401b1f8
7 changed files with 105 additions and 17 deletions
+9 -1
View File
@@ -5,6 +5,7 @@ import (
"errors"
"flag"
"fmt"
"net"
"os"
"time"
@@ -19,6 +20,7 @@ func main() {
func run() int {
timeout := flag.Duration("timeout", 15*time.Second, "overall TCP/handshake timeout")
probe := flag.String("probe", "fast", "fast: handshake+init+inbound byte; deep: MTProto req_pq/resPQ via DC (stricter, slower)")
dcID := flag.Int("dc-id", 2, "Telegram DC id (signed int16) embedded in MTProxy header")
server := flag.String("server", "", "proxy hostname (if not using tg:// positional)")
portFlag := flag.Int("port", 0, "proxy port (if not using tg:// positional)")
@@ -61,7 +63,8 @@ func run() int {
ctx, cancel := context.WithTimeout(context.Background(), *timeout)
defer cancel()
err = checker.Check(ctx, host, port, parsed, int16(*dcID))
opts := &checker.Options{Probe: checker.ParseProbe(*probe)}
err = checker.Check(ctx, host, port, parsed, int16(*dcID), opts)
if err != nil {
if errors.Is(err, checker.ErrProxyClosed) {
fmt.Fprintf(os.Stderr, "FAIL: %v\n", err)
@@ -71,6 +74,11 @@ func run() int {
fmt.Fprintf(os.Stderr, "FAIL: timeout\n")
return 4
}
var ne net.Error
if errors.As(err, &ne) && ne.Timeout() {
fmt.Fprintf(os.Stderr, "FAIL: timeout\n")
return 4
}
fmt.Fprintf(os.Stderr, "FAIL: %v\n", err)
return 1
}
+11 -8
View File
@@ -31,11 +31,12 @@ func main() {
}
type config struct {
listFile string
checkInterval time.Duration
httpAddr string
checkTimeout time.Duration
dcID int16
listFile string
checkInterval time.Duration
httpAddr string
checkTimeout time.Duration
dcID int16
probe checker.ProbeMode
allowedPrefixes []netip.Prefix
}
@@ -79,12 +80,14 @@ func loadConfig() (*config, error) {
if err != nil {
return nil, err
}
probe := checker.ParseProbe(os.Getenv("MTPROXY_PROBE"))
return &config{
listFile: listFile,
checkInterval: interval,
httpAddr: httpAddr,
checkTimeout: checkTimeout,
dcID: int16(dcParsed),
probe: probe,
allowedPrefixes: prefixes,
}, nil
}
@@ -146,7 +149,7 @@ func readProxyLines(path string) ([]string, error) {
return lines, nil
}
func checkOneLine(ctx context.Context, line string, dcID int16) proxyEntry {
func checkOneLine(ctx context.Context, line string, dcID int16, probe checker.ProbeMode) proxyEntry {
now := time.Now().UTC().Format(time.RFC3339)
ent := proxyEntry{RawLine: line, CheckedAt: now}
t, err := parseurl.ParseTGProxy(line)
@@ -164,7 +167,7 @@ func checkOneLine(ctx context.Context, line string, dcID int16) proxyEntry {
ent.Error = ent.ParseError
return ent
}
err = checker.Check(ctx, t.Host, t.Port, parsed, dcID)
err = checker.Check(ctx, t.Host, t.Port, parsed, dcID, &checker.Options{Probe: probe})
code, msg := checkresult.Classify(err)
ent.ExitCode = code
ent.OK = err == nil
@@ -191,7 +194,7 @@ func runCycle(cfg *config, st *store) {
entries := make([]proxyEntry, 0, len(lines))
for _, line := range lines {
ctx, cancel := context.WithTimeout(context.Background(), cfg.checkTimeout)
ent := checkOneLine(ctx, line, cfg.dcID)
ent := checkOneLine(ctx, line, cfg.dcID, cfg.probe)
cancel()
entries = append(entries, ent)
}