feat: optimize VK TURN credential retrieval and reuse session identity
Добавлено кэширование success_token для капчи. Установлен размер пула 1 для использования одной учетной записи во всех потоках. Дополнительно устранил warnings от golangcli-lint: Удален rand.Seed Реализована проверка ошибки в endSession Реализована обработка Body.Close()
This commit is contained in:
1 parent
41e7cb1632
commit
4a0b038bdc
3 files changed
+32
-7
No files matched your search
+30
-5
@@ -238,7 +238,11 @@ func fetchPowInput(ctx context.Context, redirectUri string, dialer *dnsdialer.Di
|
||||
if err != nil {
|
||||
return "", 0, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer func() {
|
||||
if closeErr := resp.Body.Close(); closeErr != nil {
|
||||
log.Printf("Failed to close response body: %v", closeErr)
|
||||
}
|
||||
}()
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
@@ -300,7 +304,11 @@ func callCaptchaNotRobot(ctx context.Context, sessionToken, hash string, dialer
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer httpResp.Body.Close()
|
||||
defer func() {
|
||||
if closeErr := httpResp.Body.Close(); closeErr != nil {
|
||||
log.Printf("Failed to close response body: %v", closeErr)
|
||||
}
|
||||
}()
|
||||
|
||||
body, err := io.ReadAll(httpResp.Body)
|
||||
if err != nil {
|
||||
@@ -365,13 +373,20 @@ func callCaptchaNotRobot(ctx context.Context, sessionToken, hash string, dialer
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
|
||||
// Step 4: endSession
|
||||
vkReq("captchaNotRobot.endSession", baseParams)
|
||||
if _, err := vkReq("captchaNotRobot.endSession", baseParams); err != nil {
|
||||
log.Printf("endSession failed: %v", err)
|
||||
}
|
||||
|
||||
return successToken, nil
|
||||
}
|
||||
|
||||
// endregion automatic captcha solver
|
||||
|
||||
var (
|
||||
cachedCaptchaTokenMu sync.Mutex
|
||||
cachedCaptchaToken string
|
||||
)
|
||||
|
||||
func getVkCreds(link string, dialer *dnsdialer.Dialer) (string, string, string, error) {
|
||||
profile := getRandomProfile()
|
||||
name := generateName()
|
||||
@@ -446,7 +461,14 @@ func getVkCreds(link string, dialer *dnsdialer.Dialer) (string, string, string,
|
||||
return "", "", "", fmt.Errorf("missing access_token in response: %v", resp)
|
||||
}
|
||||
|
||||
cachedCaptchaTokenMu.Lock()
|
||||
curSuccessToken := cachedCaptchaToken
|
||||
cachedCaptchaTokenMu.Unlock()
|
||||
|
||||
data = fmt.Sprintf("vk_join_link=https://vk.com/call/join/%s&name=%s&access_token=%s", link, escapedName, token1)
|
||||
if curSuccessToken != "" {
|
||||
data += fmt.Sprintf("&success_token=%s", neturl.QueryEscape(curSuccessToken))
|
||||
}
|
||||
url = "https://api.vk.ru/method/calls.getAnonymousToken?v=5.274&client_id=6287487"
|
||||
|
||||
var token2 string
|
||||
@@ -472,6 +494,10 @@ func getVkCreds(link string, dialer *dnsdialer.Dialer) (string, string, string,
|
||||
return "", "", "", fmt.Errorf("auto captcha solve error: %w", solveErr)
|
||||
}
|
||||
|
||||
cachedCaptchaTokenMu.Lock()
|
||||
cachedCaptchaToken = successToken
|
||||
cachedCaptchaTokenMu.Unlock()
|
||||
|
||||
if captchaErr.CaptchaAttempt == "0" || captchaErr.CaptchaAttempt == "" {
|
||||
captchaErr.CaptchaAttempt = "1"
|
||||
}
|
||||
@@ -1263,7 +1289,6 @@ func poolCreds(f getCredsFunc, poolSize int) getCredsFunc {
|
||||
}
|
||||
|
||||
func main() { //nolint:cyclop
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
signalChan := make(chan os.Signal, 1)
|
||||
@@ -1335,7 +1360,7 @@ func main() { //nolint:cyclop
|
||||
port: *port,
|
||||
link: link,
|
||||
udp: *udp,
|
||||
getCreds: poolCreds(getCreds, *n),
|
||||
getCreds: poolCreds(getCreds, 1),
|
||||
}
|
||||
|
||||
if *tcpMode {
|
||||
|
||||
@@ -9,6 +9,7 @@ require (
|
||||
github.com/gorilla/websocket v1.5.3
|
||||
github.com/pion/dtls/v3 v3.0.11
|
||||
github.com/pion/logging v0.2.4
|
||||
github.com/pion/transport/v4 v4.0.1
|
||||
github.com/pion/turn/v5 v5.0.2
|
||||
github.com/xtaci/kcp-go/v5 v5.6.18
|
||||
github.com/xtaci/smux v1.5.34
|
||||
@@ -22,7 +23,6 @@ require (
|
||||
github.com/miekg/dns v1.1.69 // indirect
|
||||
github.com/pion/randutil v0.1.0 // indirect
|
||||
github.com/pion/stun/v3 v3.1.1 // indirect
|
||||
github.com/pion/transport/v4 v4.0.1 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/templexxx/cpu v0.1.1 // indirect
|
||||
github.com/templexxx/xorsimd v0.4.3 // indirect
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
# Получаем default gateway (IPv4)
|
||||
# Получаем default gateway (IPv4)
|
||||
$gateway = Get-NetRoute `
|
||||
-DestinationPrefix "0.0.0.0/0" `
|
||||
| Sort-Object RouteMetric `
|
||||
|
||||
Reference in new issue
Block a user