Files

34 lines
1.2 KiB
Go

package main
import (
"context"
"errors"
"strings"
"time"
"mtproxy_checker/internal/checker"
"mtproxy_checker/internal/tdlibexec"
)
func runTDLibBlock(proxyLine, helper string, timeout time.Duration, probe checker.ProbeMode, ent proxyEntry) tdlibProbe {
if probe != checker.ProbeFast {
return tdlibProbe{SkippedReason: "tdlib runs only with probe fast (or empty MTPROXY_PROBE)", Ran: false}
}
if ent.ParseError != "" {
return tdlibProbe{SkippedReason: "skipped: standard parse error", Ran: false}
}
if strings.TrimSpace(helper) == "" {
return tdlibProbe{SkippedReason: "MTPROXY_TDLIB_HELPER not set", Ran: false}
}
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
res, err := tdlibexec.Run(ctx, helper, proxyLine)
if err != nil {
if errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled) {
return tdlibProbe{Ran: true, OK: false, ExitCode: 4, Error: err.Error(), DurationMs: res.DurationMs}
}
return tdlibProbe{Ran: true, OK: false, ExitCode: 1, Error: err.Error(), DurationMs: res.DurationMs}
}
return tdlibProbe{Ran: true, OK: res.OK, ExitCode: res.ExitCode, Error: res.Error, DurationMs: res.DurationMs}
}