40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package checker
|
|
|
|
import "strings"
|
|
|
|
// ProbeMode selects how strictly we validate after MTProxy init.
|
|
type ProbeMode int
|
|
|
|
const (
|
|
// ProbeFast: handshake + init, then short wait like Telethon TcpMTProxy (#1134): OK if proxy does not close immediately.
|
|
ProbeFast ProbeMode = iota
|
|
// ProbeDeep: MTProto req_pq then any valid unencrypted MTProto reply from DC (tunnel carries DC traffic; not only resPQ).
|
|
ProbeDeep
|
|
// ProbeDeepStrict: req_pq and response must be resPQ#05162463 (legacy strict check).
|
|
ProbeDeepStrict
|
|
)
|
|
|
|
// Options configures Check. Nil or zero value uses ProbeFast.
|
|
type Options struct {
|
|
Probe ProbeMode
|
|
}
|
|
|
|
// ParseProbe maps env/flag strings: "", "fast" -> ProbeFast; "deep" -> ProbeDeep; "deep-strict" -> ProbeDeepStrict.
|
|
func ParseProbe(s string) ProbeMode {
|
|
switch strings.ToLower(strings.TrimSpace(s)) {
|
|
case "deep-strict", "strict-deep", "respq-strict":
|
|
return ProbeDeepStrict
|
|
case "deep", "respq", "dc":
|
|
return ProbeDeep
|
|
default:
|
|
return ProbeFast
|
|
}
|
|
}
|
|
|
|
func effectiveOpts(opts *Options) *Options {
|
|
if opts == nil {
|
|
return &Options{Probe: ProbeFast}
|
|
}
|
|
return opts
|
|
}
|